Move panner bypass state up to the PannerShell so that it is preserved even when...
[ardour2.git] / libs / ardour / session_vst.cc
blob2aa873c6e641cd8df324e4f3150d8d8026575649
1 /*
2 Copyright (C) 2004
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.
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.
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.
20 #include <stdbool.h>
21 #include <cstdio>
23 #include <fst.h>
24 #include <fst/vestige/aeffectx.h>
26 #include "ardour/session.h"
27 #include "ardour/tempo.h"
28 #include "ardour/vst_plugin.h"
30 #include "i18n.h"
32 #define DEBUG_CALLBACKS
33 static int debug_callbacks = -1;
35 #ifdef DEBUG_CALLBACKS
36 #define SHOW_CALLBACK if (debug_callbacks) printf
37 #else
38 #define SHOW_CALLBACK(...)
39 #endif
41 using namespace ARDOUR;
43 long Session::vst_callback (AEffect* effect,
44 long opcode,
45 long index,
46 long value,
47 void* ptr,
48 float opt)
50 static VstTimeInfo _timeInfo;
51 VSTPlugin* plug;
52 Session* session;
54 if (debug_callbacks < 0) {
55 debug_callbacks = (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0);
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);
68 switch(opcode){
70 case audioMasterAutomate:
71 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
72 // index, value, returns 0
73 if (plug) {
74 plug->set_parameter (index, opt);
76 return 0;
78 case audioMasterVersion:
79 SHOW_CALLBACK ("amc: audioMasterVersion\n");
80 // vst version, currently 2 (0 for older)
81 return 2;
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;
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);
96 return 0;
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;
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);
113 return 0;
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;
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);
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);
139 if (session->transport_speed() != 0.0f) {
140 _timeInfo.flags |= kVstTransportPlaying;
144 return (long)&_timeInfo;
146 case audioMasterProcessEvents:
147 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
148 // VstEvents* in <ptr>
149 return 0;
151 case audioMasterSetTime:
152 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
153 // VstTimenfo* in <ptr>, filter in <value>, not supported
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;
164 break;
166 case audioMasterGetNumAutomatableParameters:
167 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
168 return 0;
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;
177 case audioMasterIOChanged:
178 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
179 // numInputs and/or numOutputs has changed
180 return 0;
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;
188 return 0;
190 case audioMasterSizeWindow:
191 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
192 // index: width, value: height
193 return 0;
195 case audioMasterGetSampleRate:
196 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
197 if (session) {
198 return session->frame_rate();
200 return 0;
202 case audioMasterGetBlockSize:
203 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
204 if (session) {
205 return session->get_block_size();
207 return 0;
209 case audioMasterGetInputLatency:
210 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
211 return 0;
213 case audioMasterGetOutputLatency:
214 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
215 return 0;
217 case audioMasterGetPreviousPlug:
218 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
219 // input pin in <value> (-1: first to come), returns cEffect*
220 return 0;
222 case audioMasterGetNextPlug:
223 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
224 // output pin in <value> (-1: first to come), returns cEffect*
226 case audioMasterWillReplaceOrAccumulate:
227 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
228 // returns: 0: not supported, 1: replace, 2: accumulate
229 return 0;
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;
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;
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;
254 case audioMasterOfflineWrite:
255 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
256 // same as read
257 return 0;
259 case audioMasterOfflineGetCurrentPass:
260 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
261 case audioMasterOfflineGetCurrentMetaPass:
262 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
263 return 0;
265 case audioMasterSetOutputSampleRate:
266 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
267 // for variable i/o, sample rate in <opt>
268 return 0;
270 case audioMasterGetSpeakerArrangement:
271 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
272 // (long)input in <value>, output in <ptr>
273 return 0;
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;
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;
287 case audioMasterGetVendorVersion:
288 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
289 // returns vendor-specific version
290 return 900;
292 case audioMasterVendorSpecific:
293 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
294 // no definition, vendor specific handling
295 return 0;
297 case audioMasterSetIcon:
298 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
299 // void* in <ptr>, format not defined yet
300 return 0;
302 case audioMasterCanDo:
303 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
304 // string in ptr, see below
305 return 0;
307 case audioMasterGetLanguage:
308 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
309 // see enum
310 return 0;
312 case audioMasterOpenWindow:
313 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
314 // returns platform specific ptr
315 return 0;
317 case audioMasterCloseWindow:
318 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
319 // close window, platform specific handle in <ptr>
320 return 0;
322 case audioMasterGetDirectory:
323 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
324 // get plug directory, FSSpec on MAC, else char*
325 return 0;
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);
333 return 0;
335 case audioMasterBeginEdit:
336 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
337 // begin of automation session (when mouse down), parameter index in <index>
338 return 0;
340 case audioMasterEndEdit:
341 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
342 // end of automation session (when mouse up), parameter index in <index>
343 return 0;
345 case audioMasterOpenFileSelector:
346 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
347 // open a fileselector window with VstFileSelect* in <ptr>
348 return 0;
350 default:
351 SHOW_CALLBACK ("VST master dispatcher: undefed: %ld\n", opcode);
352 break;
355 return 0;