summaryrefslogtreecommitdiff
path: root/muse2
diff options
context:
space:
mode:
authorrj <rj@rj>2013-10-10 14:26:42 +0200
committerrj <rj@rj>2013-10-10 14:26:42 +0200
commit48c1e3e74a76b5d061241d8cfb734f2664db10cb (patch)
tree38b151b4a8803f8b8f823eae055e40243cda6b88 /muse2
parent693b7264e1baa4956d1cb7947b425491bdb25338 (diff)
added visual metronome to bigtime
Diffstat (limited to 'muse2')
-rw-r--r--muse2/muse/app.cpp2
-rw-r--r--muse2/muse/widgets/bigtime.cpp319
-rw-r--r--muse2/muse/widgets/bigtime.h41
3 files changed, 197 insertions, 165 deletions
diff --git a/muse2/muse/app.cpp b/muse2/muse/app.cpp
index 42ed58e4..df061217 100644
--- a/muse2/muse/app.cpp
+++ b/muse2/muse/app.cpp
@@ -275,7 +275,7 @@ void addProject(const QString& name)
if (projectRecentList.contains(name))
return;
- projectRecentList.append(name);
+ projectRecentList.push_front(name);
if (projectRecentList.size() > PROJECT_LIST_LEN)
projectRecentList.pop_back();
diff --git a/muse2/muse/widgets/bigtime.cpp b/muse2/muse/widgets/bigtime.cpp
index 5adf4966..e7a6478a 100644
--- a/muse2/muse/widgets/bigtime.cpp
+++ b/muse2/muse/widgets/bigtime.cpp
@@ -22,10 +22,12 @@
//=========================================================
#include <stdio.h>
#include <limits.h>
+#include <cmath>
#include <QCheckBox>
#include <QLabel>
#include <QResizeEvent>
+#include <QPainter>
#include "globals.h"
#include "bigtime.h"
@@ -51,59 +53,56 @@ namespace MusEGui {
BigTime::BigTime(QWidget* parent)
: QWidget(parent, Qt::Window | Qt::WindowStaysOnTopHint) // Possibly also Qt::X11BypassWindowManagerHint
- {
-
- tickmode = true;
- dwin = new QWidget(this, Qt::WindowStaysOnTopHint); // Possibly also Qt::X11BypassWindowManagerHint
- dwin->setObjectName("bigtime-dwin");
- dwin->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
- fmtButton = new QCheckBox(QString(""), this);
- fmtButton->resize(18,18);
- fmtButton->setChecked(true);
- fmtButton->setToolTip(tr("format display"));
- fmtButton->setFocusPolicy(Qt::NoFocus);
- barLabel = new QLabel(dwin);
- beatLabel = new QLabel(dwin);
- tickLabel = new QLabel(dwin);
- //hourLabel = new QLabel(dwin);
- minLabel = new QLabel(dwin);
- secLabel = new QLabel(dwin);
- frameLabel = new QLabel(dwin);
- subFrameLabel = new QLabel(dwin);
- sep1 = new QLabel(QString("."), dwin);
- sep2 = new QLabel(QString("."), dwin);
- sep3 = new QLabel(QString(":"), dwin);
- sep4 = new QLabel(QString(":"), dwin);
- sep5 = new QLabel(QString(":"), dwin);
- absTickLabel = new QLabel(dwin);
- absFrameLabel = new QLabel(dwin);
- barLabel->setToolTip(tr("bar"));
- beatLabel->setToolTip(tr("beat"));
- tickLabel->setToolTip(tr("tick"));
- //hourLabel->setToolTip(tr("hour"));
- minLabel->setToolTip(tr("minute"));
- secLabel->setToolTip(tr("second"));
- frameLabel->setToolTip(tr("frame"));
- subFrameLabel->setToolTip(tr("subframe"));
- absTickLabel->setToolTip(tr("tick"));
- absFrameLabel->setToolTip(tr("frame"));
- fmtButtonToggled(true);
- connect(fmtButton, SIGNAL(toggled(bool)), SLOT(fmtButtonToggled(bool)));
- //oldbar = oldbeat = oldtick = oldhour = oldmin = oldsec = oldframe = -1;
- oldbar = oldbeat = oldtick = oldmin = oldsec = oldframe = oldsubframe = -1;
- oldAbsTick = oldAbsFrame = -1;
- setString(INT_MAX);
-
- dwin->setStyleSheet("font-size:10px; font-family:'Courier'; "); // Tim p4.0.8
-
- configChanged();
-
- //QFont f(QString("Courier"));
- //f.setPixelSize(10);
- //dwin->setFont(f);
+{
- setWindowTitle(tr("MusE: Bigtime"));
- }
+ tickmode = true;
+ dwin = new QWidget(this, Qt::WindowStaysOnTopHint); // Possibly also Qt::X11BypassWindowManagerHint
+ dwin->setObjectName("bigtime-dwin");
+ dwin->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
+ dwin->setStyleSheet("font-size:10px; font-family:'Courier'; "); // Tim p4.0.8
+
+ fmtButton = new QCheckBox(QString(""), this);
+ fmtButton->resize(18,18);
+ fmtButton->setChecked(true);
+ fmtButton->setToolTip(tr("format display"));
+ fmtButton->setFocusPolicy(Qt::NoFocus);
+ barLabel = new QLabel(dwin);
+ beatLabel = new QLabel(dwin);
+ tickLabel = new QLabel(dwin);
+ //hourLabel = new QLabel(dwin);
+ minLabel = new QLabel(dwin);
+ secLabel = new QLabel(dwin);
+ frameLabel = new QLabel(dwin);
+ subFrameLabel = new QLabel(dwin);
+ sep1 = new QLabel(QString("."), dwin);
+ sep2 = new QLabel(QString("."), dwin);
+ sep3 = new QLabel(QString(":"), dwin);
+ sep4 = new QLabel(QString(":"), dwin);
+ sep5 = new QLabel(QString(":"), dwin);
+ absTickLabel = new QLabel(dwin);
+ absFrameLabel = new QLabel(dwin);
+ barLabel->setToolTip(tr("bar"));
+ beatLabel->setToolTip(tr("beat"));
+ tickLabel->setToolTip(tr("tick"));
+ //hourLabel->setToolTip(tr("hour"));
+ minLabel->setToolTip(tr("minute"));
+ secLabel->setToolTip(tr("second"));
+ frameLabel->setToolTip(tr("frame"));
+ subFrameLabel->setToolTip(tr("subframe"));
+ absTickLabel->setToolTip(tr("tick"));
+ absFrameLabel->setToolTip(tr("frame"));
+ fmtButtonToggled(true);
+ connect(fmtButton, SIGNAL(toggled(bool)), SLOT(fmtButtonToggled(bool)));
+ //oldbar = oldbeat = oldtick = oldhour = oldmin = oldsec = oldframe = -1;
+ oldbar = oldbeat = oldtick = oldmin = oldsec = oldframe = oldsubframe = -1;
+ oldAbsTick = oldAbsFrame = -1;
+ setString(INT_MAX);
+ metronome = new VerticalMetronomeWidget(dwin);
+
+ configChanged();
+
+ setWindowTitle(tr("MusE: Bigtime"));
+}
//---------------------------------------------------------
// fmtButtonToggled
@@ -212,23 +211,23 @@ void BigTime::closeEvent(QCloseEvent *ev)
bool BigTime::setString(unsigned v)
{
if (v == INT_MAX) {
- barLabel->setText(QString("----"));
- beatLabel->setText(QString("--"));
- tickLabel->setText(QString("---"));
- //hourLabel->setText(QString("--"));
- //minLabel->setText(QString("--"));
- minLabel->setText(QString("---"));
- secLabel->setText(QString("--"));
- frameLabel->setText(QString("--"));
- subFrameLabel->setText(QString("--"));
-
+ barLabel->setText(QString("----"));
+ beatLabel->setText(QString("--"));
+ tickLabel->setText(QString("---"));
+ //hourLabel->setText(QString("--"));
+ //minLabel->setText(QString("--"));
+ minLabel->setText(QString("---"));
+ secLabel->setText(QString("--"));
+ frameLabel->setText(QString("--"));
+ subFrameLabel->setText(QString("--"));
+
absTickLabel->setText(QString("----------"));
absFrameLabel->setText(QString("----------"));
oldAbsTick = oldAbsFrame = -1;
- //oldbar = oldbeat = oldtick = oldhour = oldmin = oldsec = oldframe = -1;
+ //oldbar = oldbeat = oldtick = oldhour = oldmin = oldsec = oldframe = -1;
oldbar = oldbeat = oldtick = oldmin = oldsec = oldframe = oldsubframe = -1;
- return true;
- }
+ return true;
+ }
// Quick fix: Not much to do but ignore the supplied tick: We need the exact frame here.
unsigned absFrame = MusEGlobal::audio->pos().frame();
@@ -325,86 +324,76 @@ bool BigTime::setString(unsigned v)
//---------------------------------------------------------
// setPos
//---------------------------------------------------------
-
+#define PI 3.14159265
void BigTime::setPos(int idx, unsigned v, bool)
- {
- if (idx == 0)
- setString(v);
- }
+{
+ if (idx == 0)
+ {
+ int calcV = v%(MusEGlobal::config.midiDivision*2);
+ double rangeAdjuster = PI/double(MusEGlobal::config.midiDivision);
+ metronome->setMetronome(sin(double(calcV)*rangeAdjuster));
+ //printf("calcV=%d rangeAdjuster %f metronomePosition=%f midiDivision=%d\n",v,rangeAdjuster, metronomePosition, MusEGlobal::config.midiDivision);
+ setString(v);
+ }
+ metronome->update();
+}
//---------------------------------------------------------
// resizeEvent
//---------------------------------------------------------
void BigTime::resizeEvent(QResizeEvent *ev)
- {
+{
QWidget::resizeEvent(ev);
dwin->resize(ev->size());
QFont f = dwin->font();
- QFontMetrics fm(f);
- int fs = f.pixelSize();
- int hspace = 20;
- //int tw = fm.width(QString("00:00:00:00"));
- int tw = fm.width(QString("000:00:00:00"));
+ QFontMetrics fm(f);
+ int fs = f.pixelSize();
+ int hspace = 20;
+ int tw = fm.width(QString("000:00:00:00"));
- fs = ((ev->size().width() - hspace*2)*fs) / tw;
+ fs = ((ev->size().width() - hspace*2)*fs) / tw;
- // set min/max
- if (fs < 10)
- fs = 10;
- else if (fs > 256)
- fs = 256;
+ // set min/max
+ if (fs < 10)
+ fs = 10;
+ else if (fs > 256)
+ fs = 256;
- //if(debugMsg)
- // printf("resize BigTime: Font name:%s CurSize:%d NewSize:%d, NewWidth:%d\n",
- // f.family().toLatin1().constData(), fs, nfs, ev->size().width());
-
- //f.setPixelSize(fs);
-
- //dwin->setFont(f);
QString fstr = QString("font-size:%1px; font-family:'Courier'; ").arg(fs); // Tim p4.0.8
dwin->setStyleSheet(fstr);
setBgColor(MusEGlobal::config.bigTimeBackgroundColor);
setFgColor(MusEGlobal::config.bigTimeForegroundColor);
int digitWidth = dwin->fontMetrics().width(QString("0"));
- int vspace = (ev->size().height() - (fs*2)) / 3;
+ int vspace = (ev->size().height() - (fs*2)) / 3;
int tickY = vspace;
- int timeY = vspace*2 + fs;
+ int timeY = vspace*2 + fs;
int absTickY = tickY;
int absFrameY = timeY;
- barLabel->resize(digitWidth*4, fs);
- beatLabel->resize(digitWidth*2, fs);
- tickLabel->resize(digitWidth*3, fs);
- //hourLabel->resize(digitWidth*2, fs);
- //minLabel->resize(digitWidth*2, fs);
+ barLabel->resize(digitWidth*4, fs);
+ beatLabel->resize(digitWidth*2, fs);
+ tickLabel->resize(digitWidth*3, fs);
minLabel->resize(digitWidth*3, fs);
- secLabel->resize(digitWidth*2, fs);
- frameLabel->resize(digitWidth*2, fs);
+ secLabel->resize(digitWidth*2, fs);
+ frameLabel->resize(digitWidth*2, fs);
subFrameLabel->resize(digitWidth*2, fs);
absTickLabel->resize(digitWidth*10, fs);
absFrameLabel->resize(digitWidth*10, fs);
sep1->resize(digitWidth, fs);
- sep2->resize(digitWidth, fs);
- sep3->resize(digitWidth, fs);
- sep4->resize(digitWidth, fs);
- sep5->resize(digitWidth, fs);
-
- barLabel->move( hspace + (digitWidth*0), tickY);
- sep1->move( hspace + (digitWidth*4), tickY);
- beatLabel->move( hspace + (digitWidth*5), tickY);
- sep2->move( hspace + (digitWidth*7), tickY);
- tickLabel->move( hspace + (digitWidth*8), tickY);
-
- //hourLabel->move( hspace + (digitWidth*0), timeY);
- //sep3->move( hspace + (digitWidth*2), timeY);
- //minLabel->move( hspace + (digitWidth*3), timeY);
- //sep4->move( hspace + (digitWidth*5), timeY);
- //secLabel->move( hspace + (digitWidth*6), timeY);
- //sep5->move( hspace + (digitWidth*8), timeY);
- //frameLabel->move( hspace + (digitWidth*9), timeY);
+ sep2->resize(digitWidth, fs);
+ sep3->resize(digitWidth, fs);
+ sep4->resize(digitWidth, fs);
+ sep5->resize(digitWidth, fs);
+
+ barLabel->move( hspace + (digitWidth*0), tickY);
+ sep1->move( hspace + (digitWidth*4), tickY);
+ beatLabel->move( hspace + (digitWidth*5), tickY);
+ sep2->move( hspace + (digitWidth*7), tickY);
+ tickLabel->move( hspace + (digitWidth*8), tickY);
+
minLabel->move( hspace + (digitWidth*0), timeY);
sep3->move( hspace + (digitWidth*3), timeY);
secLabel->move( hspace + (digitWidth*4), timeY);
@@ -415,64 +404,68 @@ void BigTime::resizeEvent(QResizeEvent *ev)
absTickLabel->move( hspace + (digitWidth*0), absTickY);
absFrameLabel->move( hspace + (digitWidth*0), absFrameY);
- }
+
+ metronome->move(0,dwin->height() - dwin->height()/10);
+ metronome->resize(dwin->width(),dwin->height()/10);
+}
//---------------------------------------------------------
// setForegroundColor
//---------------------------------------------------------
void BigTime::setFgColor(QColor c)
- {
- QPalette newpalette(palette());
- newpalette.setColor(QPalette::Foreground, c);
- setPalette(newpalette);
-
- barLabel->setPalette(newpalette);
- beatLabel->setPalette(newpalette);
- tickLabel->setPalette(newpalette);
- //hourLabel->setPalette(newpalette);
- minLabel->setPalette(newpalette);
- secLabel->setPalette(newpalette);
- frameLabel->setPalette(newpalette);
- subFrameLabel->setPalette(newpalette);
-
- absTickLabel->setPalette(newpalette);
- absFrameLabel->setPalette(newpalette);
- sep1->setPalette(newpalette);
- sep2->setPalette(newpalette);
- sep3->setPalette(newpalette);
- sep4->setPalette(newpalette);
- sep5->setPalette(newpalette);
- }
+{
+ QPalette newpalette(palette());
+ newpalette.setColor(QPalette::Foreground, c);
+ setPalette(newpalette);
+
+ barLabel->setPalette(newpalette);
+ beatLabel->setPalette(newpalette);
+ tickLabel->setPalette(newpalette);
+ //hourLabel->setPalette(newpalette);
+ minLabel->setPalette(newpalette);
+ secLabel->setPalette(newpalette);
+ frameLabel->setPalette(newpalette);
+ subFrameLabel->setPalette(newpalette);
+
+ absTickLabel->setPalette(newpalette);
+ absFrameLabel->setPalette(newpalette);
+ sep1->setPalette(newpalette);
+ sep2->setPalette(newpalette);
+ sep3->setPalette(newpalette);
+ sep4->setPalette(newpalette);
+ sep5->setPalette(newpalette);
+}
//---------------------------------------------------------
// setBackgroundColor
//---------------------------------------------------------
void BigTime::setBgColor(QColor c)
- {
- QPalette newpalette(palette());
- newpalette.setColor(QPalette::Window, c);
- setPalette(newpalette);
-
- barLabel->setPalette(newpalette);
- beatLabel->setPalette(newpalette);
- tickLabel->setPalette(newpalette);
- //hourLabel->setPalette(newpalette);
- minLabel->setPalette(newpalette);
- secLabel->setPalette(newpalette);
- frameLabel->setPalette(newpalette);
- subFrameLabel->setPalette(newpalette);
-
- absTickLabel->setPalette(newpalette);
- absFrameLabel->setPalette(newpalette);
- sep1->setPalette(newpalette);
- sep2->setPalette(newpalette);
- sep3->setPalette(newpalette);
- sep4->setPalette(newpalette);
- sep5->setPalette(newpalette);
-
- setPalette(newpalette);
- }
+{
+ QPalette newpalette(palette());
+ newpalette.setColor(QPalette::Window, c);
+ setPalette(newpalette);
+
+ barLabel->setPalette(newpalette);
+ beatLabel->setPalette(newpalette);
+ tickLabel->setPalette(newpalette);
+ //hourLabel->setPalette(newpalette);
+ minLabel->setPalette(newpalette);
+ secLabel->setPalette(newpalette);
+ frameLabel->setPalette(newpalette);
+ subFrameLabel->setPalette(newpalette);
+
+ absTickLabel->setPalette(newpalette);
+ absFrameLabel->setPalette(newpalette);
+ sep1->setPalette(newpalette);
+ sep2->setPalette(newpalette);
+ sep3->setPalette(newpalette);
+ sep4->setPalette(newpalette);
+ sep5->setPalette(newpalette);
+
+ setPalette(newpalette);
+}
+
} // namespace MusEGui
diff --git a/muse2/muse/widgets/bigtime.h b/muse2/muse/widgets/bigtime.h
index 3e3a2480..6d2557a4 100644
--- a/muse2/muse/widgets/bigtime.h
+++ b/muse2/muse/widgets/bigtime.h
@@ -24,6 +24,9 @@
#define __BIGTIME_H__
#include <QWidget>
+#include <QPaintEvent>
+#include <QPainter>
+#include <cmath>
class QCheckBox;
class QLabel;
@@ -32,6 +35,41 @@ namespace MusEGui {
class MusE;
+class VerticalMetronomeWidget : public QWidget
+{
+ float metronomePosition;
+
+
+protected:
+ void paintEvent (QPaintEvent *ev )
+ {
+ QRect rr(ev->rect());
+ QPainter p(this);
+
+ //p.fillRect(rr,Qt::yellow);
+ int y = (rr.height() - (rr.height()*fabs(metronomePosition)))-1;
+ if (metronomePosition > -0.05 and metronomePosition < 0.15) {
+ p.setPen(Qt::red);
+ p.drawLine(0,y-1,rr.width(),y-1);
+ }
+ else {
+ p.setPen(Qt::yellow);
+ }
+ p.drawLine(0,y,rr.width(),y);
+ }
+public:
+ VerticalMetronomeWidget(QWidget* parent) : QWidget(parent) {
+ metronomePosition=0.0;
+ }
+
+ void setMetronome(float v)
+ {
+ metronomePosition = v;
+ update();
+ }
+};
+
+
//---------------------------------------------------------
// BigTime
//---------------------------------------------------------
@@ -42,9 +80,9 @@ class BigTime : public QWidget {
bool tickmode;
MusE* seq;
-
bool setString(unsigned);
+ VerticalMetronomeWidget *metronome;
QWidget *dwin;
QCheckBox *fmtButton;
QLabel *absTickLabel;
@@ -64,6 +102,7 @@ class BigTime : public QWidget {
protected:
virtual void resizeEvent(QResizeEvent*);
virtual void closeEvent(QCloseEvent*);
+ //void paintEvent (QPaintEvent *event );
public slots:
void setPos(int, unsigned, bool);