diff options
-rw-r--r-- | muse2/ChangeLog | 5 | ||||
-rw-r--r-- | muse2/al/al.cpp | 6 | ||||
-rw-r--r-- | muse2/al/al.h | 6 | ||||
-rw-r--r-- | muse2/awl/posedit.cpp | 319 | ||||
-rw-r--r-- | muse2/awl/posedit.h | 11 | ||||
-rw-r--r-- | muse2/muse/app.cpp | 7 | ||||
-rw-r--r-- | muse2/muse/app.h | 1 | ||||
-rw-r--r-- | muse2/muse/master/lmaster.cpp | 2 | ||||
-rw-r--r-- | muse2/muse/osc.cpp | 4 | ||||
-rw-r--r-- | muse2/muse/transport.cpp | 19 | ||||
-rw-r--r-- | muse2/muse/transport.h | 1 |
11 files changed, 330 insertions, 51 deletions
diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 322ac344..7ac1723b 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,6 +1,11 @@ 09.12.2010: - Fix: column orders mess up in the main window, and they do not save properly in the .med files. (Orcan) + - Made MusE the owner of transport object so it's now deleted when MusE object is deleted. (Tim) + - Improved PosEdit class, supports undo/redo levels, focus-out + return pressed updating. (Tim) + This also fixes the Transport position boxes' sections jumping to last section. + TODO: There's still trouble editing with KB in Bar-Beat-Tick mode, the bar and beat being '1' based. + TODO: Fix SigEdit (the time Signature Editor boxes). 08.12.2010: - Ported many more Qt3 methods to Qt4. (Orcan) - Turned off Qt3Support. Muse2 is now a pure Qt4 application. (Orcan) diff --git a/muse2/al/al.cpp b/muse2/al/al.cpp index dddb6805..38cc301a 100644 --- a/muse2/al/al.cpp +++ b/muse2/al/al.cpp @@ -21,9 +21,9 @@ #include "al.h" namespace AL { - int sampleRate = 44100; - int mtcType = 0; - int division = 384; + //int sampleRate = 44100; + //int mtcType = 0; + //int division = 384; bool debugMsg = false; }; diff --git a/muse2/al/al.h b/muse2/al/al.h index 2f1a02d9..6f4a07cb 100644 --- a/muse2/al/al.h +++ b/muse2/al/al.h @@ -24,9 +24,9 @@ namespace AL { extern bool debugMsg; - extern int sampleRate; - extern int mtcType; - extern int division; + //extern int sampleRate; + //extern int mtcType; + //extern int division; } diff --git a/muse2/awl/posedit.cpp b/muse2/awl/posedit.cpp index a6ca9b30..97f36a63 100644 --- a/muse2/awl/posedit.cpp +++ b/muse2/awl/posedit.cpp @@ -25,6 +25,7 @@ //#include "sig.h" //#include "sync.h" // Tim. +extern int mtcType; namespace Awl { @@ -38,17 +39,25 @@ namespace Awl { PosEdit::PosEdit(QWidget* parent) : QAbstractSpinBox(parent) { + validator = new QIntValidator(this); + initialized = false; setReadOnly(false); setSmpte(false); + + //connect(this, SIGNAL(editingFinished()), SLOT(finishEdit())); + //connect(this, SIGNAL(returnPressed()), SLOT(enterPressed())); } +// What was this for? Tim. +/* void* PosEdit::operator new(size_t n) { void* p = new char[n]; memset(p, 0, n); return p; } +*/ PosEdit::~PosEdit() { @@ -73,11 +82,35 @@ QSize PosEdit::sizeHint() const //--------------------------------------------------------- bool PosEdit::event(QEvent* event) +{ + if (event->type() == QEvent::KeyPress) { - if (event->type() == QEvent::KeyPress) { QKeyEvent* ke = static_cast<QKeyEvent*>(event); + if (ke->key() == Qt::Key_Return) + { + //printf("key press event Return\n"); // REMOVE Tim. + //enterPressed(); + finishEdit(); + emit returnPressed(); + emit editingFinished(); + return true; + } + + if (ke->key() == Qt::Key_Escape) + { + //printf("key press event Escape\n"); // REMOVE Tim. + if(lineEdit()) + lineEdit()->undo(); + // "By default, isAccepted() is set to true, but don't rely on this as subclasses may + // choose to clear it in their constructor." + // Just to be sure. Otherwise escape will close a midi editor for example, which is annoying. + ke->setAccepted(true); + return true; + } + int segment = curSegment(); - if (ke->key() == Qt::Key_Backtab) { + if (ke->key() == Qt::Key_Backtab) + { if (_smpte) { if (segment == 3) { lineEdit()->setSelection(7, 2); @@ -102,8 +135,9 @@ bool PosEdit::event(QEvent* event) return true; } } - } - if (ke->key() == Qt::Key_Tab) { + } + if (ke->key() == Qt::Key_Tab) + { if (_smpte) { if (segment == 0) { lineEdit()->setSelection(4, 2); @@ -128,21 +162,32 @@ bool PosEdit::event(QEvent* event) return true; } } - } } - else if (event->type() == QEvent::FocusIn) { - QFocusEvent* fe = static_cast<QFocusEvent*>(event); - QAbstractSpinBox::focusInEvent(fe); - int segment = curSegment(); - switch(segment) { - case 0: lineEdit()->setSelection(0,4); break; - case 1: lineEdit()->setSelection(5,2); break; - case 2: lineEdit()->setSelection(8,3); break; - } - return true; - } - return QAbstractSpinBox::event(event); } + else if (event->type() == QEvent::FocusIn) + { + QFocusEvent* fe = static_cast<QFocusEvent*>(event); + QAbstractSpinBox::focusInEvent(fe); + int segment = curSegment(); + switch(segment) { + case 0: lineEdit()->setSelection(0,4); break; + case 1: lineEdit()->setSelection(5,2); break; + case 2: lineEdit()->setSelection(8,3); break; + } + return true; + } + else if (event->type() == QEvent::FocusOut) + { + QFocusEvent* fe = static_cast<QFocusEvent*>(event); + QAbstractSpinBox::focusOutEvent(fe); + finishEdit(); + emit lostFocus(); + emit editingFinished(); + return true; + } + + return QAbstractSpinBox::event(event); +} //--------------------------------------------------------- // setSmpte @@ -152,9 +197,11 @@ void PosEdit::setSmpte(bool f) { _smpte = f; if (_smpte) - lineEdit()->setInputMask("999:99:99:99"); + //lineEdit()->setInputMask("999:99:99:99"); + lineEdit()->setInputMask("999:99:99:99;0"); else - lineEdit()->setInputMask("9999.99.999"); + //lineEdit()->setInputMask("9999.99.999"); + lineEdit()->setInputMask("9999.99.999;0"); updateValue(); } @@ -164,6 +211,8 @@ void PosEdit::setSmpte(bool f) void PosEdit::setValue(const Pos& time) { + if(_pos == time) + return; _pos = time; updateValue(); } @@ -227,8 +276,27 @@ QAbstractSpinBox::StepEnabled PosEdit::stepEnabled() const case 2: if (frame == 0) en &= ~QAbstractSpinBox::StepDownEnabled; - else if (frame == 23) + else + { + int nf = 23; // 24 frames sec + switch(mtcType) { + //case 0: // 24 frames sec + // nf = 23; + // break; + case 1: + nf = 24; // 25 frames sec + break; + case 2: // 30 drop frame + case 3: // 30 non drop frame + nf = 29; + break; + default: + break; + } + //if (frame == 23) + if (frame >= nf) en &= ~QAbstractSpinBox::StepUpEnabled; + } break; case 3: if (subframe == 0) @@ -281,19 +349,119 @@ QAbstractSpinBox::StepEnabled PosEdit::stepEnabled() const void PosEdit::fixup(QString& input) const { - printf("fixup <%s>\n", input.toLatin1().constData()); + printf("fixup <%s>\n", input.toLatin1().constData()); // REMOVE Tim. } //--------------------------------------------------------- // validate //--------------------------------------------------------- -QValidator::State PosEdit::validate(QString&,int&) const +QValidator::State PosEdit::validate(QString& s,int& /*i*/) const +{ + //printf("validate string:%s int:%d\n", s.toLatin1().data(), i); // REMOVE Tim. + //printf("validate string:%s\n", s.toLatin1().data()); // REMOVE Tim. + + QStringList sl = s.split(_smpte ? ':' : '.'); + QValidator::State state; + QValidator::State rv = QValidator::Acceptable; + // "By default, the pos parameter is not used by this [QIntValidator] validator." + int dpos = 0; + + if (_smpte) { - // TODO -// printf("validate\n"); - return QValidator::Acceptable; + if(sl.size() != 4) + { + printf("validate smpte string:%s sections:%d != 4\n", s.toLatin1().data(), sl.size()); + return QValidator::Invalid; + } + + validator->setRange(0, 999); + state = validator->validate(sl[0], dpos); + if(state == QValidator::Invalid) + return state; + if(state == QValidator::Intermediate) + rv = state; + + validator->setRange(0, 59); + state = validator->validate(sl[1], dpos); + if(state == QValidator::Invalid) + return state; + if(state == QValidator::Intermediate) + rv = state; + + int nf = 23; // 24 frames sec + switch(mtcType) { + //case 0: // 24 frames sec + // nf = 23; + // break; + case 1: + nf = 24; // 25 frames sec + break; + case 2: // 30 drop frame + case 3: // 30 non drop frame + nf = 29; + break; + default: + break; + } + validator->setRange(0, nf); + state = validator->validate(sl[2], dpos); + if(state == QValidator::Invalid) + return state; + if(state == QValidator::Intermediate) + rv = state; + + validator->setRange(0, 99); + state = validator->validate(sl[3], dpos); + if(state == QValidator::Invalid) + return state; + if(state == QValidator::Intermediate) + rv = state; } + else + { + if(sl.size() != 3) + { + printf("validate bbt string:%s sections:%d != 3\n", s.toLatin1().data(), sl.size()); + return QValidator::Invalid; + } + + int tb = AL::sigmap.ticksBeat(_pos.tick()); + unsigned tm = AL::sigmap.ticksMeasure(_pos.tick()); + int bm = tm / tb; + + validator->setRange(1, 9999); + //printf("validate substring 0:%s\n", sl[0].toLatin1().data()); // REMOVE Tim. + // Special hack because validator says 0000 is intermediate. + if(sl[0] == "0000") + return QValidator::Invalid; + state = validator->validate(sl[0], dpos); + if(state == QValidator::Invalid) + return state; + if(state == QValidator::Intermediate) + rv = state; + + validator->setRange(1, bm); + //printf("validate substring 1:%s\n", sl[1].toLatin1().data()); // REMOVE Tim. + // Special hack because validator says 00 is intermediate. + if(sl[1] == "00") + return QValidator::Invalid; + state = validator->validate(sl[1], dpos); + if(state == QValidator::Invalid) + return state; + if(state == QValidator::Intermediate) + rv = state; + + validator->setRange(0, tb-1); + //printf("validate substring 2:%s\n", sl[2].toLatin1().data()); // REMOVE Tim. + state = validator->validate(sl[2], dpos); + if(state == QValidator::Invalid) + return state; + if(state == QValidator::Intermediate) + rv = state; + } + return rv; +} //--------------------------------------------------------- // curSegment @@ -361,13 +529,32 @@ void PosEdit::stepBy(int steps) selLen = 2; break; case 2: - frame += steps; - if (frame < 0) - frame = 0; - if (frame > 24) //TD frame type? - frame = 24; - selPos = 7; - selLen = 2; + { + int nf = 23; // 24 frames sec + switch(mtcType) { + //case 0: // 24 frames sec + // nf = 23; + // break; + case 1: + nf = 24; // 25 frames sec + break; + case 2: // 30 drop frame + case 3: // 30 non drop frame + nf = 29; + break; + default: + break; + } + frame += steps; + if (frame < 0) + frame = 0; + //if (frame > 24) //TD frame type? + // frame = 24; + if (frame > nf) + frame = nf; + selPos = 7; + selLen = 2; + } break; case 3: subframe += steps; @@ -439,11 +626,67 @@ void PosEdit::stepBy(int steps) lineEdit()->setSelection(selPos, selLen); } - void PosEdit::paintEvent(QPaintEvent* event) { - if (!initialized) - updateValue(); - initialized = true; - QAbstractSpinBox::paintEvent(event); - } +//--------------------------------------------------------- +// paintEvent +//--------------------------------------------------------- + +void PosEdit::paintEvent(QPaintEvent* event) +{ + if (!initialized) + updateValue(); + initialized = true; + QAbstractSpinBox::paintEvent(event); +} + +//--------------------------------------------------------- +// finishEdit +//--------------------------------------------------------- + +void PosEdit::finishEdit() +{ + // If our validator did its job correctly, the entire line edit text should be valid now... + + bool changed = false; + QStringList sl = text().split(_smpte ? ':' : '.'); + if (_smpte) + { + if(sl.size() != 4) + { + printf("finishEdit smpte string:%s sections:%d != 4\n", text().toLatin1().data(), sl.size()); + return; + } + + Pos newPos(sl[0].toInt(), sl[1].toInt(), sl[2].toInt(), sl[3].toInt()); + if (!(newPos == _pos)) + { + changed = true; + _pos = newPos; + } + } + else + { + if(sl.size() != 3) + { + printf("finishEdit bbt string:%s sections:%d != 3\n", text().toLatin1().data(), sl.size()); + return; + } + + Pos newPos(sl[0].toInt() - 1, sl[1].toInt() - 1, sl[2].toInt()); + if (!(newPos == _pos)) + { + changed = true; + _pos = newPos; + } + } + + if (changed) + { + //updateValue(); + emit valueChanged(_pos); + } } + +} // namespace Awl + + diff --git a/muse2/awl/posedit.h b/muse2/awl/posedit.h index 314b2b9d..5b04c640 100644 --- a/muse2/awl/posedit.h +++ b/muse2/awl/posedit.h @@ -41,6 +41,8 @@ class PosEdit : public QAbstractSpinBox Pos _pos; bool initialized; + QIntValidator* validator; + virtual void paintEvent(QPaintEvent* event); virtual void stepBy(int steps); virtual StepEnabled stepEnabled() const; @@ -49,9 +51,16 @@ class PosEdit : public QAbstractSpinBox void updateValue(); int curSegment() const; virtual bool event(QEvent*); + void finishEdit(); signals: void valueChanged(const Pos&); + + // Choose these three carefully, watch out for focusing recursion. + void returnPressed(); + void lostFocus(); + // This is emitted when focus lost or return pressed (same as QAbstractSpinBox). + void editingFinished(); public slots: void setValue(const Pos& time); @@ -66,7 +75,7 @@ class PosEdit : public QAbstractSpinBox Pos pos() const { return _pos; } void setSmpte(bool); bool smpte() const { return _smpte; } - void* operator new(size_t); + // void* operator new(size_t); // What was this for? Tim. }; } diff --git a/muse2/muse/app.cpp b/muse2/muse/app.cpp index 81f313ea..67adbb23 100644 --- a/muse2/muse/app.cpp +++ b/muse2/muse/app.cpp @@ -1630,6 +1630,13 @@ MusE::MusE(int argc, char** argv) : QMainWindow() song->update(); } +MusE::~MusE() +{ + //printf("MusE::~MusE\n"); + //if(transport) + // delete transport; +} + //--------------------------------------------------------- // setHeartBeat //--------------------------------------------------------- diff --git a/muse2/muse/app.h b/muse2/muse/app.h index c8348af3..39ee7eb4 100644 --- a/muse2/muse/app.h +++ b/muse2/muse/app.h @@ -334,6 +334,7 @@ class MusE : public QMainWindow public: MusE(int argc, char** argv); + ~MusE(); Arranger* arranger; QRect configGeometryMain; bool importMidi(const QString name, bool merge); diff --git a/muse2/muse/master/lmaster.cpp b/muse2/muse/master/lmaster.cpp index cb969428..c9a94167 100644 --- a/muse2/muse/master/lmaster.cpp +++ b/muse2/muse/master/lmaster.cpp @@ -430,6 +430,7 @@ void LMaster::itemDoubleClicked(QTreeWidgetItem* i) // returnPressed() //! called when editor is closed //--------------------------------------------------------- + void LMaster::returnPressed() { if (!editedItem) @@ -556,6 +557,7 @@ void LMaster::returnPressed() editedItem = 0; editorColumn = -1; editingNewItem = false; + } diff --git a/muse2/muse/osc.cpp b/muse2/muse/osc.cpp index 91a3a0ee..0cfb0c23 100644 --- a/muse2/muse/osc.cpp +++ b/muse2/muse/osc.cpp @@ -243,7 +243,9 @@ int oscMessageHandler(const char* path, const char* types, lo_arg** argv, #endif //const char* sub = strstr(p, instance->name().toLatin1().constData()); - const char* sub = strstr(p, instance->label().toLatin1().constData()); + ///const char* sub = strstr(p, instance->label().toLatin1().constData()); + QByteArray ba = instance->label().toLatin1(); + const char* sub = strstr(p, ba.constData()); if(sub == NULL) continue; diff --git a/muse2/muse/transport.cpp b/muse2/muse/transport.cpp index 36b0486d..0e2a33e0 100644 --- a/muse2/muse/transport.cpp +++ b/muse2/muse/transport.cpp @@ -220,11 +220,12 @@ void Transport::setRecord(bool flag) // Transport //--------------------------------------------------------- -Transport::Transport(QWidget*, const char* name) +Transport::Transport(QWidget* parent, const char* name) // : QWidget(0, name, WStyle_Customize | WType_TopLevel | WStyle_Tool //| WStyle_NoBorder | WStyle_StaysOnTop) //: QWidget(0, name, Qt::WStyle_Customize | Qt::Window | Qt::WStyle_NoBorder | Qt::WStyle_StaysOnTop) - : QWidget(0, Qt::Window | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint ) // Possibly also Qt::X11BypassWindowManagerHint + //: QWidget(0, name, Qt::Window | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint ) // Possibly also Qt::X11BypassWindowManagerHint + : QWidget(parent, Qt::Window | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint ) // Possibly also Qt::X11BypassWindowManagerHint { setObjectName(name); setWindowTitle(QString("Muse: Transport")); @@ -500,6 +501,11 @@ Transport::Transport(QWidget*, const char* name) hbox->addWidget(righthandle); } +Transport::~Transport() +{ + //printf("Transport::~Transport\n"); +} + //--------------------------------------------------------- // configChanged //--------------------------------------------------------- @@ -561,9 +567,12 @@ void Transport::setPos(int idx, unsigned v, bool) case 0: time1->setValue(v); time2->setValue(v); - slider->blockSignals(true); - slider->setValue(v); - slider->blockSignals(false); + if(slider->value() != v) + { + slider->blockSignals(true); + slider->setValue(v); + slider->blockSignals(false); + } if (song->masterFlag()) setTempo(tempomap.tempo(v)); { diff --git a/muse2/muse/transport.h b/muse2/muse/transport.h index d9932bac..be352dfa 100644 --- a/muse2/muse/transport.h +++ b/muse2/muse/transport.h @@ -129,6 +129,7 @@ class Transport : public QWidget public: Transport(QWidget* parent, const char* name = 0); + ~Transport(); QColor getHandleColor() const { return lefthandle->palette().color(QPalette::Window); } }; #endif |