# HG changeset patch # User Chris Cannam # Date 1235560522 0 # Node ID f76efdd7d1807a0be3bece4921f7f194d83aed4c # Parent fdbb3971bafc62beaebd2bd379ebbbc7f5b4e175 * Somewhat better MIDI-based time instant timing diff -r fdbb3971bafc -r f76efdd7d180 main/MainWindow.cpp --- a/main/MainWindow.cpp Tue Feb 24 17:53:01 2009 +0000 +++ b/main/MainWindow.cpp Wed Feb 25 11:15:22 2009 +0000 @@ -119,7 +119,7 @@ MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) : - MainWindowBase(withAudioOutput, withOSCSupport), + MainWindowBase(withAudioOutput, withOSCSupport, true), m_overview(0), m_mainMenusCreated(false), m_paneMenu(0), @@ -137,6 +137,7 @@ m_soloAction(0), m_soloModified(false), m_prevSolo(false), + m_lastInsertedMIDITime(0), m_rwdStartAction(0), m_rwdAction(0), m_ffwdAction(0), @@ -1666,6 +1667,8 @@ connect(m_playAction, SIGNAL(triggered()), this, SLOT(play())); connect(m_playSource, SIGNAL(playStatusChanged(bool)), m_playAction, SLOT(setChecked(bool))); + connect(m_playSource, SIGNAL(playStatusChanged(bool)), + this, SLOT(playStatusChanged(bool))); connect(this, SIGNAL(canPlay(bool)), m_playAction, SLOT(setEnabled(bool))); m_ffwdAction = toolbar->addAction(il.load("ffwd"), @@ -3406,16 +3409,26 @@ void MainWindow::midiEventsAvailable() { - //!!! for now. but this won't do -- we are passing a signal/slot - //!!! connection across threads here, so timing will not be good - //!!! -- we do need to use the original midi event timestamp - MIDIEvent ev(m_midiInput->readEvent()); - if (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON) { - insertInstant(); + // 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 + // happens in the MIDI input class and not here. + while (m_midiInput->getEventsAvailable() > 0) { + MIDIEvent ev(m_midiInput->readEvent()); + if (ev.getMessageType() != MIDIConstants::MIDI_NOTE_ON) { + continue; + } + insertInstantAt(ev.getTime()); } } void +MainWindow::playStatusChanged(bool playing) +{ + m_lastInsertedMIDITime = -1.0; // <0 means "never during this playback" +} + +void MainWindow::layerRemoved(Layer *layer) { setupExistingLayersMenus(); diff -r fdbb3971bafc -r f76efdd7d180 main/MainWindow.h --- a/main/MainWindow.h Tue Feb 24 17:53:01 2009 +0000 +++ b/main/MainWindow.h Wed Feb 25 11:15:22 2009 +0000 @@ -166,6 +166,7 @@ virtual void handleOSCMessage(const OSCMessage &); virtual void midiEventsAvailable(); + virtual void playStatusChanged(bool); virtual void website(); virtual void help(); @@ -205,6 +206,8 @@ bool m_soloModified; bool m_prevSolo; + double m_lastInsertedMIDITime; + QFrame *m_playControlsSpacer; int m_playControlsWidth;