diff main/MainWindow.cpp @ 793:568c6da853e6

Fix incoherent logic for what happens if MIDI arrives while no suitable layer is current (from coverity scan)
author Chris Cannam
date Wed, 03 Sep 2014 09:19:55 +0100
parents c8e378ad8a10
children c305961985c4
line wrap: on
line diff
--- a/main/MainWindow.cpp	Wed Sep 03 09:17:01 2014 +0100
+++ b/main/MainWindow.cpp	Wed Sep 03 09:19:55 2014 +0100
@@ -4054,7 +4054,10 @@
     NoteLayer *currentNoteLayer = 0;
     TimeValueLayer *currentTimeValueLayer = 0;
 
-    if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
+    if (m_paneStack) {
+        currentPane = m_paneStack->getCurrentPane();
+    }
+
     if (currentPane) {
         currentNoteLayer = dynamic_cast<NoteLayer *>
             (currentPane->getSelectedLayer());
@@ -4062,6 +4065,14 @@
             (currentPane->getSelectedLayer());
     }
 
+    if (!currentNoteLayer && !currentTimeValueLayer) {
+        // discard these events
+        while (m_midiInput->getEventsAvailable() > 0) {
+            (void)m_midiInput->readEvent();
+        }
+        return;
+    }
+
     // This is called through a serialised signal/slot invocation
     // (across threads).  It could happen quite some time after the
     // event was actually received, which is why event timestamping