Skip to content

Commit

Permalink
Fix #306524: Control playback speed with the keyboard
Browse files Browse the repository at this point in the history
Implemented three new commands that increase, decrease, and reset the playback speed to 100%. The speed increment defaults to 5% but is configurable via an advanced preference. The new commands are not assigned default keyboard shortcuts but are configurable by the user.

Also renamed “relative tempo” to “playback speed” in the relevant code, since that more accurately describes what it actually is. This distinction will become more important later if (or when) MuseScore gains true relative-tempo control at the score level (as opposed to the playback/transport level).
  • Loading branch information
Spire42 committed Jun 9, 2020
1 parent a8b02fa commit 2e7c744
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 84 deletions.
4 changes: 2 additions & 2 deletions audio/drivers/jackaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ void JackAudio::checkTransportSeek(int cur_frame, int nframes, bool inCountIn)
jack_transport_query(client, &pos);

if (preferences.getBool(PREF_IO_JACK_USEJACKTRANSPORT)) {
if (mscore->playPanelInterface() && mscore->playPanelInterface()->isTempoSliderPressed())
if (mscore->playPanelInterface() && mscore->playPanelInterface()->isSpeedSliderPressed())
return;
int cur_utick = seq->score()->utime2utick((qreal)cur_frame / MScore::sampleRate);
int utick = seq->score()->utime2utick((qreal)pos.frame / MScore::sampleRate);
Expand All @@ -720,7 +720,7 @@ void JackAudio::checkTransportSeek(int cur_frame, int nframes, bool inCountIn)
seq->setRelTempo(newRelTempo);
// Update UI
if (mscore->getPlayPanel()) {
mscore->playPanelInterface()->setRelTempo(newRelTempo);
mscore->playPanelInterface()->setSpeed(newRelTempo);
mscore->playPanelInterface()->setTempo(seq->curTempo() * newRelTempo);
}
}
Expand Down
1 change: 1 addition & 0 deletions global/settings/types/preferencekeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#define PREF_APP_PLAYBACK_FOLLOWSONG "application/playback/followSong"
#define PREF_APP_PLAYBACK_PANPLAYBACK "application/playback/panPlayback"
#define PREF_APP_PLAYBACK_PLAYREPEATS "application/playback/playRepeats"
#define PREF_APP_PLAYBACK_SPEEDINCREMENT "application/playback/speedIncrement"
#define PREF_APP_PLAYBACK_LOOPTOSELECTIONONPLAY "application/playback/setLoopToSelectionOnPlay"
#define PREF_APP_USESINGLEPALETTE "application/useSinglePalette"
#define PREF_APP_PALETTESCALE "application/paletteScale"
Expand Down
16 changes: 9 additions & 7 deletions libmscore/mscore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ int MScore::pedalEventsMinTicks;

bool MScore::playRepeats;
bool MScore::panPlayback;
int MScore::playbackSpeedIncrement;
qreal MScore::nudgeStep;
qreal MScore::nudgeStep10;
qreal MScore::nudgeStep50;
Expand Down Expand Up @@ -303,13 +304,14 @@ void MScore::init()
selectColor[2].setNamedColor("#C53F00"); //orange
selectColor[3].setNamedColor("#C31989"); //purple

defaultColor = Qt::black;
dropColor = QColor("#1778db");
defaultPlayDuration = 300; // ms
warnPitchRange = true;
pedalEventsMinTicks = 1;
playRepeats = true;
panPlayback = true;
defaultColor = Qt::black;
dropColor = QColor("#1778db");
defaultPlayDuration = 300; // ms
warnPitchRange = true;
pedalEventsMinTicks = 1;
playRepeats = true;
panPlayback = true;
playbackSpeedIncrement = 5;

lastError = "";

Expand Down
1 change: 1 addition & 0 deletions libmscore/mscore.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ class MScore {

static bool playRepeats;
static bool panPlayback;
static int playbackSpeedIncrement;
static qreal nudgeStep;
static qreal nudgeStep10;
static qreal nudgeStep50;
Expand Down
8 changes: 6 additions & 2 deletions mscore/iplaypanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ class IPlayPanel {
public:
virtual ~IPlayPanel() {}

virtual double speed() const = 0;
virtual void setTempo(double) = 0;
virtual void setRelTempo(qreal) = 0;
virtual bool isTempoSliderPressed() const = 0;
virtual void setSpeed(double) = 0;
virtual void increaseSpeed() = 0;
virtual void decreaseSpeed() = 0;
virtual void resetSpeed() = 0;
virtual bool isSpeedSliderPressed() const = 0;
};

}
Expand Down
49 changes: 40 additions & 9 deletions mscore/musescore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ void updateExternalValuesFromPreferences() {
MScore::defaultPlayDuration = preferences.getInt(PREF_SCORE_NOTE_DEFAULTPLAYDURATION);
MScore::panPlayback = preferences.getBool(PREF_APP_PLAYBACK_PANPLAYBACK);
MScore::playRepeats = preferences.getBool(PREF_APP_PLAYBACK_PLAYREPEATS);
MScore::playbackSpeedIncrement = preferences.getInt(PREF_APP_PLAYBACK_SPEEDINCREMENT);
MScore::warnPitchRange = preferences.getBool(PREF_SCORE_NOTE_WARNPITCHRANGE);
MScore::pedalEventsMinTicks = preferences.getInt(PREF_IO_MIDI_PEDAL_EVENTS_MIN_TICKS);
MScore::layoutBreakColor = preferences.getColor(PREF_UI_SCORE_LAYOUTBREAKCOLOR);
Expand Down Expand Up @@ -460,6 +461,9 @@ void MuseScore::preferencesChanged(bool fromWorkspace, bool changeUI)
getAction("show-tours")->setChecked(preferences.getBool(PREF_UI_APP_STARTUP_SHOWTOURS));
_statusBar->setVisible(preferences.getBool(PREF_UI_APP_SHOWSTATUSBAR));

if (playPanel)
playPanel->setSpeedIncrement(preferences.getInt(PREF_APP_PLAYBACK_SPEEDINCREMENT));

if (changeUI)
MuseScore::updateUiStyleAndTheme(); // this is a slow operation
updateIcons();
Expand Down Expand Up @@ -3016,6 +3020,28 @@ void MuseScore::reDisplayDockWidget(QDockWidget* widget, bool visible)
widget->setVisible(visible);
}

//---------------------------------------------------------
// createPlayPanel
//---------------------------------------------------------

void MuseScore::createPlayPanel()
{
if (!playPanel) {
playPanel = new PlayPanel(this);
connect(playPanel, SIGNAL(metronomeGainChanged(float)), seq, SLOT(setMetronomeGain(float)));
connect(playPanel, SIGNAL(speedChanged(double)), seq, SLOT(setRelTempo(double)));
connect(playPanel, SIGNAL(posChange(int)), seq, SLOT(seek(int)));
connect(playPanel, SIGNAL(closed(bool)), playId, SLOT(setChecked(bool)));
connect(synti, SIGNAL(gainChanged(float)), playPanel, SLOT(setGain(float)));
playPanel->setSpeedIncrement(preferences.getInt(PREF_APP_PLAYBACK_SPEEDINCREMENT));
playPanel->setGain(synti->gain());
playPanel->setScore(cs);
addDockWidget(Qt::RightDockWidgetArea, playPanel);
playPanel->setVisible(false);
playPanel->setFloating(false);
}
}

//---------------------------------------------------------
// showPlayPanel
//---------------------------------------------------------
Expand All @@ -3027,15 +3053,8 @@ void MuseScore::showPlayPanel(bool visible)
if (playPanel == 0) {
if (!visible)
return;
playPanel = new PlayPanel(this);
connect(playPanel, SIGNAL(metronomeGainChanged(float)), seq, SLOT(setMetronomeGain(float)));
connect(playPanel, SIGNAL(relTempoChanged(double)),seq, SLOT(setRelTempo(double)));
connect(playPanel, SIGNAL(posChange(int)), seq, SLOT(seek(int)));
connect(playPanel, SIGNAL(closed(bool)), playId, SLOT(setChecked(bool)));
connect(synti, SIGNAL(gainChanged(float)), playPanel, SLOT(setGain(float)));
playPanel->setGain(synti->gain());
playPanel->setScore(cs);
addDockWidget(Qt::RightDockWidgetArea, playPanel);

createPlayPanel();

// The play panel must be set visible before being set floating for positioning
// and window geometry reasons.
Expand Down Expand Up @@ -6449,6 +6468,18 @@ void MuseScore::cmd(QAction* a, const QString& cmd)
;
else if (cmd == "countin") // no action
;
else if (cmd == "playback-speed-increase") {
createPlayPanel();
playPanel->increaseSpeed();
}
else if (cmd == "playback-speed-decrease") {
createPlayPanel();
playPanel->decreaseSpeed();
}
else if (cmd == "playback-speed-reset") {
createPlayPanel();
playPanel->resetSpeed();
}
else if (cmd == "lock") {
if (_sstate == STATE_LOCK)
changeState(STATE_NORMAL);
Expand Down
2 changes: 2 additions & 0 deletions mscore/musescore.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
void setPlayRepeats(bool repeat);
void setPanPlayback(bool pan);

void createPlayPanel();

ScoreTab* createScoreTab();
void askResetOldScorePositions(Score* score);

Expand Down
2 changes: 1 addition & 1 deletion mscore/osc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void MuseScore::oscTempo(int val)
val = 300;
qreal t = val * .01;
if (playPanel)
playPanel->setRelTempo(t);
playPanel->setSpeed(t);
if (seq)
seq->setRelTempo(double(t));
}
Expand Down
Loading

0 comments on commit 2e7c744

Please sign in to comment.