/* * Copyright (C) 2002 - David W. Durham * * This file is part of ReZound, an audio editing application. * * ReZound is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * ReZound 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "settings.h" #include #include // for getenv #include CNestedDataFile *gSettingsRegistry=NULL; CNestedDataFile *gUserMacroStore=NULL; CNestedDataFile *gKeyBindingsStore=NULL; const CNestedDataFile *gDefaultKeyBindingsStore=NULL; string gPromptDialogDirectory=""; string gUserDataDirectory=""; string gSysDataDirectory=""; const string encodeFilenamePresetParameter(const string _filename) { string filename=_filename; if(gSysDataDirectory!="" && filename.find(gSysDataDirectory+"/")==0) filename.replace(0,gSysDataDirectory.size(),"$share"); return filename; } const string decodeFilenamePresetParameter(const string _filename) { string filename=_filename; if(gSysDataDirectory!="" && filename.find("$share/")==0) filename.replace(0,6,gSysDataDirectory); return filename; } string gUserPresetsFilename=""; CNestedDataFile *gUserPresetsFile=NULL; string gSysPresetsFilename=""; CNestedDataFile *gSysPresetsFile=NULL; string gDefaultAudioMethod=""; unsigned gDesiredOutputSampleRate=44100; unsigned gDesiredOutputChannelCount=2; int gDesiredOutputBufferCount=2; unsigned gDesiredOutputBufferSize=2048; // in frames (must be a power of 2) #ifdef ENABLE_OSS string gOSSOutputDevice="/dev/dsp"; string gOSSInputDevice="/dev/dsp"; #endif #ifdef ENABLE_ALSA string gALSAOutputDevice="hw:0"; string gALSAInputDevice="hw:0"; #endif #ifdef ENABLE_PORTAUDIO int gPortAudioOutputDevice=0; int gPortAudioInputDevice=0; #endif #ifdef ENABLE_JACK string gJACKOutputPortNames[64]; string gJACKInputPortNames[64]; #endif string gLADSPAPath=""; string gFallbackWorkDir="/tmp"; // ??? would be something else on non-unix platforms string gClipboardDir="/tmp"; // ??? would be something else on non-unix platforms string gClipboardFilenamePrefix="rezclip"; size_t gWhichClipboard=0; size_t gMaxReopenHistory=16; float gSkipMiddleMarginSeconds=2.0; float gLoopGapLengthSeconds=0.75; float gPlayPositionShift=-0.08; // a guess at latency between hearing and where it would place the cue string gAddCueWhilePlaying_CueName=""; bool gAddCueWhilePlaying_Anchored=false; string gAddCueAtClick_CueName=""; bool gAddCueAtClick_Anchored=false; unsigned gMeterUpdateTime=50; bool gLevelMetersEnabled=true; unsigned gMeterRMSWindowTime=200; unsigned gMaxPeakFallDelayTime=500; double gMaxPeakFallRate=0.02; bool gStereoPhaseMetersEnabled=true; unsigned gStereoPhaseMeterPointCount=100; bool gStereoPhaseMeterUnrotate=true; bool gFrequencyAnalyzerEnabled=true; unsigned gAnalyzerPeakFallDelayTime=400; double gAnalyzerPeakFallRate=0.025; CrossfadeEdgesTypes gCrossfadeEdges=cetInner; float gCrossfadeStartTime=10.0; // default 20ms crossfade time float gCrossfadeStopTime=10.0; CrossfadeFadeMethods gCrossfadeFadeMethod=cfmLinear; map gRegisteredActionFactories; // ---------------------------------------------------------------------------- #include "AStatusComm.h" #include "AFrontendHooks.h" #include "CSound_defs.h" #include #include #include #include /* read backend setting variables with the exception of gUserDataDir */ void readBackendSettings() { // determine where the share data is located { // first try env var const char *rezShareEnvVar=getenv("REZ_SHARE_DIR"); if(rezShareEnvVar!=NULL && CPath(rezShareEnvVar).exists()) { printf("using environment variable $REZ_SHARE_DIR='%s' to override normal setting for share data direcory\n",rezShareEnvVar); gSysDataDirectory=rezShareEnvVar; } // next try the source directory where the code was built else if(CPath(SOURCE_DIR"/share").exists()) gSysDataDirectory=SOURCE_DIR"/share"; // next try the registry setting else if(gSettingsRegistry->keyExists("shareDirectory") && CPath(gSettingsRegistry->getValue("shareDirectory")).exists()) gSysDataDirectory=gSettingsRegistry->getValue("shareDirectory"); // finally fall back on the #define set by configure saying where ReZound will be installed else gSysDataDirectory=DATA_DIR"/rezound"; recheckShareDataDir: string checkFile=gSysDataDirectory+istring(CPath::dirDelim)+"presets.dat"; // now, if the presets.dat file doesn't exist in the share data dir, ask for a setting if(!CPath(checkFile).exists()) { if(Question("presets.dat not found in share data dir, '"+gSysDataDirectory+"'.\n Would you like to manually select the share data directory directory?",yesnoQues)==yesAns) { gFrontendHooks->promptForDirectory(gSysDataDirectory,"Select Share Data Directory"); goto recheckShareDataDir; } } // fully qualify the share data directory gSysDataDirectory=CPath(gSysDataDirectory).realPath(); printf("using path '%s' for share data directory\n",gSysDataDirectory.c_str()); } // parse the system presets gSysPresetsFilename=gSysDataDirectory+istring(CPath::dirDelim)+"presets.dat"; gSysPresetsFile=new CNestedDataFile("",false); try { gSysPresetsFile->parseFile(gSysPresetsFilename); } catch(exception &e) { Error(e.what()); } // parse the user presets gUserPresetsFilename=gUserDataDirectory+istring(CPath::dirDelim)+"presets.dat"; CPath(gUserPresetsFilename).touch(); gUserPresetsFile=new CNestedDataFile("",false); try { gUserPresetsFile->parseFile(gUserPresetsFilename); } catch(exception &e) { Error(e.what()); } GET_SETTING("promptDialogDirectory",gPromptDialogDirectory,string) GET_SETTING("DesiredOutputSampleRate",gDesiredOutputSampleRate,unsigned) GET_SETTING("DesiredOutputChannelCount",gDesiredOutputChannelCount,unsigned) GET_SETTING("DesiredOutputBufferCount",gDesiredOutputBufferCount,int) gDesiredOutputBufferCount=max(2,gDesiredOutputBufferCount); GET_SETTING("DesiredOutputBufferSize",gDesiredOutputBufferSize,unsigned) if(gDesiredOutputBufferSize<256 || (gDesiredOutputBufferSize & gDesiredOutputBufferSize-1)) throw runtime_error(string(__func__)+" -- DesiredOutputBufferSize in "+gSettingsRegistry->getFilename()+" must be a power of 2 and >= than 256"); #ifdef ENABLE_OSS GET_SETTING("OSSOutputDevice",gOSSOutputDevice,string) GET_SETTING("OSSInputDevice",gOSSInputDevice,string) #endif #ifdef ENABLE_ALSA GET_SETTING("ALSAOutputDevice",gALSAOutputDevice,string) GET_SETTING("ALSAInputDevice",gALSAInputDevice,string) #endif #ifdef ENABLE_PORTAUDIO GET_SETTING("PortAudioOutputDevice",gPortAudioOutputDevice,int) GET_SETTING("PortAudioInputDevice",gPortAudioInputDevice,int) #endif #ifdef ENABLE_JACK // ??? could do these with vector values I suppose for(unsigned t=0;tkeyExists("crossfadeEdges")) { gCrossfadeEdges= (CrossfadeEdgesTypes)gSettingsRegistry->getValue("crossfadeEdges"); gCrossfadeStartTime= gSettingsRegistry->getValue("crossfadeStartTime"); gCrossfadeStopTime= gSettingsRegistry->getValue("crossfadeStopTime"); gCrossfadeFadeMethod= (CrossfadeFadeMethods)gSettingsRegistry->getValue("crossfadeFadeMethod"); } } void writeBackendSettings() { gSettingsRegistry->setValue("shareDirectory",gSysDataDirectory); gSettingsRegistry->setValue("promptDialogDirectory",gPromptDialogDirectory); gSettingsRegistry->setValue("DesiredOutputSampleRate",gDesiredOutputSampleRate); gSettingsRegistry->setValue("DesiredOutputChannelCount",gDesiredOutputChannelCount); gSettingsRegistry->setValue("DesiredOutputBufferCount",gDesiredOutputBufferCount); gSettingsRegistry->setValue("DesiredOutputBufferSize",gDesiredOutputBufferSize); #ifdef ENABLE_OSS gSettingsRegistry->setValue("OSSOutputDevice",gOSSOutputDevice); gSettingsRegistry->setValue("OSSInputDevice",gOSSInputDevice); #endif #ifdef ENABLE_PORTAUDIO gSettingsRegistry->setValue("PortAudioOutputDevice",gPortAudioOutputDevice); gSettingsRegistry->setValue("PortAudioInputDevice",gPortAudioInputDevice); #endif #ifdef ENABLE_JACK // ??? could do these with vector values I suppose for(unsigned t=0;tsetValue("JACKOutputPortName"+istring(t+1),gJACKOutputPortNames[t]); else { gSettingsRegistry->removeKey("JACKOutputPortName"+istring(t+2)); break; } } for(unsigned t=0;tsetValue("JACKInputPortName"+istring(t+1),gJACKInputPortNames[t]); else { gSettingsRegistry->removeKey("JACKInputPortName"+istring(t+2)); break; } } #endif gSettingsRegistry->setValue("LADSPA_PATH",gLADSPAPath); gSettingsRegistry->setValue("fallbackWorkDir",gFallbackWorkDir); gSettingsRegistry->setValue("clipboardDir",gClipboardDir); gSettingsRegistry->setValue("clipboardFilenamePrefix",gClipboardFilenamePrefix); gSettingsRegistry->setValue("whichClipboard",gWhichClipboard); gSettingsRegistry->setValue("ReopenHistory" DOT "maxReopenHistory",gMaxReopenHistory); gSettingsRegistry->setValue("skipMiddleMarginSeconds",gSkipMiddleMarginSeconds); gSettingsRegistry->setValue("loopGapLengthSeconds",gLoopGapLengthSeconds); gSettingsRegistry->setValue("playPositionShift",gPlayPositionShift); gSettingsRegistry->setValue("addCueWhilePlaying_CueName",gAddCueWhilePlaying_CueName); gSettingsRegistry->setValue("addCueWhilePlaying_Anchored",gAddCueWhilePlaying_Anchored); gSettingsRegistry->setValue("addCueAtClick_CueName",gAddCueAtClick_CueName); gSettingsRegistry->setValue("addCueAtClick_Anchored",gAddCueAtClick_Anchored); gSettingsRegistry->setValue("Meters" DOT "meterUpdateTime",gMeterUpdateTime); gSettingsRegistry->setValue("Meters" DOT "Level" DOT "enabled",gLevelMetersEnabled); gSettingsRegistry->setValue("Meters" DOT "Level" DOT "RMSWindowTime",gMeterRMSWindowTime); gSettingsRegistry->setValue("Meters" DOT "Level" DOT "maxPeakFallDelayTime",gMaxPeakFallDelayTime); gSettingsRegistry->setValue("Meters" DOT "Level" DOT "maxPeakFallRate",gMaxPeakFallRate); gSettingsRegistry->setValue("Meters" DOT "StereoPhase" DOT "enabled",gStereoPhaseMetersEnabled); gSettingsRegistry->setValue("Meters" DOT "StereoPhase" DOT "pointCount",gStereoPhaseMeterPointCount); gSettingsRegistry->setValue("Meters" DOT "StereoPhase" DOT "unrotate",gStereoPhaseMeterUnrotate); gSettingsRegistry->setValue("Meters" DOT "Analyzer" DOT "enabled",gFrequencyAnalyzerEnabled); gSettingsRegistry->setValue("Meters" DOT "Analyzer" DOT "peakFallDelayTime",gAnalyzerPeakFallDelayTime); gSettingsRegistry->setValue("Meters" DOT "Analyzer" DOT "peakFallRate",gAnalyzerPeakFallRate); gSettingsRegistry->setValue("crossfadeEdges",(int)gCrossfadeEdges); gSettingsRegistry->setValue("crossfadeStartTime",gCrossfadeStartTime); gSettingsRegistry->setValue("crossfadeStopTime",gCrossfadeStopTime); gSettingsRegistry->setValue("crossfadeFadeMethod",(int)gCrossfadeFadeMethod); }