Added more tests & fixed #53 (sendPitchBend range).
This commit is contained in:
parent
419606785d
commit
c29dfd84d7
|
|
@ -289,7 +289,8 @@ template<class SerialPort, class Settings>
|
|||
void MidiInterface<SerialPort, Settings>::sendPitchBend(double inPitchValue,
|
||||
Channel inChannel)
|
||||
{
|
||||
const int value = int(inPitchValue * double(MIDI_PITCHBEND_MAX));
|
||||
const int scale = inPitchValue > 0.0 ? MIDI_PITCHBEND_MAX : MIDI_PITCHBEND_MIN;
|
||||
const int value = int(inPitchValue * double(scale));
|
||||
sendPitchBend(value, inChannel);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ typedef midi::MidiInterface<SerialMock> MidiInterface;
|
|||
|
||||
// --
|
||||
|
||||
TEST(MidiOutput, sendSingle)
|
||||
TEST(MidiOutput, sendGenericSingle)
|
||||
{
|
||||
SerialMock serial;
|
||||
MidiInterface midi(serial);
|
||||
|
|
@ -41,7 +41,7 @@ TEST(MidiOutput, sendSingle)
|
|||
EXPECT_THAT(buffer, ElementsAre(0x9b, 47, 42));
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendWithRunningStatus)
|
||||
TEST(MidiOutput, sendGenericWithRunningStatus)
|
||||
{
|
||||
SerialMock serial;
|
||||
MidiInterface midi(serial);
|
||||
|
|
@ -57,7 +57,7 @@ TEST(MidiOutput, sendWithRunningStatus)
|
|||
EXPECT_THAT(buffer, ElementsAre(0x9b, 47, 42, 42, 47));
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendWithoutRunningStatus)
|
||||
TEST(MidiOutput, sendGenericWithoutRunningStatus)
|
||||
{
|
||||
typedef VariableSettings<false, true> Settings; // No running status
|
||||
typedef midi::MidiInterface<SerialMock, Settings> MidiInterface;
|
||||
|
|
@ -85,7 +85,7 @@ TEST(MidiOutput, sendWithoutRunningStatus)
|
|||
EXPECT_THAT(buffer, ElementsAre(0x9b, 47, 42, 0x8b, 47, 42));
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendBreakingRunningStatus)
|
||||
TEST(MidiOutput, sendGenericBreakingRunningStatus)
|
||||
{
|
||||
SerialMock serial;
|
||||
MidiInterface midi(serial);
|
||||
|
|
@ -99,48 +99,149 @@ TEST(MidiOutput, sendBreakingRunningStatus)
|
|||
EXPECT_THAT(buffer, ElementsAre(0x9b, 47, 42, 0x8b, 47, 42));
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendMultipleNoteOff)
|
||||
// --
|
||||
|
||||
TEST(MidiOutput, sendNoteOn)
|
||||
{
|
||||
SerialMock serial;
|
||||
MidiInterface midi(serial);
|
||||
test_mocks::uint8 buffer[5] = { 0 };
|
||||
|
||||
midi.begin();
|
||||
midi.send(midi::NoteOff, 10, 11, 12);
|
||||
midi.send(midi::NoteOff, 12, 13, 12);
|
||||
midi.sendNoteOn(10, 11, 12);
|
||||
midi.sendNoteOn(12, 13, 12);
|
||||
EXPECT_EQ(serial.mTxBuffer.getLength(), 5);
|
||||
serial.mTxBuffer.read(buffer, 5);
|
||||
EXPECT_THAT(buffer, ElementsAre(0x9b, 10, 11, 12, 13));
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendNoteOff)
|
||||
{
|
||||
SerialMock serial;
|
||||
MidiInterface midi(serial);
|
||||
test_mocks::uint8 buffer[5] = { 0 };
|
||||
|
||||
midi.begin();
|
||||
midi.sendNoteOff(10, 11, 12);
|
||||
midi.sendNoteOff(12, 13, 12);
|
||||
EXPECT_EQ(serial.mTxBuffer.getLength(), 5);
|
||||
serial.mTxBuffer.read(buffer, 5);
|
||||
EXPECT_THAT(buffer, ElementsAre(0x8b, 10, 11, 12, 13));
|
||||
}
|
||||
|
||||
/* TEST(MidiOutput, Issue41)
|
||||
TEST(MidiOutput, sendProgramChange)
|
||||
{
|
||||
typedef VariableSettings<true, false> Settings; // Running status, multibyte parsing
|
||||
typedef midi::MidiInterface<SerialMock, Settings> MidiInterface;
|
||||
|
||||
// #41: issue with sending series of ControlChange
|
||||
SerialMock serial;
|
||||
MidiInterface midi(serial);
|
||||
test_mocks::uint8 buffer[9] = { 0 };
|
||||
test_mocks::uint8 buffer[3] = { 0 };
|
||||
|
||||
midi.begin(MIDI_CHANNEL_OMNI);
|
||||
midi.turnThruOff();
|
||||
midi.begin();
|
||||
midi.sendProgramChange(42, 12);
|
||||
midi.sendProgramChange(47, 12);
|
||||
EXPECT_EQ(serial.mTxBuffer.getLength(), 3);
|
||||
serial.mTxBuffer.read(buffer, 3);
|
||||
EXPECT_THAT(buffer, ElementsAre(0xcb, 42, 47));
|
||||
}
|
||||
|
||||
// Simulate some pitch bend messages
|
||||
serial.mRxBuffer.write(0xe0);
|
||||
serial.mRxBuffer.write(0);
|
||||
serial.mRxBuffer.write(12);
|
||||
serial.mRxBuffer.write(0);
|
||||
serial.mRxBuffer.write(42);
|
||||
serial.mRxBuffer.write(0);
|
||||
serial.mRxBuffer.write(47);
|
||||
midi.read();
|
||||
TEST(MidiOutput, sendControlChange)
|
||||
{
|
||||
SerialMock serial;
|
||||
MidiInterface midi(serial);
|
||||
test_mocks::uint8 buffer[5] = { 0 };
|
||||
|
||||
EXPECT_EQ(serial.mTxBuffer.getLength(), 9);
|
||||
serial.mTxBuffer.read(buffer, 9);
|
||||
EXPECT_THAT(buffer, ElementsAre(0xbb, 80, 42, 80, 47, 80, 42, 80, 47));
|
||||
} */
|
||||
midi.begin();
|
||||
midi.sendControlChange(42, 12, 12);
|
||||
midi.sendControlChange(47, 12, 12);
|
||||
EXPECT_EQ(serial.mTxBuffer.getLength(), 5);
|
||||
serial.mTxBuffer.read(buffer, 5);
|
||||
EXPECT_THAT(buffer, ElementsAre(0xbb, 42, 12, 47, 12));
|
||||
}
|
||||
|
||||
// --
|
||||
TEST(MidiOutput, sendPitchBend)
|
||||
{
|
||||
SerialMock serial;
|
||||
MidiInterface midi(serial);
|
||||
test_mocks::uint8 buffer[7] = { 0 };
|
||||
|
||||
// Int signature - arbitrary values
|
||||
{
|
||||
midi.begin();
|
||||
midi.sendPitchBend(0, 12);
|
||||
midi.sendPitchBend(100, 12);
|
||||
midi.sendPitchBend(-100, 12);
|
||||
EXPECT_EQ(serial.mTxBuffer.getLength(), 7);
|
||||
serial.mTxBuffer.read(buffer, 7);
|
||||
EXPECT_THAT(buffer, ElementsAre(0xeb,
|
||||
0x00, 0x40,
|
||||
0x64, 0x40,
|
||||
0x1c, 0x3f));
|
||||
}
|
||||
// Int signature - min/max
|
||||
{
|
||||
midi.begin();
|
||||
midi.sendPitchBend(0, 12);
|
||||
midi.sendPitchBend(MIDI_PITCHBEND_MAX, 12);
|
||||
midi.sendPitchBend(MIDI_PITCHBEND_MIN, 12);
|
||||
EXPECT_EQ(serial.mTxBuffer.getLength(), 7);
|
||||
serial.mTxBuffer.read(buffer, 7);
|
||||
EXPECT_THAT(buffer, ElementsAre(0xeb,
|
||||
0x00, 0x40,
|
||||
0x7f, 0x7f,
|
||||
0x00, 0x00));
|
||||
}
|
||||
// Float signature
|
||||
{
|
||||
midi.begin();
|
||||
midi.sendPitchBend(0.0, 12);
|
||||
midi.sendPitchBend(1.0, 12);
|
||||
midi.sendPitchBend(-1.0, 12);
|
||||
EXPECT_EQ(serial.mTxBuffer.getLength(), 7);
|
||||
serial.mTxBuffer.read(buffer, 7);
|
||||
EXPECT_THAT(buffer, ElementsAre(0xeb,
|
||||
0x00, 0x40,
|
||||
0x7f, 0x7f,
|
||||
0x00, 0x00));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendPolyPressure)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendAfterTouch)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendSysEx)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendTimeCodeQuarterFrame)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendSongPosition)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendSongSelect)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendTuneRequest)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST(MidiOutput, sendRealTime)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
END_UNNAMED_NAMESPACE
|
||||
|
|
|
|||
Loading…
Reference in New Issue