summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Jonsson <spamatica@gmail.com>2011-02-14 21:16:56 +0000
committerRobert Jonsson <spamatica@gmail.com>2011-02-14 21:16:56 +0000
commit1371ee8ba22423680d84623997f07b368a342164 (patch)
treeac3c5ea55dc813b67478b305b602d14b4475c700
parent7fa70010daf92f90bf47933e846c0ded239a98f7 (diff)
more graphical automation fixes
-rw-r--r--muse2/ChangeLog4
-rw-r--r--muse2/muse/arranger/pcanvas.cpp29
-rw-r--r--muse2/muse/arranger/tlist.cpp82
-rw-r--r--muse2/muse/arranger/tlist.h3
-rw-r--r--muse2/muse/audiotrack.cpp6
-rw-r--r--muse2/muse/ctrl.cpp15
-rw-r--r--muse2/muse/ctrl.h2
7 files changed, 113 insertions, 28 deletions
diff --git a/muse2/ChangeLog b/muse2/ChangeLog
index 98c7b170..75f9581e 100644
--- a/muse2/ChangeLog
+++ b/muse2/ChangeLog
@@ -1,6 +1,10 @@
14.02.2011:
- Fixed midi track info panel layout and spacing. Should be much better now. (Tim)
- Added patch to remove warnings from WillyFoobar (rj)
+ - Fixes to graphical automation (rj)
+ * select color in menu
+ * offset bug, can now edit automation although it's scrolled down
+ TODO redrawing issues when using slider automation for instance.
13.02.2011:
- restore toolbar locations for main window and editors (rj)
- fixed some layout issues in general settings (rj)
diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp
index 7ffe2b42..38941068 100644
--- a/muse2/muse/arranger/pcanvas.cpp
+++ b/muse2/muse/arranger/pcanvas.cpp
@@ -2959,8 +2959,8 @@ void PartCanvas::drawAutomation(QPainter& p, const QRect& r, AudioTrack *t)
prevVal = cvFirst.val;
// prepare prevVal
- if (cl->id() == AC_VOLUME ) { // use db scale for volume
- printf("volume cvval=%f\n", cvFirst.val);
+ if (cl->valueType() == VAL_LOG ) { // use db scale for volume
+ //printf("volume cvval=%f\n", cvFirst.val);
prevVal = dbToVal(cvFirst.val); // represent volume between 0 and 1
if (prevVal < 0) prevVal = 0.0;
}
@@ -2973,12 +2973,13 @@ void PartCanvas::drawAutomation(QPainter& p, const QRect& r, AudioTrack *t)
// draw a square around the point
p.drawRect(mapx(tempomap.frame2tick(prevPosFrame))-1, (rr.bottom()-2)-prevVal*height-1, 3, 3);
+ p.drawRect(mapx(tempomap.frame2tick(prevPosFrame))-2, (rr.bottom()-2)-prevVal*height-2, 5, 5);
for (; ic !=cl->end(); ++ic)
{
CtrlVal cv = ic->second;
double nextVal = cv.val; // was curVal
- if (cl->id() == AC_VOLUME ) { // use db scale for volume
+ if (cl->valueType() == VAL_LOG ) { // use db scale for volume
nextVal = dbToVal(cv.val); // represent volume between 0 and 1
if (nextVal < 0) nextVal = 0.0;
}
@@ -3005,7 +3006,8 @@ void PartCanvas::drawAutomation(QPainter& p, const QRect& r, AudioTrack *t)
goto quitDrawing;
// draw a square around the point
- p.drawRect(mapx(tempomap.frame2tick(prevPosFrame))-1, (rr.bottom()-2)-prevVal*height-1, 3, 3);
+ p.drawRect(mapx(tempomap.frame2tick(prevPosFrame))-2, (rr.bottom()-2)-prevVal*height-2, 5, 5);
+ p.drawRect(mapx(tempomap.frame2tick(prevPosFrame))-1, (rr.bottom()-1)-prevVal*height-2, 3, 3);
}
//printf("outer draw %f\n", cvFirst.val );
p.drawLine(mapx(tempomap.frame2tick(prevPosFrame)),
@@ -3036,7 +3038,7 @@ void PartCanvas::checkAutomation(Track * t, const QPoint &pointer, bool addNewCt
int circumference = 5;
if (t->isMidiTrack())
return;
- //printf("checkAutomation p.x()=%d p.y()=%d\n", mapx(pointer.x()), mapx(pointer.y()));
+ //printf("checkAutomation p.x()=%d p.y()=%d\n", mapx(pointer.x()), mapy(pointer.y()));
int currX = mapx(pointer.x());
int currY = mapy(pointer.y());
@@ -3053,16 +3055,16 @@ void PartCanvas::checkAutomation(Track * t, const QPoint &pointer, bool addNewCt
int oldX=-1;
int oldY=-1;
- int ypixel;
- int xpixel;
+ int ypixel=0;
+ int xpixel=-1;
- // First check that there ARE automation, ic == cl->end means no automation
+ // First check that there IS automation, ic == cl->end means no automation
if (ic != cl->end()) {
for (; ic !=cl->end(); ic++)
{
CtrlVal &cv = ic->second;
double y;
- if (cl->id() == AC_VOLUME ) { // use db scale for volume
+ if (cl->valueType() == VAL_LOG ) { // use db scale for volume
y = dbToVal(cv.val); // represent volume between 0 and 1
if (y < 0) y = 0;
}
@@ -3210,10 +3212,15 @@ void PartCanvas::processAutomationMovements(QMouseEvent *event)
if (nextFrame!=-1 && currFrame > nextFrame) currFrame=nextFrame-1;
automation.currentCtrl->frame = currFrame;
- int mouseY = automation.currentTrack->height() - (mapy(event->pos().y()) - automation.currentTrack->y())-2;
+ int posy=mapy(event->pos().y());
+ int tracky = mapy(automation.currentTrack->y());
+ int trackHeight = automation.currentTrack->height();
+ //printf("posy=%d tracky=%d trackHeight=%d\n", posy,tracky,trackHeight);
+
+ int mouseY = trackHeight - (posy - tracky)-2;
double yfraction = ((double)mouseY)/automation.currentTrack->height();
- if (automation.currentCtrlList->id() == AC_VOLUME ) { // use db scale for volume
+ if (automation.currentCtrlList->valueType() == VAL_LOG ) { // use db scale for volume
double cvval = valToDb(yfraction);
//printf("calc yfraction = %f v=%f ",yfraction,cvval);
diff --git a/muse2/muse/arranger/tlist.cpp b/muse2/muse/arranger/tlist.cpp
index 542e64c8..ab228e3b 100644
--- a/muse2/muse/arranger/tlist.cpp
+++ b/muse2/muse/arranger/tlist.cpp
@@ -20,6 +20,7 @@
#include <QResizeEvent>
#include <QScrollBar>
#include <QWheelEvent>
+#include <QIcon>
#include "popupmenu.h"
#include "globals.h"
@@ -52,6 +53,7 @@ extern QMenu* populateAddSynth(QWidget* parent);
static const int MIN_TRACKHEIGHT = 20;
static const int WHEEL_DELTA = 120;
+QColor collist[] = { Qt::red, Qt::yellow, Qt::blue , Qt::black, Qt::white, Qt::green };
//---------------------------------------------------------
// TList
@@ -781,26 +783,90 @@ TrackList TList::getRecEnabledTracks()
}
//---------------------------------------------------------
-// mousePressEvent
+// changeAutomation
//---------------------------------------------------------
void TList::changeAutomation(QAction* act)
{
- printf("changeAutomation!\n");
+ //printf("changeAutomation %d\n", act->data().toInt());
if (editAutomation->type() == Track::MIDI) {
printf("this is wrong, we can't edit automation for midi tracks from arranger yet!\n");
return;
}
+ int colindex = act->data().toInt() & 0xff;
+ int id = (act->data().toInt() & 0x00ffffff) / 256;
+ if (colindex < 100)
+ return; // this was meant for changeAutomationColor
+ // one of these days I'll rewrite this so it's understandable
+ // this is just to get it up and running...
+
CtrlListList* cll = ((AudioTrack*)editAutomation)->controller();
for(CtrlListList::iterator icll =cll->begin();icll!=cll->end();++icll) {
CtrlList *cl = icll->second;
- if (act->data() == cl->id()) // got it, change state
- cl->setVisible(!cl->isVisible());
+ if (id == cl->id()) // got it, change state
+ cl->setVisible(act->isChecked());
}
song->update(SC_TRACK_MODIFIED);
}
+//---------------------------------------------------------
+// changeAutomation
+//---------------------------------------------------------
+void TList::changeAutomationColor(QAction* act)
+{
+ if (editAutomation->type() == Track::MIDI) {
+ printf("this is wrong, we can't edit automation for midi tracks from arranger yet!\n");
+ return;
+ }
+ int colindex = act->data().toInt() & 0xff;
+ int id = (act->data().toInt() & 0x00ffffff) / 256;
+
+ if (colindex > 100)
+ return; // this was meant for changeAutomation
+ // one of these days I'll rewrite this so it's understandable
+ // this is just to get it up and running...
+
+ //printf("change automation color %d %d\n", id, colindex);
+
+ CtrlListList* cll = ((AudioTrack*)editAutomation)->controller();
+ for(CtrlListList::iterator icll =cll->begin();icll!=cll->end();++icll) {
+ CtrlList *cl = icll->second;
+ if (cl->id() == id) // got it, change color
+ cl->setColor(collist[colindex]);
+ }
+ song->update(SC_TRACK_MODIFIED);
+}
+
+//---------------------------------------------------------
+// colorMenu
+//---------------------------------------------------------
+QMenu* TList::colorMenu(QColor c, int id)
+{
+ QMenu * m = new QMenu(this);
+ for (int i = 0; i< 6; i++) {
+ QPixmap pix(10,10);
+ QPainter p(&pix);
+ p.fillRect(0,0,10,10,collist[i]);
+ p.setPen(Qt::black);
+ p.drawRect(0,0,10,10);
+ QIcon icon(pix);
+ QAction *act = m->addAction(icon,"");
+ act->setCheckable(true);
+ if (c == collist[i])
+ act->setChecked(true);
+ int data = id * 256; // shift 8 bits
+ data += i; // color in the bottom 8 bits
+ act->setData(data);
+ }
+ connect(m, SIGNAL(triggered(QAction*)), SLOT(changeAutomationColor(QAction*)));
+ return m;
+
+}
+
+//---------------------------------------------------------
+// mousePressEvent
+//---------------------------------------------------------
void TList::mousePressEvent(QMouseEvent* ev)
{
int x = ev->x();
@@ -958,13 +1024,17 @@ void TList::mousePressEvent(QMouseEvent* ev)
QAction* act = 0;
for(CtrlListList::iterator icll =cll->begin();icll!=cll->end();++icll) {
CtrlList *cl = icll->second;
- printf("id = %d", cl->id());
+ //printf("id = %d", cl->id());
if (cl->dontShow())
continue;
act = p->addAction(cl->name());
act->setCheckable(true);
act->setChecked(cl->isVisible());
- act->setData(cl->id());
+ int data = cl->id() * 256; // shift 8 bits
+ data += 150; // illegal color > 100
+ act->setData(data);
+ QMenu *m = colorMenu(cl->color(), cl->id());
+ act->setMenu(m);
}
connect(p, SIGNAL(triggered(QAction*)), SLOT(changeAutomation(QAction*)));
//connect(p, SIGNAL(aboutToHide()), muse, SLOT(routingPopupMenuAboutToHide()));
diff --git a/muse2/muse/arranger/tlist.h b/muse2/muse/arranger/tlist.h
index 9ecd5d57..8bebef95 100644
--- a/muse2/muse/arranger/tlist.h
+++ b/muse2/muse/arranger/tlist.h
@@ -19,6 +19,7 @@ class QPaintEvent;
class QResizeEvent;
class QScrollBar;
class QWheelEvent;
+class QMenu;
class ScrollScale;
class Track;
@@ -84,11 +85,13 @@ class TList : public QWidget {
void classesPopupMenu(Track*, int x, int y);
TrackList getRecEnabledTracks();
void setHeaderToolTips();
+ QMenu* colorMenu(QColor c, int id);
private slots:
void returnPressed();
void songChanged(int flags);
void changeAutomation(QAction*);
+ void changeAutomationColor(QAction*);
signals:
///void selectionChanged();
diff --git a/muse2/muse/audiotrack.cpp b/muse2/muse/audiotrack.cpp
index af066437..11404993 100644
--- a/muse2/muse/audiotrack.cpp
+++ b/muse2/muse/audiotrack.cpp
@@ -79,9 +79,9 @@ AudioTrack::AudioTrack(TrackType t)
_automationType = AUTO_OFF;
//setChannels(1);
setChannels(2);
- addController(new CtrlList(AC_VOLUME,"Volume",0.0,3.16 /* roughly 10 db */));
- addController(new CtrlList(AC_PAN, "Pan", -1.0, 1.0));
- addController(new CtrlList(AC_MUTE,"Mute",0.0,1.0, true /*dont show in arranger */));
+ addController(new CtrlList(AC_VOLUME,"Volume",0.0,3.16 /* roughly 10 db */, VAL_LOG));
+ addController(new CtrlList(AC_PAN, "Pan", -1.0, 1.0, VAL_LINEAR));
+ addController(new CtrlList(AC_MUTE,"Mute",0.0,1.0, VAL_LINEAR, true /*dont show in arranger */));
// Changed by Tim. p3.3.15
//outBuffers = new float*[MAX_CHANNELS];
diff --git a/muse2/muse/ctrl.cpp b/muse2/muse/ctrl.cpp
index e5da5f2b..bb77e0c5 100644
--- a/muse2/muse/ctrl.cpp
+++ b/muse2/muse/ctrl.cpp
@@ -20,13 +20,13 @@
void CtrlList::initColor(int i)
{
- QColor collist[] = { Qt::red, Qt::yellow, Qt::blue , Qt::green, Qt::white, Qt::black };
+ QColor collist[] = { Qt::red, Qt::yellow, Qt::blue , Qt::black, Qt::white, Qt::green };
- if (i < 5)
- _displayColor = collist[i%6];
+ if (i < 6)
+ _displayColor = collist[i%6];
else
- _displayColor = Qt::gray;
- _visible = false;
+ _displayColor = Qt::green;
+ _visible = false;
}
@@ -47,7 +47,7 @@ CtrlList::CtrlList(int id)
//---------------------------------------------------------
// CtrlList
//---------------------------------------------------------
-CtrlList::CtrlList(int id, QString name, double min, double max, bool dontShow)
+CtrlList::CtrlList(int id, QString name, double min, double max, CtrlValueType v, bool dontShow)
{
_id = id;
_default = 0.0;
@@ -56,6 +56,7 @@ CtrlList::CtrlList(int id, QString name, double min, double max, bool dontShow)
_name = name;
_min = min;
_max = max;
+ _valueType = v;
_dontShow = dontShow;
initColor(id);
}
@@ -70,7 +71,7 @@ CtrlList::CtrlList()
_curVal = 0.0;
_mode = INTERPOLATE;
_dontShow = false;
- initColor(-1);
+ initColor(0);
}
//---------------------------------------------------------
diff --git a/muse2/muse/ctrl.h b/muse2/muse/ctrl.h
index 307a3783..4d864b9f 100644
--- a/muse2/muse/ctrl.h
+++ b/muse2/muse/ctrl.h
@@ -96,7 +96,7 @@ class CtrlList : public std::map<int, CtrlVal, std::less<int> > {
public:
CtrlList();
CtrlList(int id);
- CtrlList(int id, QString name, double min, double max, bool dontShow=false);
+ CtrlList(int id, QString name, double min, double max, CtrlValueType v, bool dontShow=false);
Mode mode() const { return _mode; }
void setMode(Mode m) { _mode = m; }