unimidi 0.4.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/README.md +7 -7
- data/lib/unimidi/adapter/alsa-rawmidi.rb +4 -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 +47 -32
- 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 +124 -46
- 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: 8a01014709788ce8d62b5331aa871210c5b52caf3172fa88abf737ea0ab1da6e
|
4
|
+
data.tar.gz: 2afe488142025675ce6fcf6413183a4b354b091215199bccecb46fa92b3c0400
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb09c7b5e9ba139f3e4161c2881af05ae6e0536857001118d41e47b611322e093a562995bd3840cc82790d1a84ad8317533948b7f6d098460a7eb1922ecda532
|
7
|
+
data.tar.gz: 954b97c19189b650ab55643d99989d4b88603938f762cf0289f6360672c6174e753202086ad24acd3cdf955db4191fcdda0f256eb1cb18c180389de204e55095
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Also see [MicroMIDI](http://github.com/arirusso/micromidi) which builds a full M
|
|
16
16
|
|
17
17
|
Using Ruby 1.9.2 or JRuby 1.6.1 (or newer) is strongly recommended. JRuby should be run in 1.9 mode where applicable
|
18
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.
|
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.
|
20
20
|
|
21
21
|
Platform
|
22
22
|
|
@@ -24,7 +24,7 @@ Platform
|
|
24
24
|
* Linux: [alsa-rawmidi](http://github.com/arirusso/alsa-rawmidi)
|
25
25
|
* OSX: [ffi-coremidi](http://github.com/arirusso/ffi-coremidi)
|
26
26
|
* Windows/Cygwin: [midi-winmm](http://github.com/arirusso/midi-winmm)
|
27
|
-
|
27
|
+
|
28
28
|
### Install
|
29
29
|
|
30
30
|
If you're using Bundler, add this line to your application's Gemfile:
|
@@ -34,7 +34,7 @@ If you're using Bundler, add this line to your application's Gemfile:
|
|
34
34
|
Otherwise...
|
35
35
|
|
36
36
|
`gem install unimidi`
|
37
|
-
|
37
|
+
|
38
38
|
### Usage
|
39
39
|
|
40
40
|
##### Blog Posts
|
@@ -75,13 +75,13 @@ See below for additional notes on testing with JRuby
|
|
75
75
|
##### Linux
|
76
76
|
|
77
77
|
* *libasound* and *libasound-dev* packages are required
|
78
|
-
|
79
|
-
### Author
|
78
|
+
|
79
|
+
### Author
|
80
80
|
|
81
81
|
[Ari Russo](http://github.com/arirusso) <ari.russo at gmail.com>
|
82
|
-
|
82
|
+
|
83
83
|
### License
|
84
84
|
|
85
85
|
Apache 2.0, See the file LICENSE
|
86
86
|
|
87
|
-
Copyright (c) 2010-
|
87
|
+
Copyright (c) 2010-2022 Ari Russo
|
@@ -1,15 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'alsa-rawmidi'
|
4
4
|
|
5
|
+
module UniMIDI
|
5
6
|
module Adapter
|
6
|
-
|
7
7
|
# Load underlying devices using the alsa-rawmidi gem
|
8
8
|
module AlsaRawMIDI
|
9
|
-
|
10
9
|
module Loader
|
11
|
-
|
12
|
-
extend self
|
10
|
+
module_function
|
13
11
|
|
14
12
|
# @return [Array<AlsaRawMIDI::Input>]
|
15
13
|
def inputs
|
@@ -20,11 +18,7 @@ module UniMIDI
|
|
20
18
|
def outputs
|
21
19
|
::AlsaRawMIDI::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 '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,22 +1,21 @@
|
|
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
|
17
16
|
# @return [Array<String>]
|
18
17
|
def list
|
19
|
-
all.map do |device|
|
18
|
+
all.map do |device|
|
20
19
|
name = device.pretty_name
|
21
20
|
puts(name)
|
22
21
|
name
|
@@ -34,19 +33,23 @@ module UniMIDI
|
|
34
33
|
# When their input is received, the device is selected and enabled
|
35
34
|
def gets(&block)
|
36
35
|
device = nil
|
37
|
-
|
38
|
-
puts
|
39
|
-
puts "Select a MIDI #{
|
36
|
+
direction = get_direction
|
37
|
+
puts ''
|
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
|
-
device.open(&block)
|
52
|
+
device.open(&block)
|
50
53
|
device
|
51
54
|
end
|
52
55
|
|
@@ -63,42 +66,51 @@ 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
|
|
91
|
+
# The direction of the device eg "input", "output"
|
92
|
+
# @return [String]
|
93
|
+
def get_direction
|
94
|
+
name.split('::').last.downcase
|
95
|
+
end
|
96
|
+
|
87
97
|
# Enable the given device
|
88
98
|
# @param [Input, Output] device
|
89
99
|
# @return [Input, Output]
|
90
100
|
def use_device(device, &block)
|
91
|
-
|
92
|
-
|
101
|
+
if device.enabled?
|
102
|
+
yield(device) if block_given?
|
103
|
+
else
|
104
|
+
device.open(&block)
|
105
|
+
end
|
106
|
+
device
|
93
107
|
end
|
94
|
-
|
95
108
|
end
|
96
109
|
|
97
110
|
# Methods that are shared by both Input and Output instances
|
98
111
|
module InstanceMethods
|
99
|
-
|
100
112
|
# @param [AlsaRawMIDI::Input, AlsaRawMIDI::Output, CoreMIDI::Destination, CoreMIDI::Source, MIDIJRuby::Input, MIDIJRuby::Output, MIDIWinMM::Input, MIDIWinMM::Output] device
|
101
|
-
def initialize(device)
|
113
|
+
def initialize(device)
|
102
114
|
@device = device
|
103
115
|
@enabled = false
|
104
116
|
|
@@ -110,7 +122,7 @@ module UniMIDI
|
|
110
122
|
# Can be passed a block to which the device will be passed in as the yieldparam
|
111
123
|
# @param [*Object] args
|
112
124
|
# @return [Input, Output] self
|
113
|
-
def open(*args
|
125
|
+
def open(*args)
|
114
126
|
unless @enabled
|
115
127
|
@device.open(*args)
|
116
128
|
@enabled = true
|
@@ -125,8 +137,8 @@ module UniMIDI
|
|
125
137
|
at_exit do
|
126
138
|
close
|
127
139
|
end
|
128
|
-
self
|
129
140
|
end
|
141
|
+
self
|
130
142
|
end
|
131
143
|
|
132
144
|
# A human readable display name for this device
|
@@ -149,6 +161,12 @@ module UniMIDI
|
|
149
161
|
end
|
150
162
|
end
|
151
163
|
|
164
|
+
# Returns true if the device is not enabled
|
165
|
+
# @return [Boolean]
|
166
|
+
def closed?
|
167
|
+
!@enabled
|
168
|
+
end
|
169
|
+
|
152
170
|
# Add attributes for the device instance
|
153
171
|
# :direction, :id, :name
|
154
172
|
def self.included(base)
|
@@ -165,9 +183,9 @@ module UniMIDI
|
|
165
183
|
# Populate the direction attribute
|
166
184
|
def populate_direction
|
167
185
|
@direction = case @device.type
|
168
|
-
|
169
|
-
|
170
|
-
|
186
|
+
when :source, :input then :input
|
187
|
+
when :destination, :output then :output
|
188
|
+
end
|
171
189
|
end
|
172
190
|
|
173
191
|
# Populate attributes from the underlying device object
|
@@ -176,9 +194,6 @@ module UniMIDI
|
|
176
194
|
@name = @device.name
|
177
195
|
populate_direction
|
178
196
|
end
|
179
|
-
|
180
197
|
end
|
181
|
-
|
182
198
|
end
|
183
|
-
|
184
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
|