| 1 | /* |
|---|
| 2 | * Hydrogen |
|---|
| 3 | * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net] |
|---|
| 4 | * |
|---|
| 5 | * http://www.hydrogen-music.org |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU General Public License as published by |
|---|
| 9 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | * (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * This program is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY, without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| 18 | * along with this program; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | * |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | #include <stdlib.h> |
|---|
| 24 | #include <hydrogen/Preferences.h> |
|---|
| 25 | |
|---|
| 26 | #include <hydrogen/LocalFileMng.h> |
|---|
| 27 | |
|---|
| 28 | #ifndef WIN32 |
|---|
| 29 | #include <pwd.h> |
|---|
| 30 | #include <unistd.h> |
|---|
| 31 | #endif |
|---|
| 32 | #include <sys/types.h> |
|---|
| 33 | #include <sys/stat.h> |
|---|
| 34 | #include <stdlib.h> |
|---|
| 35 | #include <fstream> |
|---|
| 36 | #include <iostream> |
|---|
| 37 | #include <cstdio> |
|---|
| 38 | #include <list> |
|---|
| 39 | #include <hydrogen/midiMap.h> |
|---|
| 40 | |
|---|
| 41 | #include <hydrogen/data_path.h> |
|---|
| 42 | #include "config.h" |
|---|
| 43 | #include "version.h" |
|---|
| 44 | |
|---|
| 45 | #include <QDir> |
|---|
| 46 | #include <QApplication> |
|---|
| 47 | |
|---|
| 48 | namespace H2Core |
|---|
| 49 | { |
|---|
| 50 | |
|---|
| 51 | Preferences* Preferences::instance = NULL; |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | /// Return an instance of Preferences |
|---|
| 55 | Preferences* Preferences::getInstance() |
|---|
| 56 | { |
|---|
| 57 | if ( instance == NULL ) { |
|---|
| 58 | instance = new Preferences(); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | return instance; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | Preferences::Preferences() |
|---|
| 66 | : Object( "Preferences" ) |
|---|
| 67 | , demoPath( QString( DataPath::get_data_path() ) + "/demo_songs/" ) |
|---|
| 68 | , m_sLastNews( "" ) |
|---|
| 69 | { |
|---|
| 70 | INFOLOG( "INIT" ); |
|---|
| 71 | |
|---|
| 72 | //Default jack track-outputs are post fader |
|---|
| 73 | m_nJackTrackOutputMode = POST_FADER; |
|---|
| 74 | m_bJackTrackOuts = false; |
|---|
| 75 | // switch to enable / disable lash, only on h2 startup |
|---|
| 76 | m_brestartLash = false; |
|---|
| 77 | m_bsetLash = false; |
|---|
| 78 | |
|---|
| 79 | //server list |
|---|
| 80 | std::list<QString> sServerList; |
|---|
| 81 | |
|---|
| 82 | // //musicCategories |
|---|
| 83 | // std::list<QString> m_musicCategories; |
|---|
| 84 | |
|---|
| 85 | char * ladpath = getenv( "LADSPA_PATH" ); // read the Environment variable LADSPA_PATH |
|---|
| 86 | if ( ladpath ) { |
|---|
| 87 | INFOLOG( "Found LADSPA_PATH enviroment variable" ); |
|---|
| 88 | QString sLadspaPath = ladpath; |
|---|
| 89 | int pos; |
|---|
| 90 | while ( ( pos = sLadspaPath.indexOf( ":" ) ) != -1 ) { |
|---|
| 91 | QString sPath = sLadspaPath.left( pos ); |
|---|
| 92 | m_ladspaPathVect.push_back( sPath ); |
|---|
| 93 | sLadspaPath = sLadspaPath.mid( pos + 1, sLadspaPath.length() ); |
|---|
| 94 | } |
|---|
| 95 | m_ladspaPathVect.push_back( sLadspaPath ); |
|---|
| 96 | } else { |
|---|
| 97 | #ifdef Q_OS_MACX |
|---|
| 98 | m_ladspaPathVect.push_back( qApp->applicationDirPath() + "/../Resources/plugins" ); |
|---|
| 99 | m_ladspaPathVect.push_back( "/Library/Audio/Plug-Ins/LADSPA/" ); |
|---|
| 100 | m_ladspaPathVect.push_back( QDir::homePath().append( "/Library/Audio/Plug-Ins/LADSPA" )); |
|---|
| 101 | #else |
|---|
| 102 | m_ladspaPathVect.push_back( "/usr/lib/ladspa" ); |
|---|
| 103 | m_ladspaPathVect.push_back( "/usr/local/lib/ladspa" ); |
|---|
| 104 | #endif |
|---|
| 105 | |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | m_pDefaultUIStyle = new UIStyle(); |
|---|
| 112 | |
|---|
| 113 | #ifdef Q_OS_MACX |
|---|
| 114 | m_sPreferencesFilename = QDir::homePath().append( "/Library/Application Support/Hydrogen/hydrogen.conf" ); |
|---|
| 115 | m_sPreferencesDirectory = QDir::homePath().append( "/Library/Application Support/Hydrogen/" ); |
|---|
| 116 | m_sDataDirectory = QDir::homePath().append( "/Library/Application Support/Hydrogen/data/" ); |
|---|
| 117 | #else |
|---|
| 118 | m_sPreferencesFilename = QDir::homePath().append( "/.hydrogen/hydrogen.conf" ); |
|---|
| 119 | m_sPreferencesDirectory = QDir::homePath().append( "/.hydrogen/" ); |
|---|
| 120 | m_sDataDirectory = QDir::homePath().append( "/.hydrogen/data/" ); |
|---|
| 121 | #endif |
|---|
| 122 | |
|---|
| 123 | __lastsampleDirectory = QDir::homePath(); //audio file browser |
|---|
| 124 | __playsamplesonclicking = false; // audio file browser |
|---|
| 125 | |
|---|
| 126 | __expandSongItem = true; //SoundLibraryPanel |
|---|
| 127 | __expandPatternItem = true; //SoundLibraryPanel |
|---|
| 128 | |
|---|
| 129 | loadPreferences( true ); // Global settings |
|---|
| 130 | loadPreferences( false ); // User settings |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | Preferences::~Preferences() |
|---|
| 136 | { |
|---|
| 137 | savePreferences(); |
|---|
| 138 | |
|---|
| 139 | INFOLOG( "DESTROY" ); |
|---|
| 140 | instance = NULL; |
|---|
| 141 | delete m_pDefaultUIStyle; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | /// |
|---|
| 150 | /// Load the preferences file |
|---|
| 151 | /// |
|---|
| 152 | void Preferences::loadPreferences( bool bGlobal ) |
|---|
| 153 | { |
|---|
| 154 | bool recreate = false; // configuration file must be recreated? |
|---|
| 155 | |
|---|
| 156 | QString sPreferencesDirectory; |
|---|
| 157 | QString sPreferencesFilename; |
|---|
| 158 | QString sDataDirectory; |
|---|
| 159 | if ( bGlobal ) { |
|---|
| 160 | sPreferencesDirectory = DataPath::get_data_path(); |
|---|
| 161 | sPreferencesFilename = sPreferencesDirectory + "/hydrogen.default.conf"; |
|---|
| 162 | INFOLOG( "Loading preferences file (GLOBAL) [" + sPreferencesFilename + "]" ); |
|---|
| 163 | } else { |
|---|
| 164 | sPreferencesFilename = m_sPreferencesFilename; |
|---|
| 165 | sPreferencesDirectory = m_sPreferencesDirectory; |
|---|
| 166 | sDataDirectory = QDir::homePath().append( "/.hydrogen/data" ); |
|---|
| 167 | INFOLOG( "Loading preferences file (USER) [" + sPreferencesFilename + "]" ); |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | // preferences directory exists? |
|---|
| 175 | QDir prefDir( sPreferencesDirectory ); |
|---|
| 176 | if ( !prefDir.exists() ) { |
|---|
| 177 | if ( bGlobal ) { |
|---|
| 178 | WARNINGLOG( "System configuration directory '" + sPreferencesDirectory + "' not found." ); |
|---|
| 179 | } else { |
|---|
| 180 | ERRORLOG( "Configuration directory '" + sPreferencesDirectory + "' not found." ); |
|---|
| 181 | createPreferencesDirectory(); |
|---|
| 182 | } |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | // data directory exists? |
|---|
| 186 | QDir dataDir( sDataDirectory ); |
|---|
| 187 | if ( !dataDir.exists() ) { |
|---|
| 188 | WARNINGLOG( "Data directory not found." ); |
|---|
| 189 | createDataDirectory(); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | // soundLibrary directory exists? |
|---|
| 193 | QString sDir = sDataDirectory; |
|---|
| 194 | QString sDrumkitDir; |
|---|
| 195 | QString sSongDir; |
|---|
| 196 | QString sPatternDir; |
|---|
| 197 | |
|---|
| 198 | INFOLOG( "Creating soundLibrary directories in " + sDir ); |
|---|
| 199 | |
|---|
| 200 | sDrumkitDir = sDir + "/drumkits"; |
|---|
| 201 | sSongDir = sDir + "/songs"; |
|---|
| 202 | sPatternDir = sDir + "/patterns"; |
|---|
| 203 | |
|---|
| 204 | QDir drumkitDir( sDrumkitDir ); |
|---|
| 205 | QDir songDir( sSongDir ); |
|---|
| 206 | QDir patternDir( sPatternDir ); |
|---|
| 207 | |
|---|
| 208 | if ( ! drumkitDir.exists() || ! songDir.exists() || ! patternDir.exists() ) |
|---|
| 209 | { |
|---|
| 210 | createSoundLibraryDirectories(); |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | // pref file exists? |
|---|
| 214 | std::ifstream input( sPreferencesFilename.toAscii() , std::ios::in | std::ios::binary ); |
|---|
| 215 | if ( input ) { |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | // read preferences file |
|---|
| 219 | QDomDocument doc; |
|---|
| 220 | QFile file( sPreferencesFilename ); |
|---|
| 221 | |
|---|
| 222 | if ( !file.open(QIODevice::ReadOnly) ) |
|---|
| 223 | return; |
|---|
| 224 | |
|---|
| 225 | if ( !doc.setContent( &file ) ) { |
|---|
| 226 | file.close(); |
|---|
| 227 | return; |
|---|
| 228 | } |
|---|
| 229 | file.close(); |
|---|
| 230 | |
|---|
| 231 | QDomNode rootNode = doc.firstChildElement( "hydrogen_preferences" ); |
|---|
| 232 | if ( !rootNode.isNull() ) { |
|---|
| 233 | |
|---|
| 234 | // version |
|---|
| 235 | QString version = LocalFileMng::readXmlString( rootNode, "version", "" ); |
|---|
| 236 | if ( version == "" ) { |
|---|
| 237 | recreate = true; |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | //////// GENERAL /////////// |
|---|
| 241 | //m_sLadspaPath = LocalFileMng::readXmlString( this, rootNode, "ladspaPath", m_sLadspaPath ); |
|---|
| 242 | m_bShowDevelWarning = LocalFileMng::readXmlBool( rootNode, "showDevelWarning", m_bShowDevelWarning ); |
|---|
| 243 | restoreLastSong = LocalFileMng::readXmlBool( rootNode, "restoreLastSong", restoreLastSong ); |
|---|
| 244 | m_bPatternModePlaysSelected = LocalFileMng::readXmlBool( rootNode, "patternModePlaysSelected", TRUE ); |
|---|
| 245 | m_bUseLash = LocalFileMng::readXmlBool( rootNode, "useLash", FALSE ); |
|---|
| 246 | |
|---|
| 247 | //restore the right m_bsetlash value |
|---|
| 248 | m_bsetLash = m_bUseLash; |
|---|
| 249 | |
|---|
| 250 | hearNewNotes = LocalFileMng::readXmlBool( rootNode, "hearNewNotes", hearNewNotes ); |
|---|
| 251 | recordEvents = LocalFileMng::readXmlBool( rootNode, "recordEvents", recordEvents ); |
|---|
| 252 | quantizeEvents = LocalFileMng::readXmlBool( rootNode, "quantizeEvents", quantizeEvents ); |
|---|
| 253 | |
|---|
| 254 | QDomNode pRecentUsedSongsNode = rootNode.firstChildElement( "recentUsedSongs" ); |
|---|
| 255 | if ( !pRecentUsedSongsNode.isNull() ) { |
|---|
| 256 | QDomElement pSongElement = pRecentUsedSongsNode.firstChildElement( "song" ); |
|---|
| 257 | if( !pSongElement.isNull() && !pSongElement.text().isEmpty() ){ |
|---|
| 258 | m_recentFiles.push_back( pSongElement.text() ); |
|---|
| 259 | } |
|---|
| 260 | pSongElement = pRecentUsedSongsNode.nextSiblingElement( "song" ); |
|---|
| 261 | |
|---|
| 262 | } else { |
|---|
| 263 | WARNINGLOG( "recentUsedSongs node not found" ); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | QDomNode pRecentFXNode = rootNode.firstChildElement( "recentlyUsedEffects" ); |
|---|
| 267 | if ( ! pRecentFXNode.isNull() ) { |
|---|
| 268 | QDomElement pFXElement = pRecentFXNode.firstChildElement( "FX" ); |
|---|
| 269 | if ( !pFXElement.isNull() && ! pFXElement.text().isEmpty()) { |
|---|
| 270 | m_recentFX.push_back( pFXElement.text() ); |
|---|
| 271 | } |
|---|
| 272 | pFXElement = pRecentFXNode.nextSiblingElement( "FX" ); |
|---|
| 273 | } else { |
|---|
| 274 | WARNINGLOG( "recentlyUsedEffects node not found" ); |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | sServerList.clear(); |
|---|
| 278 | QDomNode pServerListNode = rootNode.firstChildElement( "serverList" ); |
|---|
| 279 | if ( !pServerListNode.isNull() ) { |
|---|
| 280 | QDomElement pServerElement = pServerListNode.firstChildElement( "server" ); |
|---|
| 281 | if ( !pServerElement.isNull() && !pServerElement.text().isEmpty() ) { |
|---|
| 282 | sServerList.push_back( pServerElement.text() ); |
|---|
| 283 | } |
|---|
| 284 | pServerElement = pServerListNode.nextSiblingElement( "server" ); |
|---|
| 285 | } else { |
|---|
| 286 | WARNINGLOG( "serverList node not found" ); |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | m_patternCategories.clear(); |
|---|
| 290 | QDomNode pPatternCategoriesNode = rootNode.firstChildElement( "patternCategories" ); |
|---|
| 291 | if ( !pPatternCategoriesNode.isNull() ) { |
|---|
| 292 | QDomElement pPatternCategoriesElement = pPatternCategoriesNode.firstChildElement( "categories" ); |
|---|
| 293 | if ( !pPatternCategoriesElement.isNull() && !pPatternCategoriesElement.text().isEmpty() ) { |
|---|
| 294 | m_patternCategories.push_back( pPatternCategoriesElement.text() ); |
|---|
| 295 | } |
|---|
| 296 | pPatternCategoriesElement = pPatternCategoriesNode.nextSiblingElement( "categories" ); |
|---|
| 297 | } else { |
|---|
| 298 | WARNINGLOG( "patternCategories node not found" ); |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | m_sLastNews = LocalFileMng::readXmlString( rootNode, "lastNews", "-", true ); |
|---|
| 304 | |
|---|
| 305 | /////////////// AUDIO ENGINE ////////////// |
|---|
| 306 | QDomNode audioEngineNode = rootNode.firstChildElement( "audio_engine" ); |
|---|
| 307 | if ( audioEngineNode.isNull() ) { |
|---|
| 308 | WARNINGLOG( "audio_engine node not found" ); |
|---|
| 309 | recreate = true; |
|---|
| 310 | } else { |
|---|
| 311 | m_sAudioDriver = LocalFileMng::readXmlString( audioEngineNode, "audio_driver", m_sAudioDriver ); |
|---|
| 312 | m_bUseMetronome = LocalFileMng::readXmlBool( audioEngineNode, "use_metronome", m_bUseMetronome ); |
|---|
| 313 | m_fMetronomeVolume = LocalFileMng::readXmlFloat( audioEngineNode, "metronome_volume", 0.5f ); |
|---|
| 314 | m_nMaxNotes = LocalFileMng::readXmlInt( audioEngineNode, "maxNotes", m_nMaxNotes ); |
|---|
| 315 | m_nBufferSize = LocalFileMng::readXmlInt( audioEngineNode, "buffer_size", m_nBufferSize ); |
|---|
| 316 | m_nSampleRate = LocalFileMng::readXmlInt( audioEngineNode, "samplerate", m_nSampleRate ); |
|---|
| 317 | |
|---|
| 318 | //// OSS DRIVER //// |
|---|
| 319 | QDomNode ossDriverNode = audioEngineNode.firstChildElement( "oss_driver" ); |
|---|
| 320 | if ( ossDriverNode.isNull() ) { |
|---|
| 321 | WARNINGLOG( "oss_driver node not found" ); |
|---|
| 322 | recreate = true; |
|---|
| 323 | } else { |
|---|
| 324 | m_sOSSDevice = LocalFileMng::readXmlString( ossDriverNode, "ossDevice", m_sOSSDevice ); |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | //// JACK DRIVER //// |
|---|
| 328 | QDomNode jackDriverNode = audioEngineNode.firstChildElement( "jack_driver" ); |
|---|
| 329 | if ( jackDriverNode.isNull() ) { |
|---|
| 330 | WARNINGLOG( "jack_driver node not found" ); |
|---|
| 331 | recreate = true; |
|---|
| 332 | } else { |
|---|
| 333 | m_sJackPortName1 = LocalFileMng::readXmlString( jackDriverNode, "jack_port_name_1", m_sJackPortName1 ); |
|---|
| 334 | m_sJackPortName2 = LocalFileMng::readXmlString( jackDriverNode, "jack_port_name_2", m_sJackPortName2 ); |
|---|
| 335 | QString sMode = LocalFileMng::readXmlString( jackDriverNode, "jack_transport_mode", "NO_JACK_TRANSPORT" ); |
|---|
| 336 | if ( sMode == "NO_JACK_TRANSPORT" ) { |
|---|
| 337 | m_bJackTransportMode = NO_JACK_TRANSPORT; |
|---|
| 338 | } else if ( sMode == "USE_JACK_TRANSPORT" ) { |
|---|
| 339 | m_bJackTransportMode = USE_JACK_TRANSPORT; |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | //jack time master |
|---|
| 343 | QString tmMode = LocalFileMng::readXmlString( jackDriverNode, "jack_transport_mode_master", "NO_JACK_TIME_MASTER" ); |
|---|
| 344 | if ( tmMode == "NO_JACK_TIME_MASTER" ) { |
|---|
| 345 | m_bJackMasterMode = NO_JACK_TIME_MASTER; |
|---|
| 346 | } else if ( tmMode == "USE_JACK_TIME_MASTER" ) { |
|---|
| 347 | m_bJackMasterMode = USE_JACK_TIME_MASTER; |
|---|
| 348 | } |
|---|
| 349 | //~ jack time master |
|---|
| 350 | |
|---|
| 351 | m_bJackTrackOuts = LocalFileMng::readXmlBool( jackDriverNode, "jack_track_outs", m_bJackTrackOuts ); |
|---|
| 352 | m_bJackConnectDefaults = LocalFileMng::readXmlBool( jackDriverNode, "jack_connect_defaults", m_bJackConnectDefaults ); |
|---|
| 353 | |
|---|
| 354 | m_nJackTrackOutputMode = LocalFileMng::readXmlInt( jackDriverNode, "jack_track_output_mode", m_nJackTrackOutputMode ); |
|---|
| 355 | m_nJackArdourTransportWorkaround = LocalFileMng::readXmlBool( jackDriverNode, "jack_ardour_transport_workaround", m_nJackArdourTransportWorkaround ); |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | |
|---|
| 359 | /// ALSA AUDIO DRIVER /// |
|---|
| 360 | QDomNode alsaAudioDriverNode = audioEngineNode.firstChildElement( "alsa_audio_driver" ); |
|---|
| 361 | if ( alsaAudioDriverNode.isNull() ) { |
|---|
| 362 | WARNINGLOG( "alsa_audio_driver node not found" ); |
|---|
| 363 | recreate = true; |
|---|
| 364 | } else { |
|---|
| 365 | m_sAlsaAudioDevice = LocalFileMng::readXmlString( alsaAudioDriverNode, "alsa_audio_device", m_sAlsaAudioDevice ); |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | /// MIDI DRIVER /// |
|---|
| 369 | QDomNode midiDriverNode = audioEngineNode.firstChildElement( "midi_driver" ); |
|---|
| 370 | if ( midiDriverNode.isNull() ) { |
|---|
| 371 | WARNINGLOG( "midi_driver node not found" ); |
|---|
| 372 | recreate = true; |
|---|
| 373 | } else { |
|---|
| 374 | m_sMidiDriver = LocalFileMng::readXmlString( midiDriverNode, "driverName", "ALSA" ); |
|---|
| 375 | m_sMidiPortName = LocalFileMng::readXmlString( midiDriverNode, "port_name", "None" ); |
|---|
| 376 | m_nMidiChannelFilter = LocalFileMng::readXmlInt( midiDriverNode, "channel_filter", -1 ); |
|---|
| 377 | m_bMidiNoteOffIgnore = LocalFileMng::readXmlBool( midiDriverNode, "ignore_note_off", true ); |
|---|
| 378 | } |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | /////////////// GUI ////////////// |
|---|
| 385 | QDomNode guiNode = rootNode.firstChildElement( "gui" ); |
|---|
| 386 | if ( guiNode.isNull() ) { |
|---|
| 387 | WARNINGLOG( "gui node not found" ); |
|---|
| 388 | recreate = true; |
|---|
| 389 | } else { |
|---|
| 390 | // QT Style |
|---|
| 391 | m_sQTStyle = LocalFileMng::readXmlString( guiNode, "QTStyle", m_sQTStyle, true ); |
|---|
| 392 | |
|---|
| 393 | // Application font family |
|---|
| 394 | applicationFontFamily = LocalFileMng::readXmlString( guiNode, "application_font_family", applicationFontFamily ); |
|---|
| 395 | |
|---|
| 396 | // Application font pointSize |
|---|
| 397 | applicationFontPointSize = LocalFileMng::readXmlInt( guiNode, "application_font_pointsize", applicationFontPointSize ); |
|---|
| 398 | |
|---|
| 399 | // mixer font family |
|---|
| 400 | mixerFontFamily = LocalFileMng::readXmlString( guiNode, "mixer_font_family", mixerFontFamily ); |
|---|
| 401 | |
|---|
| 402 | // mixer font pointSize |
|---|
| 403 | mixerFontPointSize = LocalFileMng::readXmlInt( guiNode, "mixer_font_pointsize", mixerFontPointSize ); |
|---|
| 404 | |
|---|
| 405 | // Mixer falloff speed |
|---|
| 406 | mixerFalloffSpeed = LocalFileMng::readXmlFloat( guiNode, "mixer_falloff_speed", 1.1f ); |
|---|
| 407 | |
|---|
| 408 | // pattern editor grid resolution |
|---|
| 409 | m_nPatternEditorGridResolution = LocalFileMng::readXmlInt( guiNode, "patternEditorGridResolution", m_nPatternEditorGridResolution ); |
|---|
| 410 | m_bPatternEditorUsingTriplets = LocalFileMng::readXmlBool( guiNode, "patternEditorUsingTriplets", m_bPatternEditorUsingTriplets ); |
|---|
| 411 | m_bShowInstrumentPeaks = LocalFileMng::readXmlBool( guiNode, "showInstrumentPeaks", m_bShowInstrumentPeaks ); |
|---|
| 412 | m_bIsFXTabVisible = LocalFileMng::readXmlBool( guiNode, "isFXTabVisible", m_bIsFXTabVisible ); |
|---|
| 413 | |
|---|
| 414 | |
|---|
| 415 | // pattern editor grid height |
|---|
| 416 | m_nPatternEditorGridHeight = LocalFileMng::readXmlInt( guiNode, "patternEditorGridHeight", m_nPatternEditorGridHeight ); |
|---|
| 417 | |
|---|
| 418 | // pattern editor grid width |
|---|
| 419 | m_nPatternEditorGridWidth = LocalFileMng::readXmlInt( guiNode, "patternEditorGridWidth", m_nPatternEditorGridWidth ); |
|---|
| 420 | |
|---|
| 421 | // mainForm window properties |
|---|
| 422 | setMainFormProperties( readWindowProperties( guiNode, "mainForm_properties", mainFormProperties ) ); |
|---|
| 423 | setMixerProperties( readWindowProperties( guiNode, "mixer_properties", mixerProperties ) ); |
|---|
| 424 | setPatternEditorProperties( readWindowProperties( guiNode, "patternEditor_properties", patternEditorProperties ) ); |
|---|
| 425 | setSongEditorProperties( readWindowProperties( guiNode, "songEditor_properties", songEditorProperties ) ); |
|---|
| 426 | setAudioEngineInfoProperties( readWindowProperties( guiNode, "audioEngineInfo_properties", audioEngineInfoProperties ) ); |
|---|
| 427 | |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | m_bFollowPlayhead = LocalFileMng::readXmlBool( guiNode, "followPlayhead", true ); |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | //beatcounter |
|---|
| 434 | QString bcMode = LocalFileMng::readXmlString( guiNode, "bc", "BC_OFF" ); |
|---|
| 435 | if ( bcMode == "BC_OFF" ) { |
|---|
| 436 | m_bbc = BC_OFF; |
|---|
| 437 | } else if ( bcMode == "BC_ON" ) { |
|---|
| 438 | m_bbc = BC_ON; |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | QString setPlay = LocalFileMng::readXmlString( guiNode, "setplay", "SET_PLAY_OFF" ); |
|---|
| 443 | if ( setPlay == "SET_PLAY_OFF" ) { |
|---|
| 444 | m_mmcsetplay = SET_PLAY_OFF; |
|---|
| 445 | } else if ( setPlay == "SET_PLAY_ON" ) { |
|---|
| 446 | m_mmcsetplay = SET_PLAY_ON; |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | m_countOffset = LocalFileMng::readXmlInt( guiNode, "countoffset", 0 ); |
|---|
| 450 | m_startOffset = LocalFileMng::readXmlInt( guiNode, "playoffset", 0 ); |
|---|
| 451 | |
|---|
| 452 | //~ beatcounter |
|---|
| 453 | |
|---|
| 454 | //SoundLibraryPanel expand items |
|---|
| 455 | __expandSongItem = LocalFileMng::readXmlBool( guiNode, "expandSongItem", __expandSongItem ); |
|---|
| 456 | __expandPatternItem = LocalFileMng::readXmlBool( guiNode, "expandPatternItem", __expandPatternItem ); |
|---|
| 457 | |
|---|
| 458 | for ( unsigned nFX = 0; nFX < MAX_FX; nFX++ ) { |
|---|
| 459 | QString sNodeName = "ladspaFX_properties" + to_string( nFX ); |
|---|
| 460 | setLadspaProperties( nFX, readWindowProperties( guiNode, sNodeName, m_ladspaProperties[nFX] ) ); |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | QDomNode pUIStyle = guiNode.firstChildElement( "UI_Style" ); |
|---|
| 464 | if ( !pUIStyle.isNull() ) { |
|---|
| 465 | readUIStyle( pUIStyle ); |
|---|
| 466 | } else { |
|---|
| 467 | WARNINGLOG( "UI_Style node not found" ); |
|---|
| 468 | recreate = true; |
|---|
| 469 | } |
|---|
| 470 | } |
|---|
| 471 | |
|---|
| 472 | /////////////// FILES ////////////// |
|---|
| 473 | QDomNode filesNode = rootNode.firstChildElement( "files" ); |
|---|
| 474 | if ( filesNode.isNull() ) { |
|---|
| 475 | WARNINGLOG( "files node not found" ); |
|---|
| 476 | recreate = true; |
|---|
| 477 | } else { |
|---|
| 478 | // last used song |
|---|
| 479 | lastSongFilename = LocalFileMng::readXmlString( filesNode, "lastSongFilename", lastSongFilename, true ); |
|---|
| 480 | m_sDefaultEditor = LocalFileMng::readXmlString( filesNode, "defaulteditor", m_sDefaultEditor, true ); |
|---|
| 481 | } |
|---|
| 482 | |
|---|
| 483 | // FIXME: hack hack hack! Isn't better to create a "release" method in MidiMap class instead of destroying a singleton? |
|---|
| 484 | if ( MidiMap::__instance != NULL) { |
|---|
| 485 | delete MidiMap::__instance; |
|---|
| 486 | } |
|---|
| 487 | MidiMap* mM = MidiMap::getInstance(); |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | QDomNode pMidiEventMapNode = rootNode.firstChildElement( "midiEventMap" ); |
|---|
| 491 | if ( !pMidiEventMapNode.isNull() ) { |
|---|
| 492 | |
|---|
| 493 | QDomNode pMidiEventNode = pMidiEventMapNode.firstChildElement( "midiEvent" ); |
|---|
| 494 | |
|---|
| 495 | while ( !pMidiEventNode.isNull() ) { |
|---|
| 496 | |
|---|
| 497 | if( pMidiEventNode.firstChildElement().nodeValue() == QString("mmcEvent")){ |
|---|
| 498 | QString event = pMidiEventNode.firstChildElement("mmcEvent").firstChildElement().nodeValue(); |
|---|
| 499 | QString s_action = pMidiEventNode.firstChildElement("action").firstChildElement().nodeValue(); |
|---|
| 500 | QString s_param = pMidiEventNode.firstChildElement("parameter").firstChildElement().nodeValue(); |
|---|
| 501 | Action* pAction = new Action( s_action ); |
|---|
| 502 | pAction->setParameter1( s_param ); |
|---|
| 503 | mM->registerMMCEvent(event, pAction); |
|---|
| 504 | } |
|---|
| 505 | |
|---|
| 506 | if( pMidiEventNode.firstChildElement().nodeValue() == QString("noteEvent")){ |
|---|
| 507 | QString event = pMidiEventNode.firstChildElement("noteEvent").firstChildElement().nodeValue(); |
|---|
| 508 | QString s_action = pMidiEventNode.firstChildElement("action").firstChildElement().nodeValue(); |
|---|
| 509 | QString s_param = pMidiEventNode.firstChildElement("parameter").firstChildElement().nodeValue(); |
|---|
| 510 | QString s_eventParameter = pMidiEventNode.firstChildElement("eventParameter").firstChildElement().nodeValue(); |
|---|
| 511 | Action* pAction = new Action( s_action ); |
|---|
| 512 | pAction->setParameter1( s_param ); |
|---|
| 513 | mM->registerNoteEvent(s_eventParameter.toInt(), pAction); |
|---|
| 514 | } |
|---|
| 515 | |
|---|
| 516 | if( pMidiEventNode.firstChildElement().nodeValue() == QString("ccEvent") ){ |
|---|
| 517 | QString event = pMidiEventNode.firstChildElement("ccEvent").firstChildElement().nodeValue(); |
|---|
| 518 | QString s_action = pMidiEventNode.firstChildElement("action").firstChildElement().nodeValue(); |
|---|
| 519 | QString s_param = pMidiEventNode.firstChildElement("parameter").firstChildElement().nodeValue(); |
|---|
| 520 | QString s_eventParameter = pMidiEventNode.firstChildElement("eventParameter").firstChildElement().nodeValue(); |
|---|
| 521 | Action * pAction = new Action( s_action ); |
|---|
| 522 | pAction->setParameter1( s_param ); |
|---|
| 523 | mM->registerCCEvent( s_eventParameter.toInt(), pAction ); |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | pMidiEventNode = pMidiEventNode.nextSiblingElement( "midiEvent" ); |
|---|
| 527 | |
|---|
| 528 | } |
|---|
| 529 | } else { |
|---|
| 530 | WARNINGLOG( "midiMap node not found" ); |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | |
|---|
| 535 | } // rootNode |
|---|
| 536 | else { |
|---|
| 537 | WARNINGLOG( "hydrogen_preferences node not found" ); |
|---|
| 538 | recreate = true; |
|---|
| 539 | } |
|---|
| 540 | } else { |
|---|
| 541 | if ( bGlobal ) { |
|---|
| 542 | WARNINGLOG( "System configuration file not found." ); |
|---|
| 543 | } else { |
|---|
| 544 | WARNINGLOG( "Configuration file not found." ); |
|---|
| 545 | recreate = true; |
|---|
| 546 | } |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | // The preferences file should be recreated? |
|---|
| 551 | if ( recreate == true ) { |
|---|
| 552 | WARNINGLOG( "Recreating configuration file." ); |
|---|
| 553 | savePreferences(); |
|---|
| 554 | } |
|---|
| 555 | |
|---|
| 556 | } |
|---|
| 557 | |
|---|
| 558 | |
|---|
| 559 | |
|---|
| 560 | /// |
|---|
| 561 | /// Save the preferences file |
|---|
| 562 | /// |
|---|
| 563 | void Preferences::savePreferences() |
|---|
| 564 | { |
|---|
| 565 | //string prefDir = QDir::homePath().append("/.hydrogen").toStdString(); |
|---|
| 566 | QString filename = m_sPreferencesFilename; |
|---|
| 567 | |
|---|
| 568 | INFOLOG( "Saving preferences file: " + filename ); |
|---|
| 569 | |
|---|
| 570 | QDomDocument doc; |
|---|
| 571 | |
|---|
| 572 | QDomNode rootNode = doc.createElement( "hydrogen_preferences" ); |
|---|
| 573 | |
|---|
| 574 | // hydrogen version |
|---|
| 575 | LocalFileMng::writeXmlString( rootNode, "version", QString( get_version().c_str() ) ); |
|---|
| 576 | |
|---|
| 577 | ////// GENERAL /////// |
|---|
| 578 | LocalFileMng::writeXmlString( rootNode, "restoreLastSong", restoreLastSong ? "true": "false" ); |
|---|
| 579 | |
|---|
| 580 | LocalFileMng::writeXmlString( rootNode, "patternModePlaysSelected", m_bPatternModePlaysSelected ? "true": "false" ); |
|---|
| 581 | |
|---|
| 582 | LocalFileMng::writeXmlString( rootNode, "useLash", m_bsetLash ? "true": "false" ); |
|---|
| 583 | |
|---|
| 584 | //show development version warning |
|---|
| 585 | LocalFileMng::writeXmlString( rootNode, "showDevelWarning", m_bShowDevelWarning ? "true": "false" ); |
|---|
| 586 | |
|---|
| 587 | // hear new notes in the pattern editor |
|---|
| 588 | LocalFileMng::writeXmlString( rootNode, "hearNewNotes", hearNewNotes ? "true": "false" ); |
|---|
| 589 | |
|---|
| 590 | // key/midi event prefs |
|---|
| 591 | LocalFileMng::writeXmlString( rootNode, "recordEvents", recordEvents ? "true": "false" ); |
|---|
| 592 | LocalFileMng::writeXmlString( rootNode, "quantizeEvents", quantizeEvents ? "true": "false" ); |
|---|
| 593 | |
|---|
| 594 | // Recent used songs |
|---|
| 595 | QDomNode recentUsedSongsNode = doc.createElement( "recentUsedSongs" ); |
|---|
| 596 | { |
|---|
| 597 | unsigned nSongs = 5; |
|---|
| 598 | if ( m_recentFiles.size() < 5 ) { |
|---|
| 599 | nSongs = m_recentFiles.size(); |
|---|
| 600 | } |
|---|
| 601 | for ( unsigned i = 0; i < nSongs; i++ ) { |
|---|
| 602 | LocalFileMng::writeXmlString( recentUsedSongsNode, "song", m_recentFiles[ i ] ); |
|---|
| 603 | } |
|---|
| 604 | } |
|---|
| 605 | rootNode.appendChild( recentUsedSongsNode ); |
|---|
| 606 | |
|---|
| 607 | QDomNode recentFXNode = doc.createElement( "recentlyUsedEffects" ); |
|---|
| 608 | { |
|---|
| 609 | int nFX = 0; |
|---|
| 610 | QString FXname; |
|---|
| 611 | foreach( FXname, m_recentFX ) { |
|---|
| 612 | LocalFileMng::writeXmlString( recentFXNode, "FX", FXname ); |
|---|
| 613 | if ( ++nFX > 10 ) break; |
|---|
| 614 | } |
|---|
| 615 | } |
|---|
| 616 | rootNode.appendChild( recentFXNode ); |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | std::list<QString>::const_iterator cur_Server; |
|---|
| 620 | |
|---|
| 621 | QDomNode serverListNode = doc.createElement( "serverList" ); |
|---|
| 622 | for( cur_Server = sServerList.begin(); cur_Server != sServerList.end(); ++cur_Server ){ |
|---|
| 623 | LocalFileMng::writeXmlString( serverListNode , QString("server") , QString( *cur_Server ) ); |
|---|
| 624 | } |
|---|
| 625 | rootNode.appendChild( serverListNode ); |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | std::list<QString>::const_iterator cur_patternCategories; |
|---|
| 629 | |
|---|
| 630 | QDomNode patternCategoriesNode = doc.createElement( "patternCategories" ); |
|---|
| 631 | for( cur_patternCategories = m_patternCategories.begin(); cur_patternCategories != m_patternCategories.end(); ++cur_patternCategories ){ |
|---|
| 632 | LocalFileMng::writeXmlString( patternCategoriesNode , QString("categories") , QString( *cur_patternCategories ) ); |
|---|
| 633 | } |
|---|
| 634 | rootNode.appendChild( patternCategoriesNode ); |
|---|
| 635 | |
|---|
| 636 | |
|---|
| 637 | |
|---|
| 638 | |
|---|
| 639 | LocalFileMng::writeXmlString( rootNode, "lastNews", m_sLastNews ); |
|---|
| 640 | |
|---|
| 641 | |
|---|
| 642 | //---- AUDIO ENGINE ---- |
|---|
| 643 | QDomNode audioEngineNode = doc.createElement( "audio_engine" ); |
|---|
| 644 | { |
|---|
| 645 | // audio driver |
|---|
| 646 | LocalFileMng::writeXmlString( audioEngineNode, "audio_driver", m_sAudioDriver ); |
|---|
| 647 | |
|---|
| 648 | // use metronome |
|---|
| 649 | LocalFileMng::writeXmlString( audioEngineNode, "use_metronome", m_bUseMetronome ? "true": "false" ); |
|---|
| 650 | LocalFileMng::writeXmlString( audioEngineNode, "metronome_volume", to_string( m_fMetronomeVolume ) ); |
|---|
| 651 | LocalFileMng::writeXmlString( audioEngineNode, "maxNotes", to_string( m_nMaxNotes ) ); |
|---|
| 652 | LocalFileMng::writeXmlString( audioEngineNode, "buffer_size", to_string( m_nBufferSize ) ); |
|---|
| 653 | LocalFileMng::writeXmlString( audioEngineNode, "samplerate", to_string( m_nSampleRate ) ); |
|---|
| 654 | |
|---|
| 655 | //// OSS DRIVER //// |
|---|
| 656 | QDomNode ossDriverNode = doc.createElement( "oss_driver" ); |
|---|
| 657 | { |
|---|
| 658 | LocalFileMng::writeXmlString( ossDriverNode, "ossDevice", m_sOSSDevice ); |
|---|
| 659 | } |
|---|
| 660 | audioEngineNode.appendChild( ossDriverNode ); |
|---|
| 661 | |
|---|
| 662 | //// JACK DRIVER //// |
|---|
| 663 | QDomNode jackDriverNode = doc.createElement( "jack_driver" ); |
|---|
| 664 | { |
|---|
| 665 | LocalFileMng::writeXmlString( jackDriverNode, "jack_port_name_1", m_sJackPortName1 ); // jack port name 1 |
|---|
| 666 | LocalFileMng::writeXmlString( jackDriverNode, "jack_port_name_2", m_sJackPortName2 ); // jack port name 2 |
|---|
| 667 | |
|---|
| 668 | // jack transport slave |
|---|
| 669 | QString sMode; |
|---|
| 670 | if ( m_bJackTransportMode == NO_JACK_TRANSPORT ) { |
|---|
| 671 | sMode = "NO_JACK_TRANSPORT"; |
|---|
| 672 | } else if ( m_bJackTransportMode == USE_JACK_TRANSPORT ) { |
|---|
| 673 | sMode = "USE_JACK_TRANSPORT"; |
|---|
| 674 | } |
|---|
| 675 | LocalFileMng::writeXmlString( jackDriverNode, "jack_transport_mode", sMode ); |
|---|
| 676 | |
|---|
| 677 | //jack time master |
|---|
| 678 | QString tmMode; |
|---|
| 679 | if ( m_bJackMasterMode == NO_JACK_TIME_MASTER ) { |
|---|
| 680 | tmMode = "NO_JACK_TIME_MASTER"; |
|---|
| 681 | } else if ( m_bJackMasterMode == USE_JACK_TIME_MASTER ) { |
|---|
| 682 | tmMode = "NO_JACK_TIME_MASTER"; |
|---|
| 683 | } |
|---|
| 684 | LocalFileMng::writeXmlString( jackDriverNode, "jack_transport_mode_master", tmMode ); |
|---|
| 685 | //~ jack time master |
|---|
| 686 | |
|---|
| 687 | // jack default connection |
|---|
| 688 | QString jackConnectDefaultsString = "false"; |
|---|
| 689 | if ( m_bJackConnectDefaults ) { |
|---|
| 690 | jackConnectDefaultsString = "true"; |
|---|
| 691 | } |
|---|
| 692 | LocalFileMng::writeXmlString( jackDriverNode, "jack_connect_defaults", jackConnectDefaultsString ); |
|---|
| 693 | |
|---|
| 694 | //pre-fader or post-fader track outputs ? |
|---|
| 695 | LocalFileMng::writeXmlString( jackDriverNode, "jack_track_output_mode", to_string ( m_nJackTrackOutputMode )); |
|---|
| 696 | |
|---|
| 697 | // jack track outs |
|---|
| 698 | QString jackTrackOutsString = "false"; |
|---|
| 699 | if ( m_bJackTrackOuts ) { |
|---|
| 700 | jackTrackOutsString = "true"; |
|---|
| 701 | } |
|---|
| 702 | LocalFileMng::writeXmlString( jackDriverNode, "jack_track_outs", jackTrackOutsString ); |
|---|
| 703 | QString jackArdourTransportWorkaroundString = |
|---|
| 704 | (m_nJackArdourTransportWorkaround) ? "true" : "false"; |
|---|
| 705 | LocalFileMng::writeXmlString( jackDriverNode, "jack_ardour_transport_workaround", jackArdourTransportWorkaroundString ); |
|---|
| 706 | } |
|---|
| 707 | audioEngineNode.appendChild( jackDriverNode ); |
|---|
| 708 | |
|---|
| 709 | //// ALSA AUDIO DRIVER //// |
|---|
| 710 | QDomNode alsaAudioDriverNode = doc.createElement( "alsa_audio_driver" ); |
|---|
| 711 | { |
|---|
| 712 | LocalFileMng::writeXmlString( alsaAudioDriverNode, "alsa_audio_device", m_sAlsaAudioDevice ); |
|---|
| 713 | } |
|---|
| 714 | audioEngineNode.appendChild( alsaAudioDriverNode ); |
|---|
| 715 | |
|---|
| 716 | /// MIDI DRIVER /// |
|---|
| 717 | QDomNode midiDriverNode = doc.createElement( "midi_driver" ); |
|---|
| 718 | { |
|---|
| 719 | LocalFileMng::writeXmlString( midiDriverNode, "driverName", m_sMidiDriver ); |
|---|
| 720 | LocalFileMng::writeXmlString( midiDriverNode, "port_name", m_sMidiPortName ); |
|---|
| 721 | LocalFileMng::writeXmlString( midiDriverNode, "channel_filter", to_string( m_nMidiChannelFilter ) ); |
|---|
| 722 | |
|---|
| 723 | if ( m_bMidiNoteOffIgnore ) { |
|---|
| 724 | LocalFileMng::writeXmlString( midiDriverNode, "ignore_note_off", "true" ); |
|---|
| 725 | } else { |
|---|
| 726 | LocalFileMng::writeXmlString( midiDriverNode, "ignore_note_off", "false" ); |
|---|
| 727 | } |
|---|
| 728 | |
|---|
| 729 | if ( m_bMidiDiscardNoteAfterAction ) { |
|---|
| 730 | LocalFileMng::writeXmlString( midiDriverNode, "discard_note_after_action", "true" ); |
|---|
| 731 | } else { |
|---|
| 732 | LocalFileMng::writeXmlString( midiDriverNode, "discard_note_after_action", "false" ); |
|---|
| 733 | } |
|---|
| 734 | } |
|---|
| 735 | audioEngineNode.appendChild( midiDriverNode ); |
|---|
| 736 | |
|---|
| 737 | |
|---|
| 738 | |
|---|
| 739 | } |
|---|
| 740 | rootNode.appendChild( audioEngineNode ); |
|---|
| 741 | |
|---|
| 742 | //---- GUI ---- |
|---|
| 743 | QDomNode guiNode = doc.createElement( "gui" ); |
|---|
| 744 | { |
|---|
| 745 | LocalFileMng::writeXmlString( guiNode, "QTStyle", m_sQTStyle ); |
|---|
| 746 | LocalFileMng::writeXmlString( guiNode, "application_font_family", applicationFontFamily ); |
|---|
| 747 | LocalFileMng::writeXmlString( guiNode, "application_font_pointsize", to_string( applicationFontPointSize ) ); |
|---|
| 748 | LocalFileMng::writeXmlString( guiNode, "mixer_font_family", mixerFontFamily ); |
|---|
| 749 | LocalFileMng::writeXmlString( guiNode, "mixer_font_pointsize", to_string( mixerFontPointSize ) ); |
|---|
| 750 | LocalFileMng::writeXmlString( guiNode, "mixer_falloff_speed", to_string( mixerFalloffSpeed ) ); |
|---|
| 751 | LocalFileMng::writeXmlString( guiNode, "patternEditorGridResolution", to_string( m_nPatternEditorGridResolution ) ); |
|---|
| 752 | LocalFileMng::writeXmlString( guiNode, "patternEditorGridHeight", to_string( m_nPatternEditorGridHeight ) ); |
|---|
| 753 | LocalFileMng::writeXmlString( guiNode, "patternEditorGridWidth", to_string( m_nPatternEditorGridWidth ) ); |
|---|
| 754 | LocalFileMng::writeXmlBool( guiNode, "patternEditorUsingTriplets", m_bPatternEditorUsingTriplets ); |
|---|
| 755 | LocalFileMng::writeXmlBool( guiNode, "showInstrumentPeaks", m_bShowInstrumentPeaks ); |
|---|
| 756 | LocalFileMng::writeXmlBool( guiNode, "isFXTabVisible", m_bIsFXTabVisible ); |
|---|
| 757 | |
|---|
| 758 | |
|---|
| 759 | // MainForm window properties |
|---|
| 760 | writeWindowProperties( guiNode, "mainForm_properties", mainFormProperties ); |
|---|
| 761 | writeWindowProperties( guiNode, "mixer_properties", mixerProperties ); |
|---|
| 762 | writeWindowProperties( guiNode, "patternEditor_properties", patternEditorProperties ); |
|---|
| 763 | writeWindowProperties( guiNode, "songEditor_properties", songEditorProperties ); |
|---|
| 764 | writeWindowProperties( guiNode, "drumkitManager_properties", drumkitManagerProperties ); |
|---|
| 765 | writeWindowProperties( guiNode, "audioEngineInfo_properties", audioEngineInfoProperties ); |
|---|
| 766 | for ( unsigned nFX = 0; nFX < MAX_FX; nFX++ ) { |
|---|
| 767 | QString sNode = "ladspaFX_properties" + to_string( nFX ); |
|---|
| 768 | writeWindowProperties( guiNode, sNode, m_ladspaProperties[nFX] ); |
|---|
| 769 | } |
|---|
| 770 | |
|---|
| 771 | LocalFileMng::writeXmlBool( guiNode, "followPlayhead", m_bFollowPlayhead ); |
|---|
| 772 | |
|---|
| 773 | |
|---|
| 774 | //beatcounter |
|---|
| 775 | QString bcMode; |
|---|
| 776 | if ( m_bbc == BC_OFF ) { |
|---|
| 777 | bcMode = "BC_OFF"; |
|---|
| 778 | } else if ( m_bbc == BC_ON ) { |
|---|
| 779 | bcMode = "BC_ON"; |
|---|
| 780 | } |
|---|
| 781 | LocalFileMng::writeXmlString( guiNode, "bc", bcMode ); |
|---|
| 782 | |
|---|
| 783 | |
|---|
| 784 | |
|---|
| 785 | QString setPlay; |
|---|
| 786 | if ( m_mmcsetplay == SET_PLAY_OFF ) { |
|---|
| 787 | setPlay = "SET_PLAY_OFF"; |
|---|
| 788 | } else if ( m_mmcsetplay == SET_PLAY_ON ) { |
|---|
| 789 | setPlay = "SET_PLAY_ON"; |
|---|
| 790 | } |
|---|
| 791 | LocalFileMng::writeXmlString( guiNode, "setplay", setPlay ); |
|---|
| 792 | |
|---|
| 793 | LocalFileMng::writeXmlString( guiNode, "countoffset", to_string(m_countOffset) ); |
|---|
| 794 | LocalFileMng::writeXmlString( guiNode, "playoffset", to_string(m_startOffset) ); |
|---|
| 795 | //~ beatcounter |
|---|
| 796 | |
|---|
| 797 | //SoundLibraryPanel expand items |
|---|
| 798 | LocalFileMng::writeXmlString( guiNode, "expandSongItem", __expandSongItem ? "true": "false" ); |
|---|
| 799 | LocalFileMng::writeXmlString( guiNode, "expandPatternItem", __expandPatternItem ? "true": "false" ); |
|---|
| 800 | |
|---|
| 801 | // User interface style |
|---|
| 802 | writeUIStyle( guiNode ); |
|---|
| 803 | } |
|---|
| 804 | rootNode.appendChild( guiNode ); |
|---|
| 805 | |
|---|
| 806 | //---- FILES ---- |
|---|
| 807 | QDomNode filesNode = doc.createElement( "files" ); |
|---|
| 808 | { |
|---|
| 809 | // last used song |
|---|
| 810 | LocalFileMng::writeXmlString( filesNode, "lastSongFilename", lastSongFilename ); |
|---|
| 811 | LocalFileMng::writeXmlString( filesNode, "defaulteditor", m_sDefaultEditor ); |
|---|
| 812 | } |
|---|
| 813 | rootNode.appendChild( filesNode ); |
|---|
| 814 | |
|---|
| 815 | MidiMap * mM = MidiMap::getInstance(); |
|---|
| 816 | std::map< QString, Action* > mmcMap = mM->getMMCMap(); |
|---|
| 817 | |
|---|
| 818 | //---- MidiMap ---- |
|---|
| 819 | QDomNode midiEventMapNode = doc.createElement( "midiEventMap" ); |
|---|
| 820 | { |
|---|
| 821 | std::map< QString, Action* >::iterator dIter( mmcMap.begin() ); |
|---|
| 822 | for( dIter = mmcMap.begin(); dIter != mmcMap.end(); dIter++ ){ |
|---|
| 823 | |
|---|
| 824 | QString event = dIter->first; |
|---|
| 825 | Action * pAction = dIter->second; |
|---|
| 826 | |
|---|
| 827 | if ( pAction->getType() != "NOTHING" ){ |
|---|
| 828 | QDomNode midiEventNode = doc.createElement( "midiEvent" ); |
|---|
| 829 | |
|---|
| 830 | LocalFileMng::writeXmlString( midiEventNode, "mmcEvent" , event ); |
|---|
| 831 | LocalFileMng::writeXmlString( midiEventNode, "action" , pAction->getType()); |
|---|
| 832 | LocalFileMng::writeXmlString( midiEventNode, "parameter" , pAction->getParameter1() ); |
|---|
| 833 | |
|---|
| 834 | midiEventMapNode.appendChild( midiEventNode ); |
|---|
| 835 | } |
|---|
| 836 | } |
|---|
| 837 | |
|---|
| 838 | for( int note=0; note < 128; note++ ){ |
|---|
| 839 | Action * pAction = mM->getNoteAction( note ); |
|---|
| 840 | if( pAction != NULL && pAction->getType() != "NOTHING") { |
|---|
| 841 | QDomNode midiEventNode = doc.createElement( "midiEvent" ); |
|---|
| 842 | |
|---|
| 843 | LocalFileMng::writeXmlString( midiEventNode, "noteEvent" , QString("NOTE") ); |
|---|
| 844 | LocalFileMng::writeXmlString( midiEventNode, "eventParameter" , QString::number( note ) ); |
|---|
| 845 | LocalFileMng::writeXmlString( midiEventNode, "action" , pAction->getType() ); |
|---|
| 846 | LocalFileMng::writeXmlString( midiEventNode, "parameter" , pAction->getParameter1() ); |
|---|
| 847 | |
|---|
| 848 | |
|---|
| 849 | midiEventMapNode.appendChild(midiEventNode); |
|---|
| 850 | } |
|---|
| 851 | } |
|---|
| 852 | |
|---|
| 853 | for( int parameter=0; parameter < 128; parameter++ ){ |
|---|
| 854 | Action * pAction = mM->getCCAction( parameter ); |
|---|
| 855 | if( pAction != NULL && pAction->getType() != "NOTHING") |
|---|
| 856 | { |
|---|
| 857 | QDomNode midiEventNode = doc.createElement( "midiEvent" ); |
|---|
| 858 | |
|---|
| 859 | LocalFileMng::writeXmlString( midiEventNode, "ccEvent" , QString("CC") ); |
|---|
| 860 | LocalFileMng::writeXmlString( midiEventNode, "eventParameter" , QString::number( parameter ) ); |
|---|
| 861 | |
|---|
| 862 | |
|---|
| 863 | LocalFileMng::writeXmlString( midiEventNode, "action" , pAction->getType() ); |
|---|
| 864 | |
|---|
| 865 | LocalFileMng::writeXmlString( midiEventNode, "parameter" , pAction->getParameter1() ); |
|---|
| 866 | |
|---|
| 867 | midiEventMapNode.appendChild( midiEventNode ); |
|---|
| 868 | } |
|---|
| 869 | } |
|---|
| 870 | } |
|---|
| 871 | |
|---|
| 872 | rootNode.appendChild( midiEventMapNode ); |
|---|
| 873 | |
|---|
| 874 | doc.appendChild( rootNode ); |
|---|
| 875 | |
|---|
| 876 | QFile file( filename ); |
|---|
| 877 | if ( !file.open(QIODevice::WriteOnly) ) |
|---|
| 878 | return; |
|---|
| 879 | |
|---|
| 880 | QTextStream TextStream( &file ); |
|---|
| 881 | doc.save( TextStream, 1 ); |
|---|
| 882 | |
|---|
| 883 | file.close(); |
|---|
| 884 | } |
|---|
| 885 | |
|---|
| 886 | |
|---|
| 887 | |
|---|
| 888 | /// |
|---|
| 889 | /// Create preferences directory |
|---|
| 890 | /// |
|---|
| 891 | void Preferences::createPreferencesDirectory() |
|---|
| 892 | { |
|---|
| 893 | QString prefDir = m_sPreferencesDirectory; |
|---|
| 894 | INFOLOG( "Creating preference file directory in " + prefDir ); |
|---|
| 895 | |
|---|
| 896 | QDir dir; |
|---|
| 897 | dir.mkdir( prefDir ); |
|---|
| 898 | } |
|---|
| 899 | |
|---|
| 900 | |
|---|
| 901 | |
|---|
| 902 | /// |
|---|
| 903 | /// Create data directory |
|---|
| 904 | /// |
|---|
| 905 | void Preferences::createDataDirectory() |
|---|
| 906 | { |
|---|
| 907 | QString sDir = m_sDataDirectory; |
|---|
| 908 | INFOLOG( "Creating data directory in " + sDir ); |
|---|
| 909 | |
|---|
| 910 | QDir dir; |
|---|
| 911 | dir.mkdir( sDir ); |
|---|
| 912 | // mkdir(dir.c_str(),S_IRWXU); |
|---|
| 913 | } |
|---|
| 914 | |
|---|
| 915 | void Preferences::createSoundLibraryDirectories() |
|---|
| 916 | { |
|---|
| 917 | QString sDir = m_sDataDirectory; |
|---|
| 918 | QString sDrumkitDir; |
|---|
| 919 | QString sSongDir; |
|---|
| 920 | QString sPatternDir; |
|---|
| 921 | QString sPlaylistDir; |
|---|
| 922 | |
|---|
| 923 | INFOLOG( "Creating soundLibrary directories in " + sDir ); |
|---|
| 924 | |
|---|
| 925 | sDrumkitDir = sDir + "/drumkits"; |
|---|
| 926 | sSongDir = sDir + "/songs"; |
|---|
| 927 | sPatternDir = sDir + "/patterns"; |
|---|
| 928 | sPlaylistDir = sDir + "/playlists"; |
|---|
| 929 | |
|---|
| 930 | QDir dir; |
|---|
| 931 | dir.mkdir( sDrumkitDir ); |
|---|
| 932 | dir.mkdir( sSongDir ); |
|---|
| 933 | dir.mkdir( sPatternDir ); |
|---|
| 934 | dir.mkdir( sPlaylistDir ); |
|---|
| 935 | } |
|---|
| 936 | |
|---|
| 937 | |
|---|
| 938 | void Preferences::setMostRecentFX( QString FX_name ) |
|---|
| 939 | { |
|---|
| 940 | int pos = m_recentFX.indexOf( FX_name ); |
|---|
| 941 | |
|---|
| 942 | if ( pos != -1 ) |
|---|
| 943 | m_recentFX.removeAt( pos ); |
|---|
| 944 | |
|---|
| 945 | m_recentFX.push_front( FX_name ); |
|---|
| 946 | } |
|---|
| 947 | |
|---|
| 948 | void Preferences::setRecentFiles( std::vector<QString> recentFiles ) |
|---|
| 949 | { |
|---|
| 950 | // find single filenames. (skip duplicates) |
|---|
| 951 | std::vector<QString> temp; |
|---|
| 952 | for ( unsigned i = 0; i < recentFiles.size(); i++ ) { |
|---|
| 953 | QString sFilename = recentFiles[ i ]; |
|---|
| 954 | |
|---|
| 955 | bool bExists = false; |
|---|
| 956 | for ( unsigned j = 0; j < temp.size(); j++ ) { |
|---|
| 957 | if ( sFilename == temp[ j ] ) { |
|---|
| 958 | bExists = true; |
|---|
| 959 | break; |
|---|
| 960 | } |
|---|
| 961 | } |
|---|
| 962 | if ( !bExists ) { |
|---|
| 963 | temp.push_back( sFilename ); |
|---|
| 964 | } |
|---|
| 965 | } |
|---|
| 966 | |
|---|
| 967 | m_recentFiles = temp; |
|---|
| 968 | } |
|---|
| 969 | |
|---|
| 970 | |
|---|
| 971 | |
|---|
| 972 | /// Read the xml nodes related to window properties |
|---|
| 973 | WindowProperties Preferences::readWindowProperties( QDomNode parent, const QString& windowName, WindowProperties defaultProp ) |
|---|
| 974 | { |
|---|
| 975 | WindowProperties prop = defaultProp; |
|---|
| 976 | |
|---|
| 977 | QDomNode windowPropNode = parent.firstChildElement( windowName.toAscii() ); |
|---|
| 978 | if ( windowPropNode.isNull() ) { |
|---|
| 979 | WARNINGLOG( "Error reading configuration file: " + windowName + " node not found" ); |
|---|
| 980 | } else { |
|---|
| 981 | prop.visible = LocalFileMng::readXmlBool( windowPropNode, "visible", true ); |
|---|
| 982 | prop.x = LocalFileMng::readXmlInt( windowPropNode, "x", prop.x ); |
|---|
| 983 | prop.y = LocalFileMng::readXmlInt( windowPropNode, "y", prop.y ); |
|---|
| 984 | prop.width = LocalFileMng::readXmlInt( windowPropNode, "width", prop.width ); |
|---|
| 985 | prop.height = LocalFileMng::readXmlInt( windowPropNode, "height", prop.height ); |
|---|
| 986 | } |
|---|
| 987 | |
|---|
| 988 | return prop; |
|---|
| 989 | } |
|---|
| 990 | |
|---|
| 991 | |
|---|
| 992 | |
|---|
| 993 | /// Write the xml nodes related to window properties |
|---|
| 994 | void Preferences::writeWindowProperties( QDomNode parent, const QString& windowName, const WindowProperties& prop ) |
|---|
| 995 | { |
|---|
| 996 | QDomDocument doc; |
|---|
| 997 | QDomNode windowPropNode = doc.createElement( windowName.toAscii() ); |
|---|
| 998 | if ( prop.visible ) { |
|---|
| 999 | LocalFileMng::writeXmlString( windowPropNode, "visible", "true" ); |
|---|
| 1000 | } else { |
|---|
| 1001 | LocalFileMng::writeXmlString( windowPropNode, "visible", "false" ); |
|---|
| 1002 | } |
|---|
| 1003 | |
|---|
| 1004 | LocalFileMng::writeXmlString( windowPropNode, "x", to_string( prop.x ) ); |
|---|
| 1005 | LocalFileMng::writeXmlString( windowPropNode, "y", to_string( prop.y ) ); |
|---|
| 1006 | LocalFileMng::writeXmlString( windowPropNode, "width", to_string( prop.width ) ); |
|---|
| 1007 | LocalFileMng::writeXmlString( windowPropNode, "height", to_string( prop.height ) ); |
|---|
| 1008 | parent.appendChild( windowPropNode ); |
|---|
| 1009 | } |
|---|
| 1010 | |
|---|
| 1011 | |
|---|
| 1012 | |
|---|
| 1013 | void Preferences::writeUIStyle( QDomNode parent ) |
|---|
| 1014 | { |
|---|
| 1015 | QDomDocument doc; |
|---|
| 1016 | QDomNode node = doc.createElement( "UI_Style" ); |
|---|
| 1017 | |
|---|
| 1018 | // SONG EDITOR |
|---|
| 1019 | QDomNode songEditorNode = doc.createElement( "songEditor" ); |
|---|
| 1020 | LocalFileMng::writeXmlString( songEditorNode, "backgroundColor", m_pDefaultUIStyle->m_songEditor_backgroundColor.toStringFmt() ); |
|---|
| 1021 | LocalFileMng::writeXmlString( songEditorNode, "alternateRowColor", m_pDefaultUIStyle->m_songEditor_alternateRowColor.toStringFmt() ); |
|---|
| 1022 | LocalFileMng::writeXmlString( songEditorNode, "selectedRowColor", m_pDefaultUIStyle->m_songEditor_selectedRowColor.toStringFmt() ); |
|---|
| 1023 | LocalFileMng::writeXmlString( songEditorNode, "lineColor", m_pDefaultUIStyle->m_songEditor_lineColor.toStringFmt() ); |
|---|
| 1024 | LocalFileMng::writeXmlString( songEditorNode, "textColor", m_pDefaultUIStyle->m_songEditor_textColor.toStringFmt() ); |
|---|
| 1025 | LocalFileMng::writeXmlString( songEditorNode, "pattern1Color", m_pDefaultUIStyle->m_songEditor_pattern1Color.toStringFmt() ); |
|---|
| 1026 | node.appendChild( songEditorNode ); |
|---|
| 1027 | |
|---|
| 1028 | // PATTERN EDITOR |
|---|
| 1029 | QDomNode patternEditorNode = doc.createElement( "patternEditor" ); |
|---|
| 1030 | LocalFileMng::writeXmlString( patternEditorNode, "backgroundColor", m_pDefaultUIStyle->m_patternEditor_backgroundColor.toStringFmt() ); |
|---|
| 1031 | LocalFileMng::writeXmlString( patternEditorNode, "alternateRowColor", m_pDefaultUIStyle->m_patternEditor_alternateRowColor.toStringFmt() ); |
|---|
| 1032 | LocalFileMng::writeXmlString( patternEditorNode, "selectedRowColor", m_pDefaultUIStyle->m_patternEditor_selectedRowColor.toStringFmt() ); |
|---|
| 1033 | LocalFileMng::writeXmlString( patternEditorNode, "textColor", m_pDefaultUIStyle->m_patternEditor_textColor.toStringFmt() ); |
|---|
| 1034 | LocalFileMng::writeXmlString( patternEditorNode, "noteColor", m_pDefaultUIStyle->m_patternEditor_noteColor.toStringFmt() ); |
|---|
| 1035 | LocalFileMng::writeXmlString( patternEditorNode, "lineColor", m_pDefaultUIStyle->m_patternEditor_lineColor.toStringFmt() ); |
|---|
| 1036 | LocalFileMng::writeXmlString( patternEditorNode, "line1Color", m_pDefaultUIStyle->m_patternEditor_line1Color.toStringFmt() ); |
|---|
| 1037 | LocalFileMng::writeXmlString( patternEditorNode, "line2Color", m_pDefaultUIStyle->m_patternEditor_line2Color.toStringFmt() ); |
|---|
| 1038 | LocalFileMng::writeXmlString( patternEditorNode, "line3Color", m_pDefaultUIStyle->m_patternEditor_line3Color.toStringFmt() ); |
|---|
| 1039 | LocalFileMng::writeXmlString( patternEditorNode, "line4Color", m_pDefaultUIStyle->m_patternEditor_line4Color.toStringFmt() ); |
|---|
| 1040 | LocalFileMng::writeXmlString( patternEditorNode, "line5Color", m_pDefaultUIStyle->m_patternEditor_line5Color.toStringFmt() ); |
|---|
| 1041 | node.appendChild( patternEditorNode ); |
|---|
| 1042 | |
|---|
| 1043 | parent.appendChild( node ); |
|---|
| 1044 | } |
|---|
| 1045 | |
|---|
| 1046 | |
|---|
| 1047 | |
|---|
| 1048 | void Preferences::readUIStyle( QDomNode parent ) |
|---|
| 1049 | { |
|---|
| 1050 | // SONG EDITOR |
|---|
| 1051 | QDomNode pSongEditorNode = parent.firstChildElement( "songEditor" ); |
|---|
| 1052 | if ( !pSongEditorNode.isNull() ) { |
|---|
| 1053 | m_pDefaultUIStyle->m_songEditor_backgroundColor = H2RGBColor( LocalFileMng::readXmlString( pSongEditorNode, "backgroundColor", m_pDefaultUIStyle->m_songEditor_backgroundColor.toStringFmt() ) ); |
|---|
| 1054 | m_pDefaultUIStyle->m_songEditor_alternateRowColor = H2RGBColor( LocalFileMng::readXmlString( pSongEditorNode, "alternateRowColor", m_pDefaultUIStyle->m_songEditor_alternateRowColor.toStringFmt() ) ); |
|---|
| 1055 | m_pDefaultUIStyle->m_songEditor_selectedRowColor = H2RGBColor( LocalFileMng::readXmlString( pSongEditorNode, "selectedRowColor", m_pDefaultUIStyle->m_songEditor_selectedRowColor.toStringFmt() ) ); |
|---|
| 1056 | m_pDefaultUIStyle->m_songEditor_lineColor = H2RGBColor( LocalFileMng::readXmlString( pSongEditorNode, "lineColor", m_pDefaultUIStyle->m_songEditor_lineColor.toStringFmt() ) ); |
|---|
| 1057 | m_pDefaultUIStyle->m_songEditor_textColor = H2RGBColor( LocalFileMng::readXmlString( pSongEditorNode, "textColor", m_pDefaultUIStyle->m_songEditor_textColor.toStringFmt() ) ); |
|---|
| 1058 | m_pDefaultUIStyle->m_songEditor_pattern1Color = H2RGBColor( LocalFileMng::readXmlString( pSongEditorNode, "pattern1Color", m_pDefaultUIStyle->m_songEditor_pattern1Color.toStringFmt() ) ); |
|---|
| 1059 | } else { |
|---|
| 1060 | WARNINGLOG( "songEditor node not found" ); |
|---|
| 1061 | } |
|---|
| 1062 | |
|---|
| 1063 | // PATTERN EDITOR |
|---|
| 1064 | QDomNode pPatternEditorNode = parent.firstChildElement( "patternEditor" ); |
|---|
| 1065 | if ( !pPatternEditorNode.isNull() ) { |
|---|
| 1066 | m_pDefaultUIStyle->m_patternEditor_backgroundColor = H2RGBColor( LocalFileMng::readXmlString( pPatternEditorNode, "backgroundColor", m_pDefaultUIStyle->m_patternEditor_backgroundColor.toStringFmt() ) ); |
|---|
| 1067 | m_pDefaultUIStyle->m_patternEditor_alternateRowColor = H2RGBColor( LocalFileMng::readXmlString( pPatternEditorNode, "alternateRowColor", m_pDefaultUIStyle->m_patternEditor_alternateRowColor.toStringFmt() ) ); |
|---|
| 1068 | m_pDefaultUIStyle->m_patternEditor_selectedRowColor = H2RGBColor( LocalFileMng::readXmlString( pPatternEditorNode, "selectedRowColor", m_pDefaultUIStyle->m_patternEditor_selectedRowColor.toStringFmt() ) ); |
|---|
| 1069 | m_pDefaultUIStyle->m_patternEditor_textColor = H2RGBColor( LocalFileMng::readXmlString( pPatternEditorNode, "textColor", m_pDefaultUIStyle->m_patternEditor_textColor.toStringFmt() ) ); |
|---|
| 1070 | m_pDefaultUIStyle->m_patternEditor_noteColor = H2RGBColor( LocalFileMng::readXmlString( pPatternEditorNode, "noteColor", m_pDefaultUIStyle->m_patternEditor_noteColor.toStringFmt() ) ); |
|---|
| 1071 | m_pDefaultUIStyle->m_patternEditor_lineColor = H2RGBColor( LocalFileMng::readXmlString( pPatternEditorNode, "lineColor", m_pDefaultUIStyle->m_patternEditor_lineColor.toStringFmt() ) ); |
|---|
| 1072 | m_pDefaultUIStyle->m_patternEditor_line1Color = H2RGBColor( LocalFileMng::readXmlString( pPatternEditorNode, "line1Color", m_pDefaultUIStyle->m_patternEditor_line1Color.toStringFmt() ) ); |
|---|
| 1073 | m_pDefaultUIStyle->m_patternEditor_line2Color = H2RGBColor( LocalFileMng::readXmlString( pPatternEditorNode, "line2Color", m_pDefaultUIStyle->m_patternEditor_line2Color.toStringFmt() ) ); |
|---|
| 1074 | m_pDefaultUIStyle->m_patternEditor_line3Color = H2RGBColor( LocalFileMng::readXmlString( pPatternEditorNode, "line3Color", m_pDefaultUIStyle->m_patternEditor_line3Color.toStringFmt() ) ); |
|---|
| 1075 | m_pDefaultUIStyle->m_patternEditor_line4Color = H2RGBColor( LocalFileMng::readXmlString( pPatternEditorNode, "line4Color", m_pDefaultUIStyle->m_patternEditor_line4Color.toStringFmt() ) ); |
|---|
| 1076 | m_pDefaultUIStyle->m_patternEditor_line5Color = H2RGBColor( LocalFileMng::readXmlString( pPatternEditorNode, "line5Color", m_pDefaultUIStyle->m_patternEditor_line5Color.toStringFmt() ) ); |
|---|
| 1077 | } else { |
|---|
| 1078 | WARNINGLOG( "patternEditor node not found" ); |
|---|
| 1079 | } |
|---|
| 1080 | } |
|---|
| 1081 | |
|---|
| 1082 | |
|---|
| 1083 | // ----------------------- |
|---|
| 1084 | |
|---|
| 1085 | |
|---|
| 1086 | |
|---|
| 1087 | |
|---|
| 1088 | WindowProperties::WindowProperties() |
|---|
| 1089 | : Object( "WindowProperties" ) |
|---|
| 1090 | { |
|---|
| 1091 | // infoLog( "INIT" ); |
|---|
| 1092 | x = 0; |
|---|
| 1093 | y = 0; |
|---|
| 1094 | width = 0; |
|---|
| 1095 | height = 0; |
|---|
| 1096 | visible = true; |
|---|
| 1097 | } |
|---|
| 1098 | |
|---|
| 1099 | |
|---|
| 1100 | |
|---|
| 1101 | WindowProperties::~WindowProperties() |
|---|
| 1102 | { |
|---|
| 1103 | // infoLog( "DESTROY" ); |
|---|
| 1104 | } |
|---|
| 1105 | |
|---|
| 1106 | |
|---|
| 1107 | |
|---|
| 1108 | |
|---|
| 1109 | // ::::::::::::::::::::::::::::::: |
|---|
| 1110 | |
|---|
| 1111 | |
|---|
| 1112 | |
|---|
| 1113 | UIStyle::UIStyle() |
|---|
| 1114 | : Object( "UIStyle" ) |
|---|
| 1115 | { |
|---|
| 1116 | // infoLog( "INIT" ); |
|---|
| 1117 | } |
|---|
| 1118 | |
|---|
| 1119 | |
|---|
| 1120 | |
|---|
| 1121 | // :::::::::::::::::::::::::::::::::::::: |
|---|
| 1122 | |
|---|
| 1123 | |
|---|
| 1124 | |
|---|
| 1125 | H2RGBColor::H2RGBColor( int r, int g, int b ) |
|---|
| 1126 | : Object( "H2RGBColor" ) |
|---|
| 1127 | , m_red( r ) |
|---|
| 1128 | , m_green( g ) |
|---|
| 1129 | , m_blue( b ) |
|---|
| 1130 | { |
|---|
| 1131 | // infoLog( "INIT" ); |
|---|
| 1132 | } |
|---|
| 1133 | |
|---|
| 1134 | |
|---|
| 1135 | |
|---|
| 1136 | H2RGBColor::~H2RGBColor() |
|---|
| 1137 | { |
|---|
| 1138 | // infoLog( "DESTROY" ); |
|---|
| 1139 | } |
|---|
| 1140 | |
|---|
| 1141 | |
|---|
| 1142 | |
|---|
| 1143 | H2RGBColor::H2RGBColor( const QString& sColor ) |
|---|
| 1144 | : Object( "H2RGBColor" ) |
|---|
| 1145 | { |
|---|
| 1146 | // infoLog( "INIT " + sColor ); |
|---|
| 1147 | QString temp = sColor; |
|---|
| 1148 | |
|---|
| 1149 | QStringList list = temp.split(","); |
|---|
| 1150 | m_red = list[0].toInt(); |
|---|
| 1151 | m_green = list[1].toInt(); |
|---|
| 1152 | m_blue = list[2].toInt(); |
|---|
| 1153 | |
|---|
| 1154 | /* |
|---|
| 1155 | int nPos = temp.indexOf( ',' ); |
|---|
| 1156 | QString sRed = temp.substr( 0, nPos ); |
|---|
| 1157 | temp.erase( 0, nPos + 1 ); |
|---|
| 1158 | |
|---|
| 1159 | nPos = temp.find( ',' ); |
|---|
| 1160 | QString sGreen = temp.substr( 0, nPos ); |
|---|
| 1161 | temp.erase( 0, nPos + 1 ); |
|---|
| 1162 | |
|---|
| 1163 | nPos = temp.find( ',' ); |
|---|
| 1164 | QString sBlue = temp.substr( 0, nPos ); |
|---|
| 1165 | |
|---|
| 1166 | m_red = atoi( sRed.c_str() ); |
|---|
| 1167 | m_green = atoi( sGreen.c_str() ); |
|---|
| 1168 | m_blue = atoi( sBlue.c_str() ); |
|---|
| 1169 | */ |
|---|
| 1170 | } |
|---|
| 1171 | |
|---|
| 1172 | |
|---|
| 1173 | |
|---|
| 1174 | QString H2RGBColor::toStringFmt() |
|---|
| 1175 | { |
|---|
| 1176 | char tmp[255]; |
|---|
| 1177 | sprintf( tmp, "%d,%d,%d", m_red, m_green, m_blue ); |
|---|
| 1178 | |
|---|
| 1179 | //string sRes = to_string( m_red ) + "," + to_string( m_green ) + "," + to_string( m_blue ); |
|---|
| 1180 | // return sRes; |
|---|
| 1181 | |
|---|
| 1182 | return QString( tmp ); |
|---|
| 1183 | } |
|---|
| 1184 | |
|---|
| 1185 | }; |
|---|