diff options
author | Robert Jonsson <spamatica@gmail.com> | 2010-10-13 19:34:22 +0000 |
---|---|---|
committer | Robert Jonsson <spamatica@gmail.com> | 2010-10-13 19:34:22 +0000 |
commit | 8a2c2824a59d7644e13bc52c9a0ecbd641f21f95 (patch) | |
tree | 064ad3f2bf8daab0ad27b128abd86a9bbdb1e496 /muse2/muse/widgets/poslabel.cpp | |
parent | a27706d9629e8b592cca4659f865b70adef24e6d (diff) |
new branch muse2, first checkin
Diffstat (limited to 'muse2/muse/widgets/poslabel.cpp')
-rw-r--r-- | muse2/muse/widgets/poslabel.cpp | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/muse2/muse/widgets/poslabel.cpp b/muse2/muse/widgets/poslabel.cpp new file mode 100644 index 00000000..3066b640 --- /dev/null +++ b/muse2/muse/widgets/poslabel.cpp @@ -0,0 +1,152 @@ +//========================================================= +// MusE +// Linux Music Editor +// $Id: poslabel.cpp,v 1.2.2.2 2009/04/06 01:24:55 terminator356 Exp $ +// (C) Copyright 2001 Werner Schweer (ws@seh.de) +//========================================================= + +#include <stdlib.h> +#include <cmath> +#include <qapplication.h> +#include <qstyle.h> +//Added by qt3to4: +#include <QLabel> + +#include "poslabel.h" +#include "sig.h" +#include "tempo.h" +#include "globals.h" + +extern int mtcType; + +//--------------------------------------------------------- +// PosLabel +//--------------------------------------------------------- + +PosLabel::PosLabel(QWidget* parent, const char* name) + : QLabel(parent, name) + { + _tickValue = 0; + _sampleValue = 0; + _smpte = false; + setFrameStyle(WinPanel | Sunken); + setLineWidth(2); + setMidLineWidth(3); + int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this); // ddskrjo 0 + setIndent(fw); + updateValue(); + } + +//--------------------------------------------------------- +// sizeHint +//--------------------------------------------------------- + +QSize PosLabel::sizeHint() const + { + QFontMetrics fm(font()); + int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this); // ddskrjo 0 + int h = fm.height() + fw * 2; + int w; + if (_smpte) + w = 2 + fm.width('9') * 9 + fm.width(':') * 3 + fw * 4; + else + w = 2 + fm.width('9') * 9 + fm.width('.') * 2 + fw * 4; + return QSize(w, h).expandedTo(QApplication::globalStrut()); + } + +//--------------------------------------------------------- +// updateValue +//--------------------------------------------------------- + +void PosLabel::updateValue() + { + QString s; + if (_smpte) { + double time = double(_sampleValue) / double(sampleRate); + int min = int(time) / 60; + int sec = int(time) % 60; + double rest = time - (min * 60 + sec); + switch(mtcType) { + case 0: // 24 frames sec + rest *= 24; + break; + case 1: // 25 + rest *= 25; + break; + case 2: // 30 drop frame + rest *= 30; + break; + case 3: // 30 non drop frame + rest *= 30; + break; + } + int frame = int(rest); + int subframe = int((rest-frame)*100); + s.sprintf("%03d:%02d:%02d:%02d", min, sec, frame, subframe); + } + else { + int bar, beat; + unsigned tick; + sigmap.tickValues(_tickValue, &bar, &beat, &tick); + //s.sprintf("%04d.%02d.%03ud", bar+1, beat+1, tick); + s.sprintf("%04d.%02d.%03u", bar+1, beat+1, tick); + } + setText(s); + } + +//--------------------------------------------------------- +// setSampleValue +//--------------------------------------------------------- + +void PosLabel::setSampleValue(unsigned val) + { + if (val == _sampleValue) + return; + _sampleValue = val; + updateValue(); + } + +//--------------------------------------------------------- +// setTickValue +//--------------------------------------------------------- + +void PosLabel::setTickValue(unsigned val) + { + if (val == _tickValue) + return; + if (val >= MAX_TICK) + abort(); + _tickValue = val; + updateValue(); + } + +//--------------------------------------------------------- +// setValue +//--------------------------------------------------------- + +void PosLabel::setValue(unsigned val) + { + unsigned oval = _smpte ? _sampleValue : _tickValue; + if (val == oval) + return; + if (_smpte) + _sampleValue = val; + else + _tickValue = val; + updateValue(); + } + +//--------------------------------------------------------- +// setSmpte +//--------------------------------------------------------- + +void PosLabel::setSmpte(bool val) + { + _smpte = val; + if (val) + _sampleValue = tempomap.tick2frame(_tickValue); + else + _tickValue = tempomap.frame2tick(_sampleValue); + updateValue(); + } + |