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
35 #include "pbd/debug.h"
39 #define DEBUG_CALLBACKS
40 static int debug_callbacks = -1;
42 #ifdef DEBUG_CALLBACKS
43 #define SHOW_CALLBACK if (debug_callbacks) printf
45 #define SHOW_CALLBACK(...)
48 using namespace ARDOUR;
50 int Session::vst_current_loading_id = 0;
51 const char* Session::vst_can_do_strings[] = {
53 X_("sendVstTimeInfo"),
55 X_("sendVstMidiEvent"),
56 X_("receiveVstEvents"),
57 X_("receiveVstMidiEvent"),
60 X_("shellCategorycurID")
62 const int Session::vst_can_do_string_count = sizeof (vst_can_do_strings) / sizeof (char*);
64 intptr_t Session::vst_callback (
73 static VstTimeInfo _timeInfo;
77 if (debug_callbacks < 0) {
78 debug_callbacks = (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0);
81 if (effect && effect->user) {
82 plug = (VSTPlugin *) (effect->user);
83 session = &plug->session();
84 SHOW_CALLBACK ("am callback 0x%p, opcode = %d, plugin = \"%s\" ", (void*) DEBUG_THREAD_SELF, opcode, plug->name());
88 SHOW_CALLBACK ("am callback 0x%p, opcode = %d", (void*) DEBUG_THREAD_SELF, opcode);
93 case audioMasterAutomate:
94 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
95 // index, value, returns 0
97 plug->set_parameter (index, opt);
101 case audioMasterVersion:
102 SHOW_CALLBACK ("amc: audioMasterVersion\n");
103 // vst version, currently 2 (0 for older)
106 case audioMasterCurrentId:
107 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
108 // returns the unique id of a plug that's currently loading
109 return vst_current_loading_id;
111 case audioMasterIdle:
112 SHOW_CALLBACK ("amc: audioMasterIdle\n");
113 #ifdef WINDOWS_VST_SUPPORT
114 fst_audio_master_idle();
117 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
121 case audioMasterPinConnected:
122 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
123 // inquire if an input or output is beeing connected;
124 // index enumerates input or output counting from zero:
125 // value is 0 for input and != 0 otherwise. note: the
126 // return value is 0 for <true> such that older versions
127 // will always return true.
133 if (index < plug->numInputs) {
138 if (index < plug->numOutputs) {
147 case audioMasterWantMidi:
148 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
149 // <value> is a filter which is currently ignored
150 if (plug && plug->get_info() != NULL) {
151 plug->get_info()->n_inputs.set_midi (1);
155 case audioMasterGetTime:
156 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
157 // returns const VstTimeInfo* (or 0 if not supported)
158 // <value> should contain a mask indicating which fields are required
159 // (see valid masks above), as some items may require extensive
164 framepos_t now = session->transport_frame();
166 _timeInfo.samplePos = now;
167 _timeInfo.sampleRate = session->frame_rate();
169 const TempoMetric& tm (session->tempo_map().metric_at (now));
171 if (value & (kVstTempoValid)) {
172 const Tempo& t (tm.tempo());
173 _timeInfo.tempo = t.beats_per_minute ();
174 _timeInfo.flags |= (kVstTempoValid);
176 if (value & (kVstTimeSigValid)) {
177 const Meter& m (tm.meter());
178 _timeInfo.timeSigNumerator = m.divisions_per_bar ();
179 _timeInfo.timeSigDenominator = m.note_divisor ();
180 _timeInfo.flags |= (kVstTimeSigValid);
182 if ((value & (kVstPpqPosValid)) || (value & (kVstBarsValid))) {
183 Timecode::BBT_Time bbt;
186 session->tempo_map().bbt_time_rt (now, bbt);
188 /* PPQ = pulse per quarter
189 * VST's "pulse" is our "division".
191 * 8 divisions per bar, 1 division = quarter, so 8 quarters per bar, ppq = 1
192 * 8 divisions per bar, 1 division = eighth, so 4 quarters per bar, ppq = 2
193 * 4 divisions per bar, 1 division = quarter, so 4 quarters per bar, ppq = 1
194 * 4 divisions per bar, 1 division = half, so 8 quarters per bar, ppq = 0.5
195 * 4 divisions per bar, 1 division = fifth, so (4 * 5/4) quarters per bar, ppq = 5/4
197 * general: divs_per_bar / (note_type / 4.0)
199 double ppq_scaling = tm.meter().note_divisor() / 4.0;
201 /* Note that this assumes constant meter/tempo throughout the session. Stupid VST */
202 double ppqBar = double(bbt.bars - 1) * tm.meter().divisions_per_bar();
203 double ppqBeat = double(bbt.beats - 1);
204 double ppqTick = double(bbt.ticks) / Timecode::BBT_Time::ticks_per_beat;
206 ppqBar *= ppq_scaling;
207 ppqBeat *= ppq_scaling;
208 ppqTick *= ppq_scaling;
210 if (value & (kVstPpqPosValid)) {
211 _timeInfo.ppqPos = ppqBar + ppqBeat + ppqTick;
212 _timeInfo.flags |= (kVstPpqPosValid);
215 if (value & (kVstBarsValid)) {
216 _timeInfo.barStartPos = ppqBar;
217 _timeInfo.flags |= (kVstBarsValid);
225 if (value & (kVstSmpteValid)) {
228 session->timecode_time (now, t);
230 _timeInfo.smpteOffset = (t.hours * t.rate * 60.0 * 60.0) +
231 (t.minutes * t.rate * 60.0) +
232 (t.seconds * t.rate) +
236 _timeInfo.smpteOffset *= 80.0; /* VST spec is 1/80th frames */
238 if (session->timecode_drop_frames()) {
239 if (session->timecode_frames_per_second() == 30.0) {
240 _timeInfo.smpteFrameRate = 5;
242 _timeInfo.smpteFrameRate = 4; /* 29.97 assumed, thanks VST */
245 if (session->timecode_frames_per_second() == 24.0) {
246 _timeInfo.smpteFrameRate = 0;
247 } else if (session->timecode_frames_per_second() == 24.975) {
248 _timeInfo.smpteFrameRate = 2;
249 } else if (session->timecode_frames_per_second() == 25.0) {
250 _timeInfo.smpteFrameRate = 1;
252 _timeInfo.smpteFrameRate = 3; /* 30 fps */
255 _timeInfo.flags |= (kVstSmpteValid);
258 if (session->transport_speed() != 0.0f) {
259 _timeInfo.flags |= (kVstTransportPlaying);
262 if (session->get_play_loop()) {
266 _timeInfo.samplePos = 0;
267 _timeInfo.sampleRate = AudioEngine::instance()->sample_rate();
270 return (intptr_t) &_timeInfo;
272 case audioMasterProcessEvents:
273 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
274 // VstEvents* in <ptr>
275 if (plug && plug->midi_buffer()) {
276 VstEvents* v = (VstEvents*)ptr;
277 for (int n = 0 ; n < v->numEvents; ++n) {
278 VstMidiEvent *vme = (VstMidiEvent*) (v->events[n]->dump);
279 if (vme->type == kVstMidiType) {
280 plug->midi_buffer()->push_back(vme->deltaFrames, 3, (uint8_t*)vme->midiData);
286 case audioMasterSetTime:
287 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
288 // VstTimenfo* in <ptr>, filter in <value>, not supported
290 case audioMasterTempoAt:
291 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
292 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
294 const Tempo& t (session->tempo_map().tempo_at (value));
295 return t.beats_per_minute() * 1000;
301 case audioMasterGetNumAutomatableParameters:
302 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
305 case audioMasterGetParameterQuantization:
306 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
307 // returns the integer value for +1.0 representation,
308 // or 1 if full single float precision is maintained
309 // in automation. parameter index in <value> (-1: all, any)
312 case audioMasterIOChanged:
313 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
314 // numInputs and/or numOutputs has changed
317 case audioMasterNeedIdle:
318 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
319 // plug needs idle calls (outside its editor window)
321 plug->state()->wantIdle = 1;
325 case audioMasterSizeWindow:
326 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
327 // index: width, value: height
330 case audioMasterGetSampleRate:
331 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
333 return session->frame_rate();
337 case audioMasterGetBlockSize:
338 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
340 return session->get_block_size();
344 case audioMasterGetInputLatency:
345 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
348 case audioMasterGetOutputLatency:
349 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
352 case audioMasterGetPreviousPlug:
353 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
354 // input pin in <value> (-1: first to come), returns cEffect*
357 case audioMasterGetNextPlug:
358 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
359 // output pin in <value> (-1: first to come), returns cEffect*
361 case audioMasterWillReplaceOrAccumulate:
362 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
363 // returns: 0: not supported, 1: replace, 2: accumulate
366 case audioMasterGetCurrentProcessLevel:
367 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
368 // returns: 0: not supported,
369 // 1: currently in user thread (gui)
370 // 2: currently in audio thread (where process is called)
371 // 3: currently in 'sequencer' thread (midi, timer etc)
372 // 4: currently offline processing and thus in user thread
373 // other: not defined, but probably pre-empting user thread.
376 case audioMasterGetAutomationState:
377 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
378 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
382 case audioMasterOfflineStart:
383 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
386 case audioMasterOfflineRead:
387 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
388 // ptr points to offline structure, see below. return 0: error, 1 ok
391 case audioMasterOfflineWrite:
392 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
396 case audioMasterOfflineGetCurrentPass:
397 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
400 case audioMasterOfflineGetCurrentMetaPass:
401 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
404 case audioMasterSetOutputSampleRate:
405 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
406 // for variable i/o, sample rate in <opt>
409 case audioMasterGetSpeakerArrangement:
410 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
411 // (long)input in <value>, output in <ptr>
414 case audioMasterGetVendorString:
415 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
416 // fills <ptr> with a string identifying the vendor (max 64 char)
417 strcpy ((char*) ptr, "Linux Audio Systems");
420 case audioMasterGetProductString:
421 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
422 // fills <ptr> with a string with product name (max 64 char)
423 strcpy ((char*) ptr, PROGRAM_NAME);
426 case audioMasterGetVendorVersion:
427 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
428 // returns vendor-specific version
431 case audioMasterVendorSpecific:
432 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
433 // no definition, vendor specific handling
436 case audioMasterSetIcon:
437 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
438 // void* in <ptr>, format not defined yet
441 case audioMasterCanDo:
442 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
443 // string in ptr, (const char*)ptr
444 for (int i = 0; i < vst_can_do_string_count; i++) {
445 if (! strcmp(vst_can_do_strings[i], (const char*)ptr)) {
451 case audioMasterGetLanguage:
452 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
456 case audioMasterOpenWindow:
457 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
458 // returns platform specific ptr
461 case audioMasterCloseWindow:
462 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
463 // close window, platform specific handle in <ptr>
466 case audioMasterGetDirectory:
467 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
468 // get plug directory, FSSpec on MAC, else char*
471 case audioMasterUpdateDisplay:
472 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
473 // something has changed, update 'multi-fx' display
475 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
479 case audioMasterBeginEdit:
480 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
481 // begin of automation session (when mouse down), parameter index in <index>
484 case audioMasterEndEdit:
485 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
486 // end of automation session (when mouse up), parameter index in <index>
489 case audioMasterOpenFileSelector:
490 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
491 // open a fileselector window with VstFileSelect* in <ptr>
495 SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode);