summaryrefslogtreecommitdiff
path: root/muse2
diff options
context:
space:
mode:
Diffstat (limited to 'muse2')
-rw-r--r--muse2/muse/master/master.cpp89
-rw-r--r--muse2/muse/master/master.h7
-rw-r--r--muse2/muse/master/masteredit.cpp2
3 files changed, 92 insertions, 6 deletions
diff --git a/muse2/muse/master/master.cpp b/muse2/muse/master/master.cpp
index 76d22a2f..712d2985 100644
--- a/muse2/muse/master/master.cpp
+++ b/muse2/muse/master/master.cpp
@@ -216,8 +216,63 @@ void Master::draw(QPainter& p, const QRect& rect)
{
drawTickRaster(p, rect.x(), rect.y(),
rect.width(), rect.height(), 0);
+
+ if ((tool == MusEGui::DrawTool) && drawLineMode) {
+ p.setPen(Qt::black);
+ p.drawLine(line1x, line1y, line2x, line2y);
+ }
}
+ //---------------------------------------------------------
+// changeValRamp
+//---------------------------------------------------------
+
+void Master::newValRamp(int x1, int y1, int x2, int y2)
+{
+ MusECore::Undo operations;
+
+ int h = height();
+
+// loop through all tick positions between x1 and x2
+// remove all tempo changes and add new ones for changed
+
+ int tickStart = editor->rasterVal1(x1);
+ int tickEnd = editor->rasterVal2(x2);
+
+ const MusECore::TempoList* tl = &MusEGlobal::tempomap;
+ for (MusECore::ciTEvent i = tl->begin(); i != tl->end(); ++i) {
+ MusECore::TEvent* e = i->second;
+ int etick = mapx(i->first);
+ int endOldTick = i->first;
+ int stick = mapx(i->second->tick);
+ int startOldTick = i->second->tick;
+ //printf("stick=%d startOldTick=%d tickEnd=%d\n",stick, startOldTick, tickEnd);
+ if (startOldTick > tickStart && startOldTick < tickEnd ) {
+ operations.push_back(MusECore::UndoOp(MusECore::UndoOp::DeleteTempo, startOldTick, e->tempo));
+ //printf("tempo = %f %d %d\n", 60000000.0/e->tempo, endOldTick, startOldTick);
+ }
+ }
+
+ int priorTick = editor->rasterVal1(x1);
+ int tempoVal = int(60000000000.0/(280000 - y1));
+ operations.push_back(MusECore::UndoOp(MusECore::UndoOp::AddTempo, tickStart, tempoVal));
+ for (int i = x1; i < x2; i++) {
+ int tick = editor->rasterVal1(i);
+ if (tick > priorTick) {
+ double xproportion = double(tick-tickStart)/double(tickEnd-tickStart);
+ int yproportion = double(y2 - y1) * xproportion;
+ int yNew = y1 + yproportion;
+ int tempoVal = int(60000000000.0/(280000 - yNew));
+ //printf("tickStart %d tickEnd %d yNew %d xproportion %f yproportion %d\n", tickStart, tickEnd, yNew, xproportion, yproportion);
+ operations.push_back(MusECore::UndoOp(MusECore::UndoOp::AddTempo, tick, tempoVal));
+ priorTick = tick;
+ }
+ }
+
+ MusEGlobal::song->applyOperationGroup(operations);
+}
+
+
//---------------------------------------------------------
// viewMousePressEvent
//---------------------------------------------------------
@@ -225,8 +280,13 @@ void Master::draw(QPainter& p, const QRect& rect)
void Master::viewMousePressEvent(QMouseEvent* event)
{
start = event->pos();
+ int xpos = start.x();
+ int ypos = start.y();
+
MusEGui::Tool activeTool = tool;
-// bool shift = event->state() & ShiftButton;
+ bool ctrlKey = event->modifiers() & Qt::ControlModifier;
+
+ //MusECore::MidiController::ControllerType type = MusECore::midiControllerType(_controller->num());
switch (activeTool) {
case MusEGui::PointerTool:
@@ -245,6 +305,20 @@ void Master::viewMousePressEvent(QMouseEvent* event)
deleteVal(start.x(), start.x());
break;
+ case MusEGui::DrawTool:
+ if (drawLineMode) {
+ line2x = xpos;
+ line2y = ypos;
+ newValRamp(line1x, line1y, line2x, line2y);
+ drawLineMode = false;
+ }
+ else {
+ line2x = line1x = xpos;
+ line2y = line1y = ypos;
+ drawLineMode = true;
+ }
+ redraw();
+ break;
default:
break;
}
@@ -257,9 +331,12 @@ void Master::viewMousePressEvent(QMouseEvent* event)
void Master::viewMouseMoveEvent(QMouseEvent* event)
{
QPoint pos = event->pos();
-// QPoint dist = pos - start;
-// bool moving = dist.y() >= 3 || dist.y() <= 3 || dist.x() >= 3 || dist.x() <= 3; DELETETHIS
-
+ if (tool == MusEGui::DrawTool && drawLineMode) {
+ line2x = pos.x();
+ line2y = pos.y();
+ redraw();
+ return;
+ }
switch (drag) {
case DRAG_NEW:
newVal(start.x(), pos.x(), pos.y());
@@ -349,6 +426,9 @@ void Master::setTool(int t)
case MusEGui::PencilTool:
setCursor(QCursor(*pencilIcon, 4, 15));
break;
+ case MusEGui::DrawTool:
+ drawLineMode = false;
+ break;
default:
setCursor(QCursor(Qt::ArrowCursor));
break;
@@ -373,5 +453,4 @@ void Master::newVal(int x1, int x2, int y)
MusEGlobal::audio->msgAddTempo(xx1, int(60000000000.0/(280000 - y)), false);
redraw();
}
-
} // namespace MusEGui
diff --git a/muse2/muse/master/master.h b/muse2/muse/master/master.h
index 37991a7f..04a00896 100644
--- a/muse2/muse/master/master.h
+++ b/muse2/muse/master/master.h
@@ -57,6 +57,11 @@ class Master : public MusEGui::View {
DragMode drag;
MidiEditor* editor;
+ int line1x;
+ int line1y;
+ int line2x;
+ int line2y;
+ bool drawLineMode;
virtual void pdraw(QPainter&, const QRect&);
virtual void viewMouseMoveEvent(QMouseEvent* event);
@@ -69,6 +74,8 @@ class Master : public MusEGui::View {
bool deleteVal1(unsigned int x1, unsigned int x2);
void deleteVal(int x1, int x2);
+ void newValRamp(int x1, int y1, int x2, int y2);
+
private slots:
void songChanged(MusECore::SongChangedFlags_t);
diff --git a/muse2/muse/master/masteredit.cpp b/muse2/muse/master/masteredit.cpp
index a134ef14..2fd2d4a8 100644
--- a/muse2/muse/master/masteredit.cpp
+++ b/muse2/muse/master/masteredit.cpp
@@ -116,7 +116,7 @@ MasterEdit::MasterEdit(QWidget* parent, const char* name)
settingsMenu->addAction(fullscreenAction);
// Toolbars ---------------------------------------------------------
- MusEGui::EditToolBar* tools2 = new MusEGui::EditToolBar(this, MusEGui::PointerTool | MusEGui::PencilTool | MusEGui::RubberTool);
+ MusEGui::EditToolBar* tools2 = new MusEGui::EditToolBar(this, MusEGui::PointerTool | MusEGui::PencilTool | MusEGui::RubberTool| MusEGui::DrawTool);
addToolBar(tools2);
QToolBar* enableMaster = addToolBar(tr("Enable master"));