Hydrogen - Linux Drum Machine
Main Page | Class Hierarchy | Compound List | File List | Compound Members

PreferencesMng.h

00001 /*
00002  * Hydrogen
00003  * Copyright(c) 2002-2003 by Alex >Comix< Cominu [comix@users.sourceforge.net]
00004  *
00005  * http://hydrogen.sourceforge.net
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY, without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * $Id: PreferencesMng.h,v 1.23 2003/06/09 08:53:51 comix Exp $
00022  *
00023  */
00024 
00025 #ifndef PREFERENCES_MNG
00026 #define PREFERENCES_MNG
00027 
00028 #include <string>
00029 using std::string;
00030 
00031 #include <pwd.h>
00032 #include <sys/types.h>
00033 #include <sys/stat.h>
00034 #include <unistd.h>
00035 #include <stdlib.h>
00036 #include <fstream>
00037 #include <iostream>
00038 #include <dirent.h>
00039 #include <stdio.h>
00040 
00041 #include "Object.h"
00042 
00043 const float FALLOFF_SLOW =  1.08;
00044 const float FALLOFF_NORMAL= 1.1;
00045 const float FALLOFF_FAST =  1.5;
00046 
00047 // forward declaration
00048 class TiXmlNode;
00049 
00050 class WindowProperties : public Object{
00051     public:
00052         virtual string getClassName() { return "WindowProperties";  }
00053         int x;
00054         int y;
00055         int width;
00056         int height;
00057 
00058         WindowProperties();
00059         ~WindowProperties();
00060 };
00061 
00062 
00063 
00064 //----------------------------------------------------------------------------
00068 class PreferencesMng : public Object {
00069     public:
00071         static PreferencesMng* getInstance();
00072 
00074         ~PreferencesMng();
00075 
00076         virtual string getClassName() { return "PreferencesMng";    }
00077 
00079         void loadPreferences();
00080 
00082         void savePreferences();
00083 
00084 
00086         uint getBufferSize() {  return bufferSize;  }
00087 
00089         void setBufferSize(uint bufferSize) {   this->bufferSize = bufferSize;  }
00090 
00092         string getAudioDriver() {   return audioDriver; }
00093 
00095         void setAudioDriver(string audioDriver) {   this->audioDriver = audioDriver;    }
00096 
00098         uint getSampleRate() {  return sampleRate;  }
00099 
00101         void setSampleRate(uint sampleRate) {   this->sampleRate = sampleRate;  }
00102 
00104         bool isMetronomeEnabled() { return useMetronome;    }
00105 
00107         void setUseMetronome(bool useMetronome) {   this->useMetronome = useMetronome;  }
00108 
00110         float getMetronomeVolume() {    return metronomeVolume; }
00111 
00113         void setMetronomeVolume(float metronomeVolume) {    this->metronomeVolume = metronomeVolume;    }
00114 
00115         string getApplicationFontFamily() { return applicationFontFamily;   }
00116         void setApplicationFontFamily(string family) {  applicationFontFamily = family; }
00117 
00118         int getApplicationFontPointSize() { return applicationFontPointSize;    }
00119         void setApplicationFontPointSize(int size) {    applicationFontPointSize = size;    }
00120 
00121         string getMixerFontFamily() {   return mixerFontFamily; }
00122         void setMixerFontFamily(string family) {    mixerFontFamily = family;   }
00123 
00124         int getMixerFontPointSize() {   return mixerFontPointSize;  }
00125         void setMixerFontPointSize(int size) {  mixerFontPointSize = size;  }
00126 
00127         float getMixerFalloffSpeed() {  return mixerFalloffSpeed;   }
00128         void setMixerFalloffSpeed(float value) {    mixerFalloffSpeed = value;  }
00129 
00130         string getDemoPath() {  return demoPath;    }
00131 
00132         string getInterfaceMode() { return interfaceMode;   }
00133         void setInterfaceMode( string mode ) {  interfaceMode = mode;   }
00134 
00135         string getJackPortName1() { return jackPortName1;   }
00136         string getJackPortName2() { return jackPortName2;   }
00137 
00138         void setJackPortName1( string port ) {  jackPortName1 = port;   }
00139         void setJackPortName2( string port ) {  jackPortName2 = port;   }
00140 
00141         int getMidiPortChannel() {  return midiPortChannel; }
00142         void setMidiPortChannel(int channel) {  midiPortChannel = channel;  }
00143 
00144         string getMidiDest_name() { return midiDest_name;   }
00145         int getMidiDest_client() {  return midiDest_client; }
00146         int getMidiDest_port() {    return midiDest_port;   }
00147 
00148         void setMidiDest_name( string name ) {  this->midiDest_name = name; }
00149         void setMidiDest_client( int client ) { this->midiDest_client = client; }
00150         void setMidiDest_port( int port ) { this->midiDest_port = port; }
00151 
00152 
00154         string getUserHome();
00155 
00156         WindowProperties readWindowProperties( TiXmlNode *parent, string windowName, WindowProperties defaultProp );
00157         void writeWindowProperties( TiXmlNode *parent, string windowName, WindowProperties prop );
00158 
00159         WindowProperties getMainFormProperties() {  return mainFormProperties;  }
00160         void setMainFormProperties( WindowProperties prop ) {   mainFormProperties = prop;  }
00161 
00162         WindowProperties getMixerProperties() { return mixerProperties; }
00163         void setMixerProperties( WindowProperties prop ) {  mixerProperties = prop; }
00164 
00165         WindowProperties getPatternEditorProperties() { return patternEditorProperties; }
00166         void setPatternEditorProperties( WindowProperties prop ) {  patternEditorProperties = prop; }
00167 
00168         WindowProperties getSongEditorProperties() {    return songEditorProperties;    }
00169         void setSongEditorProperties( WindowProperties prop ) { songEditorProperties = prop;    }
00170 
00171         WindowProperties getDrumkitManagerProperties() {    return drumkitManagerProperties;    }
00172         void setDrumkitManagerProperties( WindowProperties prop ) { drumkitManagerProperties = prop;    }
00173 
00174         WindowProperties getAudioEngineInfoProperties() {   return audioEngineInfoProperties;   }
00175         void setAudioEngineInfoProperties( WindowProperties prop ) {    audioEngineInfoProperties = prop;   }
00176 
00177         void setLastSongFilename( string filename ) {   lastSongFilename = filename;    }
00178         string getLastSongFilename() {  return lastSongFilename;    }
00179 
00180         void setRestoreLastSongEnabled( bool restore ) {    restoreLastSong = restore;  }
00181         bool isRestoreLastSongEnabled() {   return restoreLastSong; }
00182 
00183         void setHearNewNotes( bool value ) {    hearNewNotes = value;   }
00184         bool getHearNewNotes() {    return hearNewNotes;    }
00185 
00186         int getPatternEditorGridResolution() {  return patternEditorGridResolution; }
00187         void setPatternEditorGridResolution( int value ) {  patternEditorGridResolution = value;    }
00188 
00189     private:
00190         static PreferencesMng *instance;
00191 
00193         string demoPath;
00194 
00195         //___ General properties ___
00196 
00198         bool restoreLastSong;
00199 
00201         string lastSongFilename;
00202 
00203         bool hearNewNotes;
00204 
00205 
00206         //___ audio engine properties ___
00208         string audioDriver;
00209 
00211         bool useMetronome;
00212 
00214         float metronomeVolume;
00215 
00216 
00217 
00218         //___ oss driver properties ___
00220         uint bufferSize;
00221 
00223         uint sampleRate;
00224 
00225 
00226 
00227         //___  jack driver properties ___
00228         string jackPortName1;
00229         string jackPortName2;
00230 
00231 
00232 
00233         //___ alsa midi driver properties ___
00234         int midiPortChannel;
00235         string midiDest_name;
00236         int midiDest_client;
00237         int midiDest_port;
00238 
00239 
00240 
00241         //___ GUI properties ___
00243         string interfaceMode;
00244 
00245         string applicationFontFamily;
00246         int applicationFontPointSize;
00247 
00248         string mixerFontFamily;
00249         int mixerFontPointSize;
00250 
00251         float mixerFalloffSpeed;
00252 
00253         int patternEditorGridResolution;
00254 
00255         WindowProperties mainFormProperties;
00256         WindowProperties mixerProperties;
00257         WindowProperties patternEditorProperties;
00258         WindowProperties songEditorProperties;
00259         WindowProperties drumkitManagerProperties;
00260         WindowProperties audioEngineInfoProperties;
00261 
00262 
00263 
00265         PreferencesMng();
00266 
00268         void createPreferencesDirectory();
00269 
00271         void createDataDirectory();
00272 
00273         void writeXmlText( TiXmlNode *parent, string name, string text );
00274         void writeXmlText( TiXmlNode *parent, string name, float value );
00275         void writeXmlText( TiXmlNode *parent, string name, int value );
00276 
00277         string readXmlString( TiXmlNode* parent, string nodeName, string defaultValue );
00278         bool readXmlBool( TiXmlNode* parent, string nodeName, bool defaultValue );
00279         float readXmlFloat( TiXmlNode* parent, string nodeName, float defaultValue );
00280         int readXmlInt( TiXmlNode* parent, string nodeName, int defaultValue );
00281 
00282 };
00283 
00284 #endif
00285 

 
 
Hydrogen (c) 2002..2003 Comix