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.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/README.md +8 -11
- data/lib/unimidi/adapter/alsa-rawmidi.rb +3 -10
- data/lib/unimidi/adapter/ffi-coremidi.rb +4 -10
- data/lib/unimidi/adapter/midi-jruby.rb +4 -10
- data/lib/unimidi/adapter/midi-winmm.rb +4 -10
- data/lib/unimidi/command.rb +9 -11
- data/lib/unimidi/device.rb +35 -26
- data/lib/unimidi/input/buffer_access.rb +46 -0
- data/lib/unimidi/input/stream_reader.rb +81 -0
- data/lib/unimidi/input.rb +8 -101
- data/lib/unimidi/loader.rb +23 -23
- data/lib/unimidi/output.rb +12 -14
- data/lib/unimidi/platform.rb +23 -17
- data/lib/unimidi/type_conversion.rb +5 -7
- data/lib/unimidi.rb +13 -11
- metadata +36 -62
- data/test/adapter_test.rb +0 -66
- data/test/class_methods_test.rb +0 -95
- data/test/functional_test.rb +0 -113
- data/test/helper.rb +0 -74
- data/test/input_test.rb +0 -44
- data/test/platform_test.rb +0 -47
- data/test/type_conversion_test.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ff9c1ebf95bb17c91eede1979d6abd50b2fbc3a906c3a4ab8d270acb33c4a9d8
|
4
|
+
data.tar.gz: 4fd0198e5aa8a1547e5c5a7f480157929dcf2d38165b2df48191b82acb054aa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4291dc97699243764f892f4374c553d68bac9a35d9e1b95d4ff1ed15c2f3a2c67e46389f5e851b6de9ed1b203ad05d3e681987e2fd73cf5ce1461672b332d59a
|
7
|
+
data.tar.gz: 5bea900c9ccd502d3d5980333d8904ae89832d598675fe5dd461cf3eaff7979a7be755b6231aece6e04abfda2a371a42f835c8aca0973d48e910768f30a1fce1
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -14,9 +14,7 @@ Also see [MicroMIDI](http://github.com/arirusso/micromidi) which builds a full M
|
|
14
14
|
|
15
15
|
### Requirements
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
UniMIDI uses one of the following libraries, depending on which platform you're using it on. The necessary library should install automatically with the unimidi gem.
|
17
|
+
UniMIDI uses one of the following libraries, depending on which platform you're using it on. The necessary library should install automatically with the unimidi gem.
|
20
18
|
|
21
19
|
Platform
|
22
20
|
|
@@ -24,7 +22,7 @@ Platform
|
|
24
22
|
* Linux: [alsa-rawmidi](http://github.com/arirusso/alsa-rawmidi)
|
25
23
|
* OSX: [ffi-coremidi](http://github.com/arirusso/ffi-coremidi)
|
26
24
|
* Windows/Cygwin: [midi-winmm](http://github.com/arirusso/midi-winmm)
|
27
|
-
|
25
|
+
|
28
26
|
### Install
|
29
27
|
|
30
28
|
If you're using Bundler, add this line to your application's Gemfile:
|
@@ -34,7 +32,7 @@ If you're using Bundler, add this line to your application's Gemfile:
|
|
34
32
|
Otherwise...
|
35
33
|
|
36
34
|
`gem install unimidi`
|
37
|
-
|
35
|
+
|
38
36
|
### Usage
|
39
37
|
|
40
38
|
##### Blog Posts
|
@@ -57,7 +55,7 @@ UniMIDI includes a set of tests which assume that an output is connected to an i
|
|
57
55
|
|
58
56
|
The tests can be run using
|
59
57
|
|
60
|
-
`rake
|
58
|
+
`rake spec`
|
61
59
|
|
62
60
|
See below for additional notes on testing with JRuby
|
63
61
|
|
@@ -69,19 +67,18 @@ See below for additional notes on testing with JRuby
|
|
69
67
|
|
70
68
|
##### JRuby
|
71
69
|
|
72
|
-
* You must be in 1.9 mode. This is normally accomplished by passing --1.9 to JRuby at the command line. For testing in 1.9 mode, use `jruby --1.9 -S rake test`
|
73
70
|
* javax.sound has some documented issues with SysEx messages in some versions OSX Snow Leopard which do affect this library.
|
74
71
|
|
75
72
|
##### Linux
|
76
73
|
|
77
74
|
* *libasound* and *libasound-dev* packages are required
|
78
|
-
|
79
|
-
### Author
|
75
|
+
|
76
|
+
### Author
|
80
77
|
|
81
78
|
[Ari Russo](http://github.com/arirusso) <ari.russo at gmail.com>
|
82
|
-
|
79
|
+
|
83
80
|
### License
|
84
81
|
|
85
82
|
Apache 2.0, See the file LICENSE
|
86
83
|
|
87
|
-
Copyright (c) 2010-
|
84
|
+
Copyright (c) 2010-2022 Ari Russo
|
@@ -1,15 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'alsa-rawmidi'
|
2
3
|
|
3
4
|
module UniMIDI
|
4
|
-
|
5
5
|
module Adapter
|
6
|
-
|
7
6
|
# Load underlying devices using the alsa-rawmidi gem
|
8
7
|
module AlsaRawMIDI
|
9
|
-
|
10
8
|
module Loader
|
11
|
-
|
12
|
-
extend self
|
9
|
+
module_function
|
13
10
|
|
14
11
|
# @return [Array<AlsaRawMIDI::Input>]
|
15
12
|
def inputs
|
@@ -20,11 +17,7 @@ module UniMIDI
|
|
20
17
|
def outputs
|
21
18
|
::AlsaRawMIDI::Device.all_by_type[:output]
|
22
19
|
end
|
23
|
-
|
24
20
|
end
|
25
|
-
|
26
21
|
end
|
27
|
-
|
28
22
|
end
|
29
|
-
|
30
23
|
end
|
@@ -1,15 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'coremidi'
|
4
4
|
|
5
|
+
module UniMIDI
|
5
6
|
module Adapter
|
6
|
-
|
7
7
|
# Load underlying devices using the coremidi gem
|
8
8
|
module CoreMIDI
|
9
|
-
|
10
9
|
module Loader
|
11
|
-
|
12
|
-
extend self
|
10
|
+
module_function
|
13
11
|
|
14
12
|
# @return [Array<CoreMIDI::Source>]
|
15
13
|
def inputs
|
@@ -20,11 +18,7 @@ module UniMIDI
|
|
20
18
|
def outputs
|
21
19
|
::CoreMIDI::Endpoint.all_by_type[:destination]
|
22
20
|
end
|
23
|
-
|
24
21
|
end
|
25
|
-
|
26
22
|
end
|
27
|
-
|
28
23
|
end
|
29
|
-
|
30
24
|
end
|
@@ -1,15 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'midi-jruby'
|
4
4
|
|
5
|
+
module UniMIDI
|
5
6
|
module Adapter
|
6
|
-
|
7
7
|
# Load underlying devices using the midi-jruby gem
|
8
8
|
module MIDIJRuby
|
9
|
-
|
10
9
|
module Loader
|
11
|
-
|
12
|
-
extend self
|
10
|
+
module_function
|
13
11
|
|
14
12
|
# @return [Array<MIDIJRuby::Input>]
|
15
13
|
def inputs
|
@@ -20,11 +18,7 @@ module UniMIDI
|
|
20
18
|
def outputs
|
21
19
|
::MIDIJRuby::Device.all_by_type[:output]
|
22
20
|
end
|
23
|
-
|
24
21
|
end
|
25
|
-
|
26
22
|
end
|
27
|
-
|
28
23
|
end
|
29
|
-
|
30
24
|
end
|
@@ -1,15 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'midi-winmm'
|
4
4
|
|
5
|
+
module UniMIDI
|
5
6
|
module Adapter
|
6
|
-
|
7
7
|
# Load underlying devices using the midi-winmm gem
|
8
8
|
module MIDIWinMM
|
9
|
-
|
10
9
|
module Loader
|
11
|
-
|
12
|
-
extend self
|
10
|
+
module_function
|
13
11
|
|
14
12
|
# @return [Array<MIDIWinMM::Input>]
|
15
13
|
def inputs
|
@@ -20,11 +18,7 @@ module UniMIDI
|
|
20
18
|
def outputs
|
21
19
|
::MIDIWinMM::Device.all_by_type[:output]
|
22
20
|
end
|
23
|
-
|
24
21
|
end
|
25
|
-
|
26
22
|
end
|
27
|
-
|
28
23
|
end
|
29
|
-
|
30
24
|
end
|
data/lib/unimidi/command.rb
CHANGED
@@ -1,26 +1,24 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module UniMIDI
|
3
4
|
# Module for command-line use of UniMIDI. Used by the bin/unimidi script
|
4
5
|
module Command
|
5
|
-
|
6
|
-
extend self
|
6
|
+
module_function
|
7
7
|
|
8
8
|
# Execute a command
|
9
9
|
# @param [Symbol] command
|
10
10
|
# @param [Hash] options
|
11
11
|
# @return [Boolean]
|
12
|
-
def exec(command,
|
13
|
-
if [
|
14
|
-
puts
|
12
|
+
def exec(command, _options = {})
|
13
|
+
if %i[l list list_devices].include?(command)
|
14
|
+
puts 'input:'
|
15
15
|
Input.list
|
16
|
-
puts
|
16
|
+
puts 'output:'
|
17
17
|
Output.list
|
18
18
|
true
|
19
19
|
else
|
20
|
-
raise "Command #{command
|
21
|
-
end
|
20
|
+
raise "Command #{command} not found"
|
21
|
+
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
|
-
|
26
24
|
end
|
data/lib/unimidi/device.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module UniMIDI
|
3
4
|
# Common logic that is shared by both Input and Output devices
|
4
5
|
module Device
|
5
|
-
|
6
6
|
# Methods that are shared by both Input and Output classes
|
7
7
|
module ClassMethods
|
8
|
-
|
9
8
|
include Enumerable
|
10
9
|
|
11
10
|
# Iterate over all devices of this direction (eg Input, Output)
|
12
11
|
def each(&block)
|
13
|
-
all.each
|
12
|
+
all.each(&block)
|
14
13
|
end
|
15
14
|
|
16
15
|
# Prints ids and names of each device to the console
|
@@ -35,16 +34,20 @@ module UniMIDI
|
|
35
34
|
def gets(&block)
|
36
35
|
device = nil
|
37
36
|
direction = get_direction
|
38
|
-
puts
|
37
|
+
puts ''
|
39
38
|
puts "Select a MIDI #{direction}..."
|
40
39
|
while device.nil?
|
41
40
|
list
|
42
|
-
print
|
41
|
+
print '> '
|
43
42
|
selection = $stdin.gets.chomp
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
next unless selection != ''
|
44
|
+
|
45
|
+
selection = begin
|
46
|
+
Integer(selection)
|
47
|
+
rescue StandardError
|
48
|
+
nil
|
47
49
|
end
|
50
|
+
device = all.find { |d| d.id == selection } unless selection.nil?
|
48
51
|
end
|
49
52
|
device.open(&block)
|
50
53
|
device
|
@@ -63,46 +66,49 @@ module UniMIDI
|
|
63
66
|
end
|
64
67
|
|
65
68
|
# Select the device at the given index and enable it
|
66
|
-
# @param [
|
69
|
+
# @param [Integer] index
|
67
70
|
# @return [Input, Output]
|
68
71
|
def use(index, &block)
|
69
72
|
index = case index
|
70
73
|
when :first then 0
|
71
|
-
when :last then all.
|
74
|
+
when :last then all.count - 1
|
72
75
|
else index
|
73
76
|
end
|
74
|
-
use_device(
|
77
|
+
use_device(at(index), &block)
|
75
78
|
end
|
76
|
-
|
79
|
+
alias open use
|
77
80
|
|
78
81
|
# Select the device at the given index
|
79
|
-
# @param [
|
82
|
+
# @param [Integer] index
|
80
83
|
# @return [Input, Output]
|
81
|
-
def
|
84
|
+
def at(index)
|
82
85
|
all[index]
|
83
86
|
end
|
87
|
+
alias [] at
|
84
88
|
|
85
89
|
private
|
86
90
|
|
87
91
|
# The direction of the device eg "input", "output"
|
88
92
|
# @return [String]
|
89
93
|
def get_direction
|
90
|
-
|
94
|
+
name.split('::').last.downcase
|
91
95
|
end
|
92
96
|
|
93
97
|
# Enable the given device
|
94
98
|
# @param [Input, Output] device
|
95
99
|
# @return [Input, Output]
|
96
100
|
def use_device(device, &block)
|
97
|
-
|
101
|
+
if device.enabled?
|
102
|
+
yield(device) if block_given?
|
103
|
+
else
|
104
|
+
device.open(&block)
|
105
|
+
end
|
98
106
|
device
|
99
107
|
end
|
100
|
-
|
101
108
|
end
|
102
109
|
|
103
110
|
# Methods that are shared by both Input and Output instances
|
104
111
|
module InstanceMethods
|
105
|
-
|
106
112
|
# @param [AlsaRawMIDI::Input, AlsaRawMIDI::Output, CoreMIDI::Destination, CoreMIDI::Source, MIDIJRuby::Input, MIDIJRuby::Output, MIDIWinMM::Input, MIDIWinMM::Output] device
|
107
113
|
def initialize(device)
|
108
114
|
@device = device
|
@@ -116,7 +122,7 @@ module UniMIDI
|
|
116
122
|
# Can be passed a block to which the device will be passed in as the yieldparam
|
117
123
|
# @param [*Object] args
|
118
124
|
# @return [Input, Output] self
|
119
|
-
def open(*args
|
125
|
+
def open(*args)
|
120
126
|
unless @enabled
|
121
127
|
@device.open(*args)
|
122
128
|
@enabled = true
|
@@ -155,6 +161,12 @@ module UniMIDI
|
|
155
161
|
end
|
156
162
|
end
|
157
163
|
|
164
|
+
# Returns true if the device is not enabled
|
165
|
+
# @return [Boolean]
|
166
|
+
def closed?
|
167
|
+
!@enabled
|
168
|
+
end
|
169
|
+
|
158
170
|
# Add attributes for the device instance
|
159
171
|
# :direction, :id, :name
|
160
172
|
def self.included(base)
|
@@ -171,9 +183,9 @@ module UniMIDI
|
|
171
183
|
# Populate the direction attribute
|
172
184
|
def populate_direction
|
173
185
|
@direction = case @device.type
|
174
|
-
|
175
|
-
|
176
|
-
|
186
|
+
when :source, :input then :input
|
187
|
+
when :destination, :output then :output
|
188
|
+
end
|
177
189
|
end
|
178
190
|
|
179
191
|
# Populate attributes from the underlying device object
|
@@ -182,9 +194,6 @@ module UniMIDI
|
|
182
194
|
@name = @device.name
|
183
195
|
populate_direction
|
184
196
|
end
|
185
|
-
|
186
197
|
end
|
187
|
-
|
188
198
|
end
|
189
|
-
|
190
199
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UniMIDI
|
4
|
+
class Input
|
5
|
+
module BufferAccess
|
6
|
+
# The device buffer
|
7
|
+
# @return [Array<Hash>]
|
8
|
+
def buffer
|
9
|
+
@device.buffer
|
10
|
+
end
|
11
|
+
|
12
|
+
# Clears the input buffer
|
13
|
+
# @return [Array]
|
14
|
+
def clear_buffer
|
15
|
+
@device.buffer.clear
|
16
|
+
end
|
17
|
+
|
18
|
+
# Gets any messages in the buffer in the same format as Input::StreamReader#gets. This doesn't remove
|
19
|
+
# the messages from the buffer or have any effect on the StreamReader pointer position
|
20
|
+
# @param [*Object] args
|
21
|
+
# @return [Array<Hash>]
|
22
|
+
def gets_buffer(*_args)
|
23
|
+
@device.buffer
|
24
|
+
end
|
25
|
+
|
26
|
+
# Gets any messages in the buffer in the same format as Input#gets_s. This doesn't remove
|
27
|
+
# the messages from the buffer or have any effect on the StreamReader pointer position
|
28
|
+
# @param [*Object] args
|
29
|
+
# @return [Array<Hash>]
|
30
|
+
def gets_buffer_s(*_args)
|
31
|
+
@device.buffer.map do |msg|
|
32
|
+
msg[:data] = TypeConversion.numeric_byte_array_to_hex_string(msg[:data])
|
33
|
+
msg
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Gets any messages in the buffer in the same format as Input#gets_data. . This doesn't remove
|
38
|
+
# the messages from the buffer or have any effect on the StreamReader pointer position
|
39
|
+
# @param [*Object] args
|
40
|
+
# @return [Array<Integer>]
|
41
|
+
def gets_buffer_data(*_args)
|
42
|
+
@device.buffer.map { |msg| msg[:data] }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UniMIDI
|
4
|
+
class Input
|
5
|
+
module StreamReader
|
6
|
+
# Returns any data in the input buffer that have been received since the last call to a
|
7
|
+
# StreamReader method. If a StreamReader method has not yet been called, all data received
|
8
|
+
# since the program was initialized will be returned
|
9
|
+
#
|
10
|
+
# The data is returned as array of MIDI event hashes as such:
|
11
|
+
# [
|
12
|
+
# { :data => [144, 60, 100], :timestamp => 1024 },
|
13
|
+
# { :data => [128, 60, 100], :timestamp => 1100 },
|
14
|
+
# { :data => [144, 40, 120], :timestamp => 1200 }
|
15
|
+
# ]
|
16
|
+
#
|
17
|
+
# In this case, the data is an array of Numeric bytes
|
18
|
+
# The timestamp is the number of millis since this input was enabled
|
19
|
+
# Arguments are passed to the underlying device object
|
20
|
+
#
|
21
|
+
# @param [*Object] args
|
22
|
+
# @return [Array<Hash>]
|
23
|
+
def gets(*args)
|
24
|
+
@device.gets(*args)
|
25
|
+
rescue SystemExit, Interrupt
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns any data in the input buffer that have been received since the last call to a
|
30
|
+
# StreamReader method. If a StreamReader method has not yet been called, all data received
|
31
|
+
# since the program was initialized will be returned
|
32
|
+
#
|
33
|
+
# Similar to Input#gets except that the returned message data as string of hex digits eg:
|
34
|
+
# [
|
35
|
+
# { :data => "904060", :timestamp => 904 },
|
36
|
+
# { :data => "804060", :timestamp => 1150 },
|
37
|
+
# { :data => "90447F", :timestamp => 1300 }
|
38
|
+
# ]
|
39
|
+
#
|
40
|
+
# @param [*Object] args
|
41
|
+
# @return [Array<Hash>]
|
42
|
+
def gets_s(*args)
|
43
|
+
@device.gets_s(*args)
|
44
|
+
rescue SystemExit, Interrupt
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
alias gets_bytestr gets_s
|
48
|
+
alias gets_hex gets_s
|
49
|
+
|
50
|
+
# Returns any data in the input buffer that have been received since the last call to a
|
51
|
+
# StreamReader method. If a StreamReader method has not yet been called, all data received
|
52
|
+
# since the program was initialized will be returned
|
53
|
+
#
|
54
|
+
# Similar to Input#gets except that the returned message data as an array of data bytes such as
|
55
|
+
# [144, 60, 100, 128, 60, 100, 144, 40, 120]
|
56
|
+
#
|
57
|
+
# @param [*Object] args
|
58
|
+
# @return [Array<Integer>]
|
59
|
+
def gets_data(*args)
|
60
|
+
arr = gets(*args)
|
61
|
+
arr.map { |msg| msg[:data] }.inject(:+)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns any data in the input buffer that have been received since the last call to a
|
65
|
+
# StreamReader method. If a StreamReader method has not yet been called, all data received
|
66
|
+
# since the program was initialized will be returned
|
67
|
+
#
|
68
|
+
# Similar to Input#gets except that the returned message data as a string of data such as
|
69
|
+
# "90406080406090447F"
|
70
|
+
#
|
71
|
+
# @param [*Object] args
|
72
|
+
# @return [String]
|
73
|
+
def gets_data_s(*args)
|
74
|
+
arr = gets_bytestr(*args)
|
75
|
+
arr.map { |msg| msg[:data] }.join
|
76
|
+
end
|
77
|
+
alias gets_data_bytestr gets_data_s
|
78
|
+
alias gets_data_hex gets_data_s
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/unimidi/input.rb
CHANGED
@@ -1,113 +1,20 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'unimidi/input/buffer_access'
|
4
|
+
require 'unimidi/input/stream_reader'
|
2
5
|
|
6
|
+
module UniMIDI
|
3
7
|
# A MIDI input device
|
4
8
|
class Input
|
5
|
-
|
6
9
|
extend Device::ClassMethods
|
10
|
+
include BufferAccess
|
7
11
|
include Device::InstanceMethods
|
12
|
+
include StreamReader
|
8
13
|
|
9
14
|
# All MIDI input devices -- used to populate the class
|
10
15
|
# @return [Array<Input>]
|
11
16
|
def self.all
|
12
|
-
Loader.devices(:
|
13
|
-
end
|
14
|
-
|
15
|
-
# The device buffer
|
16
|
-
# @return [Array<Hash>]
|
17
|
-
def buffer
|
18
|
-
@device.buffer
|
19
|
-
end
|
20
|
-
|
21
|
-
#
|
22
|
-
# Plucks data from the input buffer and returns it as array of MIDI event hashes as such:
|
23
|
-
# [
|
24
|
-
# { :data => [144, 60, 100], :timestamp => 1024 },
|
25
|
-
# { :data => [128, 60, 100], :timestamp => 1100 },
|
26
|
-
# { :data => [144, 40, 120], :timestamp => 1200 }
|
27
|
-
# ]
|
28
|
-
#
|
29
|
-
# In this case, the data is an array of Numeric bytes
|
30
|
-
# The timestamp is the number of millis since this input was enabled
|
31
|
-
# Arguments are passed to the underlying device object
|
32
|
-
#
|
33
|
-
# @param [*Object] args
|
34
|
-
# @return [Array<Hash>]
|
35
|
-
def gets(*args)
|
36
|
-
@device.gets(*args)
|
37
|
-
rescue SystemExit, Interrupt
|
38
|
-
exit
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Plucks data from the input buffer and returns it as array of MIDI event hashes.
|
43
|
-
# Similar to Input#gets except that the returned message data as string of hex digits eg:
|
44
|
-
# [
|
45
|
-
# { :data => "904060", :timestamp => 904 },
|
46
|
-
# { :data => "804060", :timestamp => 1150 },
|
47
|
-
# { :data => "90447F", :timestamp => 1300 }
|
48
|
-
# ]
|
49
|
-
#
|
50
|
-
# @param [*Object] args
|
51
|
-
# @return [Array<Hash>]
|
52
|
-
def gets_s(*args)
|
53
|
-
@device.gets_s(*args)
|
54
|
-
rescue SystemExit, Interrupt
|
55
|
-
exit
|
56
|
-
end
|
57
|
-
alias_method :gets_bytestr, :gets_s
|
58
|
-
alias_method :gets_hex, :gets_s
|
59
|
-
|
60
|
-
#
|
61
|
-
# Plucks data from the input buffer and returns it as an array of data bytes such as
|
62
|
-
# [144, 60, 100, 128, 60, 100, 144, 40, 120]
|
63
|
-
#
|
64
|
-
# @param [*Object] args
|
65
|
-
# @return [Array<Fixnum>]
|
66
|
-
def gets_data(*args)
|
67
|
-
arr = gets(*args)
|
68
|
-
arr.map { |msg| msg[:data] }.inject(:+)
|
17
|
+
Loader.devices(direction: :input)
|
69
18
|
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Plucks data from the input buffer and returns it as a string of data such as
|
73
|
-
# "90406080406090447F"
|
74
|
-
#
|
75
|
-
# @param [*Object] args
|
76
|
-
# @return [String]
|
77
|
-
def gets_data_s(*args)
|
78
|
-
arr = gets_bytestr(*args)
|
79
|
-
arr.map { |msg| msg[:data] }.join
|
80
|
-
end
|
81
|
-
alias_method :gets_data_bytestr, :gets_data_s
|
82
|
-
alias_method :gets_data_hex, :gets_data_s
|
83
|
-
|
84
|
-
# Clears the input buffer
|
85
|
-
# @return [Array]
|
86
|
-
def clear_buffer
|
87
|
-
@device.buffer.clear
|
88
|
-
end
|
89
|
-
|
90
|
-
# Gets any messages in the buffer in the same format as Input#gets, without removing them from the buffer
|
91
|
-
# @param [*Object] args
|
92
|
-
# @return [Array<Hash>]
|
93
|
-
def gets_buffer(*args)
|
94
|
-
@device.buffer
|
95
|
-
end
|
96
|
-
|
97
|
-
# Gets any messages in the buffer in the same format as Input#gets_s, without removing them from the buffer
|
98
|
-
# @param [*Object] args
|
99
|
-
# @return [Array<Hash>]
|
100
|
-
def gets_buffer_s(*args)
|
101
|
-
@device.buffer.map { |msg| msg[:data] = TypeConversion.numeric_byte_array_to_hex_string(msg[:data]); msg }
|
102
|
-
end
|
103
|
-
|
104
|
-
# Gets any messages in the buffer in the same format as Input#gets_data without removing them from the buffer
|
105
|
-
# @param [*Object] args
|
106
|
-
# @return [Array<Fixnum>]
|
107
|
-
def gets_buffer_data(*args)
|
108
|
-
@device.buffer.map { |msg| msg[:data] }
|
109
|
-
end
|
110
|
-
|
111
19
|
end
|
112
|
-
|
113
20
|
end
|