summaryrefslogtreecommitdiff
path: root/muse2/muse
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2011-10-11 15:33:08 +0000
committerFlorian Jung <flo@windfisch.org>2011-10-11 15:33:08 +0000
commit4b27437712d5341129b019ec98fb8e4d3fa7ad0d (patch)
treef8ef2fddceb04aa8469d73f2e87d2ef851c827ca /muse2/muse
parent88041047222b78104191f449d3dbd7953d78a6e4 (diff)
improved drum canvas moving
Diffstat (limited to 'muse2/muse')
-rw-r--r--muse2/muse/midiedit/dcanvas.cpp55
-rw-r--r--muse2/muse/midiedit/dcanvas.h2
-rw-r--r--muse2/muse/midiedit/ecanvas.cpp4
-rw-r--r--muse2/muse/midiedit/ecanvas.h3
-rw-r--r--muse2/muse/midiedit/prcanvas.cpp12
-rw-r--r--muse2/muse/midiedit/prcanvas.h2
-rw-r--r--muse2/muse/midiedit/scoreedit.cpp3
-rw-r--r--muse2/muse/widgets/canvas.cpp11
8 files changed, 63 insertions, 29 deletions
diff --git a/muse2/muse/midiedit/dcanvas.cpp b/muse2/muse/midiedit/dcanvas.cpp
index 03432bbd..03d38fbf 100644
--- a/muse2/muse/midiedit/dcanvas.cpp
+++ b/muse2/muse/midiedit/dcanvas.cpp
@@ -22,6 +22,7 @@
#include <QPainter>
#include <QApplication>
+#include <QMessageBox>
#include <QClipboard>
#include <QDrag>
#include <QDragLeaveEvent>
@@ -115,6 +116,8 @@ DrumCanvas::DrumCanvas(MidiEditor* pr, QWidget* parent, int sx,
{
drumEditor=dynamic_cast<DrumEdit*>(pr);
+ _setCurPartIfOnlyOneEventIsSelected=false;
+
old_style_drummap_mode = drumEditor->old_style_drummap_mode();
if (old_style_drummap_mode)
@@ -257,7 +260,11 @@ MusECore::Undo DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, Dra
// Do not process if the event has already been processed (meaning it's an event in a clone part)...
if (idl == doneList.end())
{
- operations.push_back(moveItem(ci, newpos, dtype));
+ if (moveItem(operations, ci, newpos, dtype) == false) //error?
+ {
+ QMessageBox::warning(this, tr("Moving items failed"), tr("The selection couldn't be moved, because at least one note would be moved into a track which is different from both the original track and the current part's track.\nChanging the current part with ALT+LEFT/RIGHT may help."));
+ return MusECore::Undo(); //return empty list
+ }
doneList.push_back(ci);
}
ci->move(newpos);
@@ -289,29 +296,38 @@ MusECore::Undo DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, Dra
// moveItem
//---------------------------------------------------------
-MusECore::UndoOp DrumCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype)
+bool DrumCanvas::moveItem(MusECore::Undo& operations, CItem* item, const QPoint& pos, DragType dtype)
{
DEvent* nevent = (DEvent*) item;
- MusECore::MidiPart* part = (MusECore::MidiPart*)nevent->part();
+ MusECore::MidiPart* part = (MusECore::MidiPart*)nevent->part();
+ MusECore::MidiPart* dest_part = part;
+ int nheight = y2pitch(pos.y());
+
+ if (!instrument_map[nheight].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()))
+ {
+ 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;
+ }
+ else
+ dest_part=(MusECore::MidiPart*)curPart;
+ }
+
MusECore::Event event = nevent->event();
int x = pos.x();
if (x < 0)
x = 0;
- int ntick = editor->rasterVal(x) - part->tick();
+ int ntick = editor->rasterVal(x) - dest_part->tick();
if (ntick < 0)
ntick = 0;
- int nheight = y2pitch(pos.y());
MusECore::Event newEvent = event.clone();
-
- MusECore::Track* dest_track = part->track();
- if (!instrument_map[nheight].tracks.contains(dest_track))
- {
- printf ("TODO FIXME: tried to move an event into a different track. this is not supported yet, but will be soon. ignoring this one...\n");
- //FINDMICH
- return MusECore::UndoOp();
- }
+
int ev_pitch = instrument_map[nheight].pitch;
@@ -324,10 +340,19 @@ MusECore::UndoOp DrumCanvas::moveItem(CItem* item, const QPoint& pos, DragType d
// printf("DrumCanvas::moveItem Error! New event end:%d exceeds length:%d of part:%s\n", newEvent.endTick(), part->lenTick(), part->name().toLatin1().constData());
if (dtype == MOVE_COPY || dtype == MOVE_CLONE)
- return MusECore::UndoOp(MusECore::UndoOp::AddEvent, newEvent, part, false, false);
+ operations.push_back(MusECore::UndoOp(MusECore::UndoOp::AddEvent, newEvent, dest_part, false, false));
else
- return MusECore::UndoOp(MusECore::UndoOp::ModifyEvent, newEvent, event, part, false, false);
+ {
+ if (dest_part == part)
+ operations.push_back(MusECore::UndoOp(MusECore::UndoOp::ModifyEvent, newEvent, event, part, false, false));
+ else
+ {
+ operations.push_back(MusECore::UndoOp(MusECore::UndoOp::DeleteEvent, event, part, false, false));
+ operations.push_back(MusECore::UndoOp(MusECore::UndoOp::AddEvent, newEvent, dest_part, false, false));
+ }
}
+ return true;
+}
//---------------------------------------------------------
// newItem
diff --git a/muse2/muse/midiedit/dcanvas.h b/muse2/muse/midiedit/dcanvas.h
index 2911862e..9053b3bf 100644
--- a/muse2/muse/midiedit/dcanvas.h
+++ b/muse2/muse/midiedit/dcanvas.h
@@ -110,7 +110,7 @@ class DrumCanvas : public EventCanvas {
void drawTopItem(QPainter& p, const QRect& rect);
virtual void drawMoving(QPainter&, const CItem*, const QRect&);
virtual MusECore::Undo moveCanvasItems(CItemList&, int, int, DragType);
- virtual MusECore::UndoOp moveItem(CItem*, const QPoint&, DragType);
+ virtual bool moveItem(MusECore::Undo&, CItem*, const QPoint&, DragType);
virtual CItem* newItem(const QPoint&, int);
virtual void resizeItem(CItem*, bool, bool);
virtual void newItem(CItem*, bool);
diff --git a/muse2/muse/midiedit/ecanvas.cpp b/muse2/muse/midiedit/ecanvas.cpp
index 61891b2e..9941f7e5 100644
--- a/muse2/muse/midiedit/ecanvas.cpp
+++ b/muse2/muse/midiedit/ecanvas.cpp
@@ -56,6 +56,7 @@ EventCanvas::EventCanvas(MidiEditor* pr, QWidget* parent, int sx,
_steprec = false;
_midiin = false;
_playEvents = false;
+ _setCurPartIfOnlyOneEventIsSelected = true;
curVelo = 70;
setBg(Qt::white);
@@ -204,7 +205,7 @@ void EventCanvas::songChanged(int flags)
start_tick = MusEGlobal::song->roundDownBar(start_tick);
end_tick = MusEGlobal::song->roundUpBar(end_tick);
- if (n == 1) {
+ if (n == 1 && _setCurPartIfOnlyOneEventIsSelected) {
x = nevent->x();
event = nevent->event();
part = (MusECore::MidiPart*)nevent->part();
@@ -214,6 +215,7 @@ void EventCanvas::songChanged(int flags)
curPartChanged();
}
}
+
emit selectionChanged(x, event, part);
if (curPart == 0)
curPart = (MusECore::MidiPart*)(editor->parts()->begin()->second);
diff --git a/muse2/muse/midiedit/ecanvas.h b/muse2/muse/midiedit/ecanvas.h
index 1c66e9b4..2c783332 100644
--- a/muse2/muse/midiedit/ecanvas.h
+++ b/muse2/muse/midiedit/ecanvas.h
@@ -69,13 +69,14 @@ class EventCanvas : public Canvas {
int curVelo;
bool _steprec;
bool _midiin;
+ bool _setCurPartIfOnlyOneEventIsSelected;
void updateSelection();
virtual void addItem(MusECore::Part*, MusECore::Event&) = 0;
// Added by T356.
virtual QPoint raster(const QPoint&) const;
virtual MusECore::Undo moveCanvasItems(CItemList&, int, int, DragType) = 0;
- virtual MusECore::UndoOp moveItem(CItem*, const QPoint&, DragType) = 0;
+ virtual bool moveItem(MusECore::Undo&, CItem*, const QPoint&, DragType) = 0;
virtual void endMoveItems(const QPoint&, DragType, int dir);
public slots:
diff --git a/muse2/muse/midiedit/prcanvas.cpp b/muse2/muse/midiedit/prcanvas.cpp
index 9acaf186..223ae519 100644
--- a/muse2/muse/midiedit/prcanvas.cpp
+++ b/muse2/muse/midiedit/prcanvas.cpp
@@ -423,7 +423,7 @@ MusECore::Undo PianoCanvas::moveCanvasItems(MusEGui::CItemList& items, int dp, i
// Do not process if the event has already been processed (meaning it's an event in a clone part)...
if (idl == doneList.end())
{
- operations.push_back(moveItem(ci, newpos, dtype));
+ moveItem(operations, ci, newpos, dtype); // always returns true. if not, change is necessary here!
doneList.push_back(ci);
}
ci->move(newpos);
@@ -456,7 +456,7 @@ MusECore::Undo PianoCanvas::moveCanvasItems(MusEGui::CItemList& items, int dp, i
// called after moving an object
//---------------------------------------------------------
-MusECore::UndoOp PianoCanvas::moveItem(MusEGui::CItem* item, const QPoint& pos, DragType dtype)
+bool PianoCanvas::moveItem(MusECore::Undo& operations, MusEGui::CItem* item, const QPoint& pos, DragType dtype)
{
NEvent* nevent = (NEvent*) item;
MusECore::Event event = nevent->event();
@@ -492,10 +492,12 @@ MusECore::UndoOp PianoCanvas::moveItem(MusEGui::CItem* item, const QPoint& pos,
// printf("PianoCanvas::moveItem Error! New event end:%d exceeds length:%d of part:%s\n", newEvent.endTick(), part->lenTick(), part->name().toLatin1().constData());
if (dtype == MOVE_COPY || dtype == MOVE_CLONE)
- return MusECore::UndoOp(MusECore::UndoOp::AddEvent, newEvent, part, false, false);
+ operations.push_back(MusECore::UndoOp(MusECore::UndoOp::AddEvent, newEvent, part, false, false));
else
- return MusECore::UndoOp(MusECore::UndoOp::ModifyEvent, newEvent, event, part, false, false);
- }
+ operations.push_back(MusECore::UndoOp(MusECore::UndoOp::ModifyEvent, newEvent, event, part, false, false));
+
+ return true;
+}
//---------------------------------------------------------
// newItem(p, state)
diff --git a/muse2/muse/midiedit/prcanvas.h b/muse2/muse/midiedit/prcanvas.h
index 18d4f130..e9bd654d 100644
--- a/muse2/muse/midiedit/prcanvas.h
+++ b/muse2/muse/midiedit/prcanvas.h
@@ -73,7 +73,7 @@ class PianoCanvas : public EventCanvas {
void drawTopItem(QPainter &p, const QRect &rect);
virtual void drawMoving(QPainter&, const CItem*, const QRect&);
virtual MusECore::Undo moveCanvasItems(CItemList&, int, int, DragType);
- virtual MusECore::UndoOp moveItem(CItem*, const QPoint&, DragType);
+ virtual bool moveItem(MusECore::Undo&, CItem*, const QPoint&, DragType);
virtual CItem* newItem(const QPoint&, int);
virtual void resizeItem(CItem*, bool noSnap, bool);
virtual void newItem(CItem*, bool noSnap);
diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp
index 962a7ae3..a7b848f5 100644
--- a/muse2/muse/midiedit/scoreedit.cpp
+++ b/muse2/muse/midiedit/scoreedit.cpp
@@ -4595,6 +4595,9 @@ void ScoreCanvas::add_new_parts(const std::map< MusECore::Part*, std::set<MusECo
*
* CURRENT TODO
* o my record flag handling
+ * o option for disabling old-style / new-style drum tracks?
+ * o steprec and mouse-inserting notes should automatically find out
+ * the proper destination part, or create a new one in dcanvas.cpp
*
* > o drum editor: channel-stuff
* o clearly state in the changelog: when having multiple drumeditors open,
diff --git a/muse2/muse/widgets/canvas.cpp b/muse2/muse/widgets/canvas.cpp
index 41c5f4a4..9a1935a3 100644
--- a/muse2/muse/widgets/canvas.cpp
+++ b/muse2/muse/widgets/canvas.cpp
@@ -750,11 +750,6 @@ void Canvas::viewMousePressEvent(QMouseEvent* event)
switch (_tool) {
case PointerTool:
if (curItem) {
- if (curItem->part() != curPart) {
- curPart = curItem->part();
- curPartId = curPart->sn();
- curPartChanged();
- }
itemPressed(curItem);
// Changed by T356. Alt is default reserved for moving the whole window in KDE. Changed to Shift-Alt.
// Hmm, nope, shift-alt is also reserved sometimes. Must find a way to bypass,
@@ -1226,6 +1221,12 @@ void Canvas::viewMouseReleaseEvent(QMouseEvent* event)
case DRAG_MOVE_START:
case DRAG_COPY_START:
case DRAG_CLONE_START:
+ if (curItem->part() != curPart) {
+ curPart = curItem->part();
+ curPartId = curPart->sn();
+ curPartChanged();
+ }
+
if (!ctrl)
deselectAll();