midi-nibbler 0.1.0 → 0.1.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.
- data/lib/nibbler.rb +1 -1
- data/test/helper.rb +11 -0
- data/test/test_hex_char_array_filter.rb +61 -0
- data/test/test_midi_message_factory.rb +130 -0
- data/test/test_midilib_factory.rb +137 -0
- data/test/test_nibbler.rb +120 -0
- data/test/test_parser.rb +159 -0
- data/test/test_parser_buffer.rb +71 -0
- data/test/test_parser_rejected.rb +65 -0
- data/test/test_type_conversion.rb +34 -0
- metadata +11 -2
data/lib/nibbler.rb
CHANGED
data/test/helper.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
class HexCharArrayFilterTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Nibbler
|
8
|
+
include TestHelper
|
9
|
+
|
10
|
+
def test_to_nibbles_array_mixed
|
11
|
+
filter = HexCharArrayFilter.new
|
12
|
+
array = [0x90, "90", "9"]
|
13
|
+
nibbles = filter.send(:process, array)
|
14
|
+
assert_equal([0x90, "90", "9"], array)
|
15
|
+
assert_equal(["9", "0", "9", "0", "9"], nibbles)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_to_nibbles_mixed
|
19
|
+
filter = HexCharArrayFilter.new
|
20
|
+
array = [0x90, "90", "9"]
|
21
|
+
nibbles = filter.send(:process, *array)
|
22
|
+
assert_equal([0x90, "90", "9"], array)
|
23
|
+
assert_equal(["9", "0", "9", "0", "9"], nibbles)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_to_nibbles_numeric
|
27
|
+
filter = HexCharArrayFilter.new
|
28
|
+
num = 0x90
|
29
|
+
nibbles = filter.send(:process, num)
|
30
|
+
assert_equal(0x90, num)
|
31
|
+
assert_equal(["9", "0"], nibbles)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_to_nibbles_string
|
35
|
+
filter = HexCharArrayFilter.new
|
36
|
+
str = "904050"
|
37
|
+
nibbles = filter.send(:process, str)
|
38
|
+
assert_equal("904050", str)
|
39
|
+
assert_equal(["9", "0", "4", "0", "5", "0"], nibbles)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_filter_numeric
|
43
|
+
filter = HexCharArrayFilter.new
|
44
|
+
badnum = 560
|
45
|
+
output = filter.send(:filter_numeric, badnum)
|
46
|
+
assert_equal(560, badnum)
|
47
|
+
assert_equal(nil, output)
|
48
|
+
goodnum = 50
|
49
|
+
output = filter.send(:filter_numeric, goodnum)
|
50
|
+
assert_equal(50, goodnum)
|
51
|
+
assert_equal(50, output)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_filter_string
|
55
|
+
filter = HexCharArrayFilter.new
|
56
|
+
str = "(0xAdjskla#(#"
|
57
|
+
outp = filter.send(:filter_string, str)
|
58
|
+
assert_equal("0ADA", outp)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,130 @@
|
|
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
|
@@ -0,0 +1,137 @@
|
|
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
|
@@ -0,0 +1,120 @@
|
|
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
ADDED
@@ -0,0 +1,159 @@
|
|
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
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
class BufferTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Nibbler
|
8
|
+
include TestHelper
|
9
|
+
|
10
|
+
def test_buffer_nibble_str
|
11
|
+
nibbler = Nibbler.new
|
12
|
+
nibbler.parse("9")
|
13
|
+
assert_equal(["9"], nibbler.buffer)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_buffer_single_byte
|
17
|
+
nibbler = Nibbler.new
|
18
|
+
nibbler.parse(0x90)
|
19
|
+
assert_equal(["9", "0"], nibbler.buffer)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_buffer_single_byte_str
|
23
|
+
nibbler = Nibbler.new
|
24
|
+
nibbler.parse("90")
|
25
|
+
assert_equal(["9", "0"], nibbler.buffer)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_buffer_single_byte_in_array
|
29
|
+
nibbler = Nibbler.new
|
30
|
+
nibbler.parse([0x90])
|
31
|
+
assert_equal(["9", "0"], nibbler.buffer)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_buffer_two_bytes
|
35
|
+
nibbler = Nibbler.new
|
36
|
+
nibbler.parse(0x90, 0x40)
|
37
|
+
assert_equal(["9", "0", "4", "0"], nibbler.buffer)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_buffer_two_bytes_str
|
41
|
+
nibbler = Nibbler.new
|
42
|
+
nibbler.parse("90", "40")
|
43
|
+
assert_equal(["9", "0", "4", "0"], nibbler.buffer)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_buffer_two_bytes_single_str
|
47
|
+
nibbler = Nibbler.new
|
48
|
+
nibbler.parse("9040")
|
49
|
+
assert_equal(["9", "0", "4", "0"], nibbler.buffer)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_buffer_two_bytes_mixed
|
53
|
+
nibbler = Nibbler.new
|
54
|
+
nibbler.parse("90", 0x40)
|
55
|
+
assert_equal(["9", "0", "4", "0"], nibbler.buffer)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_buffer_nibble_and_byte_mixed
|
59
|
+
nibbler = Nibbler.new
|
60
|
+
nibbler.parse("9", 0x40)
|
61
|
+
assert_equal(["9", "4", "0"], nibbler.buffer)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_buffer_stepped
|
65
|
+
nibbler = Nibbler.new
|
66
|
+
nibbler.parse("9")
|
67
|
+
nibbler.parse(0x40)
|
68
|
+
assert_equal(["9", "4", "0"], nibbler.buffer)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "helper"
|
4
|
+
|
5
|
+
class ParserRejectedTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Nibbler
|
8
|
+
include TestHelper
|
9
|
+
|
10
|
+
def test_leading_chars
|
11
|
+
nibbler = Nibbler.new
|
12
|
+
msg = nibbler.parse("0", "9", "04", "040")
|
13
|
+
assert_equal(MIDIMessage::NoteOn, msg.class)
|
14
|
+
assert_equal(["0"], nibbler.rejected)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_2_leading_chars
|
18
|
+
nibbler = Nibbler.new
|
19
|
+
msg = nibbler.parse("1", "0", "9", "04", "040")
|
20
|
+
assert_equal(["1", "0"], nibbler.rejected)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_leading_string
|
24
|
+
nibbler = Nibbler.new
|
25
|
+
msg = nibbler.parse("10", "9", "04", "040")
|
26
|
+
assert_equal(MIDIMessage::NoteOn, msg.class)
|
27
|
+
assert_equal(["1", "0"], nibbler.rejected)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_long_leading_string
|
31
|
+
nibbler = Nibbler.new
|
32
|
+
msg = nibbler.parse("000001000010", "9", "04", "040")
|
33
|
+
assert_equal(MIDIMessage::NoteOn, msg.class)
|
34
|
+
assert_equal("000001000010".split(//), nibbler.rejected)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_long_leading_string_overlap
|
38
|
+
nibbler = Nibbler.new
|
39
|
+
msg = nibbler.parse("000001000010090", "4", "040")
|
40
|
+
assert_equal(MIDIMessage::NoteOn, msg.class)
|
41
|
+
assert_equal("0000010000100".split(//), nibbler.rejected)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_leading_number
|
45
|
+
nibbler = Nibbler.new
|
46
|
+
msg = nibbler.parse(0x30, "9", "04", "040")
|
47
|
+
assert_equal(MIDIMessage::NoteOn, msg.class)
|
48
|
+
assert_equal(["3", "0"], nibbler.rejected)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_2_leading_numbers
|
52
|
+
nibbler = Nibbler.new
|
53
|
+
msg = nibbler.parse(0x60, 0x30, "9", "04", "040")
|
54
|
+
assert_equal(MIDIMessage::NoteOn, msg.class)
|
55
|
+
assert_equal(["6", "0", "3", "0"], nibbler.rejected)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_3_leading_numbers
|
59
|
+
nibbler = Nibbler.new
|
60
|
+
msg = nibbler.parse(0x00, 0x30, "9", "04", "040")
|
61
|
+
assert_equal(MIDIMessage::NoteOn, msg.class)
|
62
|
+
assert_equal(["0", "0", "3", "0"], nibbler.rejected)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
class TypeConversionTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Nibbler
|
8
|
+
include TestHelper
|
9
|
+
|
10
|
+
def test_hex_chars_to_numeric_bytes
|
11
|
+
nibbles = ["4", "5", "9", "3"]
|
12
|
+
bytes = TypeConversion.hex_chars_to_numeric_bytes(nibbles)
|
13
|
+
|
14
|
+
assert_equal(["4", "5", "9", "3"], nibbles)
|
15
|
+
assert_equal([0x45, 0x93], bytes)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_hex_str_to_hex_chars
|
19
|
+
str = "904050"
|
20
|
+
nibbles = TypeConversion.send(:hex_str_to_hex_chars, str)
|
21
|
+
|
22
|
+
assert_equal("904050", str)
|
23
|
+
assert_equal(["9", "0", "4", "0", "5", "0"], nibbles)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_numeric_byte_to_hex_chars
|
27
|
+
num = 0x90
|
28
|
+
nibbles = TypeConversion.send(:numeric_byte_to_hex_chars, num)
|
29
|
+
|
30
|
+
assert_equal(0x90, num)
|
31
|
+
assert_equal(["9", "0"], nibbles)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: midi-nibbler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ari Russo
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05
|
13
|
+
date: 2011-06-05 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -52,6 +52,15 @@ files:
|
|
52
52
|
- lib/nibbler/midilib_factory.rb
|
53
53
|
- lib/nibbler/hex_char_array_filter.rb
|
54
54
|
- lib/nibbler/type_conversion.rb
|
55
|
+
- test/test_parser.rb
|
56
|
+
- test/helper.rb
|
57
|
+
- test/test_parser_rejected.rb
|
58
|
+
- test/test_nibbler.rb
|
59
|
+
- test/test_parser_buffer.rb
|
60
|
+
- test/test_hex_char_array_filter.rb
|
61
|
+
- test/test_midilib_factory.rb
|
62
|
+
- test/test_type_conversion.rb
|
63
|
+
- test/test_midi_message_factory.rb
|
55
64
|
- LICENSE
|
56
65
|
- README.rdoc
|
57
66
|
has_rdoc: true
|