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/debug.h"
27 #include "ardour/session.h"
28 #include "ardour/tempo.h"
29 #include "ardour/plugin_insert.h"
30 #include "ardour/windows_vst_plugin.h"
31 #include "ardour/vestige/aeffectx.h"
32 #include "ardour/vst_types.h"
33 #ifdef WINDOWS_VST_SUPPORT
39 using namespace ARDOUR;
41 #define SHOW_CALLBACK(MSG) DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose (MSG " val = %1 idx = %2\n", index, value))
43 int Session::vst_current_loading_id = 0;
44 const char* Session::vst_can_do_strings[] = {
46 X_("sendVstTimeInfo"),
48 X_("sendVstMidiEvent"),
49 X_("receiveVstEvents"),
50 X_("receiveVstMidiEvent"),
53 X_("shellCategorycurID")
55 const int Session::vst_can_do_string_count = sizeof (vst_can_do_strings) / sizeof (char*);
57 intptr_t Session::vst_callback (
68 static VstTimeInfo _timeinfo; // only uses as fallback
69 VstTimeInfo* timeinfo;
72 if (effect && effect->ptr1) {
73 plug = (VSTPlugin *) (effect->ptr1);
74 session = &plug->session();
75 timeinfo = plug->timeinfo ();
76 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4, plugin = \"%5\"\n",
77 std::hex, (void*) DEBUG_THREAD_SELF,
78 std::dec, opcode, plug->name()));
82 timeinfo = &_timeinfo;
83 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4\n",
84 std::hex, (void*) DEBUG_THREAD_SELF,
90 case audioMasterAutomate:
91 SHOW_CALLBACK ("audioMasterAutomate");
92 // index, value, returns 0
94 plug->parameter_changed_externally (index, opt);
98 case audioMasterVersion:
99 SHOW_CALLBACK ("audioMasterVersion");
100 // vst version, currently 2 (0 for older)
103 case audioMasterCurrentId:
104 SHOW_CALLBACK ("audioMasterCurrentId");
105 // returns the unique id of a plug that's currently loading
106 return vst_current_loading_id;
108 case audioMasterIdle:
109 SHOW_CALLBACK ("audioMasterIdle");
110 #ifdef WINDOWS_VST_SUPPORT
111 fst_audio_master_idle();
114 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
118 case audioMasterPinConnected:
119 SHOW_CALLBACK ("audioMasterPinConnected");
120 // inquire if an input or output is beeing connected;
121 // index enumerates input or output counting from zero:
122 // value is 0 for input and != 0 otherwise. note: the
123 // return value is 0 for <true> such that older versions
124 // will always return true.
127 // but ardour always connects all buffers, so we're good
132 if (plug->plugin_insert ()) {
134 const ChanMapping& map (plug->plugin_insert ()->input_map (plug->plugin_number ()));
135 map.get (DataType::AUDIO, index, &valid);
136 return valid ? 0 : 1;
138 if (index < plug->plugin()->numInputs) {
143 #if 0 // investigate, the outputs *are* connected to scratch buffers
144 if (plug->plugin_insert ()) {
146 const ChanMapping& map (plug->plugin_insert ()->output_map (plug->plugin_number ()));
147 map.get (DataType::AUDIO, index, &valid);
148 return valid ? 0 : 1;
151 if (index < plug->plugin()->numOutputs) {
160 case audioMasterWantMidi:
161 SHOW_CALLBACK ("audioMasterWantMidi");
162 // <value> is a filter which is currently ignored
163 if (plug && plug->get_info() != NULL) {
164 plug->get_info()->n_inputs.set_midi (1);
168 case audioMasterGetTime:
169 SHOW_CALLBACK ("audioMasterGetTime");
170 newflags = kVstNanosValid | kVstAutomationWriting | kVstAutomationReading;
172 timeinfo->nanoSeconds = g_get_monotonic_time () * 1000;
174 if (plug && session) {
175 samplepos_t now = plug->transport_sample();
177 timeinfo->samplePos = now;
178 timeinfo->sampleRate = session->sample_rate();
180 if (value & (kVstTempoValid)) {
181 const Tempo& t (session->tempo_map().tempo_at_sample (now));
182 timeinfo->tempo = t.quarter_notes_per_minute ();
183 newflags |= (kVstTempoValid);
185 if (value & (kVstTimeSigValid)) {
186 const MeterSection& ms (session->tempo_map().meter_section_at_sample (now));
187 timeinfo->timeSigNumerator = ms.divisions_per_bar ();
188 timeinfo->timeSigDenominator = ms.note_divisor ();
189 newflags |= (kVstTimeSigValid);
191 if ((value & (kVstPpqPosValid)) || (value & (kVstBarsValid))) {
192 Timecode::BBT_Time bbt;
195 bbt = session->tempo_map().bbt_at_sample_rt (now);
198 /* exact quarter note */
199 double ppqBar = session->tempo_map().quarter_note_at_bbt_rt (bbt);
200 /* quarter note at sample position (not rounded to note subdivision) */
201 double ppqPos = session->tempo_map().quarter_note_at_sample_rt (now);
202 if (value & (kVstPpqPosValid)) {
203 timeinfo->ppqPos = ppqPos;
204 newflags |= kVstPpqPosValid;
207 if (value & (kVstBarsValid)) {
208 timeinfo->barStartPos = ppqBar;
209 newflags |= kVstBarsValid;
217 if (value & (kVstSmpteValid)) {
220 session->timecode_time (now, t);
222 timeinfo->smpteOffset = (t.hours * t.rate * 60.0 * 60.0) +
223 (t.minutes * t.rate * 60.0) +
224 (t.seconds * t.rate) +
228 timeinfo->smpteOffset *= 80.0; /* VST spec is 1/80th samples */
230 if (session->timecode_drop_frames()) {
231 if (session->timecode_frames_per_second() == 30.0) {
232 timeinfo->smpteFrameRate = 5;
234 timeinfo->smpteFrameRate = 4; /* 29.97 assumed, thanks VST */
237 if (session->timecode_frames_per_second() == 24.0) {
238 timeinfo->smpteFrameRate = 0;
239 } else if (session->timecode_frames_per_second() == 24.975) {
240 timeinfo->smpteFrameRate = 2;
241 } else if (session->timecode_frames_per_second() == 25.0) {
242 timeinfo->smpteFrameRate = 1;
244 timeinfo->smpteFrameRate = 3; /* 30 fps */
247 newflags |= (kVstSmpteValid);
250 if (session->actively_recording ()) {
251 newflags |= kVstTransportRecording;
254 if (plug->transport_speed () != 0.0f) {
255 newflags |= kVstTransportPlaying;
258 if (session->get_play_loop ()) {
259 newflags |= kVstTransportCycleActive;
260 Location * looploc = session->locations ()->auto_loop_location ();
262 timeinfo->cycleStartPos = session->tempo_map ().quarter_note_at_sample_rt (looploc->start ());
263 timeinfo->cycleEndPos = session->tempo_map ().quarter_note_at_sample_rt (looploc->end ());
265 newflags |= kVstCyclePosValid;
270 timeinfo->samplePos = 0;
271 timeinfo->sampleRate = AudioEngine::instance()->sample_rate();
274 if ((timeinfo->flags & (kVstTransportPlaying | kVstTransportRecording | kVstTransportCycleActive))
276 (newflags & (kVstTransportPlaying | kVstTransportRecording | kVstTransportCycleActive)))
278 newflags |= kVstTransportChanged;
281 timeinfo->flags = newflags;
282 return (intptr_t) timeinfo;
284 case audioMasterProcessEvents:
285 SHOW_CALLBACK ("audioMasterProcessEvents");
286 // VstEvents* in <ptr>
287 if (plug && plug->midi_buffer()) {
288 VstEvents* v = (VstEvents*)ptr;
289 for (int n = 0 ; n < v->numEvents; ++n) {
290 VstMidiEvent *vme = (VstMidiEvent*) (v->events[n]->dump);
291 if (vme->type == kVstMidiType) {
292 plug->midi_buffer()->push_back(vme->deltaSamples, 3, (uint8_t*)vme->midiData);
298 case audioMasterSetTime:
299 SHOW_CALLBACK ("audioMasterSetTime");
300 // VstTimenfo* in <ptr>, filter in <value>, not supported
302 case audioMasterTempoAt:
303 SHOW_CALLBACK ("audioMasterTempoAt");
304 // returns tempo (in bpm * 10000) at sample sample location passed in <value>
306 const Tempo& t (session->tempo_map().tempo_at_sample (value));
307 return t.quarter_notes_per_minute() * 1000;
313 case audioMasterGetNumAutomatableParameters:
314 SHOW_CALLBACK ("audioMasterGetNumAutomatableParameters");
317 case audioMasterGetParameterQuantization:
318 SHOW_CALLBACK ("audioMasterGetParameterQuantization");
319 // returns the integer value for +1.0 representation,
320 // or 1 if full single float precision is maintained
321 // in automation. parameter index in <value> (-1: all, any)
324 case audioMasterIOChanged:
325 SHOW_CALLBACK ("audioMasterIOChanged");
326 // numInputs and/or numOutputs has changed
329 case audioMasterNeedIdle:
330 SHOW_CALLBACK ("audioMasterNeedIdle");
331 // plug needs idle calls (outside its editor window)
333 plug->state()->wantIdle = 1;
337 case audioMasterSizeWindow:
338 SHOW_CALLBACK ("audioMasterSizeWindow");
339 if (plug && plug->state()) {
340 if (plug->state()->width != index || plug->state()->height != value) {
341 plug->state()->width = index;
342 plug->state()->height = value;
344 printf ("audioMasterSizeWindow %d %d\n", plug->state()->width, plug->state()->height);
346 plug->VSTSizeWindow (); /* EMIT SIGNAL */
351 case audioMasterGetSampleRate:
352 SHOW_CALLBACK ("audioMasterGetSampleRate");
354 return session->sample_rate();
358 case audioMasterGetBlockSize:
359 SHOW_CALLBACK ("audioMasterGetBlockSize");
361 return session->get_block_size();
365 case audioMasterGetInputLatency:
366 SHOW_CALLBACK ("audioMasterGetInputLatency");
369 case audioMasterGetOutputLatency:
370 SHOW_CALLBACK ("audioMasterGetOutputLatency");
373 case audioMasterGetPreviousPlug:
374 SHOW_CALLBACK ("audioMasterGetPreviousPlug");
375 // input pin in <value> (-1: first to come), returns cEffect*
378 case audioMasterGetNextPlug:
379 SHOW_CALLBACK ("audioMasterGetNextPlug");
380 // output pin in <value> (-1: first to come), returns cEffect*
382 case audioMasterWillReplaceOrAccumulate:
383 SHOW_CALLBACK ("audioMasterWillReplaceOrAccumulate");
384 // returns: 0: not supported, 1: replace, 2: accumulate
387 case audioMasterGetCurrentProcessLevel:
388 SHOW_CALLBACK ("audioMasterGetCurrentProcessLevel");
389 // returns: 0: not supported,
390 // 1: currently in user thread (gui)
391 // 2: currently in audio thread (where process is called)
392 // 3: currently in 'sequencer' thread (midi, timer etc)
393 // 4: currently offline processing and thus in user thread
394 // other: not defined, but probably pre-empting user thread.
397 case audioMasterGetAutomationState:
398 SHOW_CALLBACK ("audioMasterGetAutomationState");
399 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
403 case audioMasterOfflineStart:
404 SHOW_CALLBACK ("audioMasterOfflineStart");
407 case audioMasterOfflineRead:
408 SHOW_CALLBACK ("audioMasterOfflineRead");
409 // ptr points to offline structure, see below. return 0: error, 1 ok
412 case audioMasterOfflineWrite:
413 SHOW_CALLBACK ("audioMasterOfflineWrite");
417 case audioMasterOfflineGetCurrentPass:
418 SHOW_CALLBACK ("audioMasterOfflineGetCurrentPass");
421 case audioMasterOfflineGetCurrentMetaPass:
422 SHOW_CALLBACK ("audioMasterOfflineGetCurrentMetaPass");
425 case audioMasterSetOutputSampleRate:
426 SHOW_CALLBACK ("audioMasterSetOutputSampleRate");
427 // for variable i/o, sample rate in <opt>
430 case audioMasterGetSpeakerArrangement:
431 SHOW_CALLBACK ("audioMasterGetSpeakerArrangement");
432 // (long)input in <value>, output in <ptr>
435 case audioMasterGetVendorString:
436 SHOW_CALLBACK ("audioMasterGetVendorString");
437 // fills <ptr> with a string identifying the vendor (max 64 char)
438 strcpy ((char*) ptr, "Linux Audio Systems");
441 case audioMasterGetProductString:
442 SHOW_CALLBACK ("audioMasterGetProductString");
443 // fills <ptr> with a string with product name (max 64 char)
444 strcpy ((char*) ptr, PROGRAM_NAME);
447 case audioMasterGetVendorVersion:
448 SHOW_CALLBACK ("audioMasterGetVendorVersion");
449 // returns vendor-specific version
452 case audioMasterVendorSpecific:
453 SHOW_CALLBACK ("audioMasterVendorSpecific");
454 // no definition, vendor specific handling
457 case audioMasterSetIcon:
458 SHOW_CALLBACK ("audioMasterSetIcon");
459 // void* in <ptr>, format not defined yet
462 case audioMasterCanDo:
463 SHOW_CALLBACK ("audioMasterCanDo");
464 // string in ptr, (const char*)ptr
465 for (int i = 0; i < vst_can_do_string_count; i++) {
466 if (! strcmp(vst_can_do_strings[i], (const char*)ptr)) {
472 case audioMasterGetLanguage:
473 SHOW_CALLBACK ("audioMasterGetLanguage");
477 case audioMasterOpenWindow:
478 SHOW_CALLBACK ("audioMasterOpenWindow");
479 // returns platform specific ptr
482 case audioMasterCloseWindow:
483 SHOW_CALLBACK ("audioMasterCloseWindow");
484 // close window, platform specific handle in <ptr>
487 case audioMasterGetDirectory:
488 SHOW_CALLBACK ("audioMasterGetDirectory");
489 // get plug directory, FSSpec on MAC, else char*
492 case audioMasterUpdateDisplay:
493 SHOW_CALLBACK ("audioMasterUpdateDisplay");
494 // something has changed, update 'multi-fx' display
496 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
500 case audioMasterBeginEdit:
501 SHOW_CALLBACK ("audioMasterBeginEdit");
502 // begin of automation session (when mouse down), parameter index in <index>
505 case audioMasterEndEdit:
506 SHOW_CALLBACK ("audioMasterEndEdit");
507 // end of automation session (when mouse up), parameter index in <index>
510 case audioMasterOpenFileSelector:
511 SHOW_CALLBACK ("audioMasterOpenFileSelector");
512 // open a fileselector window with VstFileSelect* in <ptr>
516 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("VST master dispatcher: undefed: %1\n", opcode));