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.
25 #include "ardour/audioengine.h"
26 #include "ardour/session.h"
27 #include "ardour/tempo.h"
28 #include "ardour/windows_vst_plugin.h"
29 #include "ardour/vestige/aeffectx.h"
30 #include "ardour/vst_types.h"
34 #define DEBUG_CALLBACKS
35 static int debug_callbacks = -1;
37 #ifdef DEBUG_CALLBACKS
38 #define SHOW_CALLBACK if (debug_callbacks) printf
40 #define SHOW_CALLBACK(...)
43 using namespace ARDOUR;
45 intptr_t Session::vst_callback (
54 static VstTimeInfo _timeInfo;
58 if (debug_callbacks < 0) {
59 debug_callbacks = (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0);
62 if (effect && effect->user) {
63 plug = (VSTPlugin *) (effect->user);
64 session = &plug->session();
66 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self().p, opcode, plug->name());
68 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self(), opcode, plug->name());
74 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self().p, opcode);
76 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self(), opcode);
82 case audioMasterAutomate:
83 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
84 // index, value, returns 0
86 plug->set_parameter (index, opt);
90 case audioMasterVersion:
91 SHOW_CALLBACK ("amc: audioMasterVersion\n");
92 // vst version, currently 2 (0 for older)
95 case audioMasterCurrentId:
96 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
97 // returns the unique id of a plug that's currently
101 case audioMasterIdle:
102 SHOW_CALLBACK ("amc: audioMasterIdle\n");
103 // call application idle routine (this will
104 // call effEditIdle for all open editors too)
106 #if 0 // TODO -> emit to GUI OR better delegete to fst/fst
108 // This allows the main GUI window to update if needed.
109 // Some plugins take over the GUI event loop
110 // which causes the main GUI to freeze while the plugin GUI continues to run. This code
111 // prevents the main GUI from being frozen.
114 #ifdef GDK_WINDOWING_X11
115 gtk_main_iteration_do(false);
119 } while (gtk_events_pending());
121 printf("audioMasterIdle\n");
124 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
128 case audioMasterPinConnected:
129 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
130 // inquire if an input or output is beeing connected;
131 // index enumerates input or output counting from zero:
132 // value is 0 for input and != 0 otherwise. note: the
133 // return value is 0 for <true> such that older versions
134 // will always return true.
137 case audioMasterWantMidi:
138 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
139 // <value> is a filter which is currently ignored
141 plug->get_info()->n_inputs.set_midi (1);
145 case audioMasterGetTime:
146 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
147 // returns const VstTimeInfo* (or 0 if not supported)
148 // <value> should contain a mask indicating which fields are required
149 // (see valid masks above), as some items may require extensive
154 framepos_t now = session->transport_frame();
156 _timeInfo.samplePos = now;
157 _timeInfo.sampleRate = session->frame_rate();
159 const TempoMetric& tm (session->tempo_map().metric_at (now));
161 if (value & (kVstTempoValid)) {
162 const Tempo& t (tm.tempo());
163 _timeInfo.tempo = t.beats_per_minute ();
164 _timeInfo.flags |= (kVstTempoValid);
166 if (value & (kVstTimeSigValid)) {
167 const Meter& m (tm.meter());
168 _timeInfo.timeSigNumerator = m.divisions_per_bar ();
169 _timeInfo.timeSigDenominator = m.note_divisor ();
170 _timeInfo.flags |= (kVstTimeSigValid);
172 if ((value & (kVstPpqPosValid)) || (value & (kVstBarsValid))) {
173 Timecode::BBT_Time bbt;
176 session->tempo_map().bbt_time_rt (now, bbt);
178 /* PPQ = pulse per quarter
179 * VST's "pulse" is our "division".
181 * 8 divisions per bar, 1 division = quarter, so 8 quarters per bar, ppq = 1
182 * 8 divisions per bar, 1 division = eighth, so 4 quarters per bar, ppq = 2
183 * 4 divisions per bar, 1 division = quarter, so 4 quarters per bar, ppq = 1
184 * 4 divisions per bar, 1 division = half, so 8 quarters per bar, ppq = 0.5
185 * 4 divisions per bar, 1 division = fifth, so (4 * 5/4) quarters per bar, ppq = 5/4
187 * general: divs_per_bar / (note_type / 4.0)
189 double ppq_scaling = tm.meter().note_divisor() / 4.0;
191 /* Note that this assumes constant meter/tempo throughout the session. Stupid VST */
192 double ppqBar = double(bbt.bars - 1) * tm.meter().divisions_per_bar();
193 double ppqBeat = double(bbt.beats - 1);
194 double ppqTick = double(bbt.ticks) / Timecode::BBT_Time::ticks_per_beat;
196 ppqBar *= ppq_scaling;
197 ppqBeat *= ppq_scaling;
198 ppqTick *= ppq_scaling;
200 if (value & (kVstPpqPosValid)) {
201 _timeInfo.ppqPos = ppqBar + ppqBeat + ppqTick;
202 _timeInfo.flags |= (kVstPpqPosValid);
205 if (value & (kVstBarsValid)) {
206 _timeInfo.barStartPos = ppqBar;
207 _timeInfo.flags |= (kVstBarsValid);
215 if (value & (kVstSmpteValid)) {
218 session->timecode_time (now, t);
220 _timeInfo.smpteOffset = (t.hours * t.rate * 60.0 * 60.0) +
221 (t.minutes * t.rate * 60.0) +
222 (t.seconds * t.rate) +
226 _timeInfo.smpteOffset *= 80.0; /* VST spec is 1/80th frames */
228 if (session->timecode_drop_frames()) {
229 if (session->timecode_frames_per_second() == 30.0) {
230 _timeInfo.smpteFrameRate = 5;
232 _timeInfo.smpteFrameRate = 4; /* 29.97 assumed, thanks VST */
235 if (session->timecode_frames_per_second() == 24.0) {
236 _timeInfo.smpteFrameRate = 0;
237 } else if (session->timecode_frames_per_second() == 24.975) {
238 _timeInfo.smpteFrameRate = 2;
239 } else if (session->timecode_frames_per_second() == 25.0) {
240 _timeInfo.smpteFrameRate = 1;
242 _timeInfo.smpteFrameRate = 3; /* 30 fps */
245 _timeInfo.flags |= (kVstSmpteValid);
248 if (session->transport_speed() != 0.0f) {
249 _timeInfo.flags |= (kVstTransportPlaying);
252 if (session->get_play_loop()) {
256 _timeInfo.samplePos = 0;
257 _timeInfo.sampleRate = AudioEngine::instance()->sample_rate();
260 return (intptr_t) &_timeInfo;
262 case audioMasterProcessEvents:
263 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
264 // VstEvents* in <ptr>
267 case audioMasterSetTime:
268 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
269 // VstTimenfo* in <ptr>, filter in <value>, not supported
271 case audioMasterTempoAt:
272 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
273 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
275 const Tempo& t (session->tempo_map().tempo_at (value));
276 return t.beats_per_minute() * 1000;
282 case audioMasterGetNumAutomatableParameters:
283 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
286 case audioMasterGetParameterQuantization:
287 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
288 // returns the integer value for +1.0 representation,
289 // or 1 if full single float precision is maintained
290 // in automation. parameter index in <value> (-1: all, any)
293 case audioMasterIOChanged:
294 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
295 // numInputs and/or numOutputs has changed
298 case audioMasterNeedIdle:
299 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
300 // plug needs idle calls (outside its editor window)
302 plug->state()->wantIdle = 1;
306 case audioMasterSizeWindow:
307 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
308 // index: width, value: height
311 case audioMasterGetSampleRate:
312 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
314 return session->frame_rate();
318 case audioMasterGetBlockSize:
319 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
321 return session->get_block_size();
325 case audioMasterGetInputLatency:
326 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
329 case audioMasterGetOutputLatency:
330 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
333 case audioMasterGetPreviousPlug:
334 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
335 // input pin in <value> (-1: first to come), returns cEffect*
338 case audioMasterGetNextPlug:
339 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
340 // output pin in <value> (-1: first to come), returns cEffect*
342 case audioMasterWillReplaceOrAccumulate:
343 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
344 // returns: 0: not supported, 1: replace, 2: accumulate
347 case audioMasterGetCurrentProcessLevel:
348 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
349 // returns: 0: not supported,
350 // 1: currently in user thread (gui)
351 // 2: currently in audio thread (where process is called)
352 // 3: currently in 'sequencer' thread (midi, timer etc)
353 // 4: currently offline processing and thus in user thread
354 // other: not defined, but probably pre-empting user thread.
357 case audioMasterGetAutomationState:
358 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
359 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
363 case audioMasterOfflineStart:
364 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
367 case audioMasterOfflineRead:
368 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
369 // ptr points to offline structure, see below. return 0: error, 1 ok
372 case audioMasterOfflineWrite:
373 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
377 case audioMasterOfflineGetCurrentPass:
378 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
381 case audioMasterOfflineGetCurrentMetaPass:
382 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
385 case audioMasterSetOutputSampleRate:
386 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
387 // for variable i/o, sample rate in <opt>
390 case audioMasterGetSpeakerArrangement:
391 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
392 // (long)input in <value>, output in <ptr>
395 case audioMasterGetVendorString:
396 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
397 // fills <ptr> with a string identifying the vendor (max 64 char)
398 strcpy ((char*) ptr, "Linux Audio Systems");
401 case audioMasterGetProductString:
402 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
403 // fills <ptr> with a string with product name (max 64 char)
404 strcpy ((char*) ptr, PROGRAM_NAME);
407 case audioMasterGetVendorVersion:
408 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
409 // returns vendor-specific version
412 case audioMasterVendorSpecific:
413 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
414 // no definition, vendor specific handling
417 case audioMasterSetIcon:
418 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
419 // void* in <ptr>, format not defined yet
422 case audioMasterCanDo:
423 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
424 // string in ptr, (const char*)ptr
427 case audioMasterGetLanguage:
428 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
432 case audioMasterOpenWindow:
433 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
434 // returns platform specific ptr
437 case audioMasterCloseWindow:
438 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
439 // close window, platform specific handle in <ptr>
442 case audioMasterGetDirectory:
443 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
444 // get plug directory, FSSpec on MAC, else char*
447 case audioMasterUpdateDisplay:
448 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
449 // something has changed, update 'multi-fx' display
451 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
455 case audioMasterBeginEdit:
456 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
457 // begin of automation session (when mouse down), parameter index in <index>
460 case audioMasterEndEdit:
461 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
462 // end of automation session (when mouse up), parameter index in <index>
465 case audioMasterOpenFileSelector:
466 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
467 // open a fileselector window with VstFileSelect* in <ptr>
471 SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode);