1 /*
2  * Copyright (C) 2005 - 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 "FileActionDialogs.h"
22 
23 #include "../backend/CActionParameters.h"
24 #include "../backend/ASoundFileManager.h"
25 #include "../backend/CLoadedSound.h"
26 #include "../backend/CActionSound.h"
27 #include "settings.h"
28 #include "CFrontendHooks.h"
29 
30 
31 // --- create new audio file ------------------------
32 
CNewAudioFileActionDialog(FXWindow * mainWindow)33 CNewAudioFileActionDialog::CNewAudioFileActionDialog(FXWindow *mainWindow) :
34 	CActionParamDialog(mainWindow)
35 {
36 }
37 
show(CActionSound * actionSound,CActionParameters * actionParameters)38 bool CNewAudioFileActionDialog::show(CActionSound *actionSound,CActionParameters *actionParameters)
39 {
40 	string filename=actionParameters->getSoundFileManager()->getUntitledFilename(gPromptDialogDirectory,"rez");
41 	bool rawFormat=false;
42 	unsigned channelCount=0;
43 	unsigned sampleRate=0;
44 	sample_pos_t length=0;
45 
46 	if(gFrontendHooks->promptForNewSoundParameters(filename,rawFormat,false,channelCount,false,sampleRate,false,length,false))
47 	{
48 		actionParameters->setValue<string>("filename",filename);
49 		actionParameters->setValue<bool>("rawFormat",rawFormat);
50 		actionParameters->setValue<unsigned>("channelCount",channelCount);
51 		actionParameters->setValue<unsigned>("sampleRate",sampleRate);
52 		actionParameters->setValue<sample_pos_t>("length",length);
53 		return true;
54 	}
55 	return false;
56 }
57 
58 
59 // --- open audio file ------------------------
60 
COpenAudioFileActionDialog(FXWindow * mainWindow)61 COpenAudioFileActionDialog::COpenAudioFileActionDialog(FXWindow *mainWindow) :
62 	CActionParamDialog(mainWindow)
63 {
64 }
65 
show(CActionSound * actionSound,CActionParameters * actionParameters)66 bool COpenAudioFileActionDialog::show(CActionSound *actionSound,CActionParameters *actionParameters)
67 {
68 	vector<string> filenames;
69 	bool readOnly=false;
70 	bool openAsRaw=false;
71 	if(gFrontendHooks->promptForOpenSoundFilenames(filenames,readOnly,openAsRaw))
72 	{
73 		actionParameters->setValue<vector<string> >("filenames",filenames);
74 		actionParameters->setValue<bool>("readOnly",readOnly);
75 		actionParameters->setValue<bool>("openAsRaw",openAsRaw);
76 		return true;
77 	}
78 	return false;
79 }
80 
81 
82 // --- save audio file as ---------------------
83 
CSaveAsAudioFileActionDialog(FXWindow * mainWindow)84 CSaveAsAudioFileActionDialog::CSaveAsAudioFileActionDialog(FXWindow *mainWindow) :
85 	CActionParamDialog(mainWindow)
86 {
87 }
88 
show(CActionSound * actionSound,CActionParameters * actionParameters)89 bool CSaveAsAudioFileActionDialog::show(CActionSound *actionSound,CActionParameters *actionParameters)
90 {
91 	// find the CLoadedSound object in the ASoundFileManager object (??? would be nice if this were just passed in as some of the info)
92 	ASoundFileManager *sfm=actionParameters->getSoundFileManager();
93 	CLoadedSound *loaded=NULL;
94 	for(size_t t=0;t<sfm->getOpenedCount();t++)
95 	{
96 		if(sfm->getSound(t)->sound==actionSound->sound)
97 		{
98 			loaded=sfm->getSound(t);
99 			break;
100 		}
101 	}
102 
103 	string filename;
104 	if(loaded)
105 		filename=loaded->getFilename();
106 	bool saveAsRaw=false;
107 	if(gFrontendHooks->promptForSaveSoundFilename(filename,saveAsRaw))
108 	{
109 		actionParameters->setValue<string>("filename",filename);
110 		actionParameters->setValue<bool>("saveAsRaw",saveAsRaw);
111 
112 		return true;
113 	}
114 	return false;
115 }
116 
117 
118 
119 // --- save as multiple files -----------------
120 
121 #include "../backend/ASoundTranslator.h"
122 #include "../backend/File/CSaveAsMultipleFilesAction.h"
CSaveAsMultipleFilesDialog(FXWindow * mainWindow)123 CSaveAsMultipleFilesDialog::CSaveAsMultipleFilesDialog(FXWindow *mainWindow) :
124 	CActionParamDialog(mainWindow)
125 {
126 	void *p1=newVertPanel(NULL);
127 		addDiskEntityEntry(p1,N_("Save to Directory"),".",FXDiskEntityParamValue::detDirectory,_("All the files will be saved into this directory"));
128 		addStringTextEntry(p1,N_("Filename Prefix"),_("Part#"),_("This will be added to the front of the filename"));
129 		addStringTextEntry(p1,N_("Filename Suffix"),"",_("This will be added to the end of the filename"));
130 		addComboTextEntry(p1,N_("Format"),ASoundTranslator::getFlatFormatList(),CActionParamDialog::cpvtAsInteger,_("The format to save each segment as"),false);
131 		addNumericTextEntry(p1,N_("Segment Number Start"),"",1,0,1000,_("The Number to Start With When Substituting the Track Number For '#' in the Filenames"));
132 		addCheckBoxEntry(p1,N_("Open Saved Segments"),false,_("Open the Segments After Saving Them"));
133 		vector<string> items;
134 			items.push_back(N_("Entire File"));
135 			items.push_back(N_("Selection Only"));
136 		addComboTextEntry(p1,N_("Applies to"),items,CActionParamDialog::cpvtAsInteger);
137 		addCheckBoxEntry(p1,N_("Prompt Only Once for Save Parameters"),false,_("Some formats require parameters from the user (i.e. compression type, audio format, etc).  Checking this checkbox will make it only prompt on the first file if necessary.  All other saved files will use the previous parameters if possible."));
138 }
139 
getExplanation() const140 const string CSaveAsMultipleFilesDialog::getExplanation() const
141 {
142 	return CSaveAsMultipleFilesAction::getExplanation();
143 }
144 
145 
146 
147 // --- burn to CD -----------------------------
148 
149 #include <CPath.h>
150 #include "../backend/File/CBurnToCDAction.h"
151 
152 FXDEFMAP(CBurnToCDDialog) CBurnToCDDialogMap[]=
153 {
154 	//Message_Type			ID						Message_Handler
155 	FXMAPFUNC(SEL_COMMAND,		CBurnToCDDialog::ID_DETECT_DEVICE_BUTTON,	CBurnToCDDialog::onDetectDeviceButton),
156 };
157 
FXIMPLEMENT(CBurnToCDDialog,CActionParamDialog,CBurnToCDDialogMap,ARRAYNUMBER (CBurnToCDDialogMap))158 FXIMPLEMENT(CBurnToCDDialog,CActionParamDialog,CBurnToCDDialogMap,ARRAYNUMBER(CBurnToCDDialogMap))
159 
160 CBurnToCDDialog::CBurnToCDDialog(FXWindow *mainWindow) :
161 	CActionParamDialog(mainWindow)
162 {
163 	FXPacker *p1=newVertPanel(NULL);
164 			// ??? default to file location or fallback work dir
165 		addDiskEntityEntry(p1,N_("Temp Space Directory"),gFallbackWorkDir,FXDiskEntityParamValue::detDirectory,_("A temporary file for burning will be placed in this location.  Enough space will be needed for CD quality audio of the length of the audio to be burned to the CD"));
166 
167 			// ??? default to `which cdrdao` or if not found, blank
168 		FXDiskEntityParamValue *cdrdaoPath=addDiskEntityEntry(p1,N_("Path to cdrdao"),CPath::which("cdrdao"),FXDiskEntityParamValue::detGeneralFilename);
169 
170 		vector<string> burnSpeeds;
171 		for(unsigned t=1;t<=50;t++)
172 			burnSpeeds.push_back(istring(t)+"x");
173 		FXComboTextParamValue *burnSpeed=addComboTextEntry(p1,N_("Burn Speed"),burnSpeeds,CActionParamDialog::cpvtAsInteger);
174 			burnSpeed->setIntegerValue(7);
175 
176 		vector<string> trackGaps;
177 		for(unsigned t=0;t<=10;t++)
178 			trackGaps.push_back(istring(t)+"s");
179 		FXComboTextParamValue *trackGap=addComboTextEntry(p1,N_("Gap Between Tracks"),trackGaps,CActionParamDialog::cpvtAsInteger,_("The Gap of Silence to Place Between Each Track"));
180 			trackGap->setIntegerValue(0);
181 
182 		vector<string> appliesTo;
183 			appliesTo.push_back(N_("Entire File"));
184 			appliesTo.push_back(N_("Selection Only"));
185 		addComboTextEntry(p1,N_("Applies to"),appliesTo,CActionParamDialog::cpvtAsInteger);
186 
187 		FXVerticalFrame *p2=new FXVerticalFrame(p1,LAYOUT_FILL_X, 0,0,0,0, 0,0,0,0, 0,0);
188 			FXHorizontalFrame *p3=new FXHorizontalFrame(p2,LAYOUT_FILL_X, 0,0,0,0, 0,0,0,0, 4,0);
189 				FXComposite *device=addStringTextEntry(p3,N_("Device"),"0,0,0");
190 					new FXButton(device,_("Detect"),NULL,this,ID_DETECT_DEVICE_BUTTON,BUTTON_NORMAL|LAYOUT_RIGHT);
191 			new FXLabel(p2,_("In linux >2.6, scanbus may not work and it may be\nnecessary to specify: for example: ATAPI:0,0,0"));
192 			new FXLabel(p2,_("Also, cdrdao-1.1.9 has much better drive support."));
193 
194 		addStringTextEntry(p1,N_("Extra cdrdao Options"),"");
195 		addCheckBoxEntry(p1,N_("Simulate Burn Only"),false,_("Don't Turn on Burn Laser"));
196 }
197 
onDetectDeviceButton(FXObject * object,FXSelector sel,void * ptr)198 long CBurnToCDDialog::onDetectDeviceButton(FXObject *object,FXSelector sel,void *ptr)
199 {
200 	getTextParam("Device")->setText(CBurnToCDAction::detectDevice(getDiskEntityParam("Path to cdrdao")->getEntityName()));
201 	return 0;
202 }
203 
getExplanation() const204 const string CBurnToCDDialog::getExplanation() const
205 {
206 	return CBurnToCDAction::getExplanation();
207 }
208 
209 
210 
211 // --- run macro dialog -----------------------
212 
213 #include "../backend/CMacroRecorder.h"
214 #include <CNestedDataFile/CNestedDataFile.h>
215 #include <CPath.h>
216 
217 FXDEFMAP(CRunMacroDialog) CRunMacroDialogMap[]=
218 {
219 	//Message_Type			ID						Message_Handler
220 	FXMAPFUNC(SEL_COMMAND,		CRunMacroDialog::ID_REMOVE_BUTTON,	CRunMacroDialog::onRemoveButton),
221 };
222 
FXIMPLEMENT(CRunMacroDialog,CActionParamDialog,CRunMacroDialogMap,ARRAYNUMBER (CRunMacroDialogMap))223 FXIMPLEMENT(CRunMacroDialog,CActionParamDialog,CRunMacroDialogMap,ARRAYNUMBER(CRunMacroDialogMap))
224 
225 CRunMacroDialog::CRunMacroDialog(FXWindow *mainWindow) :
226 	CActionParamDialog(mainWindow,false)
227 {
228 	FXPacker *p=newVertPanel(NULL);
229 		vector<string> items;
230 		addComboTextEntry(p,N_("Macro Name"),items,CActionParamDialog::cpvtAsString);
231 		new FXButton(p,_("Remove Macro"),NULL,this,ID_REMOVE_BUTTON,BUTTON_NORMAL|LAYOUT_LEFT);
232 }
233 
show(CActionSound * actionSound,CActionParameters * actionParameters)234 bool CRunMacroDialog::show(CActionSound *actionSound,CActionParameters *actionParameters)
235 {
236 	vector<string> items=gUserMacroStore->getValue<vector<string> >("MacroNames");
237 	getComboText("Macro Name")->setItems(items);
238 
239 	return CActionParamDialog::show(actionSound,actionParameters);
240 }
241 
onRemoveButton(FXObject * object,FXSelector sel,void * ptr)242 long CRunMacroDialog::onRemoveButton(FXObject *object,FXSelector sel,void *ptr)
243 {
244 	FXComboTextParamValue *cb=getComboText("Macro Name");
245 	const string macroName=cb->getStringValue();
246 	if(Question(_("Are you sure you want to delete the macro: ")+macroName,yesnoQues)==yesAns)
247 	{
248 		CMacroRecorder::removeMacro(gUserMacroStore,macroName);
249 
250 		vector<string> items=gUserMacroStore->getValue<vector<string> >("MacroNames");
251 		getComboText("Macro Name")->setItems(items);
252 	}
253 	return 0;
254 }
255 
256