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