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 #ifndef __AFrontendHooks_H__
22 #define __AFrontendHooks_H__
23 
24 #include "../../config/common.h"
25 
26 class AFrontendHooks;
27 
28 #include <string>
29 #include <vector>
30 
31 #include "CSound_defs.h"
32 
33 #ifdef USE_LADSPA
34 	#include "AActionDialog.h"
35 	#include "LADSPA/ladspa.h"
36 #endif
37 
38 class AActionFactory;
39 class ASoundRecorder;
40 class CLoadedSound;
41 
42 extern AFrontendHooks *gFrontendHooks;
43 
44 class AFrontendHooks
45 {
46 public:
47 
AFrontendHooks()48 	AFrontendHooks() { }
~AFrontendHooks()49 	virtual ~AFrontendHooks() { }
50 
51 	virtual void setWhichClipboard(size_t whichClipboard)=0;
52 
53 	// prompt with an open file dialog (return false if the prompt was cancelled)
54 	virtual bool promptForOpenSoundFilename(string &filename,bool &readOnly,bool &openAsRaw)=0;
55 	virtual bool promptForOpenSoundFilenames(vector<string> &filenames,bool &readOnly,bool &openAsRaw)=0;
56 
57 	// prompt with a save file dialog (return false if the prompt was cancelled)
58 	virtual bool promptForSaveSoundFilename(string &filename,bool &saveAsRaw)=0;
59 
60 	// prompt for a new sound to be created asking for the given parameters (return false if the prompt was cancelled)
61 	virtual bool promptForNewSoundParameters(string &filename,bool &rawFormat,bool hideFilename,unsigned &channelCount,bool hideChannelCount,unsigned &sampleRate,bool hideSampleRate,sample_pos_t &length,bool hideLength)=0;
62 
63 	// should prompt for the user to choose a directory
64 	virtual bool promptForDirectory(string &dirname,const string title)=0;
65 
66 	// prompt for recording, this function will have to be more than just an interface and do work
67 	// since it should probably show level meters and be able to insert cues while recording etc.
68 	virtual bool promptForRecord(ASoundRecorder *recorder)=0;
69 
70 	// prompt for parameters for recording a macro
71 	virtual bool showRecordMacroDialog(string &macroName)=0;
72 
73 	// prompt for the information needed to store with the macro after each action of the recording macro is recorded
74 	struct MacroActionParameters
75 	{
76 		// true if at playback time the user should be prompted for the action parameters rather than it using the ones defined at record time
77 	 	bool askToPromptForActionParametersAtPlayback;
78 
79 		enum SelectionPositioning
80 		{
81 			spLeaveAlone=1,
82 
83 			spAbsoluteTimeFromBeginning=2,
84 			spAbsoluteTimeFromEnd=3,
85 			spProportionateTimeFromBeginning=4,
86 
87 			spAbsoluteTimeFromStopPosition=5, 	// only allowed for the startPosPositioning
88 			spProportionateTimeFromStopPosition=6,	// only allowed for the startPosPositioning
89 
90 			spAbsoluteTimeFromStartPosition=7, 	// only allowed for the stopPosPositioning
91 			spProportionateTimeFromStartPosition=8,	// only allowed for the stopPosPositioning
92 
93 			// NOTE: 5 or 6 for a startPosPositioning cannot be used at the same time that 7 or 8 is used for the stopPosPositioning
94 			// the positionsAreRelativeToEachOther() method can conveniently be called to test for this condition
95 
96 			spSameCueName=9,
97 		};
98 
99 		SelectionPositioning startPosPositioning;
100 		SelectionPositioning stopPosPositioning;
101 
positionsAreRelativeToEachOtherMacroActionParameters102 		bool positionsAreRelativeToEachOther() const
103 		{
104 			return (startPosPositioning==5 || startPosPositioning==6) && (stopPosPositioning==7 || stopPosPositioning==8);
105 		}
106 
107 		string startPosCueName;
108 		string stopPosCueName;
109 	};
110 	virtual bool showMacroActionParamsDialog(const AActionFactory *actionFactory,MacroActionParameters &macroActionParams,CLoadedSound *loadedSound)=0; // loadedSound may be NULL
111 
112 
113 #ifdef ENABLE_JACK
114 	// prompt for JACK port names (only used whenever JACK is the audio I/O subsystem
115 	// 	??? this could be a generalized promptWithCombo and given it a message, but I've never needed it until now
116 	virtual const string promptForJACKPort(const string message,const vector<string> portNames)=0;
117 #endif
118 
119 	struct RezSaveParameters
120 	{
121 		AudioEncodingTypes audioEncodingType; // enum defined in CSound_defs.h
122 	};
123 	virtual bool promptForRezSaveParameters(RezSaveParameters &parameters)=0;
124 
125 
126 	// called when the user is loading a raw file and format parameters are needed
127 	struct RawParameters
128 	{
129 		unsigned channelCount;
130 		unsigned sampleRate;
131 
132 		enum SampleFormats
133 		{
134 			f8BitSignedPCM=0,
135 			f8BitUnsignedPCM=4,
136 			f16BitSignedPCM=1,
137 			f16BitUnsignedPCM=5,
138 			f24BitSignedPCM=2,
139 			f24BitUnsignedPCM=6,
140 			f32BitSignedPCM=3,
141 			f32BitUnsignedPCM=7,
142 			f32BitFloatPCM=8,
143 			f64BitFloatPCM=9
144 		} sampleFormat;
145 
146 		enum
147 		{
148 			eBigEndian=0,
149 			eLittleEndian=1
150 		} endian;
151 
152 		unsigned dataOffset; // in bytes
153 		unsigned dataLength; // in frames; can be 0 for no user limit
154 
155 	};
156 	virtual bool promptForRawParameters(RawParameters &parameters,bool showLoadRawParameters)=0;
157 
158 
159 	// called when the user is saving an ogg file and compression parameters are needed
160 	struct OggCompressionParameters
161 	{
162 		enum
163 		{
164 			brVBR=0,
165 			brQuality=1
166 		} method;
167 
168 		// method==brVBR
169 		int minBitRate;
170 		int normBitRate;
171 		int maxBitRate;
172 
173 		// method==brQuality
174 		float quality;
175 	};
176 	virtual bool promptForOggCompressionParameters(OggCompressionParameters &parameters)=0;
177 
178 
179 	// called when the user is saving an mp3 file and compression parameters are needed
180 	struct Mp3CompressionParameters
181 	{
182 		enum
183 		{
184 			brCBR=0,
185 			brABR=1,
186 			brQuality=2
187 		} method;
188 
189 		// method==brCBR
190 		int constantBitRate;
191 
192 		// method==brABR
193 		int minBitRate;
194 		int normBitRate;
195 		int maxBitRate;
196 
197 		// method==brQuality
198 		int quality; // 0(highest quality) -> 9(lowest quality)
199 
200 		bool useFlagsOnly;
201 		string additionalFlags;
202 	};
203 	virtual bool promptForMp3CompressionParameters(Mp3CompressionParameters &parameters)=0;
204 
205 
206 	// called when the user is loading a vox file and format parameters are needed
207 	struct VoxParameters
208 	{
209 		unsigned channelCount;
210 		unsigned sampleRate;
211 
212 	};
213 	virtual bool promptForVoxParameters(VoxParameters &parameters)=0;
214 
215 
216 	// stuff to handle frontend interfaces to LADSPA plugins
217 #ifdef USE_LADSPA
218 	virtual AActionDialog *getChannelSelectDialog()=0;
219 	// should return a frontend dialog which can handle the given LADSPA plugin descriptor
220 		// the backend will be responsible for deleteing the returned object
221 	virtual AActionDialog *getLADSPAActionDialog(const LADSPA_Descriptor *desc)=0;
222 #endif
223 
224 	// -1 can be passed for the parameters not be be changed from the previous values on the dialog
225 	// if Id comes back -1, then just wait for one
226 	// if false is returned, then cancel was pressed
227 	virtual bool promptForOpenMIDISampleDump(int &sysExChannel,int &waveformId)=0;
228 
229 	// -1 can be passed for the parameters not be be changed from the previous values on the dialog
230 	// if false is returned, then cancel was pressed
231 	virtual bool promptForSaveMIDISampleDump(int &sysExChannel,int &waveformId,int &loopType)=0;
232 
233 
234 	// called when the user is saving an format with libaudiofile
235 	struct libaudiofileSaveParameters
236 	{
237 		int sampleFormat;	// AF_SAMPFMT_xxx
238 		int defaultSampleFormatIndex; // of signed, unsigned, float, double
239 		int sampleWidth;	// bit rate
240 		int defaultSampleWidthIndex; // of 8, 16, 24, 32
241 
242 		// this is an input value that indicates which compression types are supported
243 		// pair: name of compression type, audiofiles enum value for it
244 		vector<pair<string,int> > supportedCompressionTypes;
245 
246 		int defaultCompressionTypeIndex; // of the items in the vector
247 		int compressionType;	// AF_COMPRESSION_xxx
248 
249 		bool saveCues;
250 		bool saveUserNotes;
251 	};
252 	virtual bool promptForlibaudiofileSaveParameters(libaudiofileSaveParameters &parameters,const string formatName)=0;
253 };
254 
255 #endif
256