unimidi 0.1.5-java → 0.1.6-java

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -37,6 +37,10 @@ A couple of notes about JRuby only:
37
37
 
38
38
  * please see {test/config.rb}[http://github.com/arirusso/unimidi/blob/master/test/config.rb] before running tests
39
39
 
40
+ For testing with JRuby, use
41
+
42
+ jruby --1.9 -S rake test
43
+
40
44
  == Documentation
41
45
 
42
46
  * {rdoc}[http://rdoc.info/gems/unimidi]
data/lib/unimidi.rb CHANGED
@@ -6,12 +6,15 @@
6
6
 
7
7
  module UniMIDI
8
8
 
9
- VERSION = "0.1.5"
9
+ VERSION = "0.1.6"
10
10
 
11
11
  end
12
12
 
13
+ require 'forwardable'
14
+
13
15
  require 'unimidi/congruous_api_adapter'
14
16
  require 'unimidi/platform'
17
+ require 'unimidi/type_conversion'
15
18
 
16
19
  module UniMIDI
17
20
  extend(Platform.instance.interface)
@@ -7,23 +7,18 @@ module UniMIDI
7
7
 
8
8
  module AlsaRawMIDIAdapter
9
9
 
10
- class Input
11
- include CongruousApiAdapter::Device
12
- include CongruousApiAdapter::Input
13
- DeferToClass = AlsaRawMIDI::Input
10
+ class Input < CongruousApiInput
11
+ defer_to AlsaRawMIDI::Input
14
12
  end
15
13
 
16
- class Output
17
- include CongruousApiAdapter::Device
18
- include CongruousApiAdapter::Output
19
- DeferToClass = AlsaRawMIDI::Output
14
+ class Output < CongruousApiOutput
15
+ defer_to AlsaRawMIDI::Output
20
16
  end
21
17
 
22
- class Device
23
- extend CongruousApiAdapter::Device::ClassMethods
24
- DeferToClass = AlsaRawMIDI::Device
25
- InputClass = Input
26
- OutputClass = Output
18
+ class Device < CongruousApiDevice
19
+ defer_to AlsaRawMIDI::Device
20
+ input_class Input
21
+ output_class Output
27
22
  end
28
23
 
29
24
  end
@@ -7,23 +7,18 @@ module UniMIDI
7
7
 
8
8
  module CoreMIDIAdapter
9
9
 
10
- class Input
11
- include CongruousApiAdapter::Device
12
- include CongruousApiAdapter::Input
13
- DeferToClass = CoreMIDI::Input
10
+ class Input < CongruousApiInput
11
+ defer_to CoreMIDI::Input
14
12
  end
15
13
 
16
- class Output
17
- include CongruousApiAdapter::Device
18
- include CongruousApiAdapter::Output
19
- DeferToClass = CoreMIDI::Output
14
+ class Output < CongruousApiOutput
15
+ defer_to CoreMIDI::Output
20
16
  end
21
17
 
22
- class Device
23
- extend CongruousApiAdapter::Device::ClassMethods
24
- DeferToClass = CoreMIDI::Device
25
- InputClass = Input
26
- OutputClass = Output
18
+ class Device < CongruousApiDevice
19
+ defer_to CoreMIDI::Entity
20
+ input_class Input
21
+ output_class Output
27
22
  end
28
23
 
29
24
  end
@@ -7,23 +7,18 @@ module UniMIDI
7
7
 
8
8
  module MIDIJRubyAdapter
9
9
 
10
- class Input
11
- include CongruousApiAdapter::Device
12
- include CongruousApiAdapter::Input
13
- DeferToClass = MIDIJRuby::Input
10
+ class Input < CongruousApiInput
11
+ defer_to MIDIJRuby::Input
14
12
  end
15
13
 
16
- class Output
17
- include CongruousApiAdapter::Device
18
- include CongruousApiAdapter::Output
19
- DeferToClass = MIDIJRuby::Output
14
+ class Output < CongruousApiOutput
15
+ defer_to MIDIJRuby::Output
20
16
  end
21
17
 
22
- class Device
23
- extend CongruousApiAdapter::Device::ClassMethods
24
- DeferToClass = MIDIJRuby::Device
25
- InputClass = Input
26
- OutputClass = Output
18
+ class Device < CongruousApiDevice
19
+ defer_to MIDIJRuby::Device
20
+ input_class Input
21
+ output_class Output
27
22
  end
28
23
 
29
24
  end
@@ -7,23 +7,18 @@ module UniMIDI
7
7
 
8
8
  module MIDIWinMMAdapter
9
9
 
10
- class Input
11
- include CongruousApiAdapter::Device
12
- include CongruousApiAdapter::Input
13
- DeferToClass = MIDIWinMM::Input
10
+ class Input < CongruousApiInput
11
+ defer_to MIDIWinMM::Input
14
12
  end
15
13
 
16
- class Output
17
- include CongruousApiAdapter::Device
18
- include CongruousApiAdapter::Output
19
- DeferToClass = MIDIWinMM::Output
14
+ class Output < CongruousApiOutput
15
+ defer_to MIDIWinMM::Output
20
16
  end
21
17
 
22
- class Device
23
- extend CongruousApiAdapter::Device::ClassMethods
24
- DeferToClass = MIDIWinMM::Device
25
- InputClass = Input
26
- OutputClass = Output
18
+ class Device < CongruousApiDevice
19
+ defer_to MIDIWinMM::Device
20
+ input_class Input
21
+ output_class Output
27
22
  end
28
23
 
29
24
  end
@@ -12,7 +12,7 @@ module UniMIDI
12
12
  @id = @device.id
13
13
  @name = @device.name
14
14
  end
15
-
15
+
16
16
  # enable the device for use, can be passed a block to which the device will be passed back
17
17
  def open(*a, &block)
18
18
  @device.open(*a)
@@ -23,165 +23,187 @@ module UniMIDI
23
23
  close
24
24
  end
25
25
  else
26
- self
26
+ self
27
27
  end
28
28
  end
29
-
29
+
30
30
  # close the device
31
31
  def close(*a)
32
32
  @device.close(*a)
33
33
  end
34
34
 
35
35
  def self.included(base)
36
- #base.send(:attr_reader, :device)
37
36
  base.send(:attr_reader, :name)
38
37
  base.send(:attr_reader, :id)
39
38
  end
40
39
 
41
40
  module ClassMethods
42
41
 
43
- def first
44
- new(device_class.first)
42
+ # returns the first device for this class
43
+ def first(*a)
44
+ new(@deference[self].first(*a))
45
45
  end
46
-
47
- def last
48
- new(device_class.last)
46
+
47
+ # returns the last device for this class
48
+ def last(*a)
49
+ new(@deference[self].last(*a))
49
50
  end
50
-
51
+
52
+ # returns all devices in an array
51
53
  def all
52
54
  all_by_type.values.flatten
53
55
  end
54
-
56
+
57
+ # returns all devices as a hash as such
58
+ # { :input => [input devices], :output => [output devices] }
55
59
  def all_by_type
56
- {
57
- :input => device_class.all_by_type[:input].map { |d| get_input_class.new(d) },
58
- :output => device_class.all_by_type[:output].map { |d| get_output_class.new(d) }
60
+ {
61
+ :input => @deference[self].all_by_type[:input].map { |d| @input_class.new(d) },
62
+ :output => @deference[self].all_by_type[:output].map { |d| @output_class.new(d) }
59
63
  }
60
64
  end
61
65
 
62
- def get_input_class
63
- self::InputClass
66
+ def defer_to(klass)
67
+ @deference ||= {}
68
+ @deference[self] = klass
64
69
  end
65
70
 
66
- def get_output_class
67
- self::OutputClass
71
+ def input_class(klass)
72
+ @input_class = klass
68
73
  end
69
74
 
70
- def device_class
71
- self::DeferToClass
75
+ def output_class(klass)
76
+ @output_class = klass
72
77
  end
73
78
 
74
79
  end
75
80
 
76
81
  end
77
82
 
78
- module Input
79
-
80
- def self.included(base)
81
- base.extend(Device::ClassMethods)
82
- base.extend(ClassMethods)
83
- end
83
+ end
84
84
 
85
- #
86
- # returns an array of MIDI event hashes as such:
87
- # [
88
- # { :data => [144, 60, 100], :timestamp => 1024 },
89
- # { :data => [128, 60, 100], :timestamp => 1100 },
90
- # { :data => [144, 40, 120], :timestamp => 1200 }
91
- # ]
92
- #
93
- # the data is an array of Numeric bytes
94
- # the timestamp is the number of millis since this input was enabled
95
- #
96
- def gets(*a)
97
- @device.gets(*a)
98
- end
99
-
100
- #
101
- # same as gets but returns message data as string of hex digits as such:
102
- # [
103
- # { :data => "904060", :timestamp => 904 },
104
- # { :data => "804060", :timestamp => 1150 },
105
- # { :data => "90447F", :timestamp => 1300 }
106
- # ]
107
- #
108
- def gets_bytestr(*a)
109
- @device.gets_bytestr(*a)
110
- end
111
- alias_method :gets_s, :gets_bytestr
112
- alias_method :gets_hex, :gets_bytestr
113
-
114
- #
115
- # returns an array of data bytes such as
116
- # [144, 60, 100, 128, 60, 100, 144, 40, 120]
117
- #
118
- def gets_data(*a)
119
- arr = gets
120
- arr.map { |msg| msg[:data] }.inject { |a,b| a + b }
121
- end
85
+ class CongruousApiInput
86
+
87
+ include CongruousApiAdapter::Device
88
+ extend CongruousApiAdapter::Device::ClassMethods
89
+ extend Forwardable
90
+
91
+ def_delegators :@device, :buffer
92
+
93
+ #
94
+ # returns an array of MIDI event hashes as such:
95
+ # [
96
+ # { :data => [144, 60, 100], :timestamp => 1024 },
97
+ # { :data => [128, 60, 100], :timestamp => 1100 },
98
+ # { :data => [144, 40, 120], :timestamp => 1200 }
99
+ # ]
100
+ #
101
+ # the data is an array of Numeric bytes
102
+ # the timestamp is the number of millis since this input was enabled
103
+ #
104
+ def gets(*a)
105
+ @device.gets(*a)
106
+ end
122
107
 
123
- #
124
- # returns a string of data such as
125
- # "90406080406090447F"
126
- #
127
- def gets_data_bytestr(*a)
128
- arr = gets_bytestr
129
- arr.map { |msg| msg[:data] }.join
130
- end
131
- alias_method :gets_data_s, :gets_data_bytestr
132
- alias_method :gets_data_hex, :gets_data_bytestr
133
-
134
- module ClassMethods
135
-
136
- # returns all inputs
137
- def all
138
- device_class.all.map { |d| new(d) }
139
- end
140
-
141
- end
108
+ #
109
+ # same as gets but returns message data as string of hex digits as such:
110
+ # [
111
+ # { :data => "904060", :timestamp => 904 },
112
+ # { :data => "804060", :timestamp => 1150 },
113
+ # { :data => "90447F", :timestamp => 1300 }
114
+ # ]
115
+ #
116
+ def gets_s(*a)
117
+ @device.gets_s(*a)
118
+ end
119
+ alias_method :gets_bytestr, :gets_s
120
+ alias_method :gets_hex, :gets_s
121
+
122
+ #
123
+ # returns an array of data bytes such as
124
+ # [144, 60, 100, 128, 60, 100, 144, 40, 120]
125
+ #
126
+ def gets_data(*a)
127
+ arr = gets
128
+ arr.map { |msg| msg[:data] }.inject { |a,b| a + b }
129
+ end
130
+
131
+ #
132
+ # returns a string of data such as
133
+ # "90406080406090447F"
134
+ #
135
+ def gets_data_s(*a)
136
+ arr = gets_bytestr
137
+ arr.map { |msg| msg[:data] }.join
138
+ end
139
+ alias_method :gets_data_bytestr, :gets_data_s
140
+ alias_method :gets_data_hex, :gets_data_s
141
+
142
+ # clears the buffer
143
+ def clear_buffer
144
+ @device.buffer.clear
145
+ end
146
+
147
+ # gets any messages in the buffer in the same format as CongruousApiInput#gets
148
+ def gets_buffer(*a)
149
+ @device.buffer
150
+ end
151
+
152
+ # gets any messages in the buffer in the same format as CongruousApiInput#gets_s
153
+ def gets_buffer_s(*a)
154
+ @device.buffer.map { |msg| msg[:data] = TypeConversion.numeric_byte_array_to_hex_string(msg[:data]); msg }
155
+ end
156
+
157
+ # gets any messages in the buffer in the same format as CongruousApiInput#gets_data
158
+ def gets_buffer_data(*a)
159
+ @device.buffer.map { |msg| msg[:data] }
160
+ end
142
161
 
162
+ # returns all inputs
163
+ def self.all
164
+ @deference[self].all.map { |d| new(d) }
143
165
  end
144
166
 
145
- module Output
146
-
147
- def self.included(base)
148
- base.extend(Device::ClassMethods)
149
- base.extend(ClassMethods)
150
- end
151
-
152
- # sends a message to the output. the message can be:
153
- #
154
- # bytes eg output.puts(0x90, 0x40, 0x40)
155
- # an array of bytes eg output.puts([0x90, 0x40, 0x40])
156
- # or a string eg output.puts("904040")
157
- #
158
- def puts(*a)
159
- @device.puts(*a)
160
- end
161
-
162
- # sends a message to the output in a form of a string eg "904040". this method does not do
163
- # type checking and therefore is more performant than puts
164
- def puts_bytestr(*a)
165
- @device.puts_bytestr(*a)
166
- end
167
+ end
167
168
 
168
- # sends a message to the output in a form of bytes eg output.puts_bytes(0x90, 0x40, 0x40).
169
- # this method does not do type checking and therefore is more performant than puts
170
- def puts_bytes(*a)
171
- @device.puts_bytes(*a)
172
- end
173
-
174
- module ClassMethods
175
-
176
- # returns all outputs
177
- def all
178
- device_class.all.map { |d| new(d) }
179
- end
180
-
181
- end
169
+ class CongruousApiOutput
170
+
171
+ include CongruousApiAdapter::Device
172
+ extend CongruousApiAdapter::Device::ClassMethods
173
+
174
+ # sends a message to the output. the message can be:
175
+ #
176
+ # bytes eg output.puts(0x90, 0x40, 0x40)
177
+ # an array of bytes eg output.puts([0x90, 0x40, 0x40])
178
+ # or a string eg output.puts("904040")
179
+ #
180
+ def puts(*a)
181
+ @device.puts(*a)
182
+ end
183
+
184
+ # sends a message to the output in a form of a string eg "904040". this method does not do
185
+ # type checking and therefore is more performant than puts
186
+ def puts_s(*a)
187
+ @device.puts_s(*a)
188
+ end
189
+ alias_method :puts_bytestr, :puts_s
190
+ alias_method :puts_hex, :puts_s
182
191
 
192
+ # sends a message to the output in a form of bytes eg output.puts_bytes(0x90, 0x40, 0x40).
193
+ # this method does not do type checking and therefore is more performant than puts
194
+ def puts_bytes(*a)
195
+ @device.puts_bytes(*a)
183
196
  end
184
197
 
198
+ # returns all outputs
199
+ def self.all
200
+ @deference[self].all.map { |d| new(d) }
201
+ end
202
+
203
+ end
204
+
205
+ class CongruousApiDevice
206
+ extend CongruousApiAdapter::Device::ClassMethods
185
207
  end
186
208
 
187
209
  end
@@ -4,30 +4,30 @@
4
4
  require 'singleton'
5
5
 
6
6
  module UniMIDI
7
-
8
- class Platform
9
-
10
- include Singleton
7
+
8
+ class Platform
9
+
10
+ include Singleton
11
11
 
12
- attr_reader :interface
13
-
14
- def initialize
15
- lib = case RUBY_PLATFORM
16
- when /darwin/ then "ffi-coremidi"
17
- when /java/ then "midi-jruby"
18
- when /linux/ then "alsa-rawmidi"
19
- when /mingw/ then "midi-winmm"
20
- when /win/ then "midi-winmm"
21
- end
22
- require("unimidi/adapter/#{lib}")
23
- @interface = case RUBY_PLATFORM
24
- when /darwin/ then CoreMIDIAdapter
25
- when /java/ then MIDIJRubyAdapter
26
- when /linux/ then AlsaRawMIDIAdapter
27
- when /mingw/ then MIDIWinMMAdapter
28
- when /win/ then MIDIWinMMAdapter
29
- end
12
+ attr_reader :interface
13
+
14
+ def initialize
15
+ lib = case RUBY_PLATFORM
16
+ when /darwin/ then "ffi-coremidi"
17
+ when /java/ then "midi-jruby"
18
+ when /linux/ then "alsa-rawmidi"
19
+ when /mingw/ then "midi-winmm"
20
+ #when /win/ then "midi-winmm"
21
+ end
22
+ require("unimidi/adapter/#{lib}")
23
+ @interface = case RUBY_PLATFORM
24
+ when /darwin/ then CoreMIDIAdapter
25
+ when /java/ then MIDIJRubyAdapter
26
+ when /linux/ then AlsaRawMIDIAdapter
27
+ when /mingw/ then MIDIWinMMAdapter
28
+ #when /win/ then MIDIWinMMAdapter
30
29
  end
30
+ end
31
31
 
32
32
  end
33
33
 
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+
4
+ module UniMIDI
5
+
6
+ module TypeConversion
7
+
8
+ # byte array to string of hex bytes
9
+ def numeric_byte_array_to_hex_string(bytes)
10
+ bytes.map { |b| b.hex }.join
11
+ end
12
+
13
+ end
14
+
15
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unimidi
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 5
9
- version: 0.1.5
4
+ prerelease:
5
+ version: 0.1.6
10
6
  platform: java
11
7
  authors:
12
8
  - Ari Russo
@@ -14,18 +10,17 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-05-07 00:00:00 -04:00
13
+ date: 2011-05-10 00:00:00 -04:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
17
  name: midi-jruby
22
18
  prerelease: false
23
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
24
21
  requirements:
25
22
  - - ">="
26
23
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
24
  version: "0"
30
25
  type: :runtime
31
26
  version_requirements: *id001
@@ -42,10 +37,11 @@ files:
42
37
  - lib/unimidi.rb
43
38
  - lib/unimidi/congruous_api_adapter.rb
44
39
  - lib/unimidi/platform.rb
45
- - lib/unimidi/adapter/ffi-coremidi.rb
46
- - lib/unimidi/adapter/midi-winmm.rb
40
+ - lib/unimidi/type_conversion.rb
47
41
  - lib/unimidi/adapter/alsa-rawmidi.rb
42
+ - lib/unimidi/adapter/ffi-coremidi.rb
48
43
  - lib/unimidi/adapter/midi-jruby.rb
44
+ - lib/unimidi/adapter/midi-winmm.rb
49
45
  - LICENSE
50
46
  - README.rdoc
51
47
  has_rdoc: true
@@ -58,25 +54,21 @@ rdoc_options: []
58
54
  require_paths:
59
55
  - lib
60
56
  required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
61
58
  requirements:
62
59
  - - ">="
63
60
  - !ruby/object:Gem::Version
64
- segments:
65
- - 0
66
61
  version: "0"
67
62
  required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
68
64
  requirements:
69
65
  - - ">="
70
66
  - !ruby/object:Gem::Version
71
- segments:
72
- - 1
73
- - 3
74
- - 6
75
67
  version: 1.3.6
76
68
  requirements: []
77
69
 
78
70
  rubyforge_project: unimidi
79
- rubygems_version: 1.3.6
71
+ rubygems_version: 1.5.1
80
72
  signing_key:
81
73
  specification_version: 3
82
74
  summary: Realtime MIDI input and output for Ruby.