Skip to content

Commit d1cce5e

Browse files
committed
Let parser handle running status
1 parent 0e15cca commit d1cce5e

3 files changed

Lines changed: 3 additions & 36 deletions

File tree

lib/nibbler/message_builder.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,13 @@ def sysex?
5454

5555
# Can this builder build a message from the given bytes?
5656
# @param [Array<Integer>] bytes The bytes to build a message with
57-
# @param [Integer] running_status Build the message using running status when running status is present
5857
# @return [Boolean]
59-
def can_build_next?(bytes, running_status: nil)
58+
def can_build_next?(bytes)
6059
if sysex?
6160
# check that there's a sysex end byte
6261
bytes.any? { |byte| byte == 0xF7 }
6362
else
64-
bytes_to_test = running_status ? [running_status] + bytes : bytes
65-
potential_data_bytes = bytes_to_test.drop(1)
63+
potential_data_bytes = bytes.drop(1)
6664
next_status_index = potential_data_bytes.index { |byte| Util.status_byte?(byte) }
6765
bytes_to_test = next_status_index ? potential_data_bytes.slice(0, next_status_index) : potential_data_bytes
6866
length_of_data = @length_in_bytes - 1

lib/nibbler/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def processable?(pointer)
6464
def handle_running_status(pointer, report)
6565
status_nibbles = Util::Conversion.numeric_byte_to_numeric_nibbles(@running_status)
6666
builder = message_builder_for(status_nibbles)
67-
if builder.can_build_next?(@buffer, running_status: @running_status)
67+
if builder.can_build_next?([@running_status] + @buffer)
6868
build_running_status_message(builder, pointer, report, status_nibble2: status_nibbles[1])
6969
0
7070
else

spec/message_builder_spec.rb

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -78,37 +78,6 @@
7878
end
7979
end
8080
end
81-
82-
context 'when running status' do
83-
let(:result) { builder.can_build_next?(bytes, running_status: 0x90) }
84-
85-
context 'when valid' do
86-
let(:bytes) { [0x40, 0x40] }
87-
let(:status_nibble) { 0x9 }
88-
89-
it 'returns true' do
90-
expect(result).to eq(true)
91-
end
92-
end
93-
94-
context 'when incomplete' do
95-
let(:bytes) { [0x40] }
96-
let(:status_nibble) { 0x9 }
97-
98-
it 'returns false' do
99-
expect(result).to eq(false)
100-
end
101-
end
102-
103-
context 'when invalid' do
104-
let(:bytes) { [0x40, 0x80] }
105-
let(:status_nibble) { 0x9 }
106-
107-
it 'returns false' do
108-
expect(result).to eq(false)
109-
end
110-
end
111-
end
11281
end
11382

11483
context 'when sysex message' do

0 commit comments

Comments
 (0)