void KeyboardWidget::PlayNote(int key, int e, int vel) { if (selectInstr == NULL || theProject == NULL) return; if (e == KEY_CHANGE && changeNew) { // stop last note PlayNote(key, KEY_UP, vel); e = KEY_DOWN; } // activeInstr keeps track of which instrument started the note. // We need to keep playing on the same instrument until a Key up happens, // even if the selected instrument changes. if (!activeInstr) activeInstr = selectInstr; NoteEvent *evt = (NoteEvent*) theProject->mgr.ManufEvent(activeInstr); evt->SetChannel(curChnl); evt->SetStart(0); evt->SetDuration((bsInt32) (synthParams.sampleRate * curDur)); evt->SetVolume(curVol); evt->SetPitch(key); evt->SetVelocity(vel); switch (e) { case KEY_CHANGE: // change current note evt->SetType(SEQEVT_PARAM); break; case KEY_DOWN: evtID = (evtID + 1) & 0x7FFFFFFF; evt->SetType(SEQEVT_START); break; case KEY_UP: evt->SetType(SEQEVT_STOP); activeInstr = 0; break; default: //OutputDebugString("Kbd event is unknown...\r\n"); evt->Destroy(); return; } evt->SetID(evtID); theProject->PlayEvent(evt); // NB: player will delete event. Don't touch it after calling PlayEvent! if (recording && e == KEY_DOWN) { RecNote *note = new RecNote(key, curRhythm, (int)(curVol*100.0)); recTail->InsertBefore(note); } }