unimidi 0.4.5 → 0.5.0

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.5"
23
+ VERSION = '0.5.0'
21
24
 
22
25
  Platform.bootstrap
23
-
24
26
  end
metadata CHANGED
@@ -1,71 +1,155 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unimidi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-05 00:00:00.000000000 Z
11
+ date: 2022-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: alsa-rawmidi
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 13.0.6
23
+ type: :development
24
+ prerelease: false
15
25
  version_requirements: !ruby/object:Gem::Requirement
16
26
  requirements:
17
- - - ~>
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '13.0'
30
+ - - ">="
18
31
  - !ruby/object:Gem::Version
19
- version: '0'
32
+ version: 13.0.6
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
20
35
  requirement: !ruby/object:Gem::Requirement
21
36
  requirements:
22
- - - ~>
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.11'
40
+ - - ">="
23
41
  - !ruby/object:Gem::Version
24
- version: '0'
42
+ version: 3.11.0
43
+ type: :development
25
44
  prerelease: false
26
- type: :runtime
27
- - !ruby/object:Gem::Dependency
28
- name: ffi-coremidi
29
45
  version_requirements: !ruby/object:Gem::Requirement
30
46
  requirements:
31
- - - ~>
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.11'
50
+ - - ">="
32
51
  - !ruby/object:Gem::Version
33
- version: '0'
52
+ version: 3.11.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: rubocop
34
55
  requirement: !ruby/object:Gem::Requirement
35
56
  requirements:
36
- - - ~>
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.25'
60
+ - - ">="
37
61
  - !ruby/object:Gem::Version
38
- version: '0'
62
+ version: 1.25.1
63
+ type: :development
39
64
  prerelease: false
40
- type: :runtime
41
- - !ruby/object:Gem::Dependency
42
- name: midi-jruby
43
65
  version_requirements: !ruby/object:Gem::Requirement
44
66
  requirements:
45
- - - ~>
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.25'
70
+ - - ">="
46
71
  - !ruby/object:Gem::Version
47
- version: '0'
72
+ version: 1.25.1
73
+ - !ruby/object:Gem::Dependency
74
+ name: alsa-rawmidi
48
75
  requirement: !ruby/object:Gem::Requirement
49
76
  requirements:
50
- - - ~>
77
+ - - "~>"
51
78
  - !ruby/object:Gem::Version
52
- version: '0'
53
- prerelease: false
79
+ version: '0.3'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.3.1
54
83
  type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.3'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 0.3.1
55
93
  - !ruby/object:Gem::Dependency
56
- name: midi-winmm
94
+ name: ffi-coremidi
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '0.3'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 0.3.5
103
+ type: :runtime
104
+ prerelease: false
57
105
  version_requirements: !ruby/object:Gem::Requirement
58
106
  requirements:
59
- - - ~>
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.3'
110
+ - - ">="
60
111
  - !ruby/object:Gem::Version
61
- version: '0'
112
+ version: 0.3.5
113
+ - !ruby/object:Gem::Dependency
114
+ name: midi-jruby
62
115
  requirement: !ruby/object:Gem::Requirement
63
116
  requirements:
64
- - - ~>
117
+ - - "~>"
65
118
  - !ruby/object:Gem::Version
66
- version: '0'
119
+ version: '0.1'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 0.1.4
123
+ type: :runtime
67
124
  prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '0.1'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 0.1.4
133
+ - !ruby/object:Gem::Dependency
134
+ name: midi-winmm
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.1'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 0.1.10
68
143
  type: :runtime
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '0.1'
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 0.1.10
69
153
  description: Platform independent realtime MIDI input and output for Ruby
70
154
  email:
71
155
  - ari.russo@gmail.com
@@ -73,30 +157,25 @@ executables: []
73
157
  extensions: []
74
158
  extra_rdoc_files: []
75
159
  files:
160
+ - LICENSE
161
+ - README.md
76
162
  - lib/unimidi.rb
163
+ - lib/unimidi/adapter/alsa-rawmidi.rb
164
+ - lib/unimidi/adapter/ffi-coremidi.rb
165
+ - lib/unimidi/adapter/midi-jruby.rb
166
+ - lib/unimidi/adapter/midi-winmm.rb
77
167
  - lib/unimidi/command.rb
78
168
  - lib/unimidi/device.rb
79
169
  - lib/unimidi/input.rb
170
+ - lib/unimidi/input/buffer_access.rb
171
+ - lib/unimidi/input/stream_reader.rb
80
172
  - lib/unimidi/loader.rb
81
173
  - lib/unimidi/output.rb
82
174
  - lib/unimidi/platform.rb
83
175
  - lib/unimidi/type_conversion.rb
84
- - lib/unimidi/adapter/alsa-rawmidi.rb
85
- - lib/unimidi/adapter/ffi-coremidi.rb
86
- - lib/unimidi/adapter/midi-jruby.rb
87
- - lib/unimidi/adapter/midi-winmm.rb
88
- - test/adapter_test.rb
89
- - test/class_methods_test.rb
90
- - test/functional_test.rb
91
- - test/helper.rb
92
- - test/input_test.rb
93
- - test/platform_test.rb
94
- - test/type_conversion_test.rb
95
- - LICENSE
96
- - README.md
97
176
  homepage: http://github.com/arirusso/unimidi
98
177
  licenses:
99
- - Apache 2.0
178
+ - Apache-2.0
100
179
  metadata: {}
101
180
  post_install_message:
102
181
  rdoc_options: []
@@ -104,17 +183,16 @@ require_paths:
104
183
  - lib
105
184
  required_ruby_version: !ruby/object:Gem::Requirement
106
185
  requirements:
107
- - - '>='
186
+ - - ">="
108
187
  - !ruby/object:Gem::Version
109
- version: '0'
188
+ version: 1.8.6
110
189
  required_rubygems_version: !ruby/object:Gem::Requirement
111
190
  requirements:
112
- - - '>='
191
+ - - ">="
113
192
  - !ruby/object:Gem::Version
114
193
  version: 1.3.6
115
194
  requirements: []
116
- rubyforge_project: unimidi
117
- rubygems_version: 2.1.9
195
+ rubygems_version: 3.3.3
118
196
  signing_key:
119
197
  specification_version: 4
120
198
  summary: Realtime MIDI IO for Ruby
data/test/adapter_test.rb DELETED
@@ -1,66 +0,0 @@
1
- require "helper"
2
-
3
- class UniMIDI::AdapterTest < Test::Unit::TestCase
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 < Test::Unit::TestCase
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