changeset 309:6a276fea550d

* If a time-value layer is current when a midi note event is received, place points in it with values based on the midi note pitch class
author Chris Cannam
date Thu, 26 Feb 2009 17:33:46 +0000
parents 4ad11b1cf050
children 8e750332dc77
files main/MainWindow.cpp
diffstat 1 files changed, 26 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/main/MainWindow.cpp	Thu Feb 26 10:49:08 2009 +0000
+++ b/main/MainWindow.cpp	Thu Feb 26 17:33:46 2009 +0000
@@ -3431,11 +3431,14 @@
 {
     Pane *currentPane = 0;
     NoteLayer *currentNoteLayer = 0;
+    TimeValueLayer *currentTimeValueLayer = 0;
 
     if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
     if (currentPane) {
         currentNoteLayer = dynamic_cast<NoteLayer *>
             (currentPane->getSelectedLayer());
+        currentTimeValueLayer = dynamic_cast<TimeValueLayer *>
+            (currentPane->getSelectedLayer());
     }
 
     // This is called through a serialised signal/slot invocation
@@ -3447,6 +3450,8 @@
 
         MIDIEvent ev(m_midiInput->readEvent());
 
+        size_t frame = currentPane->alignFromReference(ev.getTime());
+
         bool noteOn = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON &&
                        ev.getVelocity() > 0);
 
@@ -3458,22 +3463,39 @@
 
             if (noteOn) {
 
-                currentNoteLayer->addNoteOn(ev.getTime(),
+                currentNoteLayer->addNoteOn(frame,
                                             ev.getPitch(),
                                             ev.getVelocity());
 
             } else if (noteOff) {
 
-                currentNoteLayer->addNoteOff(ev.getTime(),
+                currentNoteLayer->addNoteOff(frame,
                                              ev.getPitch());
 
             }
 
-        } else {
+            continue;
+        }
+
+        if (currentTimeValueLayer) {
 
             if (!noteOn) continue;
-            insertInstantAt(ev.getTime());
+            Model *model = static_cast<Layer *>(currentTimeValueLayer)->getModel();
+            SparseTimeValueModel *tvm =
+                dynamic_cast<SparseTimeValueModel *>(model);
+            if (tvm) {
+                SparseTimeValueModel::Point point(frame, ev.getPitch() % 12, "");
+                SparseTimeValueModel::AddPointCommand *command =
+                    new SparseTimeValueModel::AddPointCommand
+                    (tvm, point, tr("Add Point"));
+                CommandHistory::getInstance()->addCommand(command);
+            }
+            continue;
+
         }
+
+        if (!noteOn) continue;
+        insertInstantAt(ev.getTime());
     }
 }