midi-nibbler 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +2 -2
- data/README.md +139 -0
- data/lib/nibbler.rb +13 -10
- data/lib/nibbler/hex_processor.rb +47 -0
- data/lib/nibbler/midi-message.rb +53 -0
- data/lib/nibbler/midilib.rb +67 -0
- data/lib/nibbler/parser.rb +86 -94
- data/lib/nibbler/session.rb +134 -0
- data/lib/nibbler/type_conversion.rb +17 -10
- data/test/helper.rb +3 -9
- data/test/{test_hex_char_array_filter.rb → hex_processor_test.rb} +18 -23
- data/test/midi_message_test.rb +126 -0
- data/test/midilib_test.rb +131 -0
- data/test/{test_parser_buffer.rb → parser_buffer_test.rb} +3 -8
- data/test/{test_parser_rejected.rb → parser_rejected_test.rb} +9 -14
- data/test/parser_test.rb +188 -0
- data/test/session_test.rb +135 -0
- data/test/{test_type_conversion.rb → type_conversion_test.rb} +6 -11
- metadata +60 -65
- data/README.rdoc +0 -115
- data/lib/nibbler/hex_char_array_filter.rb +0 -37
- data/lib/nibbler/midi-message_factory.rb +0 -54
- data/lib/nibbler/midilib_factory.rb +0 -66
- data/lib/nibbler/nibbler.rb +0 -89
- data/test/test_midi_message_factory.rb +0 -130
- data/test/test_midilib_factory.rb +0 -137
- data/test/test_nibbler.rb +0 -120
- data/test/test_parser.rb +0 -159
@@ -1,130 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
class MIDIMessageFactoryTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Nibbler
|
8
|
-
include TestHelper
|
9
|
-
|
10
|
-
def test_note_off
|
11
|
-
factory = MIDIMessageFactory.new
|
12
|
-
msg = factory.note_off(0, 0x40, 0x40)
|
13
|
-
assert_equal(MIDIMessage::NoteOff, msg.class)
|
14
|
-
assert_equal(0, msg.channel)
|
15
|
-
assert_equal(0x40, msg.note)
|
16
|
-
assert_equal(0x40, msg.velocity)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_note_on
|
20
|
-
factory = MIDIMessageFactory.new
|
21
|
-
msg = factory.note_on(0x0, 0x40, 0x40)
|
22
|
-
assert_equal(MIDIMessage::NoteOn, msg.class)
|
23
|
-
assert_equal(0, msg.channel)
|
24
|
-
assert_equal(0x40, msg.note)
|
25
|
-
assert_equal(0x40, msg.velocity)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_polyphonic_aftertouch
|
29
|
-
factory = MIDIMessageFactory.new
|
30
|
-
msg = factory.polyphonic_aftertouch(0x1, 0x40, 0x40)
|
31
|
-
assert_equal(MIDIMessage::PolyphonicAftertouch, msg.class)
|
32
|
-
assert_equal(1, msg.channel)
|
33
|
-
assert_equal(0x40, msg.note)
|
34
|
-
assert_equal(0x40, msg.value)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_control_change
|
38
|
-
factory = MIDIMessageFactory.new
|
39
|
-
msg = factory.control_change(0x2, 0x20, 0x20)
|
40
|
-
assert_equal(MIDIMessage::ControlChange, msg.class)
|
41
|
-
assert_equal(msg.channel, 2)
|
42
|
-
assert_equal(0x20, msg.index)
|
43
|
-
assert_equal(0x20, msg.value)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_program_change
|
47
|
-
factory = MIDIMessageFactory.new
|
48
|
-
msg = factory.program_change(0x3, 0x40)
|
49
|
-
assert_equal(MIDIMessage::ProgramChange, msg.class)
|
50
|
-
assert_equal(3, msg.channel)
|
51
|
-
assert_equal(0x40, msg.program)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_channel_aftertouch
|
55
|
-
factory = MIDIMessageFactory.new
|
56
|
-
msg = factory.channel_aftertouch(0x3, 0x50)
|
57
|
-
assert_equal(MIDIMessage::ChannelAftertouch, msg.class)
|
58
|
-
assert_equal(3, msg.channel)
|
59
|
-
assert_equal(0x50, msg.value)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_pitch_bend
|
63
|
-
factory = MIDIMessageFactory.new
|
64
|
-
msg = factory.pitch_bend(0x0, 0x20, 0x00) # center
|
65
|
-
assert_equal(MIDIMessage::PitchBend, msg.class)
|
66
|
-
assert_equal(0, msg.channel)
|
67
|
-
assert_equal(0x20, msg.low)
|
68
|
-
assert_equal(0x00, msg.high)
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_system_exclusive_command
|
72
|
-
factory = MIDIMessageFactory.new
|
73
|
-
msg = factory.system_exclusive(0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7)
|
74
|
-
assert_equal(MIDIMessage::SystemExclusive::Command, msg.class)
|
75
|
-
assert_equal([0xF0, 0x41, 0x10, 0x42, 0x12, [0x40, 0x00, 0x7F], [0x00], 0x41, 0xF7], msg.to_a)
|
76
|
-
assert_equal([0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7], msg.to_bytes)
|
77
|
-
assert_equal("F04110421240007F0041F7", msg.to_hex_s)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_system_exclusive_request
|
81
|
-
factory = MIDIMessageFactory.new
|
82
|
-
msg = factory.system_exclusive(0xF0, 0x41, 0x10, 0x42, 0x11, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7)
|
83
|
-
assert_equal(MIDIMessage::SystemExclusive::Request, msg.class)
|
84
|
-
assert_equal([0xF0, 0x41, 0x10, 0x42, 0x11, [0x40, 0x00, 0x7F], [0x00], 0x41, 0xF7], msg.to_a)
|
85
|
-
assert_equal([0xF0, 0x41, 0x10, 0x42, 0x11, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7], msg.to_bytes)
|
86
|
-
assert_equal("F04110421140007F0041F7", msg.to_hex_s)
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_system_exclusive_node
|
90
|
-
factory = MIDIMessageFactory.new
|
91
|
-
msg = factory.system_exclusive(0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7)
|
92
|
-
node = msg.node
|
93
|
-
assert_equal(MIDIMessage::SystemExclusive::Node, node.class)
|
94
|
-
assert_equal(0x41, node.manufacturer_id)
|
95
|
-
assert_equal(0x42, node.model_id)
|
96
|
-
assert_equal(0x10, node.device_id)
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_system_common_generic_3_bytes
|
100
|
-
factory = MIDIMessageFactory.new
|
101
|
-
msg = factory.system_common(0x1, 0x50, 0xA0)
|
102
|
-
assert_equal(MIDIMessage::SystemCommon, msg.class)
|
103
|
-
assert_equal(1, msg.status[1])
|
104
|
-
assert_equal(0x50, msg.data[0])
|
105
|
-
assert_equal(0xA0, msg.data[1])
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_system_common_generic_2_bytes
|
109
|
-
nibbler = Nibbler.new
|
110
|
-
msg = nibbler.parse(0xF1, 0x50)
|
111
|
-
assert_equal(MIDIMessage::SystemCommon, msg.class)
|
112
|
-
assert_equal(1, msg.status[1])
|
113
|
-
assert_equal(0x50, msg.data[0])
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_system_common_generic_1_byte
|
117
|
-
nibbler = Nibbler.new
|
118
|
-
msg = nibbler.parse(0xF1)
|
119
|
-
assert_equal(MIDIMessage::SystemCommon, msg.class)
|
120
|
-
assert_equal(1, msg.status[1])
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_system_realtime
|
124
|
-
nibbler = Nibbler.new
|
125
|
-
msg = nibbler.parse(0xF8)
|
126
|
-
assert_equal(MIDIMessage::SystemRealtime, msg.class)
|
127
|
-
assert_equal(8, msg.id)
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
class MidilibFactoryTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Nibbler
|
8
|
-
include TestHelper
|
9
|
-
|
10
|
-
Parser.new(:message_lib => :midilib)
|
11
|
-
|
12
|
-
def test_note_off
|
13
|
-
factory = MidilibFactory.new
|
14
|
-
msg = factory.note_off(0x0, 0x40, 0x40)
|
15
|
-
assert_equal(MIDI::NoteOff, msg.class)
|
16
|
-
assert_equal(0, msg.channel)
|
17
|
-
assert_equal(0x40, msg.note)
|
18
|
-
assert_equal(0x40, msg.velocity)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_note_on
|
22
|
-
factory = MidilibFactory.new
|
23
|
-
msg = factory.note_on(0x0, 0x40, 0x40)
|
24
|
-
assert_equal(MIDI::NoteOn, msg.class)
|
25
|
-
assert_equal(0, msg.channel)
|
26
|
-
assert_equal(0x40, msg.note)
|
27
|
-
assert_equal(0x40, msg.velocity)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_polyphonic_aftertouch
|
31
|
-
factory = MidilibFactory.new
|
32
|
-
msg = factory.polyphonic_aftertouch(0x1, 0x40, 0x40)
|
33
|
-
assert_equal(MIDI::PolyPressure, msg.class)
|
34
|
-
assert_equal(1, msg.channel)
|
35
|
-
assert_equal(0x40, msg.note)
|
36
|
-
assert_equal(0x40, msg.pressure)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_control_change
|
40
|
-
factory = MidilibFactory.new
|
41
|
-
msg = factory.control_change(0x2, 0x20, 0x20)
|
42
|
-
assert_equal(MIDI::Controller, msg.class)
|
43
|
-
assert_equal(msg.channel, 2)
|
44
|
-
assert_equal(0x20, msg.controller)
|
45
|
-
assert_equal(0x20, msg.value)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_program_change
|
49
|
-
factory = MidilibFactory.new
|
50
|
-
msg = factory.program_change(0x3, 0x40)
|
51
|
-
assert_equal(MIDI::ProgramChange, msg.class)
|
52
|
-
assert_equal(3, msg.channel)
|
53
|
-
assert_equal(0x40, msg.program)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_channel_aftertouch
|
57
|
-
factory = MidilibFactory.new
|
58
|
-
msg = factory.channel_aftertouch(0x3, 0x50)
|
59
|
-
assert_equal(MIDI::ChannelPressure, msg.class)
|
60
|
-
assert_equal(3, msg.channel)
|
61
|
-
assert_equal(0x50, msg.pressure)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_pitch_bend
|
65
|
-
# to-do handle the midilib lsb/msb
|
66
|
-
# right now the second data byte is being thrown away
|
67
|
-
factory = MidilibFactory.new
|
68
|
-
msg = factory.pitch_bend(0x0, 0x20, 0x00)
|
69
|
-
assert_equal(MIDI::PitchBend, msg.class)
|
70
|
-
assert_equal(0, msg.channel)
|
71
|
-
assert_equal(0x20, msg.value)
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_system_exclusive
|
75
|
-
factory = MidilibFactory.new
|
76
|
-
msg = factory.system_exclusive(0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7)
|
77
|
-
assert_equal(MIDI::SystemExclusive, msg.class)
|
78
|
-
assert_equal([0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7], msg.data)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_song_pointer
|
82
|
-
factory = MidilibFactory.new
|
83
|
-
msg = factory.system_common(0x2, 0xF0)
|
84
|
-
assert_equal(MIDI::SongPointer, msg.class)
|
85
|
-
assert_equal(0xF0, msg.pointer)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_song_select
|
89
|
-
factory = MidilibFactory.new
|
90
|
-
msg = factory.system_common(0x3, 0xA0)
|
91
|
-
assert_equal(MIDI::SongSelect, msg.class)
|
92
|
-
assert_equal(0xA0, msg.song)
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_tune_request
|
96
|
-
factory = MidilibFactory.new
|
97
|
-
msg = factory.system_common(0x6)
|
98
|
-
assert_equal(MIDI::TuneRequest, msg.class)
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_clock
|
102
|
-
factory = MidilibFactory.new
|
103
|
-
msg = factory.system_realtime(0x8)
|
104
|
-
assert_equal(MIDI::Clock, msg.class)
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_start
|
108
|
-
factory = MidilibFactory.new
|
109
|
-
msg = factory.system_realtime(0xA)
|
110
|
-
assert_equal(MIDI::Start, msg.class)
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_continue
|
114
|
-
factory = MidilibFactory.new
|
115
|
-
msg = factory.system_realtime(0xB)
|
116
|
-
assert_equal(MIDI::Continue, msg.class)
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_stop
|
120
|
-
factory = MidilibFactory.new
|
121
|
-
msg = factory.system_realtime(0xC)
|
122
|
-
assert_equal(MIDI::Stop, msg.class)
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_stop
|
126
|
-
factory = MidilibFactory.new
|
127
|
-
msg = factory.system_realtime(0xE)
|
128
|
-
assert_equal(MIDI::ActiveSense, msg.class)
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_stop
|
132
|
-
factory = MidilibFactory.new
|
133
|
-
msg = factory.system_realtime(0xF)
|
134
|
-
assert_equal(MIDI::SystemReset, msg.class)
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
data/test/test_nibbler.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
class NibblerTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Nibbler
|
8
|
-
include TestHelper
|
9
|
-
|
10
|
-
def test_varying_length_strings
|
11
|
-
nibbler = Nibbler.new
|
12
|
-
msg = nibbler.parse("9", "04", "040")
|
13
|
-
assert_equal(MIDIMessage::NoteOn, msg.class)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_note_off
|
17
|
-
nibbler = Nibbler.new
|
18
|
-
msg = nibbler.parse(0x80, 0x40, 0x40)
|
19
|
-
assert_equal(MIDIMessage::NoteOff, msg.class)
|
20
|
-
assert_equal(0, msg.channel)
|
21
|
-
assert_equal(0x40, msg.note)
|
22
|
-
assert_equal(0x40, msg.velocity)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_note_on
|
26
|
-
nibbler = Nibbler.new
|
27
|
-
msg = nibbler.parse(0x90, 0x40, 0x40)
|
28
|
-
assert_equal(MIDIMessage::NoteOn, msg.class)
|
29
|
-
assert_equal(0, msg.channel)
|
30
|
-
assert_equal(0x40, msg.note)
|
31
|
-
assert_equal(0x40, msg.velocity)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_timestamp
|
35
|
-
nibbler = Nibbler.new
|
36
|
-
stamp = Time.now.to_i
|
37
|
-
outp = nibbler.parse(0x90, 0x40, 0x40, :timestamp => stamp)
|
38
|
-
msg = outp[:messages]
|
39
|
-
assert_equal(MIDIMessage::NoteOn, msg.class)
|
40
|
-
assert_equal(0, msg.channel)
|
41
|
-
assert_equal(0x40, msg.note)
|
42
|
-
assert_equal(0x40, msg.velocity)
|
43
|
-
assert_equal(stamp, outp[:timestamp])
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_polyphonic_aftertouch
|
47
|
-
nibbler = Nibbler.new
|
48
|
-
msg = nibbler.parse(0xA1, 0x40, 0x40)
|
49
|
-
assert_equal(MIDIMessage::PolyphonicAftertouch, msg.class)
|
50
|
-
assert_equal(1, msg.channel)
|
51
|
-
assert_equal(0x40, msg.note)
|
52
|
-
assert_equal(0x40, msg.value)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_control_change
|
56
|
-
nibbler = Nibbler.new
|
57
|
-
msg = nibbler.parse(0xB2, 0x20, 0x20)
|
58
|
-
assert_equal(MIDIMessage::ControlChange, msg.class)
|
59
|
-
assert_equal(msg.channel, 2)
|
60
|
-
assert_equal(0x20, msg.index)
|
61
|
-
assert_equal(0x20, msg.value)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_program_change
|
65
|
-
nibbler = Nibbler.new
|
66
|
-
msg = nibbler.parse(0xC3, 0x40)
|
67
|
-
assert_equal(MIDIMessage::ProgramChange, msg.class)
|
68
|
-
assert_equal(3, msg.channel)
|
69
|
-
assert_equal(0x40, msg.program)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_channel_aftertouch
|
73
|
-
nibbler = Nibbler.new
|
74
|
-
msg = nibbler.parse(0xD3, 0x50)
|
75
|
-
assert_equal(MIDIMessage::ChannelAftertouch, msg.class)
|
76
|
-
assert_equal(3, msg.channel)
|
77
|
-
assert_equal(0x50, msg.value)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_pitch_bend
|
81
|
-
nibbler = Nibbler.new
|
82
|
-
msg = nibbler.parse(0xE0, 0x20, 0x00) # center
|
83
|
-
assert_equal(MIDIMessage::PitchBend, msg.class)
|
84
|
-
assert_equal(0, msg.channel)
|
85
|
-
assert_equal(0x20, msg.low)
|
86
|
-
assert_equal(0x00, msg.high)
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_system_common_generic_3_bytes
|
90
|
-
nibbler = Nibbler.new
|
91
|
-
msg = nibbler.parse(0xF1, 0x50, 0xA0)
|
92
|
-
assert_equal(MIDIMessage::SystemCommon, msg.class)
|
93
|
-
assert_equal(1, msg.status[1])
|
94
|
-
assert_equal(0x50, msg.data[0])
|
95
|
-
assert_equal(0xA0, msg.data[1])
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_system_common_generic_2_bytes
|
99
|
-
nibbler = Nibbler.new
|
100
|
-
msg = nibbler.parse(0xF1, 0x50)
|
101
|
-
assert_equal(MIDIMessage::SystemCommon, msg.class)
|
102
|
-
assert_equal(1, msg.status[1])
|
103
|
-
assert_equal(0x50, msg.data[0])
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_system_common_generic_1_byte
|
107
|
-
nibbler = Nibbler.new
|
108
|
-
msg = nibbler.parse(0xF1)
|
109
|
-
assert_equal(MIDIMessage::SystemCommon, msg.class)
|
110
|
-
assert_equal(1, msg.status[1])
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_system_realtime
|
114
|
-
nibbler = Nibbler.new
|
115
|
-
msg = nibbler.parse(0xF8)
|
116
|
-
assert_equal(MIDIMessage::SystemRealtime, msg.class)
|
117
|
-
assert_equal(8, msg.id)
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
data/test/test_parser.rb
DELETED
@@ -1,159 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
class ParserTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Nibbler
|
8
|
-
include TestHelper
|
9
|
-
|
10
|
-
def test_lookahead
|
11
|
-
parser = Parser.new
|
12
|
-
num = 6
|
13
|
-
parser.send(:buffer=, ["9", "0", "4", "0", "5", "0"])
|
14
|
-
parser.send(:populate_current)
|
15
|
-
outp = parser.send(:lookahead, num) { |nibble_2, bytes| [nibble_2, bytes] }
|
16
|
-
assert_equal([0,[0x90, 0x40, 0x50]], outp[0])
|
17
|
-
assert_equal(["9", "0", "4", "0", "5", "0"], outp[1])
|
18
|
-
assert_equal([], parser.send(:current))
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_lookahead_trailing
|
22
|
-
parser = Parser.new
|
23
|
-
num = 6
|
24
|
-
parser.send(:buffer=, ["9", "0", "4", "0", "5", "0", "5", "0"])
|
25
|
-
parser.send(:populate_current)
|
26
|
-
outp = parser.send(:lookahead, num) { |nibble_2, bytes| [nibble_2, bytes] }
|
27
|
-
assert_equal([0,[0x90, 0x40, 0x50]], outp[0])
|
28
|
-
assert_equal(["9", "0", "4", "0", "5", "0"], outp[1])
|
29
|
-
assert_equal(["5", "0"], parser.send(:current))
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_lookahead_too_short
|
33
|
-
parser = Parser.new
|
34
|
-
num = 6
|
35
|
-
parser.send(:buffer=, ["9", "0", "4"])
|
36
|
-
parser.send(:populate_current)
|
37
|
-
outp = parser.send(:lookahead, num) { |nibble_2, bytes| [nibble_2, bytes] }
|
38
|
-
assert_equal(nil, outp[0])
|
39
|
-
assert_equal([], outp[1])
|
40
|
-
assert_equal(["9", "0", "4"], parser.send(:current))
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_lookahead_sysex
|
44
|
-
parser = Parser.new
|
45
|
-
parser.send(:buffer=, "F04110421240007F0041F750".split(//))
|
46
|
-
parser.send(:populate_current)
|
47
|
-
outp = parser.send(:lookahead_sysex) { |b| b }
|
48
|
-
assert_equal([0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7], outp[0])
|
49
|
-
assert_equal("F04110421240007F0041F7".split(//), outp[1])
|
50
|
-
assert_equal(["5", "0"], parser.send(:current))
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_lookahead_sysex_too_short
|
54
|
-
parser = Parser.new
|
55
|
-
parser.send(:buffer=, ["9", "0", "4"])
|
56
|
-
parser.send(:populate_current)
|
57
|
-
outp = parser.send(:lookahead_sysex) { |b| b }
|
58
|
-
assert_equal(nil, outp[0])
|
59
|
-
assert_equal([], outp[1])
|
60
|
-
assert_equal(["9", "0", "4"], parser.send(:current))
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_process
|
64
|
-
parser = Parser.new
|
65
|
-
short = ['9', '0', '4', '0', '5', '0', '5', '0']
|
66
|
-
outp = parser.send(:process, short)
|
67
|
-
|
68
|
-
assert_equal(MIDIMessage::NoteOn, outp[:messages].first.class)
|
69
|
-
assert_equal(['5', '0'], parser.buffer)
|
70
|
-
assert_equal(['9', '0', '4', '0', '5', '0'], outp[:processed])
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_process_running_status
|
74
|
-
parser = Parser.new
|
75
|
-
two_msgs = ['9', '0', '4', '0', '5', '0', "4", "0", "6", "0"]
|
76
|
-
outp = parser.send(:process, two_msgs)
|
77
|
-
|
78
|
-
assert_equal(MIDIMessage::NoteOn, outp[:messages][0].class)
|
79
|
-
#assert_equal(MIDIMessage::NoteOn, outp[:messages][1].class)
|
80
|
-
assert_equal([], parser.buffer)
|
81
|
-
assert_equal(['9', '0', '4', '0', '5', '0', "4", "0", "6", "0"], outp[:processed])
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_process_multiple_overlapping_calls
|
85
|
-
parser = Parser.new
|
86
|
-
short = ['9', '0', '4', '0', '5', '0', '9', '0']
|
87
|
-
short2 = ["3", "0", "2", "0", "1", "0"]
|
88
|
-
|
89
|
-
outp = parser.send(:process, short)
|
90
|
-
assert_equal(MIDIMessage::NoteOn, outp[:messages].first.class)
|
91
|
-
assert_equal(['9', '0'], parser.buffer)
|
92
|
-
assert_equal(['9', '0', '4', '0', '5', '0'], outp[:processed])
|
93
|
-
|
94
|
-
outp2 = parser.send(:process, short2)
|
95
|
-
assert_equal(MIDIMessage::NoteOn, outp2[:messages].first.class)
|
96
|
-
assert_equal(['1', '0'], parser.buffer)
|
97
|
-
assert_equal(['9', '0', '3', '0', '2', '0'], outp2[:processed])
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_nibbles_to_message_leading
|
101
|
-
parser = Parser.new
|
102
|
-
short = ["5", "0", '9', '0', '4', '0', '5', '0']
|
103
|
-
parser.send(:buffer=, short)
|
104
|
-
parser.send(:populate_current)
|
105
|
-
outp = parser.send(:nibbles_to_message)
|
106
|
-
assert_equal(["5", "0", '9', '0', '4', '0', '5', '0'], parser.buffer)
|
107
|
-
assert_equal(nil, outp[:message])
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_nibbles_to_message_trailing
|
111
|
-
parser = Parser.new
|
112
|
-
short = ['9', '0', '4', '0', '5', '0', '5', '0']
|
113
|
-
parser.send(:buffer=, short)
|
114
|
-
parser.send(:populate_current)
|
115
|
-
outp = parser.send(:nibbles_to_message)
|
116
|
-
assert_equal(MIDIMessage::NoteOn, outp[:message].class)
|
117
|
-
assert_equal(['5', '0'], parser.send(:current))
|
118
|
-
assert_equal(['9', '0', '4', '0', '5', '0'], outp[:processed])
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_nibbles_to_message
|
122
|
-
parser = Parser.new
|
123
|
-
short = ['9', '0', '4', '0', '5', '0', '5', '0']
|
124
|
-
parser.send(:buffer=, short)
|
125
|
-
parser.send(:populate_current)
|
126
|
-
outp = parser.send(:nibbles_to_message)
|
127
|
-
assert_equal(MIDIMessage::NoteOn, outp[:message].class)
|
128
|
-
assert_equal(['5', '0'], parser.send(:current))
|
129
|
-
assert_equal(['9', '0', '4', '0', '5', '0'], outp[:processed])
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_nibbles_to_message_running_status
|
133
|
-
parser = Parser.new
|
134
|
-
short = ['9', '0', '4', '0', '5', '0']
|
135
|
-
parser.send(:buffer=, short)
|
136
|
-
parser.send(:populate_current)
|
137
|
-
outp = parser.send(:nibbles_to_message)
|
138
|
-
assert_equal(MIDIMessage::NoteOn, outp[:message].class)
|
139
|
-
|
140
|
-
running_status = ["5", "0", "6", "0"]
|
141
|
-
parser.send(:buffer=, running_status)
|
142
|
-
parser.send(:populate_current)
|
143
|
-
outp = parser.send(:nibbles_to_message)
|
144
|
-
assert_equal(MIDIMessage::NoteOn, outp[:message].class)
|
145
|
-
assert_equal(["5", "0", "6", "0"], outp[:processed])
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_nibbles_to_message_sysex
|
149
|
-
parser = Parser.new
|
150
|
-
sysex = "F04110421240007F0041F750".split(//)
|
151
|
-
parser.send(:buffer=, sysex)
|
152
|
-
parser.send(:populate_current)
|
153
|
-
outp = parser.send(:nibbles_to_message)
|
154
|
-
assert_equal(MIDIMessage::SystemExclusive::Command, outp[:message].class)
|
155
|
-
assert_equal(["5", "0"], parser.send(:current))
|
156
|
-
assert_equal("F04110421240007F0041F7".split(//), outp[:processed])
|
157
|
-
end
|
158
|
-
|
159
|
-
end
|