1 /*
2 * Copyright (C) 2002 - David W. Durham
3 *
4 * This file is part of ReZound, an audio editing application.
5 *
6 * ReZound is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; either version 2 of the License,
9 * or (at your option) any later version.
10 *
11 * ReZound is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 */
20
21 #include "CFrontendHooks.h"
22
23 #include <string>
24
25 #include <istring>
26 #include <CPath.h>
27
28 #include "settings.h"
29 #include "CMainWindow.h"
30
31 #include "CNewSoundDialog.h"
32 #include "CRecordDialog.h"
33 #include "CRecordMacroDialog.h"
34 #include "CMacroActionParamsDialog.h"
35 #include "CJACKPortChoiceDialog.h"
36 #include "CRezSaveParametersDialog.h"
37 #include "CRawDialog.h"
38 #include "COggDialog.h"
39 #include "CMp3Dialog.h"
40 #include "CVoxDialog.h"
41 #include "CMIDIDumpSampleIdDialog.h"
42 #include "ClibaudiofileSaveParametersDialog.h"
43
44 #include "../backend/ASoundTranslator.h"
45 #include "../backend/AStatusComm.h"
46
CFrontendHooks(FXWindow * _mainWindow)47 CFrontendHooks::CFrontendHooks(FXWindow *_mainWindow) :
48 mainWindow(_mainWindow),
49
50 openDialog(NULL),
51 saveDialog(NULL),
52 dirDialog(NULL),
53
54 newSoundDialog(NULL),
55 recordDialog(NULL),
56 recordMacroDialog(NULL),
57 JACKPortChoiceDialog(NULL),
58 rezSaveParametersDialog(NULL),
59 rawDialog(NULL),
60 oggDialog(NULL),
61 mp3Dialog(NULL),
62 voxDialog(NULL),
63 MIDIDumpSampleIdDialog(NULL),
64 libaudiofileSaveParametersDialog(NULL)
65 {
66 dirDialog=new FXDirDialog(mainWindow,_("Select Directory"));
67
68 JACKPortChoiceDialog=new CJACKPortChoiceDialog(mainWindow);
69 }
70
~CFrontendHooks()71 CFrontendHooks::~CFrontendHooks()
72 {
73 delete openDialog;
74 delete saveDialog;
75
76 delete newSoundDialog;
77 delete recordDialog;
78 delete recordMacroDialog;
79 delete JACKPortChoiceDialog;
80 delete rezSaveParametersDialog;
81 delete rawDialog;
82 delete oggDialog;
83 delete mp3Dialog;
84 delete voxDialog;
85 delete MIDIDumpSampleIdDialog;
86 delete libaudiofileSaveParametersDialog;
87 }
88
doSetupAfterBackendIsSetup()89 void CFrontendHooks::doSetupAfterBackendIsSetup()
90 {
91 openDialog=new FXFileDialog(mainWindow,_("Open File"));
92 openDialog->setPatternList(getFOXFileTypes().c_str());
93 openDialog->setCurrentPattern(0);
94 openDialog->showReadOnly(false); // would be true if I supported it
95 openDialog->setReadOnly(false);
96 { // add the "Open as Raw" check button
97 FXVerticalFrame *f=new FXVerticalFrame(openDialog,LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0, 0,0);
98 openDialog->childAtIndex(0)->reparent(f);
99 openAsRawCheckButton=new FXCheckButton(new FXPacker(f,0, 0,0,0,0, DEFAULT_SPACING*2,0,0),_("Open as Raw"),NULL,0,CHECKBUTTON_NORMAL);
100
101 if(!ASoundTranslator::findRawTranslator()) // hide if we can't handle it
102 f->hide();
103 }
104 if(openDialog->getDirectory()!=gPromptDialogDirectory.c_str())
105 openDialog->setDirectory(gPromptDialogDirectory.c_str());
106
107 saveDialog=new FXFileDialog(mainWindow,_("Save File"));
108 saveDialog->setSelectMode(SELECTFILE_ANY);
109 saveDialog->setPatternList(getFOXFileTypes().c_str());
110 saveDialog->setCurrentPattern(0);
111 saveDialog->setDirectory(gPromptDialogDirectory.c_str());
112 { // add the "Save as Raw" check button
113 FXVerticalFrame *f=new FXVerticalFrame(saveDialog,LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0, 0,0);
114 saveDialog->childAtIndex(0)->reparent(f);
115 saveAsRawCheckButton=new FXCheckButton(new FXPacker(f,0, 0,0,0,0, DEFAULT_SPACING*2,0,0),_("Save as Raw"),NULL,0,CHECKBUTTON_NORMAL);
116
117 if(!ASoundTranslator::findRawTranslator()) // hide if we can't handle it
118 f->hide();
119 }
120
121 newSoundDialog=new CNewSoundDialog(mainWindow);
122 recordDialog=new CRecordDialog(mainWindow);
123 recordMacroDialog=new CRecordMacroDialog(mainWindow);
124 macroActionParamsDialog=new CMacroActionParamsDialog(mainWindow);
125 rezSaveParametersDialog=new CRezSaveParametersDialog(mainWindow);
126 rawDialog=new CRawDialog(mainWindow);
127 oggDialog=new COggDialog(mainWindow);
128 mp3Dialog=new CMp3Dialog(mainWindow);
129 voxDialog=new CVoxDialog(mainWindow);
130 MIDIDumpSampleIdDialog=new CMIDIDumpSampleIdDialog(mainWindow);
131 libaudiofileSaveParametersDialog=new ClibaudiofileSaveParametersDialog(mainWindow);
132 }
133
setWhichClipboard(size_t whichClipboard)134 void CFrontendHooks::setWhichClipboard(size_t whichClipboard)
135 {
136 ((CMainWindow *)mainWindow)->setWhichClipboard(whichClipboard);
137 }
138
getFOXFileTypes() const139 const string CFrontendHooks::getFOXFileTypes() const
140 {
141 const vector<const ASoundTranslator *> translators=ASoundTranslator::getTranslators();
142 string types;
143 string allTypes;
144
145 /*
146 From all the registered translators build a string to use as the file type
147 drop-down in the FOX file dialogs:
148 Format Name (*.ext,*.EXT)\nFormat Name (*.ext,*.EXT)\n...
149 And built a list for "All Types" with the *.ext,*.ext,...,*.EXT,*.EXT
150 */
151 for(size_t t=0;t<translators.size();t++)
152 {
153 const vector<string> names=translators[t]->getFormatNames();
154 const vector<vector<string> > fileMasks=translators[t]->getFormatFileMasks();
155
156 for(size_t i=0;i<names.size();i++)
157 {
158 types+=names[i];
159 types+=" (";
160 for(size_t k=0;k<fileMasks[i].size();k++)
161 {
162 if(k>0)
163 types+=",";
164 types+=fileMasks[i][k]+","+istring(fileMasks[i][k]).upper();
165
166 if(allTypes!="")
167 allTypes+=",";
168 allTypes+=fileMasks[i][k];
169 }
170 types+=")\n";
171 }
172 }
173
174 for(size_t t=0;t<translators.size();t++)
175 {
176 const vector<string> names=translators[t]->getFormatNames();
177 const vector<vector<string> > fileMasks=translators[t]->getFormatFileMasks();
178
179 for(size_t i=0;i<names.size();i++)
180 {
181 for(size_t k=0;k<fileMasks[i].size();k++)
182 {
183 if(allTypes!="")
184 allTypes+=",";
185 allTypes+=istring(fileMasks[i][k]).upper();
186 }
187 }
188 }
189
190 types=string(_("All Supported Types"))+" ("+allTypes+")\n"+types+_("All Files")+"(*)\n";
191
192 return types;
193 }
194
promptForOpenSoundFilename(string & filename,bool & readOnly,bool & openAsRaw)195 bool CFrontendHooks::promptForOpenSoundFilename(string &filename,bool &readOnly,bool &openAsRaw)
196 {
197 openDialog->setFilename("");
198 if(openDialog->getDirectory()!=gPromptDialogDirectory.c_str())
199 openDialog->setDirectory(gPromptDialogDirectory.c_str());
200 openDialog->setSelectMode(SELECTFILE_EXISTING);
201 openAsRawCheckButton->setCheck(openAsRaw);
202 if(openDialog->execute())
203 {
204 // save directory to open the opendialog to next time
205 gPromptDialogDirectory=openDialog->getDirectory().text();
206
207 filename=openDialog->getFilename().text();
208 readOnly=openDialog->getReadOnly();
209 openAsRaw=openAsRawCheckButton->getCheck();
210
211 return true;
212 }
213 return false;
214 }
215
promptForOpenSoundFilenames(vector<string> & filenames,bool & readOnly,bool & openAsRaw)216 bool CFrontendHooks::promptForOpenSoundFilenames(vector<string> &filenames,bool &readOnly,bool &openAsRaw)
217 {
218 openDialog->setFilename("");
219 if(openDialog->getDirectory()!=gPromptDialogDirectory.c_str())
220 openDialog->setDirectory(gPromptDialogDirectory.c_str());
221 openDialog->setSelectMode(SELECTFILE_MULTIPLE);
222 openAsRawCheckButton->setCheck(openAsRaw);
223 if(openDialog->execute())
224 {
225 // save directory to open the opendialog to next time
226 gPromptDialogDirectory=openDialog->getDirectory().text();
227
228 // add the selected filenames to the filenames vector
229 FXString *_filenames=openDialog->getFilenames();
230 while(_filenames!=NULL && (*_filenames)!="")
231 {
232 filenames.push_back(_filenames->text());
233 _filenames++;
234 }
235 readOnly=openDialog->getReadOnly();
236 openAsRaw=openAsRawCheckButton->getCheck();
237
238 return true;
239 }
240 return false;
241 }
242
promptForSaveSoundFilename(string & filename,bool & saveAsRaw)243 bool CFrontendHooks::promptForSaveSoundFilename(string &filename,bool &saveAsRaw)
244 {
245 if(filename!="")
246 {
247 saveDialog->setFilename(CPath(filename).baseName().c_str());
248 saveDialog->setDirectory(gPromptDialogDirectory.c_str());
249 }
250 saveAsRawCheckButton->setCheck(saveAsRaw);
251
252 if(saveDialog->execute())
253 {
254 gPromptDialogDirectory=saveDialog->getDirectory().text();
255
256 filename=saveDialog->getFilename().text();
257 saveAsRaw=saveAsRawCheckButton->getCheck();
258
259 return true;
260 }
261 return false;
262 }
263
promptForNewSoundParameters(string & filename,bool & rawFormat,bool hideFilename,unsigned & channelCount,bool hideChannelCount,unsigned & sampleRate,bool hideSampleRate,sample_pos_t & length,bool hideLength)264 bool CFrontendHooks::promptForNewSoundParameters(string &filename,bool &rawFormat,bool hideFilename,unsigned &channelCount,bool hideChannelCount,unsigned &sampleRate,bool hideSampleRate,sample_pos_t &length,bool hideLength)
265 {
266 newSoundDialog->hideFilename(hideFilename);
267 if(hideChannelCount)
268 throw runtime_error(string(__func__)+" -- unimplemented: hideChannelCount");
269 newSoundDialog->hideSampleRate(hideSampleRate);
270 newSoundDialog->hideLength(hideLength);
271
272 if(!hideFilename)
273 newSoundDialog->setFilename(filename,rawFormat);
274
275 if(newSoundDialog->execute(PLACEMENT_CURSOR))
276 {
277 if(!hideFilename)
278 {
279 filename=newSoundDialog->getFilename();
280 rawFormat=newSoundDialog->getRawFormat();
281 }
282
283 if(!hideChannelCount)
284 channelCount=newSoundDialog->getChannelCount();
285
286 if(!hideSampleRate)
287 sampleRate=newSoundDialog->getSampleRate();
288
289 if(!hideLength)
290 length=newSoundDialog->getLength();
291
292 return true;
293 }
294 return false;
295 }
296
promptForDirectory(string & dirname,const string title)297 bool CFrontendHooks::promptForDirectory(string &dirname,const string title)
298 {
299 dirDialog->setTitle(title.c_str());
300 if(dirDialog->execute())
301 {
302 dirname=dirDialog->getDirectory().text();
303 return true;
304 }
305 return false;
306 }
307
promptForRecord(ASoundRecorder * recorder)308 bool CFrontendHooks::promptForRecord(ASoundRecorder *recorder)
309 {
310 if(recordDialog->show(recorder))
311 return true;
312 return false;
313 }
314
showRecordMacroDialog(string & macroName)315 bool CFrontendHooks::showRecordMacroDialog(string ¯oName)
316 {
317 recordMacroDialog->setMacroName(macroName);
318 if(recordMacroDialog->showIt())
319 {
320 macroName=recordMacroDialog->getMacroName();
321 return true;
322 }
323 return false;
324
325 }
326
showMacroActionParamsDialog(const AActionFactory * actionFactory,MacroActionParameters & macroActionParameters,CLoadedSound * loadedSound)327 bool CFrontendHooks::showMacroActionParamsDialog(const AActionFactory *actionFactory,MacroActionParameters ¯oActionParameters,CLoadedSound *loadedSound)
328 {
329 return macroActionParamsDialog->showIt(actionFactory,macroActionParameters,loadedSound);
330 }
331
promptForJACKPort(const string message,const vector<string> portNames)332 const string CFrontendHooks::promptForJACKPort(const string message,const vector<string> portNames)
333 {
334 if(JACKPortChoiceDialog->show(message,portNames))
335 return JACKPortChoiceDialog->getPortName();
336 else
337 throw runtime_error(string(__func__)+" -- choice aborted");
338 }
339
promptForRezSaveParameters(RezSaveParameters & parameters)340 bool CFrontendHooks::promptForRezSaveParameters(RezSaveParameters ¶meters)
341 {
342 return rezSaveParametersDialog->show(parameters);
343 }
344
promptForRawParameters(RawParameters & parameters,bool showLoadRawParameters)345 bool CFrontendHooks::promptForRawParameters(RawParameters ¶meters,bool showLoadRawParameters)
346 {
347 return rawDialog->show(parameters,showLoadRawParameters);
348 }
349
promptForOggCompressionParameters(OggCompressionParameters & parameters)350 bool CFrontendHooks::promptForOggCompressionParameters(OggCompressionParameters ¶meters)
351 {
352 return oggDialog->show(parameters);
353 }
354
promptForMp3CompressionParameters(Mp3CompressionParameters & parameters)355 bool CFrontendHooks::promptForMp3CompressionParameters(Mp3CompressionParameters ¶meters)
356 {
357 return mp3Dialog->show(parameters);
358 }
359
promptForVoxParameters(VoxParameters & parameters)360 bool CFrontendHooks::promptForVoxParameters(VoxParameters ¶meters)
361 {
362 return voxDialog->show(parameters);
363 }
364
365 #ifdef USE_LADSPA
366
367 #include "CChannelSelectDialog.h"
368 #include "CLADSPAActionDialog.h"
getChannelSelectDialog()369 AActionDialog *CFrontendHooks::getChannelSelectDialog()
370 {
371 return gChannelSelectDialog;
372 }
373
getLADSPAActionDialog(const LADSPA_Descriptor * desc)374 AActionDialog *CFrontendHooks::getLADSPAActionDialog(const LADSPA_Descriptor *desc)
375 {
376 return new CLADSPAActionDialog(mainWindow,desc);
377 #if 0 // nah
378 // only return a dialog if there is at least one input control ports
379 for(unsigned t=0;t<desc->PortCount;t++)
380 {
381 const LADSPA_PortDescriptor portDesc=desc->PortDescriptors[t];
382 if(LADSPA_IS_PORT_CONTROL(portDesc) && LADSPA_IS_PORT_INPUT(portDesc))
383 return new CLADSPAActionDialog(mainWindow,desc);
384 }
385 return NULL;
386 #endif
387 }
388
389 #endif
390
391
promptForOpenMIDISampleDump(int & sysExChannel,int & waveformId)392 bool CFrontendHooks::promptForOpenMIDISampleDump(int &sysExChannel,int &waveformId)
393 {
394 return MIDIDumpSampleIdDialog->showForOpen(sysExChannel,waveformId);
395 }
396
promptForSaveMIDISampleDump(int & sysExChannel,int & waveformId,int & loopType)397 bool CFrontendHooks::promptForSaveMIDISampleDump(int &sysExChannel,int &waveformId,int &loopType)
398 {
399 return MIDIDumpSampleIdDialog->showForSave(sysExChannel,waveformId,loopType);
400 }
401
promptForlibaudiofileSaveParameters(libaudiofileSaveParameters & parameters,const string formatName)402 bool CFrontendHooks::promptForlibaudiofileSaveParameters(libaudiofileSaveParameters ¶meters,const string formatName)
403 {
404 return libaudiofileSaveParametersDialog->show(parameters,formatName);
405 }
406
407