Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/nibbler/midilib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ def channel_aftertouch(second_nibble, data_byte)
end

def pitch_bend(second_nibble, data_byte1, data_byte2)
# to-do handle the midilib lsb/msb
# right now the second data byte is being thrown away
MIDI::PitchBend.new(second_nibble, data_byte1, data_byte2)
MIDI::PitchBend.new(second_nibble, data_byte2 * 128 + data_byte1)
end

def system_exclusive(*args)
MIDI::SystemExclusive.new(args)
end

def system_common(second_nibble, data_byte1 = nil, _data_byte2 = nil)
def system_common(second_nibble, data_byte1 = nil, data_byte2 = nil)
case second_nibble
when 0x2 then MIDI::SongPointer.new(data_byte1) # similar issue to pitch bend here
when 0x2 then MIDI::SongPointer.new(data_byte2 * 128 + data_byte1)
when 0x3 then MIDI::SongSelect.new(data_byte1)
when 0x6 then MIDI::TuneRequest.new
end
Expand Down
10 changes: 4 additions & 6 deletions spec/integration/midilib_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,12 @@
end

context 'when pitch bend' do
# to-do handle the midilib lsb/msb
# right now the second data byte is being thrown away
let(:message) { lib.pitch_bend(0x0, 0x20, 0x00) }
let(:message) { lib.pitch_bend(0x0, 0x10, 0x3f) }

it 'returns correct message' do
expect(message).to be_a(MIDI::PitchBend)
expect(message.channel).to eq(0)
expect(message.value).to eq(0x20)
expect(message.value).to eq(8080)
end
end

Expand All @@ -91,11 +89,11 @@
end

context 'when song pointer' do
let(:message) { lib.system_common(0x2, 0xF0) }
let(:message) { lib.system_common(0x2, 0x6d, 0x01) }

it 'returns correct message' do
expect(message).to be_a(MIDI::SongPointer)
expect(message.pointer).to eq(0xF0)
expect(message.pointer).to eq(237)
end
end

Expand Down