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"
31 #ifdef WINDOWS_VST_SUPPORT
37 #define DEBUG_CALLBACKS
38 static int debug_callbacks = -1;
40 #ifdef DEBUG_CALLBACKS
41 #define SHOW_CALLBACK if (debug_callbacks) printf
43 #define SHOW_CALLBACK(...)
46 using namespace ARDOUR;
48 int Session::vst_current_loading_id = 0;
49 const char* Session::vst_can_do_strings[] = {
51 X_("sendVstTimeInfo"),
55 const int Session::vst_can_do_string_count = sizeof (vst_can_do_strings) / sizeof (char*);
57 intptr_t Session::vst_callback (
66 static VstTimeInfo _timeInfo;
70 if (debug_callbacks < 0) {
71 debug_callbacks = (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0);
74 if (effect && effect->user) {
75 plug = (VSTPlugin *) (effect->user);
76 session = &plug->session();
78 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self().p, opcode, plug->name());
80 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self(), opcode, plug->name());
86 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self().p, opcode);
88 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self(), opcode);
94 case audioMasterAutomate:
95 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
96 // index, value, returns 0
98 plug->set_parameter (index, opt);
102 case audioMasterVersion:
103 SHOW_CALLBACK ("amc: audioMasterVersion\n");
104 // vst version, currently 2 (0 for older)
107 case audioMasterCurrentId:
108 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
109 // returns the unique id of a plug that's currently loading
110 return vst_current_loading_id;
112 case audioMasterIdle:
113 SHOW_CALLBACK ("amc: audioMasterIdle\n");
114 #ifdef WINDOWS_VST_SUPPORT
115 fst_audio_master_idle();
118 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
122 case audioMasterPinConnected:
123 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
124 // inquire if an input or output is beeing connected;
125 // index enumerates input or output counting from zero:
126 // value is 0 for input and != 0 otherwise. note: the
127 // return value is 0 for <true> such that older versions
128 // will always return true.
131 case audioMasterWantMidi:
132 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
133 // <value> is a filter which is currently ignored
135 plug->get_info()->n_inputs.set_midi (1);
139 case audioMasterGetTime:
140 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
141 // returns const VstTimeInfo* (or 0 if not supported)
142 // <value> should contain a mask indicating which fields are required
143 // (see valid masks above), as some items may require extensive
148 framepos_t now = session->transport_frame();
150 _timeInfo.samplePos = now;
151 _timeInfo.sampleRate = session->frame_rate();
153 const TempoMetric& tm (session->tempo_map().metric_at (now));
155 if (value & (kVstTempoValid)) {
156 const Tempo& t (tm.tempo());
157 _timeInfo.tempo = t.beats_per_minute ();
158 _timeInfo.flags |= (kVstTempoValid);
160 if (value & (kVstTimeSigValid)) {
161 const Meter& m (tm.meter());
162 _timeInfo.timeSigNumerator = m.divisions_per_bar ();
163 _timeInfo.timeSigDenominator = m.note_divisor ();
164 _timeInfo.flags |= (kVstTimeSigValid);
166 if ((value & (kVstPpqPosValid)) || (value & (kVstBarsValid))) {
167 Timecode::BBT_Time bbt;
170 session->tempo_map().bbt_time_rt (now, bbt);
172 /* PPQ = pulse per quarter
173 * VST's "pulse" is our "division".
175 * 8 divisions per bar, 1 division = quarter, so 8 quarters per bar, ppq = 1
176 * 8 divisions per bar, 1 division = eighth, so 4 quarters per bar, ppq = 2
177 * 4 divisions per bar, 1 division = quarter, so 4 quarters per bar, ppq = 1
178 * 4 divisions per bar, 1 division = half, so 8 quarters per bar, ppq = 0.5
179 * 4 divisions per bar, 1 division = fifth, so (4 * 5/4) quarters per bar, ppq = 5/4
181 * general: divs_per_bar / (note_type / 4.0)
183 double ppq_scaling = tm.meter().note_divisor() / 4.0;
185 /* Note that this assumes constant meter/tempo throughout the session. Stupid VST */
186 double ppqBar = double(bbt.bars - 1) * tm.meter().divisions_per_bar();
187 double ppqBeat = double(bbt.beats - 1);
188 double ppqTick = double(bbt.ticks) / Timecode::BBT_Time::ticks_per_beat;
190 ppqBar *= ppq_scaling;
191 ppqBeat *= ppq_scaling;
192 ppqTick *= ppq_scaling;
194 if (value & (kVstPpqPosValid)) {
195 _timeInfo.ppqPos = ppqBar + ppqBeat + ppqTick;
196 _timeInfo.flags |= (kVstPpqPosValid);
199 if (value & (kVstBarsValid)) {
200 _timeInfo.barStartPos = ppqBar;
201 _timeInfo.flags |= (kVstBarsValid);
209 if (value & (kVstSmpteValid)) {
212 session->timecode_time (now, t);
214 _timeInfo.smpteOffset = (t.hours * t.rate * 60.0 * 60.0) +
215 (t.minutes * t.rate * 60.0) +
216 (t.seconds * t.rate) +
220 _timeInfo.smpteOffset *= 80.0; /* VST spec is 1/80th frames */
222 if (session->timecode_drop_frames()) {
223 if (session->timecode_frames_per_second() == 30.0) {
224 _timeInfo.smpteFrameRate = 5;
226 _timeInfo.smpteFrameRate = 4; /* 29.97 assumed, thanks VST */
229 if (session->timecode_frames_per_second() == 24.0) {
230 _timeInfo.smpteFrameRate = 0;
231 } else if (session->timecode_frames_per_second() == 24.975) {
232 _timeInfo.smpteFrameRate = 2;
233 } else if (session->timecode_frames_per_second() == 25.0) {
234 _timeInfo.smpteFrameRate = 1;
236 _timeInfo.smpteFrameRate = 3; /* 30 fps */
239 _timeInfo.flags |= (kVstSmpteValid);
242 if (session->transport_speed() != 0.0f) {
243 _timeInfo.flags |= (kVstTransportPlaying);
246 if (session->get_play_loop()) {
250 _timeInfo.samplePos = 0;
251 _timeInfo.sampleRate = AudioEngine::instance()->sample_rate();
254 return (intptr_t) &_timeInfo;
256 case audioMasterProcessEvents:
257 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
258 // VstEvents* in <ptr>
261 case audioMasterSetTime:
262 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
263 // VstTimenfo* in <ptr>, filter in <value>, not supported
265 case audioMasterTempoAt:
266 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
267 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
269 const Tempo& t (session->tempo_map().tempo_at (value));
270 return t.beats_per_minute() * 1000;
276 case audioMasterGetNumAutomatableParameters:
277 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
280 case audioMasterGetParameterQuantization:
281 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
282 // returns the integer value for +1.0 representation,
283 // or 1 if full single float precision is maintained
284 // in automation. parameter index in <value> (-1: all, any)
287 case audioMasterIOChanged:
288 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
289 // numInputs and/or numOutputs has changed
292 case audioMasterNeedIdle:
293 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
294 // plug needs idle calls (outside its editor window)
296 plug->state()->wantIdle = 1;
300 case audioMasterSizeWindow:
301 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
302 // index: width, value: height
305 case audioMasterGetSampleRate:
306 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
308 return session->frame_rate();
312 case audioMasterGetBlockSize:
313 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
315 return session->get_block_size();
319 case audioMasterGetInputLatency:
320 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
323 case audioMasterGetOutputLatency:
324 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
327 case audioMasterGetPreviousPlug:
328 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
329 // input pin in <value> (-1: first to come), returns cEffect*
332 case audioMasterGetNextPlug:
333 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
334 // output pin in <value> (-1: first to come), returns cEffect*
336 case audioMasterWillReplaceOrAccumulate:
337 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
338 // returns: 0: not supported, 1: replace, 2: accumulate
341 case audioMasterGetCurrentProcessLevel:
342 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
343 // returns: 0: not supported,
344 // 1: currently in user thread (gui)
345 // 2: currently in audio thread (where process is called)
346 // 3: currently in 'sequencer' thread (midi, timer etc)
347 // 4: currently offline processing and thus in user thread
348 // other: not defined, but probably pre-empting user thread.
351 case audioMasterGetAutomationState:
352 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
353 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
357 case audioMasterOfflineStart:
358 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
361 case audioMasterOfflineRead:
362 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
363 // ptr points to offline structure, see below. return 0: error, 1 ok
366 case audioMasterOfflineWrite:
367 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
371 case audioMasterOfflineGetCurrentPass:
372 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
375 case audioMasterOfflineGetCurrentMetaPass:
376 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
379 case audioMasterSetOutputSampleRate:
380 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
381 // for variable i/o, sample rate in <opt>
384 case audioMasterGetSpeakerArrangement:
385 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
386 // (long)input in <value>, output in <ptr>
389 case audioMasterGetVendorString:
390 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
391 // fills <ptr> with a string identifying the vendor (max 64 char)
392 strcpy ((char*) ptr, "Linux Audio Systems");
395 case audioMasterGetProductString:
396 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
397 // fills <ptr> with a string with product name (max 64 char)
398 strcpy ((char*) ptr, PROGRAM_NAME);
401 case audioMasterGetVendorVersion:
402 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
403 // returns vendor-specific version
406 case audioMasterVendorSpecific:
407 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
408 // no definition, vendor specific handling
411 case audioMasterSetIcon:
412 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
413 // void* in <ptr>, format not defined yet
416 case audioMasterCanDo:
417 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
418 // string in ptr, (const char*)ptr
419 for (int i = 0; i < vst_can_do_string_count; i++) {
420 if (! strcmp(vst_can_do_strings[i], (const char*)ptr)) {
426 case audioMasterGetLanguage:
427 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
431 case audioMasterOpenWindow:
432 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
433 // returns platform specific ptr
436 case audioMasterCloseWindow:
437 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
438 // close window, platform specific handle in <ptr>
441 case audioMasterGetDirectory:
442 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
443 // get plug directory, FSSpec on MAC, else char*
446 case audioMasterUpdateDisplay:
447 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
448 // something has changed, update 'multi-fx' display
450 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
454 case audioMasterBeginEdit:
455 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
456 // begin of automation session (when mouse down), parameter index in <index>
459 case audioMasterEndEdit:
460 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
461 // end of automation session (when mouse up), parameter index in <index>
464 case audioMasterOpenFileSelector:
465 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
466 // open a fileselector window with VstFileSelect* in <ptr>
470 SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode);