2b6cb8b432
The old Preferences struct holding all preferences are removed in favor of a new Preferences class which acts as a proxy for QSettings. The settings stored in QSettings are accessed directly through access methods like getBool(key), getInt(key), etc. and changed with setPreference(key, value). Since we are using QSettings directly the preferences are stored automatically without the need for a custom write() and read() method like before. The preferences.cpp/.h and prefdialog.cpp/h are refactored to have fewer responsibilities than before. The Preferences class are all about storing and retrieving preferences - it should not contain any code to handle any other aspect of MuseScore. Testing: The Preferences class can be used in tests. All preferences are initialized with default values in mtest. If a test requires that a preference has a specific value it can be changed using setPreference() for that single test. In the tests the preferences are stored in memory only. The Preference class is supposed to be used as a singleton. In preferences.h an 'extern Preferences preferences' is set and it is defined in preferences.cpp. All files which includes preferences.h have access to the 'preferences' singleton and should use this to get and set preferences.
140 lines
4 KiB
C++
140 lines
4 KiB
C++
//=============================================================================
|
|
// MuseScore
|
|
// Music Composition & Notation
|
|
//
|
|
// Copyright (C) 2002-2012 Werner Schweer
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License version 2
|
|
// as published by the Free Software Foundation and appearing in
|
|
// the file LICENCE.GPL
|
|
//=============================================================================
|
|
|
|
#include "config.h"
|
|
#include "preferences.h"
|
|
#include "driver.h"
|
|
|
|
#ifdef USE_JACK
|
|
#include "jackaudio.h"
|
|
#endif
|
|
|
|
|
|
#ifdef USE_ALSA
|
|
#include "alsa.h"
|
|
#endif
|
|
#ifdef USE_PORTAUDIO
|
|
#include "pa.h"
|
|
#endif
|
|
|
|
namespace Ms {
|
|
|
|
#ifdef USE_PULSEAUDIO
|
|
extern Driver* getPulseAudioDriver(Seq*);
|
|
#endif
|
|
|
|
bool alsaIsUsed = false, jackIsUsed = false, portAudioIsUsed = false, pulseAudioIsUsed = false;
|
|
|
|
|
|
//---------------------------------------------------------
|
|
// driverFactory
|
|
// driver can be: jack alsa pulse portaudio
|
|
//---------------------------------------------------------
|
|
|
|
Driver* driverFactory(Seq* seq, QString driverName)
|
|
{
|
|
Driver* driver = 0;
|
|
#if 1 // DEBUG: force "no audio"
|
|
bool useJackFlag = (preferences.getBool(PREF_IO_JACK_USEJACKAUDIO) || preferences.getBool(PREF_IO_JACK_USEJACKMIDI));
|
|
bool useAlsaFlag = preferences.getBool(PREF_IO_ALSA_USEALSAAUDIO);
|
|
bool usePortaudioFlag = preferences.getBool(PREF_IO_PORTAUDIO_USEPORTAUDIO);
|
|
bool usePulseAudioFlag = preferences.getBool(PREF_IO_PULSEAUDIO_USEPULSEAUDIO);
|
|
|
|
if (!driverName.isEmpty()) {
|
|
driverName = driverName.toLower();
|
|
useJackFlag = false;
|
|
useAlsaFlag = false;
|
|
usePortaudioFlag = false;
|
|
usePulseAudioFlag = false;
|
|
if (driverName == "jack")
|
|
useJackFlag = true;
|
|
else if (driverName == "alsa")
|
|
useAlsaFlag = true;
|
|
else if (driverName == "pulse")
|
|
usePulseAudioFlag = true;
|
|
else if (driverName == "portaudio")
|
|
usePortaudioFlag = true;
|
|
}
|
|
|
|
alsaIsUsed = false;
|
|
jackIsUsed = false;
|
|
portAudioIsUsed = false;
|
|
pulseAudioIsUsed = false;
|
|
|
|
#ifdef USE_PULSEAUDIO
|
|
if (usePulseAudioFlag) {
|
|
driver = getPulseAudioDriver(seq);
|
|
if (!driver->init()) {
|
|
qDebug("init PulseAudio failed");
|
|
delete driver;
|
|
driver = 0;
|
|
}
|
|
else
|
|
pulseAudioIsUsed = true;
|
|
}
|
|
#else
|
|
(void)usePulseAudioFlag; // avoid compiler warning
|
|
#endif
|
|
#ifdef USE_PORTAUDIO
|
|
if (usePortaudioFlag) {
|
|
driver = new Portaudio(seq);
|
|
if (!driver->init()) {
|
|
qDebug("init PortAudio failed");
|
|
delete driver;
|
|
driver = 0;
|
|
}
|
|
else
|
|
portAudioIsUsed = true;
|
|
}
|
|
#else
|
|
(void)usePortaudioFlag; // avoid compiler warning
|
|
#endif
|
|
#ifdef USE_ALSA
|
|
if (driver == 0 && useAlsaFlag) {
|
|
driver = new AlsaAudio(seq);
|
|
if (!driver->init()) {
|
|
qDebug("init ALSA driver failed");
|
|
delete driver;
|
|
driver = 0;
|
|
}
|
|
else {
|
|
alsaIsUsed = true;
|
|
}
|
|
}
|
|
#else
|
|
(void)useAlsaFlag; // avoid compiler warning
|
|
#endif
|
|
#ifdef USE_JACK
|
|
if (useJackFlag) {
|
|
useAlsaFlag = false;
|
|
usePortaudioFlag = false;
|
|
driver = new JackAudio(seq);
|
|
if (!driver->init()) {
|
|
qDebug("no JACK server found");
|
|
delete driver;
|
|
driver = 0;
|
|
}
|
|
else
|
|
jackIsUsed = true;
|
|
}
|
|
#else
|
|
(void)useJackFlag; // avoid compiler warning
|
|
#endif
|
|
#endif
|
|
if (driver == 0)
|
|
qDebug("no audio driver found");
|
|
|
|
return driver;
|
|
}
|
|
|
|
}
|
|
|