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.
23 #include "ardour/session.h"
24 #include "ardour/tempo.h"
25 #include "ardour/windows_vst_plugin.h"
26 #include "ardour/vestige/aeffectx.h"
27 #include "ardour/vst_types.h"
31 #define DEBUG_CALLBACKS
32 static int debug_callbacks = -1;
34 #ifdef DEBUG_CALLBACKS
35 #define SHOW_CALLBACK if (debug_callbacks) printf
37 #define SHOW_CALLBACK(...)
40 using namespace ARDOUR;
42 intptr_t Session::vst_callback (
51 static VstTimeInfo _timeInfo;
55 if (debug_callbacks < 0) {
56 debug_callbacks = (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0);
59 if (effect && effect->user) {
60 plug = (VSTPlugin *) (effect->user);
61 session = &plug->session();
62 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self(), opcode, plug->name());
66 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self(), opcode);
71 case audioMasterAutomate:
72 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
73 // index, value, returns 0
75 plug->set_parameter (index, opt);
79 case audioMasterVersion:
80 SHOW_CALLBACK ("amc: audioMasterVersion\n");
81 // vst version, currently 2 (0 for older)
84 case audioMasterCurrentId:
85 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
86 // returns the unique id of a plug that's currently
91 SHOW_CALLBACK ("amc: audioMasterIdle\n");
92 // call application idle routine (this will
93 // call effEditIdle for all open editors too)
95 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
99 case audioMasterPinConnected:
100 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
101 // inquire if an input or output is beeing connected;
102 // index enumerates input or output counting from zero:
103 // value is 0 for input and != 0 otherwise. note: the
104 // return value is 0 for <true> such that older versions
105 // will always return true.
108 case audioMasterWantMidi:
109 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
110 // <value> is a filter which is currently ignored
112 plug->get_info()->n_inputs.set_midi (1);
116 case audioMasterGetTime:
117 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
118 // returns const VstTimeInfo* (or 0 if not supported)
119 // <value> should contain a mask indicating which fields are required
120 // (see valid masks above), as some items may require extensive
122 memset(&_timeInfo, 0, sizeof(_timeInfo));
124 _timeInfo.samplePos = session->transport_frame();
125 _timeInfo.sampleRate = session->frame_rate();
128 if (value & (kVstTempoValid)) {
129 const Tempo& t (session->tempo_map().tempo_at (session->transport_frame()));
130 _timeInfo.tempo = t.beats_per_minute ();
131 _timeInfo.flags |= (kVstTempoValid);
133 if (value & (kVstBarsValid)) {
134 const Meter& m (session->tempo_map().meter_at (session->transport_frame()));
135 _timeInfo.timeSigNumerator = m.divisions_per_bar ();
136 _timeInfo.timeSigDenominator = m.note_divisor ();
137 _timeInfo.flags |= (kVstBarsValid);
140 if (session->transport_speed() != 0.0f) {
141 _timeInfo.flags |= kVstTransportPlaying;
145 return (long)&_timeInfo;
147 case audioMasterProcessEvents:
148 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
149 // VstEvents* in <ptr>
152 case audioMasterSetTime:
153 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
154 // VstTimenfo* in <ptr>, filter in <value>, not supported
156 case audioMasterTempoAt:
157 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
158 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
160 const Tempo& t (session->tempo_map().tempo_at (value));
161 return t.beats_per_minute() * 1000;
167 case audioMasterGetNumAutomatableParameters:
168 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
171 case audioMasterGetParameterQuantization:
172 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
173 // returns the integer value for +1.0 representation,
174 // or 1 if full single float precision is maintained
175 // in automation. parameter index in <value> (-1: all, any)
178 case audioMasterIOChanged:
179 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
180 // numInputs and/or numOutputs has changed
183 case audioMasterNeedIdle:
184 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
185 // plug needs idle calls (outside its editor window)
187 plug->state()->wantIdle = 1;
191 case audioMasterSizeWindow:
192 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
193 // index: width, value: height
196 case audioMasterGetSampleRate:
197 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
199 return session->frame_rate();
203 case audioMasterGetBlockSize:
204 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
206 return session->get_block_size();
210 case audioMasterGetInputLatency:
211 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
214 case audioMasterGetOutputLatency:
215 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
218 case audioMasterGetPreviousPlug:
219 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
220 // input pin in <value> (-1: first to come), returns cEffect*
223 case audioMasterGetNextPlug:
224 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
225 // output pin in <value> (-1: first to come), returns cEffect*
227 case audioMasterWillReplaceOrAccumulate:
228 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
229 // returns: 0: not supported, 1: replace, 2: accumulate
232 case audioMasterGetCurrentProcessLevel:
233 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
234 // returns: 0: not supported,
235 // 1: currently in user thread (gui)
236 // 2: currently in audio thread (where process is called)
237 // 3: currently in 'sequencer' thread (midi, timer etc)
238 // 4: currently offline processing and thus in user thread
239 // other: not defined, but probably pre-empting user thread.
242 case audioMasterGetAutomationState:
243 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
244 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
248 case audioMasterOfflineStart:
249 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
252 case audioMasterOfflineRead:
253 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
254 // ptr points to offline structure, see below. return 0: error, 1 ok
257 case audioMasterOfflineWrite:
258 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
262 case audioMasterOfflineGetCurrentPass:
263 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
266 case audioMasterOfflineGetCurrentMetaPass:
267 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
270 case audioMasterSetOutputSampleRate:
271 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
272 // for variable i/o, sample rate in <opt>
275 case audioMasterGetSpeakerArrangement:
276 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
277 // (long)input in <value>, output in <ptr>
280 case audioMasterGetVendorString:
281 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
282 // fills <ptr> with a string identifying the vendor (max 64 char)
283 strcpy ((char*) ptr, "Linux Audio Systems");
286 case audioMasterGetProductString:
287 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
288 // fills <ptr> with a string with product name (max 64 char)
289 strcpy ((char*) ptr, PROGRAM_NAME);
292 case audioMasterGetVendorVersion:
293 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
294 // returns vendor-specific version
297 case audioMasterVendorSpecific:
298 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
299 // no definition, vendor specific handling
302 case audioMasterSetIcon:
303 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
304 // void* in <ptr>, format not defined yet
307 case audioMasterCanDo:
308 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
309 // string in ptr, see below
312 case audioMasterGetLanguage:
313 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
317 case audioMasterOpenWindow:
318 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
319 // returns platform specific ptr
322 case audioMasterCloseWindow:
323 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
324 // close window, platform specific handle in <ptr>
327 case audioMasterGetDirectory:
328 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
329 // get plug directory, FSSpec on MAC, else char*
332 case audioMasterUpdateDisplay:
333 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
334 // something has changed, update 'multi-fx' display
336 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
340 case audioMasterBeginEdit:
341 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
342 // begin of automation session (when mouse down), parameter index in <index>
345 case audioMasterEndEdit:
346 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
347 // end of automation session (when mouse up), parameter index in <index>
350 case audioMasterOpenFileSelector:
351 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
352 // open a fileselector window with VstFileSelect* in <ptr>
356 SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode);