fixes for 98% of all the warnings/errors reported by OS X gcc on tiger
[ardour.git] / libs / ardour / session_lxvst.cc
1 /*
2     Copyright (C) 2004
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /******************************************************/
21 /*The big 'audio master' callback for linuxVST plugins*/
22 /******************************************************/
23
24
25 #include <stdbool.h>
26 #include <cstdio>
27
28 #include <ardour/vstfx.h>
29 #include <ardour/vestige/aeffectx.h>
30
31 #include <ardour/session.h>
32 #include <ardour/tempo.h>
33 #include <ardour/lxvst_plugin.h>
34
35 #include "i18n.h"
36
37 #define DEBUG_CALLBACKS
38 static int debug_callbacks = -1;
39
40 #ifdef DEBUG_CALLBACKS
41 #define SHOW_CALLBACK if (debug_callbacks) printf
42 #else
43 #define SHOW_CALLBACK(...)
44 #endif
45
46 using namespace ARDOUR;
47
48 long Session::lxvst_callback (AEffect* effect,
49                             long opcode,
50                             long index,
51                             long value,
52                             void* ptr,
53                             float opt)
54 {
55         static VstTimeInfo _timeInfo;
56         LXVSTPlugin* plug;
57         Session* session;
58
59         if (debug_callbacks < 0)
60         {
61                 debug_callbacks = (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0);
62         }
63         
64         if (effect && effect->user)
65         {
66             plug = (LXVSTPlugin*) (effect->user);
67                 session = &plug->session();
68                 SHOW_CALLBACK ("am callback 0x%x, opcode = %ld, plugin = \"%s\" ", (unsigned int)pthread_self(), opcode, plug->name());
69         }
70         else
71         {
72                 plug = 0;
73                 session = 0;
74                 SHOW_CALLBACK ("am callback 0x%x, opcode = %ld", (unsigned int)pthread_self(), opcode);
75         }
76
77         switch(opcode){
78
79         case audioMasterAutomate:
80                 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
81                 
82                 // index, value, returns 0
83                 if (effect) {
84                         effect->setParameter (effect, index, opt);
85                 }
86                 return 0;
87
88         case audioMasterVersion:
89                 SHOW_CALLBACK ("amc: audioMasterVersion\n");
90                 // vst version, currently 2 (0 for older)
91                 return 2;
92
93         case audioMasterCurrentId:      
94                 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
95                 // returns the unique id of a plug that's currently
96                 // loading
97                 return 0;
98                 
99         case audioMasterIdle:
100                 SHOW_CALLBACK ("amc: audioMasterIdle\n");
101                 // call application idle routine (this will
102                 // call effEditIdle for all open editors too) 
103                 if (effect) {
104                         effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
105                 }
106                 return 0;
107
108         case audioMasterPinConnected:           
109                 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
110                 // inquire if an input or output is beeing connected;
111                 // index enumerates input or output counting from zero:
112                 // value is 0 for input and != 0 otherwise. note: the
113                 // return value is 0 for <true> such that older versions
114                 // will always return true.
115                 return 1;
116
117         case audioMasterWantMidi:
118                 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
119                 // <value> is a filter which is currently ignored
120                 return 0;
121
122         case audioMasterGetTime:
123                 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
124                 // returns const VstTimeInfo* (or 0 if not supported)
125                 // <value> should contain a mask indicating which fields are required
126                 // (see valid masks above), as some items may require extensive
127                 // conversions
128                 memset(&_timeInfo, 0, sizeof(_timeInfo));
129                 if (session) {
130                         _timeInfo.samplePos = session->transport_frame();
131                         _timeInfo.sampleRate = session->frame_rate();
132                         _timeInfo.flags = 0;
133                         
134                         if (value & (kVstTempoValid)) {
135                                 const Tempo& t (session->tempo_map().tempo_at (session->transport_frame()));
136                                 _timeInfo.tempo = t.beats_per_minute ();
137                                 _timeInfo.flags |= (kVstTempoValid);
138                         }
139                         if (value & (kVstBarsValid)) {
140                                 const Meter& m (session->tempo_map().meter_at (session->transport_frame()));
141                                 _timeInfo.timeSigNumerator = m.beats_per_bar ();
142                                 _timeInfo.timeSigDenominator = m.note_divisor ();
143                                 _timeInfo.flags |= (kVstBarsValid);
144                         }
145                         
146                         if (session->transport_speed() != 0.0f) {
147                                 _timeInfo.flags |= kVstTransportPlaying;
148                         } 
149                 }
150
151                 return (long)&_timeInfo;
152
153         case audioMasterProcessEvents:
154                 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
155                 // VstEvents* in <ptr>
156                 return 0;
157
158         case audioMasterSetTime:
159                 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
160                 // VstTimenfo* in <ptr>, filter in <value>, not supported
161
162         case audioMasterTempoAt:
163                 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
164                 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
165                 if (session) {
166                         const Tempo& t (session->tempo_map().tempo_at (value));
167                         return t.beats_per_minute() * 1000;
168                 } else {
169                         return 0;
170                 }
171                 break;
172
173         case audioMasterGetNumAutomatableParameters:
174                 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
175                 return 0;
176
177         case audioMasterGetParameterQuantization:       
178                 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
179                // returns the integer value for +1.0 representation,
180                // or 1 if full single float precision is maintained
181                // in automation. parameter index in <value> (-1: all, any)
182                 return 0;
183
184         case audioMasterIOChanged:
185                 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
186                // numInputs and/or numOutputs has changed
187                 return 0;
188
189         case audioMasterNeedIdle:
190                 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
191                 // plug needs idle calls (outside its editor window)
192                 if (plug) {
193                         plug->vstfx()->wantIdle = 1;
194                 }
195                 return 0;
196
197         case audioMasterSizeWindow:
198                 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
199                 // index: width, value: height
200                 return 0;
201
202         case audioMasterGetSampleRate:
203                 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
204                 if (session) {
205                         return session->frame_rate();
206                 }
207                 return 0;
208
209         case audioMasterGetBlockSize:
210                 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
211                 if (session) {
212                         return session->get_block_size();
213                 }
214                 return 0;
215
216         case audioMasterGetInputLatency:
217                 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
218                 return 0;
219
220         case audioMasterGetOutputLatency:
221                 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
222                 return 0;
223
224         case audioMasterGetPreviousPlug:
225                 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
226                // input pin in <value> (-1: first to come), returns cEffect*
227                 return 0;
228
229         case audioMasterGetNextPlug:
230                 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
231                // output pin in <value> (-1: first to come), returns cEffect*
232
233         case audioMasterWillReplaceOrAccumulate:
234                 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
235                // returns: 0: not supported, 1: replace, 2: accumulate
236                 return 0;
237
238         case audioMasterGetCurrentProcessLevel:
239                 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
240                 // returns: 0: not supported,
241                 // 1: currently in user thread (gui)
242                 // 2: currently in audio thread (where process is called)
243                 // 3: currently in 'sequencer' thread (midi, timer etc)
244                 // 4: currently offline processing and thus in user thread
245                 // other: not defined, but probably pre-empting user thread.
246                 return 0;
247                 
248         case audioMasterGetAutomationState:
249                 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
250                 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
251                 // offline
252                 return 0;
253
254         case audioMasterOfflineStart:
255                 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
256         case audioMasterOfflineRead:
257                 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
258                // ptr points to offline structure, see below. return 0: error, 1 ok
259                 return 0;
260
261         case audioMasterOfflineWrite:
262                 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
263                 // same as read
264                 return 0;
265
266         case audioMasterOfflineGetCurrentPass:
267                 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
268         case audioMasterOfflineGetCurrentMetaPass:
269                 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
270                 return 0;
271
272         case audioMasterSetOutputSampleRate:
273                 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
274                 // for variable i/o, sample rate in <opt>
275                 return 0;
276
277         case audioMasterGetSpeakerArrangement:
278                 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
279                 // (long)input in <value>, output in <ptr>
280                 return 0;
281
282         case audioMasterGetVendorString:
283                 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
284                 // fills <ptr> with a string identifying the vendor (max 64 char)
285                 strcpy ((char*) ptr, "Linux Audio Systems");
286                 return 0;
287
288         case audioMasterGetProductString:
289                 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
290                 // fills <ptr> with a string with product name (max 64 char)
291                 strcpy ((char*) ptr, "Ardour");
292                 return 0;
293
294         case audioMasterGetVendorVersion:
295                 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
296                 // returns vendor-specific version
297                 return 900;
298                 
299         case audioMasterVendorSpecific:
300                 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
301                 // no definition, vendor specific handling
302                 return 0;
303                 
304         case audioMasterSetIcon:
305                 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
306                 // void* in <ptr>, format not defined yet
307                 return 0;
308                 
309         case audioMasterCanDo:
310                 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
311                 // string in ptr, see below
312                 return 0;
313                 
314         case audioMasterGetLanguage:
315                 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
316                 // see enum
317                 return 0;
318                 
319         case audioMasterOpenWindow:
320                 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
321                 // returns platform specific ptr
322                 return 0;
323                 
324         case audioMasterCloseWindow:
325                 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
326                 // close window, platform specific handle in <ptr>
327                 return 0;
328                 
329         case audioMasterGetDirectory:
330                 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
331                 // get plug directory, FSSpec on MAC, else char*
332                 return 0;
333                 
334         case audioMasterUpdateDisplay:
335                 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
336                 // something has changed, update 'multi-fx' display
337                 if (effect) {
338                         effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
339                 }
340                 return 0;
341                 
342         case audioMasterBeginEdit:
343                 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
344                 // begin of automation session (when mouse down), parameter index in <index>
345                 return 0;
346                 
347         case audioMasterEndEdit:
348                 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
349                 // end of automation session (when mouse up),     parameter index in <index>
350                 return 0;
351                 
352         case audioMasterOpenFileSelector:
353                 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
354                 // open a fileselector window with VstFileSelect* in <ptr>
355                 return 0;
356                 
357         default:
358                 SHOW_CALLBACK ("LXVST master dispatcher: undefed: %d\n", (int)opcode);
359                 break;
360         }       
361         
362         return 0;
363 }
364