unimidi 0.4.6 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,30 +1,30 @@
1
- module UniMIDI
1
+ # frozen_string_literal: true
2
2
 
3
+ module UniMIDI
3
4
  # Populate UniMIDI devices using the underlying device objects from the platform-specific gems
4
- module Loader
5
-
6
- extend self
7
-
8
- # Use the given platform-specific adapter to load devices
9
- # @param [UniMIDI::Adapter::Loader] loader
10
- def use(loader)
11
- @loader = loader
12
- end
5
+ class Loader
6
+ class << self
7
+ # Use the given platform-specific adapter to load devices
8
+ # @param [UniMIDI::Adapter::Loader] loader
9
+ def use(loader)
10
+ @loader = loader
11
+ end
13
12
 
14
- # @param [Hash] options
15
- # @option options [Symbol] :direction Return only a particular direction of device eg :input, :output
16
- # @return [Array<Input>, Array<Output>]
17
- def devices(options = {})
18
- if @devices.nil?
19
- inputs = @loader.inputs.map { |device| ::UniMIDI::Input.new(device) }
20
- outputs = @loader.outputs.map { |device| ::UniMIDI::Output.new(device) }
21
- @devices = {
22
- :input => inputs,
23
- :output => outputs
24
- }
13
+ # Get all MIDI devices
14
+ # @param [Hash] options
15
+ # @option options [Symbol] :direction Return only a particular direction of device eg :input, :output
16
+ # @return [Array<Input>, Array<Output>]
17
+ def devices(options = {})
18
+ if @devices.nil?
19
+ inputs = @loader.inputs.map { |device| ::UniMIDI::Input.new(device) }
20
+ outputs = @loader.outputs.map { |device| ::UniMIDI::Output.new(device) }
21
+ @devices = {
22
+ input: inputs,
23
+ output: outputs
24
+ }
25
+ end
26
+ options[:direction].nil? ? @devices.values.flatten : @devices[options[:direction]]
25
27
  end
26
- options[:direction].nil? ? @devices.values.flatten : @devices[options[:direction]]
27
28
  end
28
-
29
29
  end
30
30
  end
@@ -1,18 +1,18 @@
1
- module UniMIDI
1
+ # frozen_string_literal: true
2
2
 
3
+ module UniMIDI
3
4
  # A MIDI output device
4
5
  class Output
5
-
6
6
  extend Device::ClassMethods
7
7
  include Device::InstanceMethods
8
8
 
9
9
  # All MIDI output devices -- used to populate the class
10
10
  # @return [Array<Output>]
11
11
  def self.all
12
- Loader.devices(:direction => :output)
12
+ Loader.devices(direction: :output)
13
13
  end
14
14
 
15
- # Sends a message to the output.
15
+ # Sends a message to the output.
16
16
  #
17
17
  # The message format can be:
18
18
  #
@@ -21,18 +21,18 @@ module UniMIDI
21
21
  # 3. A string of bytes eg "904040"
22
22
  # 4. An array of strings ["904040", "804040"]
23
23
  #
24
- # @param [*Array<Fixnum>, *Array<String>, *Fixnum, *String] messages
25
- # @return [Array<Fixnum>, Array<String>]
24
+ # @param [*Array<Integer>, *Array<String>, *Integer, *String] messages
25
+ # @return [Array<Integer>, Array<String>]
26
26
  def puts(*messages)
27
27
  message = messages.first
28
28
  case message
29
29
  when Array then messages.each { |array| puts(*array.flatten) }
30
- when Fixnum then puts_bytes(*messages)
30
+ when Integer then puts_bytes(*messages)
31
31
  when String then puts_s(*messages)
32
32
  else
33
33
  if message.respond_to?(:to_bytes)
34
34
  puts_bytes(*message.to_bytes.flatten)
35
- elsif message.respond_to?(:to_a)
35
+ elsif message.respond_to?(:to_a)
36
36
  puts_bytes(*message.to_a.flatten)
37
37
  end
38
38
  end
@@ -46,18 +46,16 @@ module UniMIDI
46
46
  @device.puts_s(*messages)
47
47
  messages.count < 2 ? messages[0] : messages
48
48
  end
49
- alias_method :puts_bytestr, :puts_s
50
- alias_method :puts_hex, :puts_s
49
+ alias puts_bytestr puts_s
50
+ alias puts_hex puts_s
51
51
 
52
52
  # Sends a message to the output in a form of bytes eg output.puts_bytes(0x90, 0x40, 0x40).
53
53
  # This method does not do type checking.
54
- # @param [*Array<Fixnum>] messages
55
- # @return [Array<Fixnum>, Array<Array<Fixnum>>]
54
+ # @param [*Array<Integer>] messages
55
+ # @return [Array<Integer>, Array<Array<Integer>>]
56
56
  def puts_bytes(*messages)
57
57
  @device.puts_bytes(*messages)
58
58
  messages.count < 2 ? messages[0] : messages
59
59
  end
60
-
61
60
  end
62
-
63
61
  end
@@ -1,28 +1,34 @@
1
- module UniMIDI
1
+ # frozen_string_literal: true
2
2
 
3
+ module UniMIDI
3
4
  # Deal with different dependencies between different user environments
4
5
  module Platform
5
-
6
6
  extend self
7
-
7
+
8
8
  # Loads the proper MIDI library and adapter for the user's environment
9
9
  def bootstrap
10
- lib = case RUBY_PLATFORM
11
- when /darwin/ then "ffi-coremidi"
12
- when /java/ then "midi-jruby"
13
- when /linux/ then "alsa-rawmidi"
14
- when /mingw/ then "midi-winmm"
15
- end
16
- require("unimidi/adapter/#{lib}")
17
- interface = case RUBY_PLATFORM
18
- when /darwin/ then Adapter::CoreMIDI
19
- when /java/ then Adapter::MIDIJRuby
20
- when /linux/ then Adapter::AlsaRawMIDI
21
- when /mingw/ then Adapter::MIDIWinMM
10
+ require("unimidi/adapter/#{platform_lib}")
11
+ Loader.use(platform_module::Loader)
12
+ end
13
+
14
+ private
15
+
16
+ def platform_lib
17
+ case RUBY_PLATFORM
18
+ when /darwin/ then 'ffi-coremidi'
19
+ when /java/ then 'midi-jruby'
20
+ when /linux/ then 'alsa-rawmidi'
21
+ when /mingw/ then 'midi-winmm'
22
22
  end
23
- Loader.use(interface::Loader)
24
23
  end
25
24
 
25
+ def platform_module
26
+ case RUBY_PLATFORM
27
+ when /darwin/ then Adapter::CoreMIDI
28
+ when /java/ then Adapter::MIDIJRuby
29
+ when /linux/ then Adapter::AlsaRawMIDI
30
+ when /mingw/ then Adapter::MIDIWinMM
31
+ end
32
+ end
26
33
  end
27
-
28
34
  end
@@ -1,17 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module UniMIDI
2
-
3
4
  # Utility for converting between different data formats
4
5
  module TypeConversion
6
+ module_function
5
7
 
6
- extend self
7
-
8
- # Convert an array of numeric bytes to string of hex bytes
9
- # @param [Array<Fixnum>] byte An array of numeric bytes eg [0x90, 0x40, 0x40]
8
+ # Convert an array of numeric bytes to string of hex bytes
9
+ # @param [Array<Integer>] byte An array of numeric bytes eg [0x90, 0x40, 0x40]
10
10
  # @return [String] A string of hex bytes eg "904040"
11
11
  def numeric_byte_array_to_hex_string(bytes)
12
12
  bytes.map { |b| b.to_s(16) }.join
13
13
  end
14
-
15
14
  end
16
-
17
15
  end
data/lib/unimidi.rb CHANGED
@@ -1,24 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
4
+ # UniMIDI
2
5
  # Realtime MIDI IO for Ruby
3
6
  #
4
- # (c)2010-2014 Ari Russo and licensed under the Apache 2.0 License
7
+ # (c)2010-2022 Ari Russo
8
+ # Licensed under the Apache 2.0 License
5
9
  #
6
10
 
7
11
  # modules
8
- require "unimidi/command"
9
- require "unimidi/device"
10
- require "unimidi/loader"
11
- require "unimidi/platform"
12
- require "unimidi/type_conversion"
12
+ require 'unimidi/command'
13
+ require 'unimidi/device'
14
+ require 'unimidi/platform'
15
+ require 'unimidi/type_conversion'
13
16
 
14
17
  # classes
15
- require "unimidi/input"
16
- require "unimidi/output"
18
+ require 'unimidi/input'
19
+ require 'unimidi/loader'
20
+ require 'unimidi/output'
17
21
 
18
22
  module UniMIDI
19
-
20
- VERSION = "0.4.6"
23
+ VERSION = '0.5.1'
21
24
 
22
25
  Platform.bootstrap
23
-
24
26
  end
metadata CHANGED
@@ -1,155 +1,135 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unimidi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-02 00:00:00.000000000 Z
11
+ date: 2022-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: minitest
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '5.5'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 5.5.0
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '5.5'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 5.5.0
33
- - !ruby/object:Gem::Dependency
34
- name: mocha
14
+ name: rake
35
15
  requirement: !ruby/object:Gem::Requirement
36
16
  requirements:
37
17
  - - "~>"
38
18
  - !ruby/object:Gem::Version
39
- version: '1.1'
19
+ version: '13.0'
40
20
  - - ">="
41
21
  - !ruby/object:Gem::Version
42
- version: 1.1.0
22
+ version: 13.0.6
43
23
  type: :development
44
24
  prerelease: false
45
25
  version_requirements: !ruby/object:Gem::Requirement
46
26
  requirements:
47
27
  - - "~>"
48
28
  - !ruby/object:Gem::Version
49
- version: '1.1'
29
+ version: '13.0'
50
30
  - - ">="
51
31
  - !ruby/object:Gem::Version
52
- version: 1.1.0
32
+ version: 13.0.6
53
33
  - !ruby/object:Gem::Dependency
54
- name: rake
34
+ name: rspec
55
35
  requirement: !ruby/object:Gem::Requirement
56
36
  requirements:
57
37
  - - "~>"
58
38
  - !ruby/object:Gem::Version
59
- version: '10.4'
39
+ version: '3.11'
60
40
  - - ">="
61
41
  - !ruby/object:Gem::Version
62
- version: 10.4.2
42
+ version: 3.11.0
63
43
  type: :development
64
44
  prerelease: false
65
45
  version_requirements: !ruby/object:Gem::Requirement
66
46
  requirements:
67
47
  - - "~>"
68
48
  - !ruby/object:Gem::Version
69
- version: '10.4'
49
+ version: '3.11'
70
50
  - - ">="
71
51
  - !ruby/object:Gem::Version
72
- version: 10.4.2
52
+ version: 3.11.0
73
53
  - !ruby/object:Gem::Dependency
74
- name: shoulda-context
54
+ name: rubocop
75
55
  requirement: !ruby/object:Gem::Requirement
76
56
  requirements:
77
57
  - - "~>"
78
58
  - !ruby/object:Gem::Version
79
- version: '1.2'
59
+ version: '1.25'
80
60
  - - ">="
81
61
  - !ruby/object:Gem::Version
82
- version: 1.2.1
62
+ version: 1.25.1
83
63
  type: :development
84
64
  prerelease: false
85
65
  version_requirements: !ruby/object:Gem::Requirement
86
66
  requirements:
87
67
  - - "~>"
88
68
  - !ruby/object:Gem::Version
89
- version: '1.2'
69
+ version: '1.25'
90
70
  - - ">="
91
71
  - !ruby/object:Gem::Version
92
- version: 1.2.1
72
+ version: 1.25.1
93
73
  - !ruby/object:Gem::Dependency
94
74
  name: alsa-rawmidi
95
75
  requirement: !ruby/object:Gem::Requirement
96
76
  requirements:
97
77
  - - "~>"
98
78
  - !ruby/object:Gem::Version
99
- version: '0.3'
79
+ version: '0.4'
100
80
  - - ">="
101
81
  - !ruby/object:Gem::Version
102
- version: 0.3.1
82
+ version: 0.4.0
103
83
  type: :runtime
104
84
  prerelease: false
105
85
  version_requirements: !ruby/object:Gem::Requirement
106
86
  requirements:
107
87
  - - "~>"
108
88
  - !ruby/object:Gem::Version
109
- version: '0.3'
89
+ version: '0.4'
110
90
  - - ">="
111
91
  - !ruby/object:Gem::Version
112
- version: 0.3.1
92
+ version: 0.4.0
113
93
  - !ruby/object:Gem::Dependency
114
94
  name: ffi-coremidi
115
95
  requirement: !ruby/object:Gem::Requirement
116
96
  requirements:
117
97
  - - "~>"
118
98
  - !ruby/object:Gem::Version
119
- version: '0.3'
99
+ version: '0.5'
120
100
  - - ">="
121
101
  - !ruby/object:Gem::Version
122
- version: 0.3.5
102
+ version: 0.5.1
123
103
  type: :runtime
124
104
  prerelease: false
125
105
  version_requirements: !ruby/object:Gem::Requirement
126
106
  requirements:
127
107
  - - "~>"
128
108
  - !ruby/object:Gem::Version
129
- version: '0.3'
109
+ version: '0.5'
130
110
  - - ">="
131
111
  - !ruby/object:Gem::Version
132
- version: 0.3.5
112
+ version: 0.5.1
133
113
  - !ruby/object:Gem::Dependency
134
114
  name: midi-jruby
135
115
  requirement: !ruby/object:Gem::Requirement
136
116
  requirements:
137
117
  - - "~>"
138
118
  - !ruby/object:Gem::Version
139
- version: '0.1'
119
+ version: '0.2'
140
120
  - - ">="
141
121
  - !ruby/object:Gem::Version
142
- version: 0.1.4
122
+ version: 0.2.0
143
123
  type: :runtime
144
124
  prerelease: false
145
125
  version_requirements: !ruby/object:Gem::Requirement
146
126
  requirements:
147
127
  - - "~>"
148
128
  - !ruby/object:Gem::Version
149
- version: '0.1'
129
+ version: '0.2'
150
130
  - - ">="
151
131
  - !ruby/object:Gem::Version
152
- version: 0.1.4
132
+ version: 0.2.0
153
133
  - !ruby/object:Gem::Dependency
154
134
  name: midi-winmm
155
135
  requirement: !ruby/object:Gem::Requirement
@@ -187,22 +167,17 @@ files:
187
167
  - lib/unimidi/command.rb
188
168
  - lib/unimidi/device.rb
189
169
  - lib/unimidi/input.rb
170
+ - lib/unimidi/input/buffer_access.rb
171
+ - lib/unimidi/input/stream_reader.rb
190
172
  - lib/unimidi/loader.rb
191
173
  - lib/unimidi/output.rb
192
174
  - lib/unimidi/platform.rb
193
175
  - lib/unimidi/type_conversion.rb
194
- - test/adapter_test.rb
195
- - test/class_methods_test.rb
196
- - test/functional_test.rb
197
- - test/helper.rb
198
- - test/input_test.rb
199
- - test/platform_test.rb
200
- - test/type_conversion_test.rb
201
176
  homepage: http://github.com/arirusso/unimidi
202
177
  licenses:
203
- - Apache 2.0
178
+ - Apache-2.0
204
179
  metadata: {}
205
- post_install_message:
180
+ post_install_message:
206
181
  rdoc_options: []
207
182
  require_paths:
208
183
  - lib
@@ -217,9 +192,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
192
  - !ruby/object:Gem::Version
218
193
  version: 1.3.6
219
194
  requirements: []
220
- rubyforge_project: unimidi
221
- rubygems_version: 2.2.2
222
- signing_key:
195
+ rubygems_version: 3.3.3
196
+ signing_key:
223
197
  specification_version: 4
224
198
  summary: Realtime MIDI IO for Ruby
225
199
  test_files: []
data/test/adapter_test.rb DELETED
@@ -1,66 +0,0 @@
1
- require "helper"
2
-
3
- class UniMIDI::AdapterTest < Minitest::Test
4
-
5
- context "Adapter" do
6
-
7
- context "Device#type" do
8
-
9
- should "be an input" do
10
- input = TestHelper.devices[:input]
11
- assert_equal(:input, input.type)
12
- end
13
-
14
- should "be an output" do
15
- output = TestHelper.devices[:output]
16
- assert_equal(:output, output.type)
17
- end
18
-
19
- end
20
-
21
- context "Device.count" do
22
-
23
- setup do
24
- @inputs = UniMIDI::Input.all
25
- end
26
-
27
- should "count all of the inputs" do
28
- assert_equal @inputs.count, UniMIDI::Input.count
29
- end
30
-
31
- end
32
-
33
- context "Device.find_by_name" do
34
-
35
- setup do
36
- index = rand(0..(UniMIDI::Output.count-1))
37
- @output = UniMIDI::Output.all[index]
38
- end
39
-
40
- should "select the correct input" do
41
- result = UniMIDI::Output.find_by_name(@output.name)
42
- assert_equal @output, result
43
- end
44
-
45
- end
46
-
47
- context "Device.first" do
48
-
49
- setup do
50
- @output = UniMIDI::Output.all.first
51
- end
52
-
53
- should "open the output" do
54
- @output.expects(:open)
55
- output = UniMIDI::Output.first
56
- @output.unstub(:open)
57
- end
58
-
59
- should "return the correct output" do
60
- output = UniMIDI::Output.first
61
- assert_equal @output, output
62
- end
63
- end
64
-
65
- end
66
- end
@@ -1,95 +0,0 @@
1
- require "helper"
2
-
3
- class UniMIDI::ClassMethodsTest < Minitest::Test
4
-
5
- context "ClassMethods" do
6
-
7
- context "#first" do
8
-
9
- context "no block given" do
10
- should "return first input" do
11
- i = UniMIDI::Input.first
12
- assert_equal(UniMIDI::Input.all.first, i)
13
- end
14
- end
15
-
16
- context "block given" do
17
- should "pass and return first input" do
18
- sleep(1)
19
- i = UniMIDI::Input.first do |i|
20
- assert_equal(true, i.enabled?)
21
- end
22
- assert_equal(UniMIDI::Input.all.first, i)
23
- end
24
-
25
- end
26
- end
27
-
28
- context "#last" do
29
-
30
- context "no block given" do
31
- should "return last input" do
32
- i = UniMIDI::Input.last
33
- assert_equal(UniMIDI::Input.all.last, i)
34
- end
35
- end
36
-
37
- context "block given" do
38
- should "pass and return last input" do
39
- sleep(1)
40
- i = UniMIDI::Input.last do |i|
41
- assert_equal(true, i.enabled?)
42
- end
43
- assert_equal(UniMIDI::Input.all.last, i)
44
- end
45
-
46
- end
47
- end
48
-
49
- context "#[]" do
50
-
51
- should "return correct input" do
52
- i = UniMIDI::Input[0]
53
- assert_equal(UniMIDI::Input.first, i)
54
- assert_equal(UniMIDI::Input.all.first, i)
55
- end
56
-
57
- end
58
-
59
- context "#use" do
60
-
61
- context "block given" do
62
- should "return and enable an input" do
63
- sleep(1)
64
- i = UniMIDI::Input.use(0) do |i|
65
- assert_equal(true, i.enabled?)
66
- end
67
- assert_equal(UniMIDI::Input.first, i)
68
- assert_equal(UniMIDI::Input.all.first, i)
69
- end
70
-
71
- end
72
-
73
- context "with symbol" do
74
-
75
- should "return an enabled input" do
76
- sleep(1)
77
- input = UniMIDI::Input.use(:first)
78
- assert_equal(true, input.enabled?)
79
- assert_equal(UniMIDI::Input.first, input)
80
- assert_equal(UniMIDI::Input.all.first, input)
81
- end
82
-
83
- end
84
-
85
- end
86
-
87
- context "#all" do
88
- should "return all devices" do
89
- assert_equal(UniMIDI::Loader.devices(:direction => :input), UniMIDI::Input.all)
90
- end
91
- end
92
-
93
- end
94
-
95
- end