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