Skip to content

Commit

Permalink
fix #311520: harmony playback preferences not honored until toggled
Browse files Browse the repository at this point in the history
Resolves: https://musescore.org/en/node/311520

The new preferences for disabling playback of chord symbols work fine,
only ater you've toggled them at least once, which forces them
to be written to the ".ini" file.
Otherwise, they are not being initialized correctly.
This is apparently from the use of QSettings to access the preferences
from code within the libmscore folder.
This technique is used at least one other place,
but it is apparently not reliable with respect to default values.

This commit adds new members of MScore class
so mscore can write them and libmscore can read them.
That is the approach used by most other preferences
that need to be accessed from libmscore.

In addition, there was a logic error
when creating a new score from a template.
There was code to handle new scores created from *old* templates,
so they wouldn't have chord symbols forced off
by the compatibility setting.
This code was erroneously being triggered for new templates as well,
making it impossible to disable chord symbol playback via a template.
That is fixed by performing the same version check used
when reading the template.
  • Loading branch information
MarcSabatella authored and igorkorsukov committed Oct 14, 2020
1 parent 9d5d395 commit c7d3364
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
2 changes: 2 additions & 0 deletions libmscore/mscore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ QColor MScore::dropColor;
bool MScore::warnPitchRange;
int MScore::pedalEventsMinTicks;

bool MScore::harmonyPlayDisableCompatibility;
bool MScore::harmonyPlayDisableNew;
bool MScore::playRepeats;
bool MScore::panPlayback;
int MScore::playbackSpeedIncrement;
Expand Down
2 changes: 2 additions & 0 deletions libmscore/mscore.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ class MScore {
static bool warnPitchRange;
static int pedalEventsMinTicks;

static bool harmonyPlayDisableCompatibility;
static bool harmonyPlayDisableNew;
static bool playRepeats;
static bool panPlayback;
static int playbackSpeedIncrement;
Expand Down
3 changes: 1 addition & 2 deletions libmscore/read114.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2770,8 +2770,7 @@ static void readStyle(MStyle* style, XmlReader& e)
//TODO style->convertToUnit(tag, val);
}

QSettings settings;
bool disableHarmonyPlay = settings.value("score/harmony/play/disableCompatibility").toBool() && !MScore::testMode;
bool disableHarmonyPlay = MScore::harmonyPlayDisableCompatibility && !MScore::testMode;
if (disableHarmonyPlay) {
style->set(Sid::harmonyPlay, false);
}
Expand Down
3 changes: 1 addition & 2 deletions libmscore/read206.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3700,8 +3700,7 @@ static void readStyle(MStyle* style, XmlReader& e)
}
}

QSettings settings;
bool disableHarmonyPlay = settings.value("score/harmony/play/disableCompatibility").toBool() && !MScore::testMode;
bool disableHarmonyPlay = MScore::harmonyPlayDisableCompatibility && !MScore::testMode;
if (disableHarmonyPlay) {
style->set(Sid::harmonyPlay, false);
}
Expand Down
3 changes: 1 addition & 2 deletions libmscore/read301.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ bool Score::read(XmlReader& e)
// note: older templates get the default values for older scores
// these can be forced back in MuseScore::getNewFile() if necessary
QString programVersion = masterScore()->mscoreVersion();
QSettings settings;
bool disableHarmonyPlay = settings.value("score/harmony/play/disableCompatibility").toBool() && !MScore::testMode;
bool disableHarmonyPlay = MScore::harmonyPlayDisableCompatibility && !MScore::testMode;
if (!programVersion.isEmpty() && programVersion < "3.5" && disableHarmonyPlay) {
style().set(Sid::harmonyPlay, false);
}
Expand Down
13 changes: 8 additions & 5 deletions mscore/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,13 +584,16 @@ MasterScore* MuseScore::getNewFile()
delete score;
return 0;
}
if (preferences.getBool(PREF_SCORE_HARMONY_PLAY_DISABLE_NEW)) {
if (MScore::harmonyPlayDisableNew) {
tscore->style().set(Sid::harmonyPlay, false);
}
else if (preferences.getBool(PREF_SCORE_HARMONY_PLAY_DISABLE_COMPATIBILITY)) {
else if (MScore::harmonyPlayDisableCompatibility) {
// if template was older, then harmonyPlay may have been forced off by the compatibility preference
// that's not appropriatew when creating new scores, even from old templates, so return it to default
tscore->style().set(Sid::harmonyPlay, MScore::defaultStyle().value(Sid::harmonyPlay));
// that's not appropriate when creating new scores from old templates
// if template was pre-3.5, return harmonyPlay to default
QString programVersion = tscore->mscoreVersion();
if (!programVersion.isEmpty() && programVersion < "3.5")
tscore->style().set(Sid::harmonyPlay, MScore::defaultStyle().value(Sid::harmonyPlay));
}
score->setStyle(tscore->style());

Expand Down Expand Up @@ -642,7 +645,7 @@ MasterScore* MuseScore::getNewFile()
}
else {
score = new MasterScore(MScore::defaultStyle());
if (preferences.getBool(PREF_SCORE_HARMONY_PLAY_DISABLE_NEW)) {
if (MScore::harmonyPlayDisableNew) {
score->style().set(Sid::harmonyPlay, false);
}
newWizard->createInstruments(score);
Expand Down
2 changes: 2 additions & 0 deletions mscore/musescore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ void updateExternalValuesFromPreferences() {
MScore::defaultColor = preferences.getColor(PREF_UI_SCORE_DEFAULTCOLOR);
MScore::defaultPlayDuration = preferences.getInt(PREF_SCORE_NOTE_DEFAULTPLAYDURATION);
MScore::panPlayback = preferences.getBool(PREF_APP_PLAYBACK_PANPLAYBACK);
MScore::harmonyPlayDisableCompatibility = preferences.getBool(PREF_SCORE_HARMONY_PLAY_DISABLE_COMPATIBILITY);
MScore::harmonyPlayDisableNew = preferences.getBool(PREF_SCORE_HARMONY_PLAY_DISABLE_NEW);
MScore::playRepeats = preferences.getBool(PREF_APP_PLAYBACK_PLAYREPEATS);
MScore::playbackSpeedIncrement = preferences.getInt(PREF_APP_PLAYBACK_SPEEDINCREMENT);
MScore::warnPitchRange = preferences.getBool(PREF_SCORE_NOTE_WARNPITCHRANGE);
Expand Down

0 comments on commit c7d3364

Please sign in to comment.