diff options
author | Robert Jonsson <spamatica@gmail.com> | 2012-09-16 14:57:22 +0000 |
---|---|---|
committer | Robert Jonsson <spamatica@gmail.com> | 2012-09-16 14:57:22 +0000 |
commit | f783083862fa7a71f7774a14176e4a6bbbe324f9 (patch) | |
tree | 9580e24fa771460448e1784a91da225ac28d5198 /muse2/muse | |
parent | 5557b72e16dbb3eef5eab76363096d828cb734f6 (diff) |
some improvements
Diffstat (limited to 'muse2/muse')
-rw-r--r-- | muse2/muse/midiedit/prcanvas.cpp | 64 | ||||
-rw-r--r-- | muse2/muse/midiedit/prcanvas.h | 2 |
2 files changed, 46 insertions, 20 deletions
diff --git a/muse2/muse/midiedit/prcanvas.cpp b/muse2/muse/midiedit/prcanvas.cpp index 2bf94269..99c2ea8c 100644 --- a/muse2/muse/midiedit/prcanvas.cpp +++ b/muse2/muse/midiedit/prcanvas.cpp @@ -499,11 +499,18 @@ MusEGui::CItem* PianoCanvas::newItem(const QPoint& p, int) e.setPitch(pitch); e.setVelo(curVelo); e.setLenTick(len); - return new NEvent(e, curPart, pitch2y(pitch)); + + NEvent *newEvent = new NEvent(e, curPart, pitch2y(pitch)); + if(_playEvents) + startPlayEvent(newEvent); + return newEvent; } void PianoCanvas::newItem(MusEGui::CItem* item, bool noSnap) { + if(_playEvents) + stopPlayEvent(); + NEvent* nevent = (NEvent*) item; MusECore::Event event = nevent->event(); int x = item->x(); @@ -998,17 +1005,7 @@ void PianoCanvas::itemPressed(const MusEGui::CItem* item) { if (!_playEvents) return; - - int port = track()->outPort(); - int channel = track()->outChannel(); - NEvent* nevent = (NEvent*) item; - MusECore::Event event = nevent->event(); - playedPitch = event.pitch() + track()->transposition; - int velo = event.velo(); - - // play note: - MusECore::MidiPlayEvent e(0, port, channel, 0x90, playedPitch, velo); - MusEGlobal::audio->msgPlayMidiEvent(&e); + startPlayEvent(item); } //--------------------------------------------------------- @@ -1018,14 +1015,8 @@ void PianoCanvas::itemPressed(const MusEGui::CItem* item) void PianoCanvas::itemReleased(const MusEGui::CItem*, const QPoint&) { if (!_playEvents) - return; - int port = track()->outPort(); - int channel = track()->outChannel(); - - // release note: - MusECore::MidiPlayEvent ev(0, port, channel, 0x90, playedPitch, 0); - MusEGlobal::audio->msgPlayMidiEvent(&ev); - playedPitch = -1; + return; + stopPlayEvent(); } //--------------------------------------------------------- @@ -1167,4 +1158,37 @@ void PianoCanvas::resizeEvent(QResizeEvent* ev) EventCanvas::resizeEvent(ev); } +//--------------------------------------------------------- +// startPlayEvent +//--------------------------------------------------------- + +void PianoCanvas::startPlayEvent(const MusEGui::CItem* item) + { + int port = track()->outPort(); + int channel = track()->outChannel(); + NEvent* nevent = (NEvent*) item; + MusECore::Event event = nevent->event(); + playedPitch = event.pitch() + track()->transposition; + int velo = event.velo(); + + // play note: + MusECore::MidiPlayEvent e(0, port, channel, 0x90, playedPitch, velo); + MusEGlobal::audio->msgPlayMidiEvent(&e); + } + +//--------------------------------------------------------- +// stopPlayEvent +//--------------------------------------------------------- + +void PianoCanvas::stopPlayEvent() + { + int port = track()->outPort(); + int channel = track()->outChannel(); + + // release note: + MusECore::MidiPlayEvent ev(0, port, channel, 0x90, playedPitch, 0); + MusEGlobal::audio->msgPlayMidiEvent(&ev); + playedPitch = -1; + } + } // namespace MusEGui diff --git a/muse2/muse/midiedit/prcanvas.h b/muse2/muse/midiedit/prcanvas.h index ee83c88e..cbe6c68c 100644 --- a/muse2/muse/midiedit/prcanvas.h +++ b/muse2/muse/midiedit/prcanvas.h @@ -92,6 +92,8 @@ class PianoCanvas : public EventCanvas { virtual void itemMoved(const CItem*, const QPoint&); virtual void curPartChanged(); virtual void resizeEvent(QResizeEvent*); + virtual void startPlayEvent(const CItem*); + virtual void stopPlayEvent(); private slots: void midiNote(int pitch, int velo); |