# HG changeset patch # User Chris Cannam # Date 1235563373 0 # Node ID d4ff14feca7615bd0f63da65be05eca1e4e329d5 # Parent 8fbbfea74058e13bac73ce8f08ce7e5a96034025 * Make it possible to record live MIDI to a note layer. Now we're a proper MIDI sequencer. Ha, ha. diff -r 8fbbfea74058 -r d4ff14feca76 main/MainWindow.cpp --- a/main/MainWindow.cpp Wed Feb 25 11:26:07 2009 +0000 +++ b/main/MainWindow.cpp Wed Feb 25 12:02:53 2009 +0000 @@ -32,6 +32,7 @@ #include "layer/TimeRulerLayer.h" #include "layer/TimeInstantLayer.h" #include "layer/TimeValueLayer.h" +#include "layer/NoteLayer.h" #include "layer/Colour3DPlotLayer.h" #include "layer/SliceLayer.h" #include "layer/SliceableLayer.h" @@ -137,7 +138,6 @@ m_soloAction(0), m_soloModified(false), m_prevSolo(false), - m_lastInsertedMIDITime(0), m_rwdStartAction(0), m_rwdAction(0), m_ffwdAction(0), @@ -3413,23 +3413,61 @@ void MainWindow::midiEventsAvailable() { + Pane *currentPane = 0; + NoteLayer *currentNoteLayer = 0; + + if (m_paneStack) currentPane = m_paneStack->getCurrentPane(); + if (currentPane) { + currentNoteLayer = dynamic_cast + (currentPane->getSelectedLayer()); + } + // 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; + + if (currentNoteLayer) { + + if (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON) { + + currentNoteLayer->addNoteOn(ev.getTime(), + ev.getPitch(), + ev.getVelocity()); + + } else if (ev.getMessageType() == MIDIConstants::MIDI_NOTE_OFF) { + + currentNoteLayer->addNoteOff(ev.getTime(), + ev.getPitch()); + + } + + } else { + if (ev.getMessageType() != MIDIConstants::MIDI_NOTE_ON) { + continue; + } + insertInstantAt(ev.getTime()); } - insertInstantAt(ev.getTime()); } } void MainWindow::playStatusChanged(bool playing) { - m_lastInsertedMIDITime = -1.0; // <0 means "never during this playback" + Pane *currentPane = 0; + NoteLayer *currentNoteLayer = 0; + + if (m_paneStack) currentPane = m_paneStack->getCurrentPane(); + if (currentPane) { + currentNoteLayer = dynamic_cast(currentPane->getSelectedLayer()); + } + + if (currentNoteLayer) { + currentNoteLayer->abandonNoteOns(); + } } void diff -r 8fbbfea74058 -r d4ff14feca76 main/MainWindow.h --- a/main/MainWindow.h Wed Feb 25 11:26:07 2009 +0000 +++ b/main/MainWindow.h Wed Feb 25 12:02:53 2009 +0000 @@ -207,8 +207,6 @@ bool m_soloModified; bool m_prevSolo; - double m_lastInsertedMIDITime; - QFrame *m_playControlsSpacer; int m_playControlsWidth;