ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

fluidsynth-dialog.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "gui/fluidsynth-dialog.h"
00024 #include "gui/gui-manager.h"
00025 #include "gui/message.h"
00026 #include "gui/widgets/tab.h"
00027 #include "gui/widgets/popup.h"
00028 
00029 #include "common/config-manager.h"
00030 #include "common/translation.h"
00031 #include "common/debug.h"
00032 
00033 namespace GUI {
00034 
00035 enum {
00036     kActivateChorusCmd      = 'acho',
00037     kChorusVoiceCountChangedCmd = 'cvcc',
00038     kChorusLevelChangedCmd      = 'clec',
00039     kChorusSpeedChangedCmd      = 'cspc',
00040     kChorusDepthChangedCmd      = 'cdec',
00041 
00042     kActivateReverbCmd      = 'arev',
00043     kReverbRoomSizeChangedCmd   = 'rrsc',
00044     kReverbDampingChangedCmd    = 'rdac',
00045     kReverbWidthChangedCmd      = 'rwic',
00046     kReverbLevelChangedCmd      = 'rlec',
00047 
00048     kResetSettingsCmd       = 'rese'
00049 };
00050 
00051 enum {
00052     kWaveFormTypeSine       = 0,
00053     kWaveFormTypeTriangle       = 1
00054 };
00055 
00056 enum {
00057     kInterpolationNone      = 0,
00058     kInterpolationLinear        = 1,
00059     kInterpolation4thOrder      = 2,
00060     kInterpolation7thOrder      = 3
00061 };
00062 
00063 FluidSynthSettingsDialog::FluidSynthSettingsDialog()
00064     : Dialog("FluidSynthSettings") {
00065     _domain = Common::ConfigManager::kApplicationDomain;
00066 
00067     _tabWidget = new TabWidget(this, "FluidSynthSettings.TabWidget");
00068 
00069     _tabWidget->addTab(_("Reverb"));
00070 
00071     _reverbActivate = new CheckboxWidget(_tabWidget, "FluidSynthSettings_Reverb.EnableTabCheckbox", _("Active"), 0, kActivateReverbCmd);
00072 
00073     _reverbRoomSizeDesc = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Reverb.RoomSizeText", _("Room:"));
00074     _reverbRoomSizeSlider = new SliderWidget(_tabWidget, "FluidSynthSettings_Reverb.RoomSizeSlider", 0, kReverbRoomSizeChangedCmd);
00075     // 0.00 - 1.20, Default: 0.20
00076     _reverbRoomSizeSlider->setMinValue(0);
00077     _reverbRoomSizeSlider->setMaxValue(120);
00078     _reverbRoomSizeLabel = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Reverb.RoomSizeLabel", "20");
00079 
00080     _reverbDampingDesc = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Reverb.DampingText", _("Damp:"));
00081     _reverbDampingSlider = new SliderWidget(_tabWidget, "FluidSynthSettings_Reverb.DampingSlider", 0, kReverbDampingChangedCmd);
00082     // 0.00 - 1.00, Default: 0.00
00083     _reverbDampingSlider->setMinValue(0);
00084     _reverbDampingSlider->setMaxValue(100);
00085     _reverbDampingLabel = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Reverb.DampingLabel", "0");
00086 
00087     _reverbWidthDesc = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Reverb.WidthText", _("Width:"));
00088     _reverbWidthSlider = new SliderWidget(_tabWidget, "FluidSynthSettings_Reverb.WidthSlider", 0, kReverbWidthChangedCmd);
00089     // 0 - 100, Default: 1
00090     _reverbWidthSlider->setMinValue(0);
00091     _reverbWidthSlider->setMaxValue(100);
00092     _reverbWidthLabel = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Reverb.WidthLabel", "1");
00093 
00094     _reverbLevelDesc = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Reverb.LevelText", _("Level:"));
00095     _reverbLevelSlider = new SliderWidget(_tabWidget, "FluidSynthSettings_Reverb.LevelSlider", 0, kReverbLevelChangedCmd);
00096     // 0.00 - 1.00, Default: 0.90
00097     _reverbLevelSlider->setMinValue(0);
00098     _reverbLevelSlider->setMaxValue(100);
00099     _reverbLevelLabel = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Reverb.LevelLabel", "90");
00100 
00101     _tabWidget->addTab(_("Chorus"));
00102 
00103     _chorusActivate = new CheckboxWidget(_tabWidget, "FluidSynthSettings_Chorus.EnableTabCheckbox", _("Active"), 0, kActivateChorusCmd);
00104 
00105     _chorusVoiceCountDesc = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Chorus.VoiceCountText", _("N:"));
00106     _chorusVoiceCountSlider = new SliderWidget(_tabWidget, "FluidSynthSettings_Chorus.VoiceCountSlider", 0, kChorusVoiceCountChangedCmd);
00107     // 0-99, Default: 3
00108     _chorusVoiceCountSlider->setMinValue(0);
00109     _chorusVoiceCountSlider->setMaxValue(99);
00110     _chorusVoiceCountLabel = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Chorus.VoiceCountLabel", "3");
00111 
00112     _chorusLevelDesc = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Chorus.LevelText", _("Level:"));
00113     _chorusLevelSlider = new SliderWidget(_tabWidget, "FluidSynthSettings_Chorus.LevelSlider", 0, kChorusLevelChangedCmd);
00114     // 0.00 - 1.00, Default: 1.00
00115     _chorusLevelSlider->setMinValue(0);
00116     _chorusLevelSlider->setMaxValue(100);
00117     _chorusLevelLabel = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Chorus.LevelLabel", "100");
00118 
00119     _chorusSpeedDesc = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Chorus.SpeedText", _("Speed:"));
00120     _chorusSpeedSlider = new SliderWidget(_tabWidget, "FluidSynthSettings_Chorus.SpeedSlider", 0, kChorusSpeedChangedCmd);
00121     // 0.30 - 5.00, Default: 0.30
00122     _chorusSpeedSlider->setMinValue(30);
00123     _chorusSpeedSlider->setMaxValue(500);
00124     _chorusSpeedLabel = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Chorus.SpeedLabel", "30");
00125 
00126     _chorusDepthDesc = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Chorus.DepthText", _("Depth:"));
00127     _chorusDepthSlider = new SliderWidget(_tabWidget, "FluidSynthSettings_Chorus.DepthSlider", 0, kChorusDepthChangedCmd);
00128     // 0.00 - 21.00, Default: 8.00
00129     _chorusDepthSlider->setMinValue(0);
00130     _chorusDepthSlider->setMaxValue(210);
00131     _chorusDepthLabel = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Chorus.DepthLabel", "80");
00132 
00133     _chorusWaveFormTypePopUpDesc = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Chorus.WaveFormTypeText", _("Type:"));
00134     _chorusWaveFormTypePopUp = new PopUpWidget(_tabWidget, "FluidSynthSettings_Chorus.WaveFormType");
00135 
00136     _chorusWaveFormTypePopUp->appendEntry(_("Sine"), kWaveFormTypeSine);
00137     _chorusWaveFormTypePopUp->appendEntry(_("Triangle"), kWaveFormTypeTriangle);
00138 
00139     _tabWidget->addTab(_("Misc"));
00140 
00141     _miscInterpolationPopUpDesc = new StaticTextWidget(_tabWidget, "FluidSynthSettings_Misc.InterpolationText", _("Interpolation:"));
00142     _miscInterpolationPopUp = new PopUpWidget(_tabWidget, "FluidSynthSettings_Misc.Interpolation");
00143 
00144     _miscInterpolationPopUp->appendEntry(_("None (fastest)"), kInterpolationNone);
00145     _miscInterpolationPopUp->appendEntry(_("Linear"), kInterpolationLinear);
00146     _miscInterpolationPopUp->appendEntry(_("Fourth-order"), kInterpolation4thOrder);
00147     _miscInterpolationPopUp->appendEntry(_("Seventh-order"), kInterpolation7thOrder);
00148 
00149     _tabWidget->setActiveTab(0);
00150 
00151     new ButtonWidget(this, "FluidSynthSettings.ResetSettings", _("Reset"), _("Reset all FluidSynth settings to their default values."), kResetSettingsCmd);
00152 
00153     new ButtonWidget(this, "FluidSynthSettings.Cancel", _("Cancel"), 0, kCloseCmd);
00154     new ButtonWidget(this, "FluidSynthSettings.Ok", _("OK"), 0, kOKCmd);
00155 }
00156 
00157 FluidSynthSettingsDialog::~FluidSynthSettingsDialog() {
00158 }
00159 
00160 void FluidSynthSettingsDialog::open() {
00161     Dialog::open();
00162 
00163     // Reset result value
00164     setResult(0);
00165 
00166     readSettings();
00167 }
00168 
00169 void FluidSynthSettingsDialog::close() {
00170     if (getResult()) {
00171         writeSettings();
00172     }
00173 
00174     Dialog::close();
00175 }
00176 
00177 void FluidSynthSettingsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
00178     switch (cmd) {
00179     case kActivateChorusCmd:
00180         setChorusSettingsState(data);
00181         break;
00182     case kChorusVoiceCountChangedCmd:
00183         _chorusVoiceCountLabel->setLabel(Common::String::format("%d", _chorusVoiceCountSlider->getValue()));
00184         _chorusVoiceCountLabel->markAsDirty();
00185         break;
00186     case kChorusLevelChangedCmd:
00187         _chorusLevelLabel->setLabel(Common::String::format("%d", _chorusLevelSlider->getValue()));
00188         _chorusLevelLabel->markAsDirty();
00189         break;
00190     case kChorusSpeedChangedCmd:
00191         _chorusSpeedLabel->setLabel(Common::String::format("%d", _chorusSpeedSlider->getValue()));
00192         _chorusSpeedLabel->markAsDirty();
00193         break;
00194     case kChorusDepthChangedCmd:
00195         _chorusDepthLabel->setLabel(Common::String::format("%d", _chorusDepthSlider->getValue()));
00196         _chorusDepthLabel->markAsDirty();
00197         break;
00198     case kActivateReverbCmd:
00199         setReverbSettingsState(data);
00200         break;
00201     case kReverbRoomSizeChangedCmd:
00202         _reverbRoomSizeLabel->setLabel(Common::String::format("%d", _reverbRoomSizeSlider->getValue()));
00203         _reverbRoomSizeLabel->markAsDirty();
00204         break;
00205     case kReverbDampingChangedCmd:
00206         _reverbDampingLabel->setLabel(Common::String::format("%d", _reverbDampingSlider->getValue()));
00207         _reverbDampingLabel->markAsDirty();
00208         break;
00209     case kReverbWidthChangedCmd:
00210         _reverbWidthLabel->setLabel(Common::String::format("%d", _reverbWidthSlider->getValue()));
00211         _reverbWidthLabel->markAsDirty();
00212         break;
00213     case kReverbLevelChangedCmd:
00214         _reverbLevelLabel->setLabel(Common::String::format("%d", _reverbLevelSlider->getValue()));
00215         _reverbLevelLabel->markAsDirty();
00216         break;
00217     case kResetSettingsCmd: {
00218         MessageDialog alert(_("Do you really want to reset all FluidSynth settings to their default values?"), _("Yes"), _("No"));
00219         if (alert.runModal() == GUI::kMessageOK) {
00220             resetSettings();
00221             readSettings();
00222             g_gui.scheduleTopDialogRedraw();
00223         }
00224         break;
00225     }
00226     case kOKCmd:
00227         setResult(1);
00228         close();
00229         break;
00230     default:
00231         Dialog::handleCommand(sender, cmd, data);
00232         break;
00233     }
00234 }
00235 
00236 void FluidSynthSettingsDialog::setChorusSettingsState(bool enabled) {
00237     _chorusVoiceCountDesc->setEnabled(enabled);
00238     _chorusVoiceCountSlider->setEnabled(enabled);
00239     _chorusVoiceCountLabel->setEnabled(enabled);
00240     _chorusLevelDesc->setEnabled(enabled);
00241     _chorusLevelSlider->setEnabled(enabled);
00242     _chorusLevelLabel->setEnabled(enabled);
00243     _chorusSpeedDesc->setEnabled(enabled);
00244     _chorusSpeedSlider->setEnabled(enabled);
00245     _chorusSpeedLabel->setEnabled(enabled);
00246     _chorusDepthDesc->setEnabled(enabled);
00247     _chorusDepthSlider->setEnabled(enabled);
00248     _chorusDepthLabel->setEnabled(enabled);
00249     _chorusWaveFormTypePopUpDesc->setEnabled(enabled);
00250     _chorusWaveFormTypePopUp->setEnabled(enabled);
00251 }
00252 
00253 void FluidSynthSettingsDialog::setReverbSettingsState(bool enabled) {
00254     _reverbRoomSizeDesc->setEnabled(enabled);
00255     _reverbRoomSizeSlider->setEnabled(enabled);
00256     _reverbRoomSizeLabel->setEnabled(enabled);
00257     _reverbDampingDesc->setEnabled(enabled);
00258     _reverbDampingSlider->setEnabled(enabled);
00259     _reverbDampingLabel->setEnabled(enabled);
00260     _reverbWidthDesc->setEnabled(enabled);
00261     _reverbWidthSlider->setEnabled(enabled);
00262     _reverbWidthLabel->setEnabled(enabled);
00263     _reverbLevelDesc->setEnabled(enabled);
00264     _reverbLevelSlider->setEnabled(enabled);
00265     _reverbLevelLabel->setEnabled(enabled);
00266 }
00267 
00268 void FluidSynthSettingsDialog::readSettings() {
00269     _chorusVoiceCountSlider->setValue(ConfMan.getInt("fluidsynth_chorus_nr", _domain));
00270     _chorusVoiceCountLabel->setLabel(Common::String::format("%d", _chorusVoiceCountSlider->getValue()));
00271     _chorusLevelSlider->setValue(ConfMan.getInt("fluidsynth_chorus_level", _domain));
00272     _chorusLevelLabel->setLabel(Common::String::format("%d", _chorusLevelSlider->getValue()));
00273     _chorusSpeedSlider->setValue(ConfMan.getInt("fluidsynth_chorus_speed", _domain));
00274     _chorusSpeedLabel->setLabel(Common::String::format("%d", _chorusSpeedSlider->getValue()));
00275     _chorusDepthSlider->setValue(ConfMan.getInt("fluidsynth_chorus_depth", _domain));
00276     _chorusDepthLabel->setLabel(Common::String::format("%d", _chorusDepthSlider->getValue()));
00277 
00278     Common::String waveForm = ConfMan.get("fluidsynth_chorus_waveform", _domain);
00279     if (waveForm == "sine") {
00280         _chorusWaveFormTypePopUp->setSelectedTag(kWaveFormTypeSine);
00281     } else if (waveForm == "triangle") {
00282         _chorusWaveFormTypePopUp->setSelectedTag(kWaveFormTypeTriangle);
00283     }
00284 
00285     _reverbRoomSizeSlider->setValue(ConfMan.getInt("fluidsynth_reverb_roomsize", _domain));
00286     _reverbRoomSizeLabel->setLabel(Common::String::format("%d", _reverbRoomSizeSlider->getValue()));
00287     _reverbDampingSlider->setValue(ConfMan.getInt("fluidsynth_reverb_damping", _domain));
00288     _reverbDampingLabel->setLabel(Common::String::format("%d", _reverbDampingSlider->getValue()));
00289     _reverbWidthSlider->setValue(ConfMan.getInt("fluidsynth_reverb_width", _domain));
00290     _reverbWidthLabel->setLabel(Common::String::format("%d", _reverbWidthSlider->getValue()));
00291     _reverbLevelSlider->setValue(ConfMan.getInt("fluidsynth_reverb_level", _domain));
00292     _reverbLevelLabel->setLabel(Common::String::format("%d", _reverbLevelSlider->getValue()));
00293 
00294     Common::String interpolation = ConfMan.get("fluidsynth_misc_interpolation", _domain);
00295     if (interpolation == "none") {
00296         _miscInterpolationPopUp->setSelectedTag(kInterpolationNone);
00297     } else if (interpolation == "linear") {
00298         _miscInterpolationPopUp->setSelectedTag(kInterpolationLinear);
00299     } else if (interpolation == "4th") {
00300         _miscInterpolationPopUp->setSelectedTag(kInterpolation4thOrder);
00301     } else if (interpolation == "7th") {
00302         _miscInterpolationPopUp->setSelectedTag(kInterpolation7thOrder);
00303     }
00304 
00305     // This may trigger redrawing, so don't do it until all sliders have
00306     // their proper values. Otherwise, the dialog may crash because of
00307     // invalid slider values.
00308     _chorusActivate->setState(ConfMan.getBool("fluidsynth_chorus_activate", _domain));
00309     _reverbActivate->setState(ConfMan.getBool("fluidsynth_reverb_activate", _domain));
00310 }
00311 
00312 void FluidSynthSettingsDialog::writeSettings() {
00313     ConfMan.setBool("fluidsynth_chorus_activate", _chorusActivate->getState());
00314     ConfMan.setInt("fluidsynth_chorus_nr", _chorusVoiceCountSlider->getValue(), _domain);
00315     ConfMan.setInt("fluidsynth_chorus_level", _chorusLevelSlider->getValue(), _domain);
00316     ConfMan.setInt("fluidsynth_chorus_speed", _chorusSpeedSlider->getValue(), _domain);
00317     ConfMan.setInt("fluidsynth_chorus_depth", _chorusDepthSlider->getValue(), _domain);
00318 
00319     uint32 waveForm = _chorusWaveFormTypePopUp->getSelectedTag();
00320     if (waveForm == kWaveFormTypeSine) {
00321         ConfMan.set("fluidsynth_chorus_waveform", "sine", _domain);
00322     } else if (waveForm == kWaveFormTypeTriangle) {
00323         ConfMan.set("fluidsynth_chorus_waveform", "triangle", _domain);
00324     } else {
00325         ConfMan.removeKey("fluidsynth_chorus_waveform", _domain);
00326     }
00327 
00328     ConfMan.setBool("fluidsynth_reverb_activate", _reverbActivate->getState());
00329     ConfMan.setInt("fluidsynth_reverb_roomsize", _reverbRoomSizeSlider->getValue(), _domain);
00330     ConfMan.setInt("fluidsynth_reverb_damping", _reverbDampingSlider->getValue(), _domain);
00331     ConfMan.setInt("fluidsynth_reverb_width", _reverbWidthSlider->getValue(), _domain);
00332     ConfMan.setInt("fluidsynth_reverb_level", _reverbLevelSlider->getValue(), _domain);
00333 
00334     uint32 interpolation = _miscInterpolationPopUp->getSelectedTag();
00335     if (interpolation == kInterpolationNone) {
00336         ConfMan.set("fluidsynth_misc_interpolation", "none", _domain);
00337     } else if (interpolation == kInterpolationLinear) {
00338         ConfMan.set("fluidsynth_misc_interpolation", "linear", _domain);
00339     } else if (interpolation == kInterpolation4thOrder) {
00340         ConfMan.set("fluidsynth_misc_interpolation", "4th", _domain);
00341     } else if (interpolation == kInterpolation7thOrder) {
00342         ConfMan.set("fluidsynth_misc_interpolation", "7th", _domain);
00343     } else {
00344         ConfMan.removeKey("fluidsynth_misc_interpolation", _domain);
00345     }
00346 
00347     // The main options dialog is responsible for writing the config file.
00348     // That's why we don't actually flush the settings to the file here.
00349 }
00350 
00351 void FluidSynthSettingsDialog::resetSettings() {
00352     ConfMan.removeKey("fluidsynth_chorus_activate", _domain);
00353     ConfMan.removeKey("fluidsynth_chorus_nr", _domain);
00354     ConfMan.removeKey("fluidsynth_chorus_level", _domain);
00355     ConfMan.removeKey("fluidsynth_chorus_speed", _domain);
00356     ConfMan.removeKey("fluidsynth_chorus_depth", _domain);
00357     ConfMan.removeKey("fluidsynth_chorus_waveform", _domain);
00358 
00359     ConfMan.removeKey("fluidsynth_reverb_activate", _domain);
00360     ConfMan.removeKey("fluidsynth_reverb_roomsize", _domain);
00361     ConfMan.removeKey("fluidsynth_reverb_damping", _domain);
00362     ConfMan.removeKey("fluidsynth_reverb_width", _domain);
00363     ConfMan.removeKey("fluidsynth_reverb_level", _domain);
00364 
00365     ConfMan.removeKey("fluidsynth_misc_interpolation", _domain);
00366 }
00367 
00368 } // End of namespace GUI


Generated on Sat May 25 2019 05:00:45 for ResidualVM by doxygen 1.7.1
curved edge   curved edge