comparison main/MainWindow.cpp @ 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
comparison
equal deleted inserted replaced
308:4ad11b1cf050 309:6a276fea550d
3429 void 3429 void
3430 MainWindow::midiEventsAvailable() 3430 MainWindow::midiEventsAvailable()
3431 { 3431 {
3432 Pane *currentPane = 0; 3432 Pane *currentPane = 0;
3433 NoteLayer *currentNoteLayer = 0; 3433 NoteLayer *currentNoteLayer = 0;
3434 TimeValueLayer *currentTimeValueLayer = 0;
3434 3435
3435 if (m_paneStack) currentPane = m_paneStack->getCurrentPane(); 3436 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
3436 if (currentPane) { 3437 if (currentPane) {
3437 currentNoteLayer = dynamic_cast<NoteLayer *> 3438 currentNoteLayer = dynamic_cast<NoteLayer *>
3438 (currentPane->getSelectedLayer()); 3439 (currentPane->getSelectedLayer());
3440 currentTimeValueLayer = dynamic_cast<TimeValueLayer *>
3441 (currentPane->getSelectedLayer());
3439 } 3442 }
3440 3443
3441 // This is called through a serialised signal/slot invocation 3444 // This is called through a serialised signal/slot invocation
3442 // (across threads). It could happen quite some time after the 3445 // (across threads). It could happen quite some time after the
3443 // event was actually received, which is why event timestamping 3446 // event was actually received, which is why event timestamping
3445 3448
3446 while (m_midiInput->getEventsAvailable() > 0) { 3449 while (m_midiInput->getEventsAvailable() > 0) {
3447 3450
3448 MIDIEvent ev(m_midiInput->readEvent()); 3451 MIDIEvent ev(m_midiInput->readEvent());
3449 3452
3453 size_t frame = currentPane->alignFromReference(ev.getTime());
3454
3450 bool noteOn = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON && 3455 bool noteOn = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON &&
3451 ev.getVelocity() > 0); 3456 ev.getVelocity() > 0);
3452 3457
3453 bool noteOff = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_OFF || 3458 bool noteOff = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_OFF ||
3454 (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON && 3459 (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON &&
3456 3461
3457 if (currentNoteLayer) { 3462 if (currentNoteLayer) {
3458 3463
3459 if (noteOn) { 3464 if (noteOn) {
3460 3465
3461 currentNoteLayer->addNoteOn(ev.getTime(), 3466 currentNoteLayer->addNoteOn(frame,
3462 ev.getPitch(), 3467 ev.getPitch(),
3463 ev.getVelocity()); 3468 ev.getVelocity());
3464 3469
3465 } else if (noteOff) { 3470 } else if (noteOff) {
3466 3471
3467 currentNoteLayer->addNoteOff(ev.getTime(), 3472 currentNoteLayer->addNoteOff(frame,
3468 ev.getPitch()); 3473 ev.getPitch());
3469 3474
3470 } 3475 }
3471 3476
3472 } else { 3477 continue;
3478 }
3479
3480 if (currentTimeValueLayer) {
3473 3481
3474 if (!noteOn) continue; 3482 if (!noteOn) continue;
3475 insertInstantAt(ev.getTime()); 3483 Model *model = static_cast<Layer *>(currentTimeValueLayer)->getModel();
3476 } 3484 SparseTimeValueModel *tvm =
3485 dynamic_cast<SparseTimeValueModel *>(model);
3486 if (tvm) {
3487 SparseTimeValueModel::Point point(frame, ev.getPitch() % 12, "");
3488 SparseTimeValueModel::AddPointCommand *command =
3489 new SparseTimeValueModel::AddPointCommand
3490 (tvm, point, tr("Add Point"));
3491 CommandHistory::getInstance()->addCommand(command);
3492 }
3493 continue;
3494
3495 }
3496
3497 if (!noteOn) continue;
3498 insertInstantAt(ev.getTime());
3477 } 3499 }
3478 } 3500 }
3479 3501
3480 void 3502 void
3481 MainWindow::playStatusChanged(bool playing) 3503 MainWindow::playStatusChanged(bool playing)