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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
|
//=============================================================================
// MusE Score
// Linux Music Score Editor
//
// Copyright (C) 2002-2016 Werner Schweer and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#ifndef __PREFERENCES_H__
#define __PREFERENCES_H__
/*
* HOW TO ADD A NEW PREFERENCE
* - Add a new define to the list of defines below
* - Add the preference to the _allPreferences map in the init() function in preferences.cpp
* and specify the default value for this preference
* - That's it. The preference is stored and retrieved automatically and can be read
* using getString(), getInt(), etc., and changed using setPreference()
*/
#include "globals.h"
namespace Ms {
extern QString mscoreGlobalShare;
enum class SessionStart : char {
EMPTY, LAST, NEW, SCORE
};
// midi remote control values:
enum {
RMIDI_REWIND,
RMIDI_TOGGLE_PLAY,
RMIDI_PLAY,
RMIDI_STOP,
RMIDI_NOTE1,
RMIDI_NOTE2,
RMIDI_NOTE4,
RMIDI_NOTE8,
RMIDI_NOTE16,
RMIDI_NOTE32,
RMIDI_NOTE64,
RMIDI_REST,
RMIDI_DOT,
RMIDI_DOTDOT,
RMIDI_TIE,
RMIDI_UNDO,
RMIDI_NOTE_EDIT_MODE,
RMIDI_REALTIME_ADVANCE,
MIDI_REMOTES
};
enum class MuseScoreStyleType : char {
DARK_FUSION = 0,
LIGHT_FUSION
};
// MusicXML export break values
enum class MusicxmlExportBreaks : char {
ALL, MANUAL, NO
};
//
// Defines for all preferences
// Every preference should have a define to ease the usage of the preference
// Make sure the string key has a sensible grouping - use / for grouping
//
#define PREF_APP_AUTOSAVE_AUTOSAVETIME "application/autosave/autosaveTime"
#define PREF_APP_AUTOSAVE_USEAUTOSAVE "application/autosave/useAutosave"
#define PREF_APP_KEYBOARDLAYOUT "application/keyboardLayout"
// file path of instrument templates
#define PREF_APP_PATHS_INSTRUMENTLIST1 "application/paths/instrumentList1"
#define PREF_APP_PATHS_INSTRUMENTLIST2 "application/paths/instrumentList2"
#define PREF_APP_PATHS_MYIMAGES "application/paths/myImages"
#define PREF_APP_PATHS_MYPLUGINS "application/paths/myPlugins"
#define PREF_APP_PATHS_MYSCORES "application/paths/myScores"
#define PREF_APP_PATHS_MYSHORTCUTS "application/paths/myShortcuts"
#define PREF_APP_PATHS_MYSOUNDFONTS "application/paths/mySoundfonts"
#define PREF_APP_PATHS_MYSTYLES "application/paths/myStyles"
#define PREF_APP_PATHS_MYTEMPLATES "application/paths/myTemplates"
#define PREF_APP_PATHS_MYEXTENSIONS "application/paths/myExtensions"
#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_LOOPTOSELECTIONONPLAY "application/playback/setLoopToSelectionOnPlay"
#define PREF_APP_USESINGLEPALETTE "application/useSinglePalette"
#define PREF_APP_STARTUP_FIRSTSTART "application/startup/firstStart"
#define PREF_APP_STARTUP_SESSIONSTART "application/startup/sessionStart"
#define PREF_APP_STARTUP_STARTSCORE "application/startup/startScore"
#define PREF_APP_WORKSPACE "application/workspace"
#define PREF_EXPORT_AUDIO_NORMALIZE "export/audio/normalize"
#define PREF_EXPORT_AUDIO_SAMPLERATE "export/audio/sampleRate"
#define PREF_EXPORT_MP3_BITRATE "export/mp3/bitRate"
#define PREF_EXPORT_MUSICXML_EXPORTLAYOUT "export/musicXML/exportLayout"
#define PREF_EXPORT_MUSICXML_EXPORTBREAKS "export/musicXML/exportBreaks"
#define PREF_EXPORT_PDF_DPI "export/pdf/dpi"
#define PREF_EXPORT_PNG_RESOLUTION "export/png/resolution"
#define PREF_EXPORT_PNG_USETRANSPARENCY "export/png/useTransparency"
#define PREF_IMPORT_GUITARPRO_CHARSET "import/guitarpro/charset"
#define PREF_IMPORT_MUSICXML_IMPORTBREAKS "import/musicXML/importBreaks"
#define PREF_IMPORT_MUSICXML_IMPORTLAYOUT "import/musicXML/importLayout"
#define PREF_IMPORT_OVERTURE_CHARSET "import/overture/charset"
#define PREF_IMPORT_STYLE_STYLEFILE "import/style/styleFile"
#define PREF_IO_ALSA_DEVICE "io/alsa/device"
#define PREF_IO_ALSA_FRAGMENTS "io/alsa/fragments"
#define PREF_IO_ALSA_PERIODSIZE "io/alsa/periodSize"
#define PREF_IO_ALSA_SAMPLERATE "io/alsa/sampleRate"
#define PREF_IO_ALSA_USEALSAAUDIO "io/alsa/useAlsaAudio"
#define PREF_IO_JACK_REMEMBERLASTCONNECTIONS "io/jack/rememberLastConnections"
#define PREF_IO_JACK_TIMEBASEMASTER "io/jack/timebaseMaster"
#define PREF_IO_JACK_USEJACKAUDIO "io/jack/useJackAudio"
#define PREF_IO_JACK_USEJACKMIDI "io/jack/useJackMIDI"
#define PREF_IO_JACK_USEJACKTRANSPORT "io/jack/useJackTransport"
#define PREF_IO_MIDI_ADVANCEONRELEASE "io/midi/advanceOnRelease"
#define PREF_IO_MIDI_ENABLEINPUT "io/midi/enableInput"
#define PREF_IO_MIDI_EXPANDREPEATS "io/midi/expandRepeats"
#define PREF_IO_MIDI_EXPORTRPNS "io/midi/exportRPNs"
#define PREF_IO_MIDI_REALTIMEDELAY "io/midi/realtimeDelay"
#define PREF_IO_MIDI_REMOTE "io/midi/remote"
#define PREF_IO_MIDI_SHORTESTNOTE "io/midi/shortestNote"
#define PREF_IO_MIDI_SHOWCONTROLSINMIXER "io/midi/showControlsInMixer"
#define PREF_IO_MIDI_USEREMOTECONTROL "io/midi/useRemoteControl"
#define PREF_IO_OSC_PORTNUMBER "io/osc/portNumber"
#define PREF_IO_OSC_USEREMOTECONTROL "io/osc/useRemoteControl"
#define PREF_IO_PORTAUDIO_DEVICE "io/portAudio/device"
#define PREF_IO_PORTAUDIO_USEPORTAUDIO "io/portAudio/usePortAudio"
#define PREF_IO_PORTMIDI_INPUTBUFFERCOUNT "io/portMidi/inputBufferCount"
#define PREF_IO_PORTMIDI_INPUTDEVICE "io/portMidi/inputDevice"
#define PREF_IO_PORTMIDI_OUTPUTBUFFERCOUNT "io/portMidi/outputBufferCount"
#define PREF_IO_PORTMIDI_OUTPUTDEVICE "io/portMidi/outputDevice"
#define PREF_IO_PORTMIDI_OUTPUTLATENCYMILLISECONDS "io/portMidi/outputLatencyMilliseconds"
#define PREF_IO_PULSEAUDIO_USEPULSEAUDIO "io/pulseAudio/usePulseAudio"
#define PREF_SCORE_CHORD_PLAYONADDNOTE "score/chord/playOnAddNote"
#define PREF_SCORE_MAGNIFICATION "score/magnification"
#define PREF_SCORE_NOTE_PLAYONCLICK "score/note/playOnClick"
#define PREF_SCORE_NOTE_DEFAULTPLAYDURATION "score/note/defaultPlayDuration"
#define PREF_SCORE_NOTE_WARNPITCHRANGE "score/note/warnPitchRange"
#define PREF_SCORE_STYLE_DEFAULTSTYLEFILE "score/style/defaultStyleFile"
#define PREF_SCORE_STYLE_PARTSTYLEFILE "score/style/partStyleFile"
#define PREF_UI_CANVAS_BG_USECOLOR "ui/canvas/background/useColor"
#define PREF_UI_CANVAS_FG_USECOLOR "ui/canvas/foreground/useColor"
#define PREF_UI_CANVAS_BG_COLOR "ui/canvas/background/color"
#define PREF_UI_CANVAS_FG_COLOR "ui/canvas/foreground/color"
#define PREF_UI_CANVAS_BG_WALLPAPER "ui/canvas/background/wallpaper"
#define PREF_UI_CANVAS_FG_WALLPAPER "ui/canvas/foreground/wallpaper"
#define PREF_UI_CANVAS_MISC_ANTIALIASEDDRAWING "ui/canvas/misc/antialiasedDrawing"
#define PREF_UI_CANVAS_MISC_SELECTIONPROXIMITY "ui/canvas/misc/selectionProximity"
#define PREF_UI_CANVAS_SCROLL_VERTICALORIENTATION "ui/canvas/scroll/verticalOrientation"
#define PREF_UI_CANVAS_SCROLL_LIMITSCROLLAREA "ui/canvas/scroll/limitScrollArea"
#define PREF_UI_APP_STARTUP_CHECKUPDATE "ui/application/startup/checkUpdate"
#define PREF_UI_APP_STARTUP_CHECK_EXTENSIONS_UPDATE "ui/application/startup/checkExtensionsUpdate"
#define PREF_UI_APP_STARTUP_SHOWNAVIGATOR "ui/application/startup/showNavigator"
#define PREF_UI_APP_STARTUP_SHOWPLAYPANEL "ui/application/startup/showPlayPanel"
#define PREF_UI_APP_STARTUP_SHOWSPLASHSCREEN "ui/application/startup/showSplashScreen"
#define PREF_UI_APP_STARTUP_SHOWSTARTCENTER "ui/application/startup/showStartCenter"
#define PREF_UI_APP_STARTUP_SHOWTOURS "ui/application/startup/showTours"
#define PREF_UI_APP_GLOBALSTYLE "ui/application/globalStyle"
#define PREF_UI_APP_LANGUAGE "ui/application/language"
#define PREF_UI_APP_RASTER_HORIZONTAL "ui/application/raster/horizontal"
#define PREF_UI_APP_RASTER_VERTICAL "ui/application/raster/vertical"
#define PREF_UI_APP_SHOWSTATUSBAR "ui/application/showStatusBar"
#define PREF_UI_APP_USENATIVEDIALOGS "ui/application/useNativeDialogs"
#define PREF_UI_PIANO_HIGHLIGHTCOLOR "ui/piano/highlightColor"
#define PREF_UI_SCORE_NOTE_DROPCOLOR "ui/score/note/dropColor"
#define PREF_UI_SCORE_DEFAULTCOLOR "ui/score/defaultColor"
#define PREF_UI_SCORE_FRAMEMARGINCOLOR "ui/score/frameMarginColor"
#define PREF_UI_SCORE_LAYOUTBREAKCOLOR "ui/score/layoutBreakColor"
#define PREF_UI_SCORE_VOICE1_COLOR "ui/score/voice1/color"
#define PREF_UI_SCORE_VOICE2_COLOR "ui/score/voice2/color"
#define PREF_UI_SCORE_VOICE3_COLOR "ui/score/voice3/color"
#define PREF_UI_SCORE_VOICE4_COLOR "ui/score/voice4/color"
#define PREF_UI_THEME_ICONHEIGHT "ui/theme/iconHeight"
#define PREF_UI_THEME_ICONWIDTH "ui/theme/iconWidth"
#define PREF_UI_THEME_FONTFAMILY "ui/theme/fontFamily"
#define PREF_UI_THEME_FONTSIZE "ui/theme/fontSize"
#define PREF_UI_PIANOROLL_DARK_SELECTION_BOX_COLOR "ui/pianoroll/dark/selectionBox/color"
#define PREF_UI_PIANOROLL_DARK_NOTE_UNSEL_COLOR "ui/pianoroll/dark/note/unselected/color"
#define PREF_UI_PIANOROLL_DARK_NOTE_SEL_COLOR "ui/pianoroll/dark/note/selected/color"
#define PREF_UI_PIANOROLL_DARK_BG_BASE_COLOR "ui/pianoroll/dark/background/base/color"
#define PREF_UI_PIANOROLL_DARK_BG_KEY_WHITE_COLOR "ui/pianoroll/dark/background/keys/white/color"
#define PREF_UI_PIANOROLL_DARK_BG_KEY_BLACK_COLOR "ui/pianoroll/dark/background/keys/black/color"
#define PREF_UI_PIANOROLL_DARK_BG_GRIDLINE_COLOR "ui/pianoroll/dark/background/gridLine/color"
#define PREF_UI_PIANOROLL_DARK_BG_TEXT_COLOR "ui/pianoroll/dark/background/text/color"
#define PREF_UI_PIANOROLL_LIGHT_SELECTION_BOX_COLOR "ui/pianoroll/light/selectionBox/color"
#define PREF_UI_PIANOROLL_LIGHT_NOTE_UNSEL_COLOR "ui/pianoroll/light/note/unselected/color"
#define PREF_UI_PIANOROLL_LIGHT_NOTE_SEL_COLOR "ui/pianoroll/light/note/selected/color"
#define PREF_UI_PIANOROLL_LIGHT_BG_BASE_COLOR "ui/pianoroll/light/background/base/color"
#define PREF_UI_PIANOROLL_LIGHT_BG_KEY_WHITE_COLOR "ui/pianoroll/light/background/keys/white/color"
#define PREF_UI_PIANOROLL_LIGHT_BG_KEY_BLACK_COLOR "ui/pianoroll/light/background/keys/black/color"
#define PREF_UI_PIANOROLL_LIGHT_BG_GRIDLINE_COLOR "ui/pianoroll/light/background/gridLine/color"
#define PREF_UI_PIANOROLL_LIGHT_BG_TEXT_COLOR "ui/pianoroll/light/background/text/color"
#define PREF_UI_BUTTON_HIGHLIGHT_COLOR_DISABLED_DARK_ON "ui/button/highlight/color/disabled/dark/on"
#define PREF_UI_BUTTON_HIGHLIGHT_COLOR_DISABLED_DARK_OFF "ui/button/highlight/color/disabled/dark/off"
#define PREF_UI_BUTTON_HIGHLIGHT_COLOR_DISABLED_LIGHT_ON "ui/button/highlight/color/disabled/light/on"
#define PREF_UI_BUTTON_HIGHLIGHT_COLOR_DISABLED_LIGHT_OFF "ui/button/highlight/color/disabled/light/off"
#define PREF_UI_BUTTON_HIGHLIGHT_COLOR_ENABLED_DARK_ON "ui/button/highlight/color/enabled/dark/on"
#define PREF_UI_BUTTON_HIGHLIGHT_COLOR_ENABLED_DARK_OFF "ui/button/highlight/color/enabled/dark/off"
#define PREF_UI_BUTTON_HIGHLIGHT_COLOR_ENABLED_LIGHT_ON "ui/button/highlight/color/enabled/light/on"
#define PREF_UI_BUTTON_HIGHLIGHT_COLOR_ENABLED_LIGHT_OFF "ui/button/highlight/color/enabled/light/off"
class PreferenceVisitor;
//---------------------------------------------------------
// Preference
//---------------------------------------------------------
class Preference {
private:
QVariant _defaultValue = 0;
bool _showInAdvancedList = true;
protected:
QMetaType::Type _type = QMetaType::UnknownType;
Preference(QVariant defaultValue) : _defaultValue(defaultValue) {}
public:
Preference(QVariant defaultValue, QMetaType::Type type, bool showInAdvancedList = true);
virtual ~Preference() {}
QVariant defaultValue() const {return _defaultValue;}
bool showInAdvancedList() const {return _showInAdvancedList;}
QMetaType::Type type() {return _type;}
virtual void accept(QString key, PreferenceVisitor&) = 0;
};
class IntPreference : public Preference {
public:
IntPreference(int defaultValue, bool showInAdvancedList = true);
virtual void accept(QString key, PreferenceVisitor&);
};
class DoublePreference : public Preference {
public:
DoublePreference(double defaultValue, bool showInAdvancedList = true);
virtual void accept(QString key, PreferenceVisitor&);
};
class BoolPreference : public Preference {
public:
BoolPreference(bool defaultValue, bool showInAdvancedList = true);
virtual void accept(QString key, PreferenceVisitor&);
};
class StringPreference: public Preference {
public:
StringPreference(QString defaultValue, bool showInAdvancedList = true);
virtual void accept(QString key, PreferenceVisitor&);
};
class ColorPreference: public Preference {
public:
ColorPreference(QColor defaultValue, bool showInAdvancedList = true);
virtual void accept(QString key, PreferenceVisitor&);
};
// Support for EnumPreference is currently not fully implemented
class EnumPreference: public Preference {
public:
EnumPreference(QVariant defaultValue, bool showInAdvancedList = true);
virtual void accept(QString, PreferenceVisitor&);
};
//---------------------------------------------------------
// Preferences
//---------------------------------------------------------
class Preferences {
public:
typedef QHash<QString, Preference*> prefs_map_t;
private:
// Map of all preferences and their default values
// A preference can not be read or set if it is not present in this map
// This map is not used for storing a preference it is only for default values
prefs_map_t _allPreferences;
// used for storing preferences in memory when _storeInMemoryOnly is true
// and for storing temporary preferences
QHash<QString, QVariant> _inMemorySettings;
bool _storeInMemoryOnly = false;
bool _returnDefaultValues = false;
bool _initialized = false;
QSettings* _settings; // should not be used directly but through settings() accessor
QSettings* settings() const;
// the following functions must be used to access and change a preference
// instead of using QSettings directly
QVariant get(const QString key) const;
bool has(const QString key) const;
void set(const QString key, QVariant value, bool temporary = false);
void remove(const QString key);
QVariant preference(const QString key) const;
QMetaType::Type type(const QString key) const;
bool checkIfKeyExists(const QString key) const;
bool checkType(const QString key, QMetaType::Type t) const;
// Used with workspace
QMap<QString, QVariant> localPreferences;
QMap<QString, QVariant> getDefaultLocalPreferences();
bool useLocalPrefs = false;
public:
Preferences();
~Preferences();
void init(bool storeInMemoryOnly = false);
void save();
// set to true to let getters return default values instead of values from QSettings
void setReturnDefaultValuesMode(bool returnDefaultValues) {_returnDefaultValues = returnDefaultValues;}
const prefs_map_t& allPreferences() const {return _allPreferences;}
// general getters
QVariant defaultValue(const QString key) const;
bool getBool(const QString key) const;
QColor getColor(const QString key) const;
QString getString(const QString key) const;
int getInt(const QString key) const;
double getDouble(const QString key) const;
// general setters
void setToDefaultValue(const QString key);
void setPreference(const QString key, QVariant value);
// A temporary preference is stored "in memory" only and not written to file.
// If there is both a "normal" preference and a temporary preference with the same
// key the temporary preference is used
void setTemporaryPreference(const QString key, QVariant value);
/*
* Some preferences like enums and structs/classes are not easily read using the general set/get methods
* and therefore require specific getters and/or setters
*/
SessionStart sessionStart() const;
MusicxmlExportBreaks musicxmlExportBreaks() const;
MuseScoreStyleType globalStyle() const;
bool isThemeDark() const;
template<typename T>
void setCustomPreference(const QString key, T t)
{
set(key, QVariant::fromValue<T>(t));
}
// The midiRemote preference requires special handling due to its complexity
MidiRemote midiRemote(int recordId) const;
void updateMidiRemote(int recordId, MidiRemoteType type, int data);
void clearMidiRemote(int recordId);
QMap<QString, QVariant> getLocalPreferences() { return localPreferences; }
void setLocalPreference(QString key, QVariant value);
void setUseLocalPreferences(bool value) { useLocalPrefs = value; }
bool getUseLocalPreferences() { return useLocalPrefs; }
void updateLocalPreferences() { localPreferences = getDefaultLocalPreferences(); }
};
// singleton
extern Preferences preferences;
// Stream operators for enum classes
// enum classes don't play well with QSettings without custom serialization
inline QDataStream&
operator<<(QDataStream &out, const Ms::MuseScoreStyleType &val)
{
return out << static_cast<int>(val);
}
inline QDataStream&
operator>>(QDataStream &in, Ms::MuseScoreStyleType &val)
{
int tmp;
in >> tmp;
val = static_cast<Ms::MuseScoreStyleType>(tmp);
return in;
}
inline QDataStream&
operator<<(QDataStream &out, const Ms::SessionStart &val)
{
return out << static_cast<int>(val);
}
inline QDataStream&
operator>>(QDataStream &in, Ms::SessionStart &val)
{
int tmp;
in >> tmp;
val = static_cast<Ms::SessionStart>(tmp);
return in;
}
inline QDataStream&
operator<<(QDataStream &out, const Ms::MusicxmlExportBreaks &val)
{
return out << static_cast<int>(val);
}
inline QDataStream&
operator>>(QDataStream &in, Ms::MusicxmlExportBreaks &val)
{
int tmp;
in >> tmp;
val = static_cast<Ms::MusicxmlExportBreaks>(tmp);
return in;
}
class PreferenceVisitor {
public:
virtual void visit(QString key, IntPreference*) = 0;
virtual void visit(QString key, DoublePreference*) = 0;
virtual void visit(QString key, BoolPreference*) = 0;
virtual void visit(QString key, StringPreference*) = 0;
virtual void visit(QString key, ColorPreference*) = 0;
};
} // namespace Ms
Q_DECLARE_METATYPE(Ms::SessionStart);
Q_DECLARE_METATYPE(Ms::MusicxmlExportBreaks);
Q_DECLARE_METATYPE(Ms::MuseScoreStyleType);
#endif
|