Push most of LXVSTPlugin and WindowsVSTPlugin up to VSTPlugin parent.
[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 #include <stdint.h>
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 intptr_t Session::lxvst_callback (AEffect* effect,
49                             int32_t opcode,
50                             int32_t index,
51                             intptr_t 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 = %d, 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 = %d", (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                         // NOTE: 'kVstBarsValid' is no longer defined in vestige headers -- I have no idea how important this is
140                         /*if (value & (kVstBarsValid)) {
141                                 const Meter& m (session->tempo_map().meter_at (session->transport_frame()));
142                                 _timeInfo.timeSigNumerator = m.beats_per_bar ();
143                                 _timeInfo.timeSigDenominator = m.note_divisor ();
144                                 _timeInfo.flags |= (kVstBarsValid);
145                         }*/
146                         
147                         if (session->transport_speed() != 0.0f) {
148                                 _timeInfo.flags |= kVstTransportPlaying;
149                         } 
150                 }
151
152                 return (long)&_timeInfo;
153
154         case audioMasterProcessEvents:
155                 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
156                 // VstEvents* in <ptr>
157                 return 0;
158
159         case audioMasterSetTime:
160                 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
161                 // VstTimenfo* in <ptr>, filter in <value>, not supported
162
163         case audioMasterTempoAt:
164                 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
165                 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
166                 if (session) {
167                         const Tempo& t (session->tempo_map().tempo_at (value));
168                         return t.beats_per_minute() * 1000;
169                 } else {
170                         return 0;
171                 }
172                 break;
173
174         case audioMasterGetNumAutomatableParameters:
175                 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
176                 return 0;
177
178         case audioMasterGetParameterQuantization:       
179                 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
180                // returns the integer value for +1.0 representation,
181                // or 1 if full single float precision is maintained
182                // in automation. parameter index in <value> (-1: all, any)
183                 return 0;
184
185         case audioMasterIOChanged:
186                 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
187                // numInputs and/or numOutputs has changed
188                 return 0;
189
190         case audioMasterNeedIdle:
191                 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
192                 // plug needs idle calls (outside its editor window)
193                 if (plug) {
194                         plug->state()->wantIdle = 1;
195                 }
196                 return 0;
197
198         case audioMasterSizeWindow:
199                 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
200                 // index: width, value: height
201                 return 0;
202
203         case audioMasterGetSampleRate:
204                 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
205                 if (session) {
206                         return session->frame_rate();
207                 }
208                 return 0;
209
210         case audioMasterGetBlockSize:
211                 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
212                 if (session) {
213                         return session->get_block_size();
214                 }
215                 return 0;
216
217         case audioMasterGetInputLatency:
218                 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
219                 return 0;
220
221         case audioMasterGetOutputLatency:
222                 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
223                 return 0;
224
225         case audioMasterGetPreviousPlug:
226                 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
227                // input pin in <value> (-1: first to come), returns cEffect*
228                 return 0;
229
230         case audioMasterGetNextPlug:
231                 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
232                // output pin in <value> (-1: first to come), returns cEffect*
233
234         case audioMasterWillReplaceOrAccumulate:
235                 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
236                // returns: 0: not supported, 1: replace, 2: accumulate
237                 return 0;
238
239         case audioMasterGetCurrentProcessLevel:
240                 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
241                 // returns: 0: not supported,
242                 // 1: currently in user thread (gui)
243                 // 2: currently in audio thread (where process is called)
244                 // 3: currently in 'sequencer' thread (midi, timer etc)
245                 // 4: currently offline processing and thus in user thread
246                 // other: not defined, but probably pre-empting user thread.
247                 return 0;
248                 
249         case audioMasterGetAutomationState:
250                 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
251                 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
252                 // offline
253                 return 0;
254
255         case audioMasterOfflineStart:
256                 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
257         case audioMasterOfflineRead:
258                 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
259                // ptr points to offline structure, see below. return 0: error, 1 ok
260                 return 0;
261
262         case audioMasterOfflineWrite:
263                 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
264                 // same as read
265                 return 0;
266
267         case audioMasterOfflineGetCurrentPass:
268                 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
269         case audioMasterOfflineGetCurrentMetaPass:
270                 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
271                 return 0;
272
273         case audioMasterSetOutputSampleRate:
274                 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
275                 // for variable i/o, sample rate in <opt>
276                 return 0;
277
278         case audioMasterGetSpeakerArrangement:
279                 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
280                 // (long)input in <value>, output in <ptr>
281                 return 0;
282
283         case audioMasterGetVendorString:
284                 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
285                 // fills <ptr> with a string identifying the vendor (max 64 char)
286                 strcpy ((char*) ptr, "Linux Audio Systems");
287                 return 0;
288
289         case audioMasterGetProductString:
290                 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
291                 // fills <ptr> with a string with product name (max 64 char)
292                 strcpy ((char*) ptr, "Ardour");
293                 return 0;
294
295         case audioMasterGetVendorVersion:
296                 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
297                 // returns vendor-specific version
298                 return 900;
299                 
300         case audioMasterVendorSpecific:
301                 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
302                 // no definition, vendor specific handling
303                 return 0;
304                 
305         case audioMasterSetIcon:
306                 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
307                 // void* in <ptr>, format not defined yet
308                 return 0;
309                 
310         case audioMasterCanDo:
311                 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
312                 // string in ptr, see below
313                 return 0;
314                 
315         case audioMasterGetLanguage:
316                 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
317                 // see enum
318                 return 0;
319                 
320         case audioMasterOpenWindow:
321                 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
322                 // returns platform specific ptr
323                 return 0;
324                 
325         case audioMasterCloseWindow:
326                 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
327                 // close window, platform specific handle in <ptr>
328                 return 0;
329                 
330         case audioMasterGetDirectory:
331                 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
332                 // get plug directory, FSSpec on MAC, else char*
333                 return 0;
334                 
335         case audioMasterUpdateDisplay:
336                 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
337                 // something has changed, update 'multi-fx' display
338                 if (effect) {
339                         effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
340                 }
341                 return 0;
342                 
343         case audioMasterBeginEdit:
344                 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
345                 // begin of automation session (when mouse down), parameter index in <index>
346                 return 0;
347                 
348         case audioMasterEndEdit:
349                 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
350                 // end of automation session (when mouse up),     parameter index in <index>
351                 return 0;
352                 
353         case audioMasterOpenFileSelector:
354                 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
355                 // open a fileselector window with VstFileSelect* in <ptr>
356                 return 0;
357                 
358         default:
359                 SHOW_CALLBACK ("LXVST master dispatcher: undefed: %d\n", (int)opcode);
360                 break;
361         }       
362         
363         return 0;
364 }
365