1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
//=========================================================
// MusE
// Linux Music Editor
// $Id: poslabel.cpp,v 1.1.1.1 2003/10/29 10:06:23 wschweer Exp $
// (C) Copyright 2001 Werner Schweer (ws@seh.de)
//=========================================================
#include <cmath>
#include <qapplication.h>
#include <qstyle.h>
#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, this);
setIndent(fw);
updateValue();
}
//---------------------------------------------------------
// sizeHint
//---------------------------------------------------------
QSize PosLabel::sizeHint() const
{
QFontMetrics fm(font());
int fw = style().pixelMetric(QStyle::PM_DefaultFrameWidth, this);
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, tick;
sigmap.tickValues(_tickValue, &bar, &beat, &tick);
s.sprintf("%04d.%02d.%03d", bar+1, beat+1, tick);
}
setText(s);
}
//---------------------------------------------------------
// setSampleValue
//---------------------------------------------------------
void PosLabel::setSampleValue(int val)
{
if (val == _sampleValue)
return;
_sampleValue = val;
updateValue();
}
//---------------------------------------------------------
// setTickValue
//---------------------------------------------------------
void PosLabel::setTickValue(int val)
{
if (val == _tickValue)
return;
_tickValue = val;
updateValue();
}
//---------------------------------------------------------
// setValue
//---------------------------------------------------------
void PosLabel::setValue(int val)
{
int 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 = lrint(tempomap.tick2time(_tickValue) * sampleRate);
else
_tickValue = tempomap.time2tick(double(_sampleValue) / double(sampleRate));
updateValue();
}
|