From 35100b50d8533d131800c5d873c3780be221b091 Mon Sep 17 00:00:00 2001 From: Robert Jonsson Date: Tue, 1 Jan 2013 21:40:01 +0000 Subject: speaker icon --- muse2/ChangeLog | 2 + muse2/muse/midiedit/dcanvas.cpp | 83 +++++++++++++++++++------ muse2/muse/midiedit/dcanvas.h | 3 + muse2/muse/midiedit/ecanvas.cpp | 38 ++++++++++++ muse2/muse/midiedit/ecanvas.h | 11 +++- muse2/muse/midiedit/prcanvas.cpp | 131 ++++----------------------------------- muse2/muse/midiedit/prcanvas.h | 4 -- 7 files changed, 129 insertions(+), 143 deletions(-) (limited to 'muse2') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 43856f22..f443b05f 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,3 +1,5 @@ +01.01.2013: Happy new year! + - Fixed playback of drumsounds during editing for new type drum editor (rj) 29.12.2012: - Added clear automation to automation menu - Changed automation color selection to hopefully make more sense with styles that diff --git a/muse2/muse/midiedit/dcanvas.cpp b/muse2/muse/midiedit/dcanvas.cpp index 8b324bde..3be0abbf 100644 --- a/muse2/muse/midiedit/dcanvas.cpp +++ b/muse2/muse/midiedit/dcanvas.cpp @@ -58,6 +58,7 @@ using MusEGlobal::debugMsg; using MusEGlobal::heavyDebugMsg; +using MusECore::MidiTrack; namespace MusEGui { @@ -97,11 +98,6 @@ CItem* DrumCanvas::addItem(MusECore::Part* part, MusECore::Event& event) int diff = event.endTick()-part->lenTick(); if (diff > 0) {// too short part? extend it - //printf("addItem - this code should not be run!\n"); DELETETHIS - //MusECore::Part* newPart = part->clone(); - //newPart->setLenTick(newPart->lenTick()+diff); - //MusEGlobal::audio->msgChangePart(part, newPart,false); - //part = newPart; part->setLenTick(part->lenTick()+diff); } @@ -172,6 +168,7 @@ DrumCanvas::~DrumCanvas() MusECore::Undo DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype) { + if(editor->parts()->empty()) return MusECore::Undo(); //return empty list @@ -304,16 +301,16 @@ bool DrumCanvas::moveItem(MusECore::Undo& operations, CItem* item, const QPoint& MusECore::MidiPart* part = (MusECore::MidiPart*)nevent->part(); MusECore::MidiPart* dest_part = part; - int nheight = y2pitch(pos.y()); - if (nheight<0) nheight=0; - if (nheight>=getOurDrumMapSize()) nheight=getOurDrumMapSize()-1; + int instrument = y2pitch(pos.y()); + if (instrument<0) instrument=0; + if (instrument>=getOurDrumMapSize()) instrument=getOurDrumMapSize()-1; - if (!instrument_map[nheight].tracks.contains(dest_part->track())) + if (!instrument_map[instrument].tracks.contains(dest_part->track())) { if (debugMsg) printf("trying to move an event into a different track. checking if curPart is set correctly...\n"); - if (!instrument_map[nheight].tracks.contains(curPart->track())) + if (!instrument_map[instrument].tracks.contains(curPart->track())) { printf ("ERROR: tried to move an event into a track which is different from both the initial part's and the curPart's track! ignoring this one...\n"); return false; @@ -322,7 +319,9 @@ bool DrumCanvas::moveItem(MusECore::Undo& operations, CItem* item, const QPoint& dest_part=(MusECore::MidiPart*)curPart; } + MusECore::Event event = nevent->event(); + int x = pos.x(); if (x < 0) x = 0; @@ -332,7 +331,7 @@ bool DrumCanvas::moveItem(MusECore::Undo& operations, CItem* item, const QPoint& MusECore::Event newEvent = event.clone(); - int ev_pitch = instrument_map[nheight].pitch; + int ev_pitch = instrument_map[instrument].pitch; newEvent.setPitch(ev_pitch); newEvent.setTick(ntick); @@ -414,6 +413,12 @@ CItem* DrumCanvas::newItem(int tick, int instrument, int velocity) e.setPitch(instrument_map[instrument].pitch); e.setVelo(velocity); e.setLenTick(ourDrumMap[instrument].len); + if(_playEvents) + { + int port = old_style_drummap_mode ? ourDrumMap[instrument].port : dynamic_cast(*instrument_map[instrument].tracks.begin())->outPort(); + int channel = old_style_drummap_mode ? ourDrumMap[instrument].channel : dynamic_cast(*instrument_map[instrument].tracks.begin())->outChannel(); + startPlayEvent(e.pitch(),e.velo(), port, channel); + } return new DEvent(e, curPart, instrument); } @@ -450,7 +455,11 @@ void DrumCanvas::newItem(CItem* item, bool noSnap, bool replace) x = editor->rasterVal(x); event.setTick(x - nevent->part()->tick()); int npitch = event.pitch(); - //event.setPitch(npitch); // commented out by flo: has no effect + + if(_playEvents) { + //stopPlayEvent(); + keyReleased(pitch2y(event.pitch()), true); // kinda backwards but this should pick the right port, stopPlayEvent does not know. + } // check for existing event // if found change command semantic from insert to delete @@ -511,6 +520,35 @@ bool DrumCanvas::deleteItem(CItem* item) return false; } +//--------------------------------------------------------- +// itemPressed +//--------------------------------------------------------- + +void DrumCanvas::itemPressed(const MusEGui::CItem* item) + { + if (!_playEvents) + return; + + MusECore::Event e = ((DEvent*)item)->event(); + int pitch = e.pitch(); + + startPlayEvent(pitch, e.velo()); //, port, channel); + } + +//--------------------------------------------------------- +// itemReleased +//--------------------------------------------------------- + +void DrumCanvas::itemReleased(const MusEGui::CItem* item, const QPoint&) + { + if (!_playEvents) + return; + MusECore::Event e = ((DEvent*)item)->event(); + keyReleased(pitch2y(e.pitch()), true); // kinda backwards but this should pick the right port, stopPlayEvent does not know. + //stopPlayEvent(); + } + + //--------------------------------------------------------- // drawItem //--------------------------------------------------------- @@ -590,6 +628,18 @@ void DrumCanvas::drawMoving(QPainter& p, const CItem* item, const QRect& rect) p.setPen(Qt::black); p.setBrush(Qt::black); p.drawPolygon(pa); + + int instrument = y2pitch(y); + int pitch = instrument_map[instrument].pitch; + MusECore::Event e = ((DEvent*)item)->event(); + if (pitch != playedPitch && _playEvents) { + keyReleased(playedPitch, true); // kinda backwards but this should pick the right port, stopPlayEvent does not know. + if (moving.size() == 1) { + int port = old_style_drummap_mode ? ourDrumMap[instrument].port : dynamic_cast(*instrument_map[instrument].tracks.begin())->outPort(); + int channel = old_style_drummap_mode ? ourDrumMap[instrument].channel : dynamic_cast(*instrument_map[instrument].tracks.begin())->outChannel(); + startPlayEvent(pitch, e.velo(), port, channel); + } + } } //--------------------------------------------------------- @@ -869,12 +919,10 @@ void DrumCanvas::keyPressed(int index, int velocity) int port = old_style_drummap_mode ? ourDrumMap[index].port : dynamic_cast(*instrument_map[index].tracks.begin())->outPort(); int channel = old_style_drummap_mode ? ourDrumMap[index].channel : dynamic_cast(*instrument_map[index].tracks.begin())->outChannel(); int pitch = old_style_drummap_mode ? ourDrumMap[index].anote : instrument_map[index].pitch; - // play note: if(_playEvents) { - MusECore::MidiPlayEvent e(0, port, channel, 0x90, pitch, velocity); - MusEGlobal::audio->msgPlayMidiEvent(&e); + startPlayEvent(pitch,velocity, port, channel); } if (_steprec) /* && pos[0] >= start_tick && pos[0] < end_tick [removed by flo93: this is handled in steprec->record] */ @@ -899,9 +947,7 @@ void DrumCanvas::keyPressed(int index, int velocity) //--------------------------------------------------------- void DrumCanvas::keyReleased(int index, bool) - { - using MusECore::MidiTrack; - + { if ((index<0) || (index>=getOurDrumMapSize())) return; @@ -915,6 +961,7 @@ void DrumCanvas::keyReleased(int index, bool) { MusECore::MidiPlayEvent e(0, port, channel, 0x90, pitch, 0); MusEGlobal::audio->msgPlayMidiEvent(&e); + playedPitch=-1; } } diff --git a/muse2/muse/midiedit/dcanvas.h b/muse2/muse/midiedit/dcanvas.h index d35a8891..fb4a5a96 100644 --- a/muse2/muse/midiedit/dcanvas.h +++ b/muse2/muse/midiedit/dcanvas.h @@ -116,6 +116,9 @@ class DrumCanvas : public EventCanvas { virtual void newItem(CItem*, bool); virtual void newItem(CItem*, bool, bool replace ); virtual bool deleteItem(CItem*); + virtual void itemPressed(const CItem*); + virtual void itemReleased(const CItem*, const QPoint&); + CItem* newItem(int tick, int instrument, int velocity); int y2pitch(int y) const; diff --git a/muse2/muse/midiedit/ecanvas.cpp b/muse2/muse/midiedit/ecanvas.cpp index c1185688..e07fc99e 100644 --- a/muse2/muse/midiedit/ecanvas.cpp +++ b/muse2/muse/midiedit/ecanvas.cpp @@ -46,6 +46,7 @@ namespace MusEGui { + //--------------------------------------------------------- // EventCanvas //--------------------------------------------------------- @@ -476,4 +477,41 @@ void EventCanvas::endMoveItems(const QPoint& pos, DragType dragtype, int dir) redraw(); } +//--------------------------------------------------------- +// startPlayEvent +//--------------------------------------------------------- + +void EventCanvas::startPlayEvent(int note, int velocity, int port, int channel) + { + if (MusEGlobal::debugMsg) + printf("EventCanvas::startPlayEvent %d %d %d %d\n", note, velocity, port, channel); + playedPitch = note + track()->transposition; + + // play note: + MusECore::MidiPlayEvent e(0, port, channel, 0x90, playedPitch, velocity); + MusEGlobal::audio->msgPlayMidiEvent(&e); + } + +void EventCanvas::startPlayEvent(int note, int velocity) + { + int port = track()->outPort(); + int channel = track()->outChannel(); + startPlayEvent(note, velocity, port, channel); +} + +//--------------------------------------------------------- +// stopPlayEvent +//--------------------------------------------------------- + +void EventCanvas::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/ecanvas.h b/muse2/muse/midiedit/ecanvas.h index 400072dc..b5120173 100644 --- a/muse2/muse/midiedit/ecanvas.h +++ b/muse2/muse/midiedit/ecanvas.h @@ -29,6 +29,8 @@ #include #include +#define KH 13 + class QMimeData; class QDrag; class QString; @@ -51,6 +53,7 @@ typedef std::map::iterator iPartToChange; namespace MusEGui { + class MidiEditor; //--------------------------------------------------------- // EventCanvas @@ -64,6 +67,7 @@ class EventCanvas : public Canvas { virtual void mouseMove(QMouseEvent* event); protected: + int playedPitch; bool _playEvents; MidiEditor* editor; unsigned start_tick, end_tick; @@ -78,6 +82,11 @@ class EventCanvas : public Canvas { virtual MusECore::Undo moveCanvasItems(CItemList&, int, int, DragType) = 0; virtual bool moveItem(MusECore::Undo&, CItem*, const QPoint&, DragType) = 0; virtual void endMoveItems(const QPoint&, DragType, int dir); + virtual void startPlayEvent(int note, int velocity); + virtual void startPlayEvent(int note, int velocity, int port, int channel); + virtual void stopPlayEvent(); + + public slots: void redrawGrid() { redraw(); } @@ -104,7 +113,7 @@ class EventCanvas : public Canvas { virtual void selectAtTick(unsigned int tick); virtual void viewDropEvent(QDropEvent* event); virtual void modifySelected(NoteInfo::ValType, int /*val*/, bool /*delta_mode*/ = true) {} - virtual void keyPress(QKeyEvent*); + virtual void keyPress(QKeyEvent*); }; } // namespace MusEGui diff --git a/muse2/muse/midiedit/prcanvas.cpp b/muse2/muse/midiedit/prcanvas.cpp index 8273c8d9..0670625a 100644 --- a/muse2/muse/midiedit/prcanvas.cpp +++ b/muse2/muse/midiedit/prcanvas.cpp @@ -67,6 +67,7 @@ NEvent::NEvent(MusECore::Event& e, MusECore::Part* p, int y) : MusEGui::CItem(e, setBBox(QRect(tick, y, e.lenTick(), KH/2)); } + //--------------------------------------------------------- // addItem //--------------------------------------------------------- @@ -83,11 +84,6 @@ CItem* PianoCanvas::addItem(MusECore::Part* part, MusECore::Event& event) int diff = event.tick()-part->lenTick(); if (diff > 0) {// too short part? extend it - //printf("addItem - this code should not be run!\n"); DELETETHIS - //MusECore::Part* newPart = part->clone(); - //newPart->setLenTick(newPart->lenTick()+diff); - //MusEGlobal::audio->msgChangePart(part, newPart,false); - //part = newPart; part->setLenTick(part->lenTick()+diff); } @@ -248,24 +244,9 @@ void PianoCanvas::drawItem(QPainter& p, const MusEGui::CItem* item, int mey = mer.y(); int mew = mer.width(); int meh = mer.height(); - //int mfx = mx; DELETETHIS - //if(mfx == mex) mfx += 1; - //int mfy = my; - //if(mfy == mey) mfy += 1; - //int mfw = mw; - //if(mfw == mew) mfw -= 1; - //if(mfx == mex) mfw -= 1; - //int mfh = mh; - //if(mfh == meh) mfh -= 1; - //if(mfy == mey) mfh -= 1; color.setAlpha(MusEGlobal::config.globalAlphaBlend); - //QLinearGradient gradient(mex + 1, mey + 1, mex + 1, mey + meh - 2); // Inside the border DELETETHIS - //gradient.setColorAt(0, color); - //gradient.setColorAt(1, color.darker()); - //QBrush brush(gradient); QBrush brush(color); p.fillRect(mr, brush); - //p.fillRect(mfx, mfy, mfw, mfh, brush); DELETETHIS if(mex >= mx && mex <= mx + mw) p.drawLine(mex, my, mex, my + mh - 1); // The left edge @@ -451,17 +432,10 @@ bool PianoCanvas::moveItem(MusECore::Undo& operations, MusEGui::CItem* item, con if (x < 0) x = 0; if (event.pitch() != npitch && _playEvents) { - int port = track()->outPort(); - int channel = track()->outChannel(); - // release note: - MusECore::MidiPlayEvent ev1(0, port, channel, 0x90, event.pitch() + track()->transposition, 0); - MusEGlobal::audio->msgPlayMidiEvent(&ev1); + stopPlayEvent(); if (moving.size() == 1) { - MusECore::MidiPlayEvent ev2(0, port, channel, 0x90, npitch + track()->transposition, event.velo()); - MusEGlobal::audio->msgPlayMidiEvent(&ev2); + startPlayEvent(npitch, event.velo()); } - else - playedPitch=-1; } MusECore::Part* part = nevent->part(); @@ -506,7 +480,7 @@ MusEGui::CItem* PianoCanvas::newItem(const QPoint& p, int) NEvent *newEvent = new NEvent(e, curPart, pitch2y(pitch)); if(_playEvents) - startPlayEvent(newEvent); + startPlayEvent(e.pitch(), e.velo()); return newEvent; } @@ -717,15 +691,10 @@ void PianoCanvas::pianoCmd(int cmd) void PianoCanvas::pianoPressed(int pitch, int velocity, bool shift) { - int port = track()->outPort(); - int channel = track()->outChannel(); - pitch += track()->transposition; - // play note: if(_playEvents) { - MusECore::MidiPlayEvent e(0, port, channel, 0x90, pitch, velocity); - MusEGlobal::audio->msgPlayMidiEvent(&e); + startPlayEvent(pitch, velocity); } if (_steprec && curPart) // && pos[0] >= start_tick && pos[0] < end_tick [removed by flo93: this is handled in steprec->record] @@ -736,18 +705,11 @@ void PianoCanvas::pianoPressed(int pitch, int velocity, bool shift) // pianoReleased //--------------------------------------------------------- -void PianoCanvas::pianoReleased(int pitch, bool) +void PianoCanvas::pianoReleased(int /*pitch*/, bool) { - int port = track()->outPort(); - int channel = track()->outChannel(); - pitch += track()->transposition; - // release key: if(_playEvents) - { - MusECore::MidiPlayEvent e(0, port, channel, 0x90, pitch, 0); - MusEGlobal::audio->msgPlayMidiEvent(&e); - } + stopPlayEvent(); } //--------------------------------------------------------- @@ -761,56 +723,28 @@ void PianoCanvas::drawCanvas(QPainter& p, const QRect& rect) int w = rect.width(); int h = rect.height(); - //DELETETHIS whoa, clean up the whole function. remove every commented out code line - - // Changed to draw in device coordinate space instead of virtual, transformed space. Tim. p4.0.30 - - //int mx = mapx(x); - //int my = mapy(y); - //int mw = mapx(x + w) - mx; - //int mw = mapx(x + w) - mx - 1; - //int mh = mapy(y + h) - my; - //int mh = mapy(y + h) - my - 1; - - // p.save(); - // FIXME Can't get horizontal lines quite right yet. Draw in virtual space for now... - ///p.setWorldMatrixEnabled(false); //--------------------------------------------------- // horizontal lines //--------------------------------------------------- int yy = ((y-1) / KH) * KH + KH; - //int yy = my + KH; - //int yy = ((my-1) / KH) * KH + KH; - //int yoff = -rmapy(yorg) - ypos; int key = 75 - (yy / KH); - //printf("PianoCanvas::drawCanvas x:%d y:%d w:%d h:%d mx:%d my:%d mw:%d mh:%d yy:%d key:%d\n", x, y, w, h, mx, my, mw, mh, yy, key); for (; yy < y + h; yy += KH) { - //for (; yy + yoff < my + mh; yy += KH) { - //for (; yy < my + mh; yy += KH) { switch (key % 7) { case 0: case 3: p.setPen(Qt::black); p.drawLine(x, yy, x + w, yy); - //p.drawLine(mx, yy + yoff, mx + mw, yy + yoff); - //p.drawLine(mx, yy, mx + mw, yy); break; default: p.fillRect(x, yy-3, w, 6, QBrush(QColor(230,230,230))); - //p.fillRect(mx, yy-3 + yoff, mw, 6, QBrush(QColor(230,230,230))); - //p.fillRect(mx, yy-3, mw, 6, QBrush(QColor(230,230,230))); break; } --key; } - //p.restore(); - ///p.setWorldMatrixEnabled(true); - - //p.setWorldMatrixEnabled(false); //--------------------------------------------------- // vertical lines @@ -818,8 +752,6 @@ void PianoCanvas::drawCanvas(QPainter& p, const QRect& rect) drawTickRaster(p, x, y, w, h, editor->raster()); - //p.restore(); - //p.setWorldMatrixEnabled(true); } //--------------------------------------------------------- @@ -993,8 +925,6 @@ void PianoCanvas::dragEnterEvent(QDragEnterEvent* event) void PianoCanvas::dragMoveEvent(QDragMoveEvent*) { - //printf("drag move %x\n", this); DELETETHIS (whole function?) - //event->acceptProposedAction(); } //--------------------------------------------------------- @@ -1003,8 +933,6 @@ void PianoCanvas::dragMoveEvent(QDragMoveEvent*) void PianoCanvas::dragLeaveEvent(QDragLeaveEvent*) { - //printf("drag leave\n"); DELETETHIS (whole function?) - //event->acceptProposedAction(); } //--------------------------------------------------------- @@ -1015,7 +943,8 @@ void PianoCanvas::itemPressed(const MusEGui::CItem* item) { if (!_playEvents) return; - startPlayEvent(item); + MusECore::Event e = ((NEvent*)item)->event(); + startPlayEvent(e.pitch(), e.velo()); } //--------------------------------------------------------- @@ -1037,23 +966,16 @@ void PianoCanvas::itemMoved(const MusEGui::CItem* item, const QPoint& pos) { int npitch = y2pitch(pos.y()); if ((playedPitch != -1) && (playedPitch != npitch)) { - int port = track()->outPort(); - int channel = track()->outChannel(); NEvent* nevent = (NEvent*) item; MusECore::Event event = nevent->event(); // release note: - MusECore::MidiPlayEvent ev1(0, port, channel, 0x90, playedPitch, 0); - MusEGlobal::audio->msgPlayMidiEvent(&ev1); + stopPlayEvent(); if (moving.size() == 1) { // items moving // play note: - MusECore::MidiPlayEvent e2(0, port, channel, 0x90, npitch + track()->transposition, event.velo()); - MusEGlobal::audio->msgPlayMidiEvent(&e2); - playedPitch = npitch + track()->transposition; + startPlayEvent(npitch, event.velo()); } - else - playedPitch = -1; } } @@ -1173,37 +1095,6 @@ 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 cbe6c68c..0dfe806c 100644 --- a/muse2/muse/midiedit/prcanvas.h +++ b/muse2/muse/midiedit/prcanvas.h @@ -34,7 +34,6 @@ #include "steprec.h" -#define KH 13 class QRect; @@ -61,7 +60,6 @@ class PianoCanvas : public EventCanvas { Q_OBJECT int colorMode; - int playedPitch; bool noteHeldDown[128]; @@ -92,8 +90,6 @@ 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); -- cgit v1.2.3