portmidi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg/
2
+ *.gemspec
data/README.markdown ADDED
@@ -0,0 +1,41 @@
1
+ Portmidi-Mapper
2
+ ===============
3
+
4
+ This is a small, incomplete wrapper around the portmidi library.
5
+
6
+ Requirements
7
+ ============
8
+
9
+ portmidi (who woulda thought) built as a dynamic library.
10
+ ffi gem.
11
+
12
+
13
+ Installing Portmidi on OS X Snow leopard
14
+ ========================================
15
+
16
+ This is a major pita, because currently portmidi doesn't officially build for 64 bit, which
17
+ makes it impossible to use with the default Snow Leopard Ruby.
18
+
19
+ You can try to enable 64 bit support, but I don't have a frekkin clue what this means. It works
20
+ for me and my application, but YMMV and I am not responsible for any damage this does
21
+ to you or your system.
22
+
23
+ To enable 64 bit compilation (you will see quite a few warnings while compiling), open
24
+ CMakeLists.txt in the trunk folder and find the following line (around line 39 in my version)
25
+
26
+ set(CMAKE_OSX_ARCHITECTURES i386 ppc CACHE STRING "do not build for 64-bit" FORCE)
27
+
28
+ and change it to: (yes, the comment is a bit silly)
29
+
30
+ set(CMAKE_OSX_ARCHITECTURES i386 ppc x86_64 CACHE STRING "do build for 64-bit" FORCE)
31
+
32
+ Now you can call
33
+
34
+ make -f pm_mac/Makefile.osx
35
+
36
+ if it builds, you can try to install the library. Currently the process seems to be a bit broken,
37
+ so you actually need to type:
38
+
39
+ sudo env PF=/usr make -f pm_mac/Makefile.osx install
40
+
41
+ yes, this sucks - I'm currently trying to find out with the portmidi authors what it would take to fix all this.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), "lib/portmidi/version")
2
+ begin
3
+ require 'jeweler'
4
+
5
+ Jeweler::Tasks.new do |gemspec|
6
+ gemspec.name = "portmidi"
7
+ gemspec.summary = "An ffi wrapper around the cross platform midi library portmidi"
8
+ gemspec.description = "An ffi wrapper around the cross platform midi library portmidi, part of the portmedia framework"
9
+ gemspec.email = "jan@krutisch.de"
10
+ gemspec.homepage = "http://github.com/halfbyte/portmidi"
11
+ gemspec.authors = ["Jan Krutisch"]
12
+ gemspec.add_dependency('ffi')
13
+ gemspec.version = Portmidi::VERSION
14
+ gemspec.requirements << "Needs portmidi compiled as a dynamic library"
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
19
+ end
data/lib/portmidi.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'portmidi/version'
2
+ require 'portmidi/pm_map'
3
+ require 'portmidi/device'
4
+ require 'portmidi/input'
5
+ require 'portmidi/output'
6
+ require 'portmidi/exceptions'
7
+
8
+ module Portmidi
9
+
10
+ def self.devices
11
+ devices = []
12
+ PM_Map.Pm_CountDevices.times do |i|
13
+ di = PM_Map::DeviceInfo.new(PM_Map.Pm_GetDeviceInfo(i))
14
+ devices << Device.new(i, di[:input], di[:output], di[:name])
15
+ end
16
+ devices
17
+ end
18
+
19
+ # this is not a very good name, but Portmidi::initialize woulda been a worse idea
20
+ def self.start
21
+ PM_Map.Pm_Initialize
22
+ end
23
+
24
+ end
@@ -0,0 +1,38 @@
1
+ module Portmidi
2
+ class Device
3
+ attr_reader :name, :device_id, :type
4
+ def initialize(device_id, input, output, name)
5
+ @device_id = device_id
6
+ @type = (input == 1 ? :input : (output == 1 ? :output : :none))
7
+ @type = :bidirectional if @type == :input && output == 1
8
+ @name = name
9
+ end
10
+
11
+ def open(buffer_size = 4, latency = 0)
12
+ case(@type)
13
+ when :input
14
+ Input.new(@device_id, buffer_size)
15
+ when :output
16
+ Output.new(@device_id, buffer_size, latency)
17
+ when :bidirectional
18
+ [Input.new(@device_id, buffer_size), Output.new(@device_id, buffer_size, latency)]
19
+ else
20
+ raise "this device has no inputs or outputs to open"
21
+ end
22
+ end
23
+
24
+ def to_s
25
+ to_str
26
+ end
27
+
28
+ def to_str
29
+ "#{@device_id}> #{@name} (#{@type})"
30
+ end
31
+
32
+ def inspect
33
+ "#<Portmidi::Device:#{@device_id} @name=\"#{@name}\", @type=:#{@type}>"
34
+ end
35
+
36
+
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ module Portmidi
2
+ class DeviceError < StandardError
3
+ def initialize(errnum)
4
+ @full_message
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module Portmidi
2
+ class Input
3
+ def initialize(device_id = 0, buffer_size = 4)
4
+ in_stream_ptr = FFI::MemoryPointer.new(:pointer)
5
+ if (errnum = PM_Map.Pm_OpenInput(in_stream_ptr, device_id, nil, buffer_size, nil, nil)) == 0
6
+ @in_stream = in_stream_ptr.read_pointer
7
+ else
8
+ raise "Could not open Device #{device_id} as output device"
9
+ end
10
+ end
11
+
12
+ def poll
13
+
14
+ end
15
+
16
+ # TODO: poll methods etc.
17
+
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Portmidi
2
+ class Output
3
+ def initialize(device_id = 0, buffer_size = 4, latency = 0)
4
+ out_stream_ptr = FFI::MemoryPointer.new(:pointer)
5
+ if (errnum = PM_Map.Pm_OpenOutput(out_stream_ptr, device_id, nil, buffer_size, nil, nil, latency)) == 0
6
+ @out_stream = out_stream_ptr.read_pointer
7
+ else
8
+ raise Portmidi::DeviceError, errnum, "Could not open Device #{device_id} as output device"
9
+ end
10
+ end
11
+
12
+ def write_short(status, data1, data2)
13
+ PM_Map.Pm_WriteShort(@out_stream, 0, PM_Map.encode_message(status, data1, data2))
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ require 'ffi'
2
+ module Portmidi
3
+ module PM_Map
4
+ extend FFI::Library
5
+ #ffi_lib File.join(File.dirname(__FILE__), 'libportmidi_d')
6
+ ffi_lib 'libportmidi'
7
+ attach_function :Pm_CountDevices, [], :int
8
+ attach_function :Pm_Initialize, [], :void
9
+ attach_function :Pm_GetDeviceInfo,[:int], :pointer
10
+
11
+ attach_function :Pm_OpenInput, [:pointer, :int, :pointer, :int, :pointer, :pointer], :int
12
+ attach_function :Pm_OpenOutput, [:pointer, :int, :pointer, :int, :pointer, :pointer, :int32], :int
13
+ attach_function :Pm_Poll, [:pointer], :int
14
+ attach_function :Pm_Read, [:pointer, :pointer, :int], :int
15
+ attach_function :Pm_WriteShort, [:pointer, :int32, :int32], :int
16
+ attach_function :Pm_GetErrorText, [:int], :pointer
17
+
18
+ #attach_function :Pt_Start, [:int, :pointer, :pointer], :int
19
+
20
+ class DeviceInfo < FFI::Struct
21
+ layout :struct_version, :int,
22
+ :midi_api, :string,
23
+ :name, :string,
24
+ :input, :int,
25
+ :output, :int,
26
+ :opened, :int
27
+ end
28
+
29
+ class Event < FFI::Struct
30
+ layout :message, :int32,
31
+ :timestamp, :int32
32
+ end
33
+
34
+ def self.encode_message(status, data1, data2)
35
+ ((((data2) << 16) & 0xFF0000) | (((data1) << 8) & 0xFF00) | ((status) & 0xFF))
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Portmidi
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: portmidi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jan Krutisch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-07 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ffi
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: An ffi wrapper around the cross platform midi library portmidi, part of the portmedia framework
26
+ email: jan@krutisch.de
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.markdown
33
+ files:
34
+ - .gitignore
35
+ - README.markdown
36
+ - Rakefile
37
+ - lib/portmidi.rb
38
+ - lib/portmidi/device.rb
39
+ - lib/portmidi/exceptions.rb
40
+ - lib/portmidi/input.rb
41
+ - lib/portmidi/output.rb
42
+ - lib/portmidi/pm_map.rb
43
+ - lib/portmidi/version.rb
44
+ has_rdoc: true
45
+ homepage: http://github.com/halfbyte/portmidi
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements:
66
+ - Needs portmidi compiled as a dynamic library
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: An ffi wrapper around the cross platform midi library portmidi
72
+ test_files: []
73
+