midi-jruby 0.1.6 → 0.2.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.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/lib/midi-jruby/api.rb +45 -38
- data/lib/midi-jruby/device.rb +6 -8
- data/lib/midi-jruby/input.rb +33 -35
- data/lib/midi-jruby/output.rb +23 -25
- data/lib/midi-jruby.rb +10 -10
- metadata +19 -43
- data/test/helper.rb +0 -58
- data/test/input_buffer_test.rb +0 -46
- data/test/io_test.rb +0 -80
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 01ef785c234f6baaab44700ac5cd1777531a25e3a0f12501f0d5fd1967378149
|
4
|
+
data.tar.gz: 5fb7355602cb317dfc63e1bfe874e656463bd7200e4f5a04d9f07aae98422571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1462d234ef4bf16103e519818bd34e364efcb9b698922dd80057870b9bf6d169aa3992e59be3c3ea7841bbd3cafd32504c36372a8ae2007372d8a720e49a199d
|
7
|
+
data.tar.gz: 4d2bc64a738362e466497418c3590669509937af9f59b4d22f30ed888d5f5d209a92fe2005458bec038a6a84267213cea90e2f06a2760ad1548eaf431bc24c15
|
data/LICENSE
CHANGED
data/README.md
CHANGED
data/lib/midi-jruby/api.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MIDIJRuby
|
2
|
-
|
3
4
|
# Access to javax.sound.midi
|
4
5
|
module API
|
5
|
-
|
6
6
|
import javax.sound.midi.MidiSystem
|
7
7
|
import javax.sound.midi.MidiDevice
|
8
8
|
import javax.sound.midi.MidiEvent
|
@@ -13,17 +13,19 @@ module MIDIJRuby
|
|
13
13
|
|
14
14
|
extend self
|
15
15
|
|
16
|
+
SYSEX_STATUS_BYTES = [0xF0, 0xF7].freeze
|
17
|
+
|
16
18
|
# Get all MIDI devices that are available via javax.sound.midi
|
17
19
|
# @return [Array<Hash>] A set of hashes for each available device
|
18
20
|
def get_devices
|
19
21
|
MidiSystem.get_midi_device_info.map do |info|
|
20
22
|
jdevice = MidiSystem.get_midi_device(info)
|
21
|
-
{
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
23
|
+
{
|
24
|
+
device: jdevice,
|
25
|
+
id: get_uuid,
|
26
|
+
name: info.get_name,
|
27
|
+
description: info.get_description,
|
28
|
+
vendor: info.get_vendor
|
27
29
|
}
|
28
30
|
end
|
29
31
|
end
|
@@ -31,15 +33,15 @@ module MIDIJRuby
|
|
31
33
|
# Get all MIDI inputs that are available via javax.sound.midi
|
32
34
|
# @return [Array<Input>]
|
33
35
|
def get_inputs
|
34
|
-
jinputs = get_devices.
|
36
|
+
jinputs = get_devices.reject { |device| device[:device].get_max_transmitters.zero? }
|
35
37
|
jinputs.map { |jinput| Input.new(jinput[:id], jinput[:device], jinput) }
|
36
38
|
end
|
37
39
|
|
38
40
|
# Get all MIDI outputs that are available via javax.sound.midi
|
39
41
|
# @return [Array<Output>]
|
40
42
|
def get_outputs
|
41
|
-
joutputs = get_devices.
|
42
|
-
joutputs.map { |joutput| Output.new(joutput[:id], joutput[:device], joutput) }
|
43
|
+
joutputs = get_devices.reject { |device| device[:device].get_max_receivers.zero? }
|
44
|
+
joutputs.map { |joutput| Output.new(joutput[:id], joutput[:device], joutput) }
|
43
45
|
end
|
44
46
|
|
45
47
|
# Enable the given input device to receive MIDI messages
|
@@ -100,9 +102,19 @@ module MIDIJRuby
|
|
100
102
|
def write_output(device, data)
|
101
103
|
bytes = Java::byte[data.size].new
|
102
104
|
data.each_with_index { |byte, i| bytes.ubyte_set(i, byte) }
|
103
|
-
|
104
|
-
|
105
|
-
|
105
|
+
if SYSEX_STATUS_BYTES.include?(data.first)
|
106
|
+
message = SysexMessage.new
|
107
|
+
message.set_message(bytes, data.length.to_java(:int))
|
108
|
+
else
|
109
|
+
message = ShortMessage.new
|
110
|
+
begin
|
111
|
+
message.set_message(*bytes)
|
112
|
+
rescue
|
113
|
+
# support older java versions
|
114
|
+
message.set_message(bytes)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
@receiver[device].send(message, device.get_microsecond_position)
|
106
118
|
true
|
107
119
|
end
|
108
120
|
|
@@ -117,15 +129,14 @@ module MIDIJRuby
|
|
117
129
|
|
118
130
|
# Input event handler class
|
119
131
|
class InputReceiver
|
120
|
-
|
121
132
|
include javax.sound.midi.Receiver
|
122
|
-
|
133
|
+
|
123
134
|
attr_reader :stream
|
124
135
|
|
125
136
|
def initialize
|
126
137
|
@buffer = []
|
127
138
|
end
|
128
|
-
|
139
|
+
|
129
140
|
# Pluck messages from the buffer
|
130
141
|
# @return [Array<Array<Fixnum>>]
|
131
142
|
def read
|
@@ -133,43 +144,39 @@ module MIDIJRuby
|
|
133
144
|
@buffer.clear
|
134
145
|
messages
|
135
146
|
end
|
136
|
-
|
147
|
+
|
137
148
|
# Add a new message to the buffer
|
138
|
-
# @param [
|
149
|
+
# @param [javax.sound.midi.MidiMessage] message
|
139
150
|
# @param [Fixnum] timestamp
|
140
151
|
# @return [Array<Array<Fixnum>>]
|
141
|
-
def send(message,
|
152
|
+
def send(message, _timestamp = -1)
|
142
153
|
bytes = if message.respond_to?(:get_packed_message)
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
154
|
+
packed = message.get_packed_message
|
155
|
+
unpack(packed)
|
156
|
+
else
|
157
|
+
string = String.from_java_bytes(message.get_message)
|
158
|
+
string.unpack('C' * string.length)
|
159
|
+
end
|
149
160
|
@buffer << bytes
|
150
161
|
end
|
151
162
|
|
152
|
-
def close
|
153
|
-
|
154
|
-
|
163
|
+
def close; end
|
164
|
+
|
155
165
|
private
|
156
|
-
|
166
|
+
|
157
167
|
# @param [String]
|
158
168
|
# @return [Array<Fixnum>]
|
159
169
|
def unpack(message)
|
160
170
|
bytes = []
|
161
171
|
string = message.to_s(16)
|
162
|
-
string = "0#{s}" if string.length.divmod(2).last
|
163
|
-
string = string.rjust(6,
|
164
|
-
while string.length
|
165
|
-
string_byte = string.slice!(0,2)
|
172
|
+
string = "0#{s}" if string.length.divmod(2).last.positive?
|
173
|
+
string = string.rjust(6, '0')
|
174
|
+
while string.length.positive?
|
175
|
+
string_byte = string.slice!(0, 2)
|
166
176
|
bytes << string_byte.hex
|
167
177
|
end
|
168
|
-
bytes.reverse
|
178
|
+
bytes.reverse
|
169
179
|
end
|
170
|
-
|
171
180
|
end
|
172
|
-
|
173
181
|
end
|
174
|
-
|
175
182
|
end
|
data/lib/midi-jruby/device.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module MIDIJRuby
|
3
4
|
# Common methods used by both input and output devices
|
4
5
|
module Device
|
5
|
-
|
6
6
|
attr_reader :enabled, # has the device been initialized?
|
7
7
|
:id, # unique int id
|
8
8
|
:name, # name property from javax.sound.midi.MidiDevice.Info
|
@@ -10,7 +10,7 @@ module MIDIJRuby
|
|
10
10
|
:vendor, # vendor property from javax.sound.midi.MidiDevice.Info
|
11
11
|
:type # :input or :output
|
12
12
|
|
13
|
-
|
13
|
+
alias enabled? enabled
|
14
14
|
|
15
15
|
# @param [Fixnum] The uuid for the given device
|
16
16
|
# @param [Java::ComSunMediaSound::MidiInDevice, Java::ComSunMediaSound::MidiOutDevice] device The underlying Java device object
|
@@ -47,8 +47,8 @@ module MIDIJRuby
|
|
47
47
|
# @return [Hash]
|
48
48
|
def self.all_by_type
|
49
49
|
@devices ||= {
|
50
|
-
:
|
51
|
-
:
|
50
|
+
input: API.get_inputs,
|
51
|
+
output: API.get_outputs
|
52
52
|
}
|
53
53
|
end
|
54
54
|
|
@@ -62,9 +62,7 @@ module MIDIJRuby
|
|
62
62
|
|
63
63
|
# @return [String]
|
64
64
|
def get_type
|
65
|
-
self.class.name.split(
|
65
|
+
self.class.name.split('::').last.downcase.to_sym
|
66
66
|
end
|
67
|
-
|
68
67
|
end
|
69
|
-
|
70
68
|
end
|
data/lib/midi-jruby/input.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MIDIJRuby
|
2
|
-
|
3
4
|
# Input device class
|
4
5
|
class Input
|
5
|
-
|
6
6
|
include Device
|
7
|
-
|
7
|
+
|
8
8
|
attr_reader :buffer
|
9
|
-
|
9
|
+
|
10
10
|
#
|
11
11
|
# An array of MIDI event hashes as such:
|
12
12
|
# [
|
@@ -25,10 +25,10 @@ module MIDIJRuby
|
|
25
25
|
@pointer = @buffer.length
|
26
26
|
messages
|
27
27
|
end
|
28
|
-
|
29
|
-
|
28
|
+
alias read gets
|
29
|
+
|
30
30
|
# Same as Input#gets but returns message data as string of hex digits:
|
31
|
-
# [
|
31
|
+
# [
|
32
32
|
# { :data => "904060", :timestamp => 904 },
|
33
33
|
# { :data => "804060", :timestamp => 1150 },
|
34
34
|
# { :data => "90447F", :timestamp => 1300 }
|
@@ -40,14 +40,14 @@ module MIDIJRuby
|
|
40
40
|
messages.each { |message| message[:data] = numeric_bytes_to_hex_string(message[:data]) }
|
41
41
|
messages
|
42
42
|
end
|
43
|
-
|
44
|
-
|
43
|
+
alias gets_bytestr gets_s
|
44
|
+
alias gets_hex gets_s
|
45
45
|
|
46
46
|
# Enable this the input for use; can be passed a block
|
47
47
|
# @param [Hash] options
|
48
48
|
# @param [Proc] block
|
49
49
|
# @return [Input] self
|
50
|
-
def enable(
|
50
|
+
def enable(_options = {})
|
51
51
|
unless @enabled
|
52
52
|
initialize_input
|
53
53
|
@enabled = true
|
@@ -62,8 +62,8 @@ module MIDIJRuby
|
|
62
62
|
self
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|
66
|
-
|
65
|
+
alias open enable
|
66
|
+
alias start enable
|
67
67
|
|
68
68
|
# Close this input
|
69
69
|
# @return [Boolean]
|
@@ -72,25 +72,25 @@ module MIDIJRuby
|
|
72
72
|
API.close_input(@device)
|
73
73
|
@enabled = false
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
# Select the first input
|
77
77
|
# @return [Input]
|
78
78
|
def self.first
|
79
|
-
Device.first(:input)
|
79
|
+
Device.first(:input)
|
80
80
|
end
|
81
81
|
|
82
82
|
# Select the last input
|
83
83
|
# @return [Input]
|
84
84
|
def self.last
|
85
|
-
Device.last(:input)
|
85
|
+
Device.last(:input)
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
# All inputs
|
89
89
|
# @return [Array<Input>]
|
90
90
|
def self.all
|
91
91
|
Device.all_by_type[:input]
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
private
|
95
95
|
|
96
96
|
# Initialize the input components
|
@@ -102,7 +102,7 @@ module MIDIJRuby
|
|
102
102
|
initialize_listener
|
103
103
|
true
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
# Initialize the input buffer
|
107
107
|
# @return [Boolean]
|
108
108
|
def initialize_buffer
|
@@ -110,46 +110,46 @@ module MIDIJRuby
|
|
110
110
|
@pointer = 0
|
111
111
|
def @buffer.clear
|
112
112
|
@pointer = 0
|
113
|
-
super
|
113
|
+
super
|
114
114
|
end
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
# Get a timestamp for the current time
|
118
118
|
# @return [Fixnum]
|
119
119
|
def now
|
120
120
|
now = Time.now.to_f - @start_time
|
121
121
|
now * 1000
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
# A hash of a MIDI message and corresponding timestamp
|
125
125
|
# @param [Array<Fixnum>] message
|
126
126
|
# @param [Fixnum] timestamp
|
127
127
|
# @return [Hash]
|
128
|
-
def get_message_formatted(message, timestamp)
|
129
|
-
{
|
130
|
-
:
|
131
|
-
:
|
128
|
+
def get_message_formatted(message, timestamp)
|
129
|
+
{
|
130
|
+
data: message,
|
131
|
+
timestamp: timestamp
|
132
132
|
}
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
# Messages in the buffer
|
136
136
|
# @return [Array<Array<Fixnum>>]
|
137
137
|
def queued_messages
|
138
138
|
@buffer.slice(@pointer, @buffer.length - @pointer)
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
# Are there any new messages in the buffer?
|
142
142
|
# @return [Boolean]
|
143
143
|
def queued_messages?
|
144
144
|
@pointer < @buffer.length
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
# Launch a background thread that collects messages
|
148
148
|
# @return [Thread]
|
149
149
|
def initialize_listener
|
150
150
|
@listener = Thread.new do
|
151
151
|
begin
|
152
|
-
loop do
|
152
|
+
loop do
|
153
153
|
while (messages = API.read_input(@device)).empty?
|
154
154
|
sleep(1.0/1000)
|
155
155
|
end
|
@@ -162,11 +162,11 @@ module MIDIJRuby
|
|
162
162
|
@listener.abort_on_exception = true
|
163
163
|
@listener
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
# @param [Array<Array<Fixnum>>]
|
167
167
|
# @return [Array<Array<Fixnum>>]
|
168
168
|
def add_to_buffer(messages)
|
169
|
-
@buffer += messages.compact.map do |message|
|
169
|
+
@buffer += messages.compact.map do |message|
|
170
170
|
get_message_formatted(message, now)
|
171
171
|
end
|
172
172
|
end
|
@@ -175,14 +175,12 @@ module MIDIJRuby
|
|
175
175
|
# @param [Array<Fixnum>] bytes
|
176
176
|
# @return [String]
|
177
177
|
def numeric_bytes_to_hex_string(bytes)
|
178
|
-
string_bytes = bytes.map do |byte|
|
178
|
+
string_bytes = bytes.map do |byte|
|
179
179
|
string = byte.to_s(16).upcase
|
180
180
|
string = "0#{string}" if byte < 0x10
|
181
181
|
string
|
182
182
|
end
|
183
183
|
string_bytes.join
|
184
|
-
end
|
185
|
-
|
184
|
+
end
|
186
185
|
end
|
187
|
-
|
188
186
|
end
|
data/lib/midi-jruby/output.rb
CHANGED
@@ -1,51 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MIDIJRuby
|
2
|
-
|
3
4
|
# Output device class
|
4
5
|
class Output
|
5
|
-
|
6
6
|
include Device
|
7
|
-
|
7
|
+
|
8
8
|
# Close this output
|
9
9
|
# @return [Boolean]
|
10
10
|
def close
|
11
11
|
API.close_output(@device)
|
12
12
|
@enabled = false
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
# Output the given MIDI message
|
16
|
-
# @param [String] data A MIDI message expressed as a string of hex digits
|
16
|
+
# @param [String] data A MIDI message expressed as a string of hex digits
|
17
17
|
# @return [Boolean]
|
18
18
|
def puts_s(data)
|
19
19
|
bytes = hex_string_to_numeric_bytes(data)
|
20
20
|
puts_bytes(*bytes)
|
21
21
|
end
|
22
|
-
|
23
|
-
|
22
|
+
alias puts_bytestr puts_s
|
23
|
+
alias puts_hex puts_s
|
24
24
|
|
25
25
|
# Output the given MIDI message
|
26
|
-
# @param [*Fixnum] data A MIDI messages expressed as Numeric bytes
|
26
|
+
# @param [*Fixnum] data A MIDI messages expressed as Numeric bytes
|
27
27
|
# @return [Boolean]
|
28
28
|
def puts_bytes(*data)
|
29
29
|
API.write_output(@device, data)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# Output the given MIDI message
|
33
|
-
# @param [*Fixnum, *String] args
|
33
|
+
# @param [*Fixnum, *String] args
|
34
34
|
# @return [Boolean]
|
35
35
|
def puts(*args)
|
36
36
|
case args.first
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
when Array then args.each { |arg| puts(*arg) }
|
38
|
+
when Numeric then puts_bytes(*args)
|
39
|
+
when String then puts_bytestr(*args)
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
43
|
-
|
42
|
+
alias write puts
|
43
|
+
|
44
44
|
# Enable this device; also takes a block
|
45
45
|
# @param [Hash] options
|
46
46
|
# @param [Proc] block
|
47
47
|
# @return [Output]
|
48
|
-
def enable(
|
48
|
+
def enable(_options = {})
|
49
49
|
unless @enabled
|
50
50
|
API.enable_output(@device)
|
51
51
|
@enabled = true
|
@@ -60,21 +60,21 @@ module MIDIJRuby
|
|
60
60
|
self
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
alias open enable
|
64
|
+
alias start enable
|
65
|
+
|
66
66
|
# Select the first output
|
67
67
|
# @return [Output]
|
68
68
|
def self.first
|
69
|
-
Device.first(:output)
|
69
|
+
Device.first(:output)
|
70
70
|
end
|
71
71
|
|
72
72
|
# Select the last output
|
73
73
|
# @return [Output]
|
74
74
|
def self.last
|
75
|
-
Device.last(:output)
|
75
|
+
Device.last(:output)
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
# All outputs
|
79
79
|
# @return [Array<Output>]
|
80
80
|
def self.all
|
@@ -89,12 +89,10 @@ module MIDIJRuby
|
|
89
89
|
def hex_string_to_numeric_bytes(string)
|
90
90
|
string = string.dup
|
91
91
|
bytes = []
|
92
|
-
until (string_byte = string.slice!(0,2)) ==
|
92
|
+
until (string_byte = string.slice!(0, 2)) == ''
|
93
93
|
bytes << string_byte.hex
|
94
94
|
end
|
95
95
|
bytes
|
96
96
|
end
|
97
|
-
|
98
97
|
end
|
99
|
-
|
100
98
|
end
|
data/lib/midi-jruby.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
4
|
# MIDI-JRuby
|
3
5
|
# Realtime MIDI IO in JRuby using the javax.sound.midi API
|
4
6
|
#
|
5
|
-
# (c) 2011-
|
7
|
+
# (c) 2011-2022 Ari Russo
|
6
8
|
# Licensed under Apache 2.0
|
7
9
|
# https://github.com/arirusso/midi-jruby
|
8
10
|
#
|
9
11
|
|
10
12
|
# libs
|
11
|
-
require
|
12
|
-
require
|
13
|
+
require 'java'
|
14
|
+
require 'forwardable'
|
13
15
|
|
14
16
|
# modules
|
15
|
-
require
|
16
|
-
require
|
17
|
+
require 'midi-jruby/api'
|
18
|
+
require 'midi-jruby/device'
|
17
19
|
|
18
20
|
# classes
|
19
|
-
require
|
20
|
-
require
|
21
|
+
require 'midi-jruby/input'
|
22
|
+
require 'midi-jruby/output'
|
21
23
|
|
22
24
|
module MIDIJRuby
|
23
|
-
|
24
|
-
VERSION = "0.1.6"
|
25
|
-
|
25
|
+
VERSION = '0.2.0'
|
26
26
|
end
|
metadata
CHANGED
@@ -1,95 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midi-jruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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:
|
11
|
+
date: 2022-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: '
|
18
|
+
version: '13.0'
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
name:
|
23
|
-
prerelease: false
|
24
|
-
type: :development
|
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
|
-
requirement: !ruby/object:Gem::Requirement
|
35
|
-
requirements:
|
36
|
-
- - "~>"
|
37
|
-
- !ruby/object:Gem::Version
|
38
|
-
version: '1.1'
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: 1.1.0
|
42
|
-
name: mocha
|
21
|
+
version: 13.0.6
|
22
|
+
name: rake
|
43
23
|
prerelease: false
|
44
24
|
type: :development
|
45
25
|
version_requirements: !ruby/object:Gem::Requirement
|
46
26
|
requirements:
|
47
27
|
- - "~>"
|
48
28
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
29
|
+
version: '13.0'
|
50
30
|
- - ">="
|
51
31
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
32
|
+
version: 13.0.6
|
53
33
|
- !ruby/object:Gem::Dependency
|
54
34
|
requirement: !ruby/object:Gem::Requirement
|
55
35
|
requirements:
|
56
36
|
- - "~>"
|
57
37
|
- !ruby/object:Gem::Version
|
58
|
-
version: '
|
38
|
+
version: '3.11'
|
59
39
|
- - ">="
|
60
40
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
name:
|
41
|
+
version: 3.11.0
|
42
|
+
name: rspec
|
63
43
|
prerelease: false
|
64
44
|
type: :development
|
65
45
|
version_requirements: !ruby/object:Gem::Requirement
|
66
46
|
requirements:
|
67
47
|
- - "~>"
|
68
48
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
49
|
+
version: '3.11'
|
70
50
|
- - ">="
|
71
51
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
52
|
+
version: 3.11.0
|
73
53
|
- !ruby/object:Gem::Dependency
|
74
54
|
requirement: !ruby/object:Gem::Requirement
|
75
55
|
requirements:
|
76
56
|
- - "~>"
|
77
57
|
- !ruby/object:Gem::Version
|
78
|
-
version: '1.
|
58
|
+
version: '1.10'
|
79
59
|
- - ">="
|
80
60
|
- !ruby/object:Gem::Version
|
81
|
-
version: 1.
|
82
|
-
name:
|
61
|
+
version: 1.10.0
|
62
|
+
name: rubocop
|
83
63
|
prerelease: false
|
84
64
|
type: :development
|
85
65
|
version_requirements: !ruby/object:Gem::Requirement
|
86
66
|
requirements:
|
87
67
|
- - "~>"
|
88
68
|
- !ruby/object:Gem::Version
|
89
|
-
version: '1.
|
69
|
+
version: '1.10'
|
90
70
|
- - ">="
|
91
71
|
- !ruby/object:Gem::Version
|
92
|
-
version: 1.
|
72
|
+
version: 1.10.0
|
93
73
|
description: Realtime MIDI IO with JRuby using the javax.sound.midi API
|
94
74
|
email:
|
95
75
|
- ari.russo@gmail.com
|
@@ -104,9 +84,6 @@ files:
|
|
104
84
|
- lib/midi-jruby/device.rb
|
105
85
|
- lib/midi-jruby/input.rb
|
106
86
|
- lib/midi-jruby/output.rb
|
107
|
-
- test/helper.rb
|
108
|
-
- test/input_buffer_test.rb
|
109
|
-
- test/io_test.rb
|
110
87
|
homepage: http://github.com/arirusso/midi-jruby
|
111
88
|
licenses:
|
112
89
|
- Apache-2.0
|
@@ -124,10 +101,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
101
|
requirements:
|
125
102
|
- - ">="
|
126
103
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
104
|
+
version: '0'
|
128
105
|
requirements: []
|
129
|
-
|
130
|
-
rubygems_version: 2.6.8
|
106
|
+
rubygems_version: 3.2.29
|
131
107
|
signing_key:
|
132
108
|
specification_version: 4
|
133
109
|
summary: Realtime MIDI IO with JRuby
|
data/test/helper.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
$:.unshift(File.join("..", "lib"))
|
2
|
-
|
3
|
-
require "minitest/autorun"
|
4
|
-
require "shoulda-context"
|
5
|
-
require "midi-jruby"
|
6
|
-
|
7
|
-
module TestHelper
|
8
|
-
|
9
|
-
extend self
|
10
|
-
|
11
|
-
# http://stackoverflow.com/questions/8148898/java-midi-in-mac-osx-broken
|
12
|
-
def sysex_ok?
|
13
|
-
ENV["_system_name"] != "OSX"
|
14
|
-
end
|
15
|
-
|
16
|
-
def bytestrs_to_ints(arr)
|
17
|
-
data = arr.map { |m| m[:data] }.join
|
18
|
-
output = []
|
19
|
-
until (bytestr = data.slice!(0,2)).eql?("")
|
20
|
-
output << bytestr.hex
|
21
|
-
end
|
22
|
-
output
|
23
|
-
end
|
24
|
-
|
25
|
-
def numeric_messages
|
26
|
-
messages = [
|
27
|
-
[0x90, 100, 100], # note on
|
28
|
-
[0x90, 43, 100], # note on
|
29
|
-
[0x90, 76, 100], # note on
|
30
|
-
[0x90, 60, 100], # note on
|
31
|
-
[0x80, 100, 100] # note off
|
32
|
-
]
|
33
|
-
if sysex_ok?
|
34
|
-
messages << [0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7]
|
35
|
-
end
|
36
|
-
messages
|
37
|
-
end
|
38
|
-
|
39
|
-
def string_messages
|
40
|
-
messages = [
|
41
|
-
"906440", # note on
|
42
|
-
"804340" # note off
|
43
|
-
]
|
44
|
-
if sysex_ok?
|
45
|
-
messages << "F04110421240007F0041F7"
|
46
|
-
end
|
47
|
-
messages
|
48
|
-
end
|
49
|
-
|
50
|
-
def input
|
51
|
-
MIDIJRuby::Input.first
|
52
|
-
end
|
53
|
-
|
54
|
-
def output
|
55
|
-
MIDIJRuby::Output.all[1]
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
data/test/input_buffer_test.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class MIDIJRuby::InputBufferTest < Minitest::Test
|
4
|
-
|
5
|
-
context "MIDIJRuby" do
|
6
|
-
|
7
|
-
setup do
|
8
|
-
@input = TestHelper.input.open
|
9
|
-
@output = TestHelper.output.open
|
10
|
-
@input.buffer.clear
|
11
|
-
@pointer = 0
|
12
|
-
end
|
13
|
-
|
14
|
-
teardown do
|
15
|
-
@input.close
|
16
|
-
@output.close
|
17
|
-
end
|
18
|
-
|
19
|
-
context "Source#buffer" do
|
20
|
-
|
21
|
-
setup do
|
22
|
-
@messages = TestHelper.numeric_messages
|
23
|
-
@messages_arr = @messages.inject(&:+).flatten
|
24
|
-
@received_arr = []
|
25
|
-
end
|
26
|
-
|
27
|
-
should "have the correct messages in the buffer" do
|
28
|
-
bytes = []
|
29
|
-
@messages.each do |message|
|
30
|
-
p "sending: #{message}"
|
31
|
-
@output.puts(message)
|
32
|
-
bytes += message
|
33
|
-
|
34
|
-
sleep(1)
|
35
|
-
|
36
|
-
buffer = @input.buffer.map { |m| m[:data] }.flatten
|
37
|
-
p "received: #{buffer.to_s}"
|
38
|
-
assert_equal(bytes, buffer)
|
39
|
-
end
|
40
|
-
assert_equal(bytes.length, @input.buffer.map { |m| m[:data] }.flatten.length)
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
data/test/io_test.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class MIDIJRuby::IOTest < Minitest::Test
|
4
|
-
|
5
|
-
# These tests assume that TestOutput is connected to TestInput
|
6
|
-
context "MIDIJRuby" do
|
7
|
-
|
8
|
-
setup do
|
9
|
-
@input = TestHelper.input.open
|
10
|
-
@output = TestHelper.output.open
|
11
|
-
@input.buffer.clear
|
12
|
-
@pointer = 0
|
13
|
-
end
|
14
|
-
|
15
|
-
teardown do
|
16
|
-
@input.close
|
17
|
-
@output.close
|
18
|
-
end
|
19
|
-
|
20
|
-
context "full IO" do
|
21
|
-
|
22
|
-
context "using Arrays" do
|
23
|
-
|
24
|
-
setup do
|
25
|
-
@messages = TestHelper.numeric_messages
|
26
|
-
@messages_arr = @messages.inject(&:+).flatten
|
27
|
-
@received_arr = []
|
28
|
-
end
|
29
|
-
|
30
|
-
should "do IO" do
|
31
|
-
@messages.each do |message|
|
32
|
-
|
33
|
-
p "sending: #{message}"
|
34
|
-
|
35
|
-
@output.puts(message)
|
36
|
-
sleep(1)
|
37
|
-
received = @input.gets.map { |m| m[:data] }.flatten
|
38
|
-
|
39
|
-
p "received: #{received}"
|
40
|
-
|
41
|
-
assert_equal(@messages_arr.slice(@pointer, received.length), received)
|
42
|
-
@pointer += received.length
|
43
|
-
@received_arr += received
|
44
|
-
end
|
45
|
-
assert_equal(@messages_arr.length, @received_arr.length)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "using byte Strings" do
|
50
|
-
|
51
|
-
setup do
|
52
|
-
@messages = TestHelper.string_messages
|
53
|
-
@messages_str = @messages.join
|
54
|
-
@received_str = ""
|
55
|
-
end
|
56
|
-
|
57
|
-
should "do IO" do
|
58
|
-
@messages.each do |message|
|
59
|
-
|
60
|
-
p "sending: #{message}"
|
61
|
-
|
62
|
-
@output.puts(message)
|
63
|
-
sleep(1)
|
64
|
-
received = @input.gets_bytestr.map { |m| m[:data] }.flatten.join
|
65
|
-
p "received: #{received}"
|
66
|
-
|
67
|
-
assert_equal(@messages_str.slice(@pointer, received.length), received)
|
68
|
-
@pointer += received.length
|
69
|
-
@received_str += received
|
70
|
-
end
|
71
|
-
assert_equal(@messages_str, @received_str)
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|