Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gracefull handle Midi overflow #825

Merged
merged 2 commits into from
Mar 3, 2021
Merged
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
10 changes: 0 additions & 10 deletions src/controllers/midi/portmidicontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,6 @@ bool PortMidiController::poll() {
return false;
}

// Returns true if events are available or an error code.
PmError gotEvents = m_pInputDevice->poll();
if (gotEvents == FALSE) {
return false;
}
if (gotEvents < 0) {
qWarning() << "PortMidi error:" << Pm_GetErrorText(gotEvents);
return false;
}

int numEvents = m_pInputDevice->read(m_midiBuffer, MIXXX_PORTMIDI_BUFFER_LEN);

//qDebug() << "PortMidiController::poll()" << numEvents;
Expand Down
47 changes: 0 additions & 47 deletions src/test/portmidicontroller_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,6 @@ TEST_F(PortMidiControllerTest, WriteSysex_Malformed) {
m_pController->sendSysexMsg(sysex, sysex.length());
};

TEST_F(PortMidiControllerTest, Poll_Read_NoInput) {
Sequence poll;
EXPECT_CALL(*m_mockInput, isOpen())
.WillRepeatedly(Return(true));
EXPECT_CALL(*m_mockInput, poll())
.InSequence(poll)
.WillOnce(Return((PmError)FALSE));
EXPECT_CALL(*m_mockInput, poll())
.InSequence(poll)
.WillOnce(Return((PmError)TRUE));
EXPECT_CALL(*m_mockInput, read(_, _))
.InSequence(poll)
.WillOnce(Return(0));

pollDevice();
pollDevice();
};

TEST_F(PortMidiControllerTest, Poll_Read_Basic) {
std::vector<PmEvent> messages;
Expand All @@ -222,9 +205,6 @@ TEST_F(PortMidiControllerTest, Poll_Read_Basic) {
Sequence read;
EXPECT_CALL(*m_mockInput, isOpen())
.WillRepeatedly(Return(true));
EXPECT_CALL(*m_mockInput, poll())
.InSequence(read)
.WillOnce(Return((PmError)TRUE));
EXPECT_CALL(*m_mockInput, read(NotNull(), _))
.InSequence(read)
.WillOnce(DoAll(SetArrayArgument<0>(messages.begin(), messages.end()),
Expand Down Expand Up @@ -260,9 +240,6 @@ TEST_F(PortMidiControllerTest, Poll_Read_SysExWithRealtime) {
Sequence read;
EXPECT_CALL(*m_mockInput, isOpen())
.WillRepeatedly(Return(true));
EXPECT_CALL(*m_mockInput, poll())
.InSequence(read)
.WillOnce(Return((PmError)TRUE));
EXPECT_CALL(*m_mockInput, read(NotNull(), _))
.InSequence(read)
.WillOnce(DoAll(SetArrayArgument<0>(messages.begin(), messages.end()),
Expand Down Expand Up @@ -295,9 +272,6 @@ TEST_F(PortMidiControllerTest, Poll_Read_SysEx) {
Sequence read;
EXPECT_CALL(*m_mockInput, isOpen())
.WillRepeatedly(Return(true));
EXPECT_CALL(*m_mockInput, poll())
.InSequence(read)
.WillOnce(Return((PmError)TRUE));
EXPECT_CALL(*m_mockInput, read(NotNull(), _))
.InSequence(read)
.WillOnce(DoAll(SetArrayArgument<0>(messages.begin(), messages.end()),
Expand Down Expand Up @@ -332,9 +306,6 @@ TEST_F(PortMidiControllerTest,
Sequence read;
EXPECT_CALL(*m_mockInput, isOpen())
.WillRepeatedly(Return(true));
EXPECT_CALL(*m_mockInput, poll())
.InSequence(read)
.WillOnce(Return((PmError)TRUE));
EXPECT_CALL(*m_mockInput, read(NotNull(), _))
.InSequence(read)
.WillOnce(DoAll(SetArrayArgument<0>(messages.begin(), messages.end()),
Expand All @@ -358,9 +329,6 @@ TEST_F(PortMidiControllerTest, Poll_Read_SysExInterrupted_FollowedByNormalMessag
Sequence read;
EXPECT_CALL(*m_mockInput, isOpen())
.WillRepeatedly(Return(true));
EXPECT_CALL(*m_mockInput, poll())
.InSequence(read)
.WillOnce(Return((PmError)TRUE));
EXPECT_CALL(*m_mockInput, read(NotNull(), _))
.InSequence(read)
.WillOnce(DoAll(SetArrayArgument<0>(messages.begin(), messages.end()),
Expand Down Expand Up @@ -396,9 +364,6 @@ TEST_F(PortMidiControllerTest, Poll_Read_SysExInterrupted_FollowedBySysExMessage
Sequence read;
EXPECT_CALL(*m_mockInput, isOpen())
.WillRepeatedly(Return(true));
EXPECT_CALL(*m_mockInput, poll())
.InSequence(read)
.WillOnce(Return((PmError)TRUE));
EXPECT_CALL(*m_mockInput, read(NotNull(), _))
.InSequence(read)
.WillOnce(DoAll(SetArrayArgument<0>(messages.begin(), messages.end()),
Expand Down Expand Up @@ -441,35 +406,23 @@ TEST_F(PortMidiControllerTest, Poll_Read_SysEx_BufferOverflow) {
.WillRepeatedly(Return(true));

// Poll 1 -- returns messages1.
EXPECT_CALL(*m_mockInput, poll())
.InSequence(read)
.WillOnce(Return((PmError)TRUE));
EXPECT_CALL(*m_mockInput, read(NotNull(), _))
.InSequence(read)
.WillOnce(DoAll(SetArrayArgument<0>(messages1.begin(), messages1.end()),
Return(messages1.size())));

// Poll 2 -- buffer overflow.
EXPECT_CALL(*m_mockInput, poll())
.InSequence(read)
.WillOnce(Return((PmError)TRUE));
EXPECT_CALL(*m_mockInput, read(NotNull(), _))
.InSequence(read)
.WillOnce(Return(pmBufferOverflow));

// Poll 3 -- returns messages2.
EXPECT_CALL(*m_mockInput, poll())
.InSequence(read)
.WillOnce(Return((PmError)TRUE));
EXPECT_CALL(*m_mockInput, read(NotNull(), _))
.InSequence(read)
.WillOnce(DoAll(SetArrayArgument<0>(messages2.begin(), messages2.end()),
Return(messages2.size())));

// Poll 4 -- returns messages3.
EXPECT_CALL(*m_mockInput, poll())
.InSequence(read)
.WillOnce(Return((PmError)TRUE));
EXPECT_CALL(*m_mockInput, read(NotNull(), _))
.InSequence(read)
.WillOnce(DoAll(SetArrayArgument<0>(messages3.begin(), messages3.end()),
Expand Down