summaryrefslogtreecommitdiff
path: root/muse2/muse/waveedit
diff options
context:
space:
mode:
authorTim E. Real <termtech@rogers.com>2013-02-20 01:16:45 +0000
committerTim E. Real <termtech@rogers.com>2013-02-20 01:16:45 +0000
commitc3650bf9b2302e1a20853f0cadc7833370e3d0dd (patch)
treefa1a229b0928290a00f974a14104e385d42c5905 /muse2/muse/waveedit
parent612acc2cd3979edf441d2f33403f6b3403c1cf05 (diff)
MASSIVE FIXES: MANY editor, usability, operation fixes and changes.
See ChangeLog.
Diffstat (limited to 'muse2/muse/waveedit')
-rw-r--r--muse2/muse/waveedit/wavecanvas.cpp56
-rw-r--r--muse2/muse/waveedit/wavecanvas.h6
-rw-r--r--muse2/muse/waveedit/waveedit.cpp51
-rw-r--r--muse2/muse/waveedit/waveedit.h4
4 files changed, 67 insertions, 50 deletions
diff --git a/muse2/muse/waveedit/wavecanvas.cpp b/muse2/muse/waveedit/wavecanvas.cpp
index b9a006eb..80341554 100644
--- a/muse2/muse/waveedit/wavecanvas.cpp
+++ b/muse2/muse/waveedit/wavecanvas.cpp
@@ -51,6 +51,7 @@
#include <set>
#include "app.h"
+#include "icons.h"
#include "xml.h"
#include "wavecanvas.h"
#include "event.h"
@@ -656,6 +657,9 @@ void WaveCanvas::draw(QPainter& p, const QRect& r)
p.drawLine(mx, my, mx, my2);
}
+ if(drag == DRAG_ZOOM)
+ p.drawPixmap(mapFromGlobal(global_start), *zoomAtIcon);
+
//p.restore();
//p.setWorldMatrixEnabled(true);
p.setWorldMatrixEnabled(wmtxen);
@@ -848,30 +852,19 @@ void WaveCanvas::wheelEvent(QWheelEvent* ev)
if (shift) { // scroll horizontally
int delta = -ev->delta() / WHEEL_DELTA;
int xpixelscale = 5*MusECore::fast_log10(rmapxDev(1));
-
-
if (xpixelscale <= 0)
xpixelscale = 1;
-
int scrollstep = WHEEL_STEPSIZE * (delta);
- ///if (ev->state() == Qt::ShiftModifier)
- // if (((QInputEvent*)ev)->modifiers() == Qt::ShiftModifier)
scrollstep = scrollstep / 10;
-
int newXpos = xpos + xpixelscale * scrollstep;
-
if (newXpos < 0)
newXpos = 0;
-
- //setYPos(newYpos);
emit horizontalScroll((unsigned)newXpos);
-
} else if (ctrl) { // zoom horizontally
- emit horizontalZoom(ev->delta()>0, ev->x());
+ emit horizontalZoom(ev->delta()>0, ev->globalPos());
} else { // scroll horizontally
emit mouseWheelMoved(ev->delta() / 10);
}
-
}
//---------------------------------------------------------
@@ -891,7 +884,7 @@ bool WaveCanvas::mousePress(QMouseEvent* event)
switch (_tool) {
default:
break;
- case CursorTool:
+ case RangeTool:
switch (button) {
case Qt::LeftButton:
if (mode == NORMAL) {
@@ -1224,7 +1217,7 @@ void WaveCanvas::viewMouseDoubleClickEvent(QMouseEvent* event)
// moveCanvasItems
//---------------------------------------------------------
-MusECore::Undo WaveCanvas::moveCanvasItems(MusEGui::CItemList& items, int /*dp*/, int dx, DragType dtype)
+MusECore::Undo WaveCanvas::moveCanvasItems(MusEGui::CItemList& items, int /*dp*/, int dx, DragType dtype, bool rasterize)
{
if(editor->parts()->empty())
return MusECore::Undo(); //return empty list
@@ -1248,7 +1241,9 @@ MusECore::Undo WaveCanvas::moveCanvasItems(MusEGui::CItemList& items, int /*dp*/
int x = ci->pos().x() + dx;
//int y = pitch2y(y2pitch(ci->pos().y()) + dp);
int y = 0;
- QPoint newpos = raster(QPoint(x, y));
+ QPoint newpos = QPoint(x, y);
+ if(rasterize)
+ newpos = raster(newpos);
// Test moving the item...
WEvent* wevent = (WEvent*) ci;
@@ -1256,7 +1251,7 @@ MusECore::Undo WaveCanvas::moveCanvasItems(MusEGui::CItemList& items, int /*dp*/
x = newpos.x();
if(x < 0)
x = 0;
- int nframe = MusEGlobal::tempomap.tick2frame(editor->rasterVal(MusEGlobal::tempomap.frame2tick(x))) - part->frame();
+ int nframe = (rasterize ? MusEGlobal::tempomap.tick2frame(editor->rasterVal(MusEGlobal::tempomap.frame2tick(x))) : x) - part->frame();
if(nframe < 0)
nframe = 0;
int diff = nframe + event.lenFrame() - part->lenFrame();
@@ -1305,7 +1300,9 @@ MusECore::Undo WaveCanvas::moveCanvasItems(MusEGui::CItemList& items, int /*dp*/
int nx = x + dx;
//int ny = pitch2y(y2pitch(y) + dp);
int ny = 0;
- QPoint newpos = raster(QPoint(nx, ny));
+ QPoint newpos = QPoint(nx, ny);
+ if(rasterize)
+ newpos = raster(newpos);
selectItem(ci, true);
iDoneList idl;
@@ -1317,7 +1314,7 @@ MusECore::Undo WaveCanvas::moveCanvasItems(MusEGui::CItemList& items, int /*dp*/
// Do not process if the event has already been processed (meaning it's an event in a clone part)...
if (idl == doneList.end())
{
- moveItem(operations, ci, newpos, dtype); // always returns true. if not, change is necessary here!
+ moveItem(operations, ci, newpos, dtype, rasterize); // always returns true. if not, change is necessary here!
doneList.push_back(ci);
}
ci->move(newpos);
@@ -1351,7 +1348,7 @@ MusECore::Undo WaveCanvas::moveCanvasItems(MusEGui::CItemList& items, int /*dp*/
// called after moving an object
//---------------------------------------------------------
-bool WaveCanvas::moveItem(MusECore::Undo& operations, MusEGui::CItem* item, const QPoint& pos, DragType dtype)
+bool WaveCanvas::moveItem(MusECore::Undo& operations, MusEGui::CItem* item, const QPoint& pos, DragType dtype, bool rasterize)
{
WEvent* wevent = (WEvent*) item;
MusECore::Event event = wevent->event();
@@ -1362,7 +1359,7 @@ bool WaveCanvas::moveItem(MusECore::Undo& operations, MusEGui::CItem* item, cons
x = 0;
MusECore::Part* part = wevent->part();
- int nframe = MusEGlobal::tempomap.tick2frame(editor->rasterVal(MusEGlobal::tempomap.frame2tick(x))) - part->frame();
+ int nframe = (rasterize ? MusEGlobal::tempomap.tick2frame(editor->rasterVal(MusEGlobal::tempomap.frame2tick(x))) : x) - part->frame();
if (nframe < 0)
nframe = 0;
newEvent.setFrame(nframe);
@@ -1384,9 +1381,11 @@ bool WaveCanvas::moveItem(MusECore::Undo& operations, MusEGui::CItem* item, cons
// newItem(p, state)
//---------------------------------------------------------
-MusEGui::CItem* WaveCanvas::newItem(const QPoint& p, int)
+MusEGui::CItem* WaveCanvas::newItem(const QPoint& p, int key_modifiers)
{
- int frame = MusEGlobal::tempomap.tick2frame(editor->rasterVal1(MusEGlobal::tempomap.frame2tick(p.x())));
+ int frame = p.x();
+ if(!(key_modifiers & Qt::ShiftModifier))
+ frame = MusEGlobal::tempomap.tick2frame(editor->rasterVal1(MusEGlobal::tempomap.frame2tick(frame)));
int len = p.x() - frame;
frame -= curPart->frame();
if (frame < 0)
@@ -1402,9 +1401,11 @@ void WaveCanvas::newItem(MusEGui::CItem* item, bool noSnap)
{
WEvent* wevent = (WEvent*) item;
MusECore::Event event = wevent->event();
+ MusECore::Part* part = wevent->part();
+ int pframe = part->frame();
int x = item->x();
- if (x<0)
- x=0;
+ if (x<pframe)
+ x=pframe;
int w = item->width();
if (!noSnap) {
@@ -1416,8 +1417,9 @@ void WaveCanvas::newItem(MusEGui::CItem* item, bool noSnap)
//w = editor->raster();
w = MusEGlobal::tempomap.tick2frame(editor->raster());
}
- MusECore::Part* part = wevent->part();
- event.setFrame(x - part->frame());
+ if (x<pframe)
+ x=pframe;
+ event.setFrame(x - pframe);
event.setLenFrame(w);
MusECore::Undo operations;
@@ -1696,7 +1698,7 @@ void WaveCanvas::cmd(int cmd)
double paramA = 0.0;
switch (cmd) {
case CMD_SELECT_ALL: // select all
- if (tool() == MusEGui::CursorTool)
+ if (tool() == MusEGui::RangeTool)
{
if (!editor->parts()->empty()) {
MusECore::iPart iBeg = editor->parts()->begin();
diff --git a/muse2/muse/waveedit/wavecanvas.h b/muse2/muse/waveedit/wavecanvas.h
index 5ad836bc..10f75291 100644
--- a/muse2/muse/waveedit/wavecanvas.h
+++ b/muse2/muse/waveedit/wavecanvas.h
@@ -114,8 +114,8 @@ class WaveCanvas : public EventCanvas {
virtual void drawItem(QPainter&, const CItem*, const QRect&);
void drawTopItem(QPainter &p, const QRect &rect);
virtual void drawMoving(QPainter&, const CItem*, const QRect&);
- virtual MusECore::Undo moveCanvasItems(CItemList&, int, int, DragType);
- virtual bool moveItem(MusECore::Undo&, CItem*, const QPoint&, DragType);
+ virtual MusECore::Undo moveCanvasItems(CItemList&, int, int, DragType, bool rasterize = true);
+ virtual bool moveItem(MusECore::Undo&, CItem*, const QPoint&, DragType, bool rasterize = true);
virtual CItem* newItem(const QPoint&, int);
virtual void resizeItem(CItem*, bool noSnap, bool);
virtual void newItem(CItem*, bool noSnap);
@@ -128,6 +128,8 @@ class WaveCanvas : public EventCanvas {
int y2pitch(int) const;
int pitch2y(int) const;
+ inline int y2height(int) const { return height(); }
+ inline int yItemOffset() const { return 0; }
virtual void drawCanvas(QPainter&, const QRect&);
virtual void itemPressed(const CItem*);
virtual void itemReleased(const CItem*, const QPoint&);
diff --git a/muse2/muse/waveedit/waveedit.cpp b/muse2/muse/waveedit/waveedit.cpp
index 95443757..03a4d045 100644
--- a/muse2/muse/waveedit/waveedit.cpp
+++ b/muse2/muse/waveedit/waveedit.cpp
@@ -67,7 +67,7 @@ extern QColor readColor(MusECore::Xml& xml);
namespace MusEGui {
static int waveEditTools = MusEGui::PointerTool | MusEGui::PencilTool | MusEGui::RubberTool |
- MusEGui::CutTool | MusEGui::CursorTool;
+ MusEGui::CutTool | MusEGui::RangeTool | PanTool | ZoomTool;
int WaveEdit::_rasterInit = 96;
int WaveEdit::colorModeInit = 0;
@@ -298,7 +298,8 @@ WaveEdit::WaveEdit(MusECore::PartList* pl, QWidget* parent, const char* name)
ymag->setFixedWidth(16);
connect(canvas, SIGNAL(mouseWheelMoved(int)), this, SLOT(moveVerticalSlider(int)));
connect(ymag, SIGNAL(valueChanged(int)), canvas, SLOT(setYScale(int)));
- connect(canvas, SIGNAL(horizontalZoom(bool,int)), SLOT(horizontalZoom(bool,int)));
+ connect(canvas, SIGNAL(horizontalZoom(bool, const QPoint&)), SLOT(horizontalZoom(bool, const QPoint&)));
+ connect(canvas, SIGNAL(horizontalZoom(int, const QPoint&)), SLOT(horizontalZoom(int, const QPoint&)));
time->setOrigin(0, 0);
@@ -334,8 +335,8 @@ WaveEdit::WaveEdit(MusECore::PartList* pl, QWidget* parent, const char* name)
connect(MusEGlobal::song, SIGNAL(songChanged(MusECore::SongChangedFlags_t)), SLOT(songChanged1(MusECore::SongChangedFlags_t)));
// For the wave editor, let's start with the operation range selection tool.
- canvas->setTool(MusEGui::CursorTool);
- tools2->set(MusEGui::CursorTool);
+ canvas->setTool(MusEGui::RangeTool);
+ tools2->set(MusEGui::RangeTool);
setEventColorMode(colorMode);
@@ -683,8 +684,16 @@ void WaveEdit::keyPressEvent(QKeyEvent* event)
tools2->set(MusEGui::CutTool);
return;
}
- else if (key == shortcuts[SHRT_TOOL_CURSOR].key) {
- tools2->set(MusEGui::CursorTool);
+ else if (key == shortcuts[SHRT_TOOL_PAN].key) {
+ tools2->set(MusEGui::PanTool);
+ return;
+ }
+ else if (key == shortcuts[SHRT_TOOL_ZOOM].key) {
+ tools2->set(MusEGui::ZoomTool);
+ return;
+ }
+ else if (key == shortcuts[SHRT_TOOL_RANGE].key) {
+ tools2->set(MusEGui::RangeTool);
return;
}
else if (key == shortcuts[SHRT_EVENT_COLOR].key) {
@@ -698,21 +707,11 @@ void WaveEdit::keyPressEvent(QKeyEvent* event)
// TODO: New WaveCanvas: Convert some of these to use frames.
else if (key == shortcuts[SHRT_ZOOM_IN].key) {
- int offset = 0;
- QPoint cp = canvas->mapFromGlobal(QCursor::pos());
- QPoint sp = mainw->mapFromGlobal(QCursor::pos());
- if(cp.x() >= 0 && cp.x() < canvas->width() && sp.y() >= 0 && sp.y() < mainw->height())
- offset = cp.x();
- horizontalZoom(true, offset);
+ horizontalZoom(true, QCursor::pos());
return;
}
else if (key == shortcuts[SHRT_ZOOM_OUT].key) {
- int offset = 0;
- QPoint cp = canvas->mapFromGlobal(QCursor::pos());
- QPoint sp = mainw->mapFromGlobal(QCursor::pos());
- if(cp.x() >= 0 && cp.x() < canvas->width() && sp.y() >= 0 && sp.y() < mainw->height())
- offset = cp.x();
- horizontalZoom(false, offset);
+ horizontalZoom(false, QCursor::pos());
return;
}
else if (key == shortcuts[SHRT_GOTO_CPOS].key) {
@@ -783,7 +782,7 @@ void WaveEdit::moveVerticalSlider(int val)
ymag->setValue(ymag->value() + val);
}
-void WaveEdit::horizontalZoom(bool zoom_in, int pos_offset)
+void WaveEdit::horizontalZoom(bool zoom_in, const QPoint& glob_pos)
{
int mag = hscroll->mag();
int zoomlvl = ScrollScale::getQuickZoomLevel(mag);
@@ -798,7 +797,19 @@ void WaveEdit::horizontalZoom(bool zoom_in, int pos_offset)
zoomlvl--;
}
int newmag = ScrollScale::convertQuickZoomLevelToMag(zoomlvl);
- hscroll->setMag(newmag, pos_offset);
+
+ QPoint cp = canvas->mapFromGlobal(glob_pos);
+ QPoint sp = mainw->mapFromGlobal(glob_pos);
+ if(cp.x() >= 0 && cp.x() < canvas->width() && sp.y() >= 0 && sp.y() < mainw->height())
+ hscroll->setMag(newmag, cp.x());
+}
+
+void WaveEdit::horizontalZoom(int mag, const QPoint& glob_pos)
+{
+ QPoint cp = canvas->mapFromGlobal(glob_pos);
+ QPoint sp = mainw->mapFromGlobal(glob_pos);
+ if(cp.x() >= 0 && cp.x() < canvas->width() && sp.y() >= 0 && sp.y() < mainw->height())
+ hscroll->setMag(hscroll->mag() + mag, cp.x());
}
//---------------------------------------------------------
diff --git a/muse2/muse/waveedit/waveedit.h b/muse2/muse/waveedit/waveedit.h
index 54fc769a..0f4a4031 100644
--- a/muse2/muse/waveedit/waveedit.h
+++ b/muse2/muse/waveedit/waveedit.h
@@ -40,6 +40,7 @@ class QAction;
class QResizeEvent;
class QSlider;
class QToolButton;
+class QPoint;
namespace MusECore {
class PartList;
@@ -101,7 +102,8 @@ class WaveEdit : public MidiEditor {
public slots:
void configChanged();
virtual void updateHScrollRange();
- void horizontalZoom(bool zoom_in, int pos_offset);
+ void horizontalZoom(bool zoom_in, const QPoint& glob_pos);
+ void horizontalZoom(int mag, const QPoint& glob_pos);
void focusCanvas();
signals: