From 9363b497e13e39191655441a32b458f0af1727d8 Mon Sep 17 00:00:00 2001 From: Be Date: Sun, 12 Jul 2020 18:22:28 -0500 Subject: [PATCH] MidiController: rename confusingly overloaded "receive" method --- src/controllers/midi/hss1394controller.cpp | 6 +- src/controllers/midi/midicontroller.cpp | 6 +- src/controllers/midi/midicontroller.h | 6 +- src/controllers/midi/portmidicontroller.cpp | 4 +- src/test/midicontrollertest.cpp | 119 ++++++++++---------- src/test/portmidicontroller_test.cpp | 14 +-- 6 files changed, 80 insertions(+), 75 deletions(-) diff --git a/src/controllers/midi/hss1394controller.cpp b/src/controllers/midi/hss1394controller.cpp index 4e58b966f6a..4d119051c16 100644 --- a/src/controllers/midi/hss1394controller.cpp +++ b/src/controllers/midi/hss1394controller.cpp @@ -112,8 +112,10 @@ int Hss1394Controller::open() { m_pChannelListener = new DeviceChannelListener(this, getName()); connect(m_pChannelListener, SIGNAL(incomingData(QByteArray, mixxx::Duration)), this, SLOT(receive(QByteArray, mixxx::Duration))); - connect(m_pChannelListener, SIGNAL(incomingData(unsigned char, unsigned char, unsigned char, mixxx::Duration)), - this, SLOT(receive(unsigned char, unsigned char, unsigned char, mixxx::Duration))); + connect(m_pChannelListener, + &DeviceChannelListener::incomingData, + this, + &Hss1394Controller::receiveShortMessage); if (!m_pChannel->InstallChannelListener(m_pChannelListener)) { qDebug() << "HSS1394 channel listener could not be installed for device" << getName(); diff --git a/src/controllers/midi/midicontroller.cpp b/src/controllers/midi/midicontroller.cpp index 78273fcf5bb..f60958cfcb0 100644 --- a/src/controllers/midi/midicontroller.cpp +++ b/src/controllers/midi/midicontroller.cpp @@ -200,8 +200,10 @@ void MidiController::commitTemporaryInputMappings() { m_temporaryInputMappings.clear(); } -void MidiController::receive(unsigned char status, unsigned char control, - unsigned char value, mixxx::Duration timestamp) { +void MidiController::receiveShortMessage(unsigned char status, + unsigned char control, + unsigned char value, + mixxx::Duration timestamp) { // The rest of this function is for legacy mappings unsigned char channel = MidiUtils::channelFromStatus(status); unsigned char opCode = MidiUtils::opCodeFromStatus(status); diff --git a/src/controllers/midi/midicontroller.h b/src/controllers/midi/midicontroller.h index 0090c12c24e..1cb4f74f457 100644 --- a/src/controllers/midi/midicontroller.h +++ b/src/controllers/midi/midicontroller.h @@ -69,8 +69,10 @@ class MidiController : public Controller { } protected slots: - virtual void receive(unsigned char status, unsigned char control, - unsigned char value, mixxx::Duration timestamp); + virtual void receiveShortMessage(unsigned char status, + unsigned char control, + unsigned char value, + mixxx::Duration timestamp); // For receiving System Exclusive messages void receive(const QByteArray data, mixxx::Duration timestamp) override; int close() override; diff --git a/src/controllers/midi/portmidicontroller.cpp b/src/controllers/midi/portmidicontroller.cpp index bf30f0feda7..10213d9b3da 100644 --- a/src/controllers/midi/portmidicontroller.cpp +++ b/src/controllers/midi/portmidicontroller.cpp @@ -149,7 +149,7 @@ bool PortMidiController::poll() { if ((status & 0xF8) == 0xF8) { // Handle real-time MIDI messages at any time - receive(status, 0, 0, timestamp); + receiveShortMessage(status, 0, 0, timestamp); continue; } @@ -163,7 +163,7 @@ bool PortMidiController::poll() { //unsigned char channel = status & 0x0F; unsigned char note = Pm_MessageData1(m_midiBuffer[i].message); unsigned char velocity = Pm_MessageData2(m_midiBuffer[i].message); - receive(status, note, velocity, timestamp); + receiveShortMessage(status, note, velocity, timestamp); } } diff --git a/src/test/midicontrollertest.cpp b/src/test/midicontrollertest.cpp index 4568b6c0691..f1405b65456 100644 --- a/src/test/midicontrollertest.cpp +++ b/src/test/midicontrollertest.cpp @@ -38,10 +38,9 @@ class MidiControllerTest : public MixxxTest { m_pController->visit(&preset); } - void receive(unsigned char status, unsigned char control, - unsigned char value) { + void receiveShortMessage(unsigned char status, unsigned char control, unsigned char value) { // TODO(rryan): This test doesn't care about timestamps. - m_pController->receive(status, control, value, mixxx::Time::elapsed()); + m_pController->receiveShortMessage(status, control, value, mixxx::Time::elapsed()); } MidiControllerPreset m_preset; @@ -64,15 +63,15 @@ TEST_F(MidiControllerTest, ReceiveMessage_PushButtonCO_PushOnOff) { loadPreset(m_preset); // Receive an on/off, sets the control on/off with each press. - receive(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); EXPECT_LT(0.0, cpb.get()); - receive(MIDI_NOTE_OFF | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_OFF | channel, control, 0x00); EXPECT_DOUBLE_EQ(0.0, cpb.get()); // Receive an on/off, sets the control on/off with each press. - receive(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); EXPECT_LT(0.0, cpb.get()); - receive(MIDI_NOTE_OFF | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_OFF | channel, control, 0x00); EXPECT_DOUBLE_EQ(0.0, cpb.get()); } @@ -90,15 +89,15 @@ TEST_F(MidiControllerTest, ReceiveMessage_PushButtonCO_PushOnOn) { loadPreset(m_preset); // Receive an on/off, sets the control on/off with each press. - receive(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); EXPECT_LT(0.0, cpb.get()); - receive(MIDI_NOTE_ON | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x00); EXPECT_DOUBLE_EQ(0.0, cpb.get()); // Receive an on/off, sets the control on/off with each press. - receive(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); EXPECT_LT(0.0, cpb.get()); - receive(MIDI_NOTE_ON | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x00); EXPECT_DOUBLE_EQ(0.0, cpb.get()); } @@ -123,13 +122,13 @@ TEST_F(MidiControllerTest, ReceiveMessage_PushButtonCO_ToggleOnOff_ButtonMidiOpt // NOTE(rryan): This behavior is broken! // Toggle the switch on, sets the push button on. - receive(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); EXPECT_LT(0.0, cpb.get()); // The push button is stuck down here! // Toggle the switch off, sets the push button off. - receive(MIDI_NOTE_OFF | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_OFF | channel, control, 0x00); EXPECT_DOUBLE_EQ(0.0, cpb.get()); } @@ -154,13 +153,13 @@ TEST_F(MidiControllerTest, ReceiveMessage_PushButtonCO_ToggleOnOff_SwitchMidiOpt // NOTE(rryan): This behavior is broken! // Toggle the switch on, sets the push button on. - receive(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); EXPECT_LT(0.0, cpb.get()); // The push button is stuck down here! // Toggle the switch off, sets the push button on again. - receive(MIDI_NOTE_OFF | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_OFF | channel, control, 0x00); EXPECT_LT(0.0, cpb.get()); // NOTE(rryan): What is supposed to happen in this case? It's an open @@ -196,15 +195,15 @@ TEST_F(MidiControllerTest, ReceiveMessage_PushButtonCO_PushCC) { loadPreset(m_preset); // Receive an on/off, sets the control on/off with each press. - receive(MIDI_CC | channel, control, 0x7F); + receiveShortMessage(MIDI_CC | channel, control, 0x7F); EXPECT_LT(0.0, cpb.get()); - receive(MIDI_CC | channel, control, 0x00); + receiveShortMessage(MIDI_CC | channel, control, 0x00); EXPECT_DOUBLE_EQ(0.0, cpb.get()); // Receive an on/off, sets the control on/off with each press. - receive(MIDI_CC | channel, control, 0x7F); + receiveShortMessage(MIDI_CC | channel, control, 0x7F); EXPECT_LT(0.0, cpb.get()); - receive(MIDI_CC | channel, control, 0x00); + receiveShortMessage(MIDI_CC | channel, control, 0x00); EXPECT_DOUBLE_EQ(0.0, cpb.get()); } @@ -225,14 +224,14 @@ TEST_F(MidiControllerTest, ReceiveMessage_ToggleCO_PushOnOff) { loadPreset(m_preset); // Receive an on/off, toggles the control. - receive(MIDI_NOTE_ON | channel, control, 0x7F); - receive(MIDI_NOTE_OFF | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_OFF | channel, control, 0x00); EXPECT_LT(0.0, cpb.get()); // Receive an on/off, toggles the control. - receive(MIDI_NOTE_ON | channel, control, 0x7F); - receive(MIDI_NOTE_OFF | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_OFF | channel, control, 0x00); EXPECT_DOUBLE_EQ(0.0, cpb.get()); } @@ -252,14 +251,14 @@ TEST_F(MidiControllerTest, ReceiveMessage_ToggleCO_PushOnOn) { loadPreset(m_preset); // Receive an on/off, toggles the control. - receive(MIDI_NOTE_ON | channel, control, 0x7F); - receive(MIDI_NOTE_ON | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x00); EXPECT_LT(0.0, cpb.get()); // Receive an on/off, toggles the control. - receive(MIDI_NOTE_ON | channel, control, 0x7F); - receive(MIDI_NOTE_ON | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x00); EXPECT_DOUBLE_EQ(0.0, cpb.get()); } @@ -289,12 +288,12 @@ TEST_F(MidiControllerTest, ReceiveMessage_ToggleCO_ToggleOnOff_ButtonMidiOption) // Toggle the switch on, since it is interpreted as a button press it // toggles the button on. - receive(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); EXPECT_LT(0.0, cpb.get()); // Toggle the switch off, since it is interpreted as a button release it // does nothing to the toggle button. - receive(MIDI_NOTE_OFF | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_OFF | channel, control, 0x00); EXPECT_LT(0.0, cpb.get()); } @@ -324,12 +323,12 @@ TEST_F(MidiControllerTest, ReceiveMessage_ToggleCO_ToggleOnOff_SwitchMidiOption) // Toggle the switch on, since it is interpreted as a button press it // toggles the control on. - receive(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); EXPECT_LT(0.0, cpb.get()); // Toggle the switch off, since it is interpreted as a button press it // toggles the control off. - receive(MIDI_NOTE_OFF | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_OFF | channel, control, 0x00); EXPECT_DOUBLE_EQ(0.0, cpb.get()); // Meanwhile, the GUI toggles the control on again. @@ -339,12 +338,12 @@ TEST_F(MidiControllerTest, ReceiveMessage_ToggleCO_ToggleOnOff_SwitchMidiOption) // Toggle the switch on, since it is interpreted as a button press it // toggles the control off (since it was on). - receive(MIDI_NOTE_ON | channel, control, 0x7F); + receiveShortMessage(MIDI_NOTE_ON | channel, control, 0x7F); EXPECT_DOUBLE_EQ(0.0, cpb.get()); // Toggle the switch off, since it is interpreted as a button press it // toggles the control on (since it was off). - receive(MIDI_NOTE_OFF | channel, control, 0x00); + receiveShortMessage(MIDI_NOTE_OFF | channel, control, 0x00); EXPECT_LT(0.0, cpb.get()); } @@ -363,14 +362,14 @@ TEST_F(MidiControllerTest, ReceiveMessage_ToggleCO_PushCC) { loadPreset(m_preset); // Receive an on/off, toggles the control. - receive(MIDI_CC | channel, control, 0x7F); - receive(MIDI_CC | channel, control, 0x00); + receiveShortMessage(MIDI_CC | channel, control, 0x7F); + receiveShortMessage(MIDI_CC | channel, control, 0x00); EXPECT_LT(0.0, cpb.get()); // Receive an on/off, toggles the control. - receive(MIDI_CC | channel, control, 0x7F); - receive(MIDI_CC | channel, control, 0x00); + receiveShortMessage(MIDI_CC | channel, control, 0x7F); + receiveShortMessage(MIDI_CC | channel, control, 0x00); EXPECT_DOUBLE_EQ(0.0, cpb.get()); } @@ -391,15 +390,15 @@ TEST_F(MidiControllerTest, ReceiveMessage_PotMeterCO_7BitCC) { loadPreset(m_preset); // Receive a 0, MIDI parameter should map to the min value. - receive(MIDI_CC | channel, control, 0x00); + receiveShortMessage(MIDI_CC | channel, control, 0x00); EXPECT_DOUBLE_EQ(kMinValue, potmeter.get()); // Receive a 0x7F, MIDI parameter should map to the potmeter max value. - receive(MIDI_CC | channel, control, 0x7F); + receiveShortMessage(MIDI_CC | channel, control, 0x7F); EXPECT_DOUBLE_EQ(kMaxValue, potmeter.get()); // Receive a 0x40, MIDI parameter should map to the potmeter middle value. - receive(MIDI_CC | channel, control, 0x40); + receiveShortMessage(MIDI_CC | channel, control, 0x40); EXPECT_DOUBLE_EQ(kMiddleValue, potmeter.get()); } @@ -434,40 +433,40 @@ TEST_F(MidiControllerTest, ReceiveMessage_PotMeterCO_14BitCC) { // Receive a 0x0000 (lsb-first), MIDI parameter should map to the min value. potmeter.set(0); - receive(MIDI_CC | channel, lsb_control, 0x00); - receive(MIDI_CC | channel, msb_control, 0x00); + receiveShortMessage(MIDI_CC | channel, lsb_control, 0x00); + receiveShortMessage(MIDI_CC | channel, msb_control, 0x00); EXPECT_DOUBLE_EQ(kMinValue, potmeter.get()); // Receive a 0x0000 (msb-first), MIDI parameter should map to the min value. potmeter.set(0); - receive(MIDI_CC | channel, msb_control, 0x00); - receive(MIDI_CC | channel, lsb_control, 0x00); + receiveShortMessage(MIDI_CC | channel, msb_control, 0x00); + receiveShortMessage(MIDI_CC | channel, lsb_control, 0x00); EXPECT_DOUBLE_EQ(kMinValue, potmeter.get()); // Receive a 0x3FFF (lsb-first), MIDI parameter should map to the max value. potmeter.set(0); - receive(MIDI_CC | channel, lsb_control, 0x7F); - receive(MIDI_CC | channel, msb_control, 0x7F); + receiveShortMessage(MIDI_CC | channel, lsb_control, 0x7F); + receiveShortMessage(MIDI_CC | channel, msb_control, 0x7F); EXPECT_DOUBLE_EQ(kMaxValue, potmeter.get()); // Receive a 0x3FFF (msb-first), MIDI parameter should map to the max value. potmeter.set(0); - receive(MIDI_CC | channel, msb_control, 0x7F); - receive(MIDI_CC | channel, lsb_control, 0x7F); + receiveShortMessage(MIDI_CC | channel, msb_control, 0x7F); + receiveShortMessage(MIDI_CC | channel, lsb_control, 0x7F); EXPECT_DOUBLE_EQ(kMaxValue, potmeter.get()); // Receive a 0x2000 (lsb-first), MIDI parameter should map to the middle // value. potmeter.set(0); - receive(MIDI_CC | channel, lsb_control, 0x00); - receive(MIDI_CC | channel, msb_control, 0x40); + receiveShortMessage(MIDI_CC | channel, lsb_control, 0x00); + receiveShortMessage(MIDI_CC | channel, msb_control, 0x40); EXPECT_DOUBLE_EQ(kMiddleValue, potmeter.get()); // Receive a 0x2000 (msb-first), MIDI parameter should map to the middle // value. potmeter.set(0); - receive(MIDI_CC | channel, msb_control, 0x40); - receive(MIDI_CC | channel, lsb_control, 0x00); + receiveShortMessage(MIDI_CC | channel, msb_control, 0x40); + receiveShortMessage(MIDI_CC | channel, lsb_control, 0x00); EXPECT_DOUBLE_EQ(kMiddleValue, potmeter.get()); // Check the 14-bit resolution is actually present. Receive a 0x2001 @@ -475,8 +474,8 @@ TEST_F(MidiControllerTest, ReceiveMessage_PotMeterCO_14BitCC) { // amount. Scaling is not quite linear for MIDI parameters so just check // that incrementing the LSB by 1 is greater than the middle value. potmeter.set(0); - receive(MIDI_CC | channel, msb_control, 0x40); - receive(MIDI_CC | channel, lsb_control, 0x01); + receiveShortMessage(MIDI_CC | channel, msb_control, 0x40); + receiveShortMessage(MIDI_CC | channel, lsb_control, 0x01); EXPECT_LT(kMiddleValue, potmeter.get()); // Check the 14-bit resolution is actually present. Receive a 0x2001 @@ -484,8 +483,8 @@ TEST_F(MidiControllerTest, ReceiveMessage_PotMeterCO_14BitCC) { // amount. Scaling is not quite linear for MIDI parameters so just check // that incrementing the LSB by 1 is greater than the middle value. potmeter.set(0); - receive(MIDI_CC | channel, lsb_control, 0x01); - receive(MIDI_CC | channel, msb_control, 0x40); + receiveShortMessage(MIDI_CC | channel, lsb_control, 0x01); + receiveShortMessage(MIDI_CC | channel, msb_control, 0x40); EXPECT_LT(kMiddleValue, potmeter.get()); } @@ -505,21 +504,21 @@ TEST_F(MidiControllerTest, ReceiveMessage_PotMeterCO_14BitPitchBend) { loadPreset(m_preset); // Receive a 0x0000, MIDI parameter should map to the min value. - receive(MIDI_PITCH_BEND | channel, 0x00, 0x00); + receiveShortMessage(MIDI_PITCH_BEND | channel, 0x00, 0x00); EXPECT_DOUBLE_EQ(kMinValue, potmeter.get()); // Receive a 0x3FFF, MIDI parameter should map to the potmeter max value. - receive(MIDI_PITCH_BEND | channel, 0x7F, 0x7F); + receiveShortMessage(MIDI_PITCH_BEND | channel, 0x7F, 0x7F); EXPECT_DOUBLE_EQ(kMaxValue, potmeter.get()); // Receive a 0x2000, MIDI parameter should map to the potmeter middle value. - receive(MIDI_PITCH_BEND | channel, 0x00, 0x40); + receiveShortMessage(MIDI_PITCH_BEND | channel, 0x00, 0x40); EXPECT_DOUBLE_EQ(kMiddleValue, potmeter.get()); // Check the 14-bit resolution is actually present. Receive a 0x2001, MIDI // parameter should map to the middle value plus a tiny amount. Scaling is // not quite linear for MIDI parameters so just check that incrementing the // LSB by 1 is greater than the middle value. - receive(MIDI_PITCH_BEND | channel, 0x01, 0x40); + receiveShortMessage(MIDI_PITCH_BEND | channel, 0x01, 0x40); EXPECT_LT(kMiddleValue, potmeter.get()); } diff --git a/src/test/portmidicontroller_test.cpp b/src/test/portmidicontroller_test.cpp index 097deb41f42..48d6c5c4855 100644 --- a/src/test/portmidicontroller_test.cpp +++ b/src/test/portmidicontroller_test.cpp @@ -35,8 +35,8 @@ class MockPortMidiController : public PortMidiController { PortMidiController::sendSysexMsg(data, length); } - MOCK_METHOD4(receive, void(unsigned char, unsigned char, unsigned char, - mixxx::Duration)); + MOCK_METHOD4(receiveShortMessage, + void(unsigned char, unsigned char, unsigned char, mixxx::Duration)); MOCK_METHOD2(receive, void(const QByteArray, mixxx::Duration)); }; @@ -228,9 +228,9 @@ TEST_F(PortMidiControllerTest, Poll_Read_Basic) { .WillOnce(DoAll(SetArrayArgument<0>(messages.begin(), messages.end()), Return(messages.size()))); - EXPECT_CALL(*m_pController, receive(0x90, 0x3C, 0x40, _)) + EXPECT_CALL(*m_pController, receiveShortMessage(0x90, 0x3C, 0x40, _)) .InSequence(read); - EXPECT_CALL(*m_pController, receive(0x80, 0x3C, 0x40, _)) + EXPECT_CALL(*m_pController, receiveShortMessage(0x80, 0x3C, 0x40, _)) .InSequence(read); pollDevice(); @@ -265,9 +265,9 @@ TEST_F(PortMidiControllerTest, Poll_Read_SysExWithRealtime) { .InSequence(read) .WillOnce(DoAll(SetArrayArgument<0>(messages.begin(), messages.end()), Return(messages.size()))); - EXPECT_CALL(*m_pController, receive(0xF8, 0x00, 0x00, _)) + EXPECT_CALL(*m_pController, receiveShortMessage(0xF8, 0x00, 0x00, _)) .InSequence(read); - EXPECT_CALL(*m_pController, receive(0xFA, 0x00, 0x00, _)) + EXPECT_CALL(*m_pController, receiveShortMessage(0xFA, 0x00, 0x00, _)) .InSequence(read); EXPECT_CALL(*m_pController, receive(sysex, _)) .InSequence(read); @@ -363,7 +363,7 @@ TEST_F(PortMidiControllerTest, Poll_Read_SysExInterrupted_FollowedByNormalMessag .InSequence(read) .WillOnce(DoAll(SetArrayArgument<0>(messages.begin(), messages.end()), Return(messages.size()))); - EXPECT_CALL(*m_pController, receive(0x90, 0x3C, 0x40, _)) + EXPECT_CALL(*m_pController, receiveShortMessage(0x90, 0x3C, 0x40, _)) .InSequence(read); pollDevice();