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