From 400bf08f714411854ded8fb7386bfcca92e4775e Mon Sep 17 00:00:00 2001 From: vgstef Date: Tue, 3 Sep 2013 15:01:03 -0400 Subject: [PATCH] Replace loop event by simple condition in Process(), improve In/Out position setting --- mscore/musescore.cpp | 6 ++- mscore/musescore.h | 1 - mscore/scoreview.cpp | 2 +- mscore/seq.cpp | 97 ++++++++++++++++++-------------------------- mscore/seq.h | 2 - 5 files changed, 46 insertions(+), 62 deletions(-) diff --git a/mscore/musescore.cpp b/mscore/musescore.cpp index 6fe36c2e3e..9b3acb784d 100644 --- a/mscore/musescore.cpp +++ b/mscore/musescore.cpp @@ -1539,6 +1539,10 @@ void MuseScore::setCurrentScoreView(ScoreView* view) showMessage(cs->filePath(), 2000); if (_navigator && _navigator->widget()) navigator()->setScoreView(view); + if (loop()) { + cs->updateLoopCursors(); + cv->showLoopCursors(); + } } //--------------------------------------------------------- @@ -4161,7 +4165,7 @@ void MuseScore::cmd(QAction* a, const QString& cmd) cs->showLoopCursors(); } else { - seq->loopStop(); + //seq->loopStop(); cs->hideLoopCursors(); } } diff --git a/mscore/musescore.h b/mscore/musescore.h index ecea25d928..626d22dadc 100644 --- a/mscore/musescore.h +++ b/mscore/musescore.h @@ -607,7 +607,6 @@ class MuseScore : public QMainWindow, public MuseScoreCore { void updateLayer(); void updatePlayMode(); bool loop() const { return loopAction->isChecked(); } - bool isLoopOut() const { return loopOutAction->isChecked(); } bool metronome() const { return metronomeAction->isChecked(); } bool panDuringPlayback() const { return panAction->isChecked(); } void noteTooShortForTupletDialog(); diff --git a/mscore/scoreview.cpp b/mscore/scoreview.cpp index cc29580b79..f6252ddc74 100644 --- a/mscore/scoreview.cpp +++ b/mscore/scoreview.cpp @@ -1524,7 +1524,7 @@ void ScoreView::setLoopCursor(TextCursor *curLoop, int tick, bool isInPos) x = x - _spatium + w/2; } else { - x = x - _spatium - w; + x = x - _spatium + w/2; } curLoop->setTick(tick); curLoop->setRect(QRectF(x, y, w, h)); diff --git a/mscore/seq.cpp b/mscore/seq.cpp index 99981b286a..d1ea72d879 100644 --- a/mscore/seq.cpp +++ b/mscore/seq.cpp @@ -336,22 +336,7 @@ void Seq::start() if ((mscore->loop())) { if(cs->selection().state() == SEL_RANGE) setLoopSelection(); - if (cs->loopOutTick() > 0) { - // Add loop Out event - NPlayEvent event; - event.setType(ME_LOOP); - // **Lower bound causes crash** insert ME_LOOP as first event if there are events with same tick - //auto hint = events.lower_bound(cs->loopOutTick()); - //events.insert(hint, std::pair(cs->loopOutTick(), event)); - events.insert(std::pair(cs->loopOutTick(), event)); - qDebug ("Add loop event at tick %d (loopInTick = %d)", cs->loopOutTick(), cs->loopInTick()); - if (cs->loopOutTick() < cs->loopInTick()) - seek(0); // If Out pos < In pos, restart playback at the beginning. - else - seek(cs->loopInTick()); - } else - seek(cs->loopInTick()); - + seek(cs->loopInTick()); } else seek(cs->playPos()); @@ -381,8 +366,8 @@ void Seq::stop() cs->setUpdateAll(); cs->end(); } - if (mscore->loop()) - loopStop(); + //if (mscore->loop()) + // loopStop(); } //--------------------------------------------------------- @@ -468,6 +453,9 @@ void Seq::guiStop() void Seq::seqMessage(int msg) { switch(msg) { + case '3': // Loop restart while playing + seek(cs->loopInTick()); + break; case '2': guiStop(); // heartBeatTimer->stop(); @@ -662,6 +650,14 @@ void Seq::process(unsigned n, float* buffer) qDebug("%d: %d - %d\n", playPos->first, f, playTime); n = 0; } + if (mscore->loop()) { + qDebug ("Process playPos = %d in/out tick = %d/%d getCurTick() = %d f = %d playTime = %d", playPos->first, cs->loopInTick(), cs->loopOutTick(), getCurTick(), f, playTime); + if (playPos->first >= cs->loopOutTick()) { + emit toGui('3'); // Exit this function to avoid segmentation fault in Scoreview + //seek(cs->loopInTick()); + return; + } + } if (n) { if (cs->playMode() == PLAYMODE_SYNTHESIZER) { metronome(n, p); @@ -695,11 +691,6 @@ void Seq::process(unsigned n, float* buffer) tickRest = tickLength; else if (event.type() == ME_TICK2) tackRest = tackLength; - else if (event.type() == ME_LOOP) { - qDebug ("event.type() == ME_LOOP in/out tick = %d/%d loop | getCurTick() = %d ", cs->loopInTick(), cs->loopOutTick(), getCurTick()); - seek(cs->loopInTick()); - return; - } mutex.lock(); ++playPos; mutex.unlock(); @@ -1198,8 +1189,9 @@ void Seq::heartBeatTimeout() QRectF r; for (;guiPos != events.cend(); ++guiPos) { - if (guiPos->first > ppos->first) - break; + if (mscore->loop()) + if (guiPos->first >= cs->loopOutTick()) + break; const NPlayEvent& n = guiPos->second; if (n.type() == ME_NOTEON) { const Note* note1 = n.note(); @@ -1270,27 +1262,40 @@ double Seq::curTempo() const void Seq::setLoopIn() { int tick; - if (state == TRANSPORT_PLAY) - tick = playPos->first; // En mode playback, set the In position where note is being played - else - tick = cs->pos(); // Otherwise, use the selected note. + if (state == TRANSPORT_PLAY) { // If in playback mode, set the In position where note is being played + auto ppos = playPos; + if (ppos != events.cbegin()) + --ppos; // We have to go back one pos to get the correct note that has just been played + tick = ppos->first; + } + else { + tick = cs->pos(); // Otherwise, use the selected note. + } + if (tick >= cs->loopOutTick()) // If In pos >= Out pos, reset Out pos to end of score + cs->setLoopOutTick(-1); cs->setLoopInTick(tick); -// qDebug ("setLoopIn : tick = %d\n",tick); + qDebug ("seq::setLoopIn() : tick = %d\n",tick); } //--------------------------------------------------------- -// set Loop in position +// set Loop Out position //--------------------------------------------------------- void Seq::setLoopOut() { int tick; - if (state == TRANSPORT_PLAY) - tick = playPos->first; // En mode playback, set the Out position where note is being played - else + if (state == TRANSPORT_PLAY) { // If in playback mode, set the Out position where note is being played + tick = playPos->first; + } + else { tick = cs->pos()+cs->inputState().ticks(); // Otherwise, use the selected note. + } + if (tick <= cs->loopInTick()) // If Out pos <= In pos, reset In pos to beginning of score + cs->setLoopInTick(-1); cs->setLoopOutTick(tick); -// qDebug ("setLoopOut : loopOutPos = %d ; cs->pos() = %d + cs->inputState().ticks() = %d\n",loopOutPos, cs->pos(), cs->inputState().ticks()); + qDebug ("seq::setLoopOut() : loopOutPos = %d ; cs->pos() = %d + cs->inputState().ticks() = %d\n", tick, cs->pos(), cs->inputState().ticks()); + if (state == TRANSPORT_PLAY) + guiToSeq(SeqMsg(SEQ_SEEK, tick)); } //--------------------------------------------------------- @@ -1304,26 +1309,4 @@ void Seq::setLoopSelection() cs->updateLoopCursors(); qDebug ("setLoopSelection : loopInTick = %d loopOutTick = %d\n",cs->selection().tickStart(), cs->selection().tickEnd()); } - -//--------------------------------------------------------- -// unset Loop In -//--------------------------------------------------------- - -void Seq::unsetLoopIn() - { - // Reinitialize the In loop position - cs->setLoopInTick(-1); - } - -//--------------------------------------------------------- -// unset Loop Out -//--------------------------------------------------------- - -void Seq::unsetLoopOut() - { - loopStop(); // Erase the loop event - - // Reinitialize the Out loop position - cs->setLoopOutTick(-1); - } } diff --git a/mscore/seq.h b/mscore/seq.h index ec13a351a5..89b5aa6af6 100644 --- a/mscore/seq.h +++ b/mscore/seq.h @@ -175,8 +175,6 @@ class Seq : public QObject, public Sequencer { void stopWait(); void setLoopIn(); void setLoopOut(); - void unsetLoopIn(); - void unsetLoopOut(); void setLoopSelection(); bool init();