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/vestige.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"),
56 const int Session::vst_can_do_string_count = sizeof (vst_can_do_strings) / sizeof (char*);
58 intptr_t Session::vst_callback (
69 static VstTimeInfo _timeinfo; // only uses as fallback
70 VstTimeInfo* timeinfo;
73 if (effect && effect->ptr1) {
74 plug = (VSTPlugin *) (effect->ptr1);
75 session = &plug->session();
76 timeinfo = plug->timeinfo ();
77 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4, plugin = \"%5\"\n",
78 std::hex, (void*) DEBUG_THREAD_SELF,
79 std::dec, opcode, plug->name()));
80 if (plug->_for_impulse_analysis) {
86 timeinfo = &_timeinfo;
87 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4\n",
88 std::hex, (void*) DEBUG_THREAD_SELF,
94 case audioMasterAutomate:
95 SHOW_CALLBACK ("audioMasterAutomate");
96 // index, value, returns 0
98 plug->parameter_changed_externally (index, opt);
102 case audioMasterVersion:
103 SHOW_CALLBACK ("audioMasterVersion");
104 // vst version, currently 2 (0 for older)
107 case audioMasterCurrentId:
108 SHOW_CALLBACK ("audioMasterCurrentId");
109 // returns the unique id of a plug that's currently loading
110 return vst_current_loading_id;
112 case audioMasterIdle:
113 SHOW_CALLBACK ("audioMasterIdle");
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 ("audioMasterPinConnected");
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 // but ardour always connects all buffers, so we're good
136 if (plug->plugin_insert ()) {
138 const ChanMapping& map (plug->plugin_insert ()->input_map (plug->plugin_number ()));
139 map.get (DataType::AUDIO, index, &valid);
140 return valid ? 0 : 1;
142 if (index < plug->plugin()->numInputs) {
147 #if 0 // investigate, the outputs *are* connected to scratch buffers
148 if (plug->plugin_insert ()) {
150 const ChanMapping& map (plug->plugin_insert ()->output_map (plug->plugin_number ()));
151 map.get (DataType::AUDIO, index, &valid);
152 return valid ? 0 : 1;
155 if (index < plug->plugin()->numOutputs) {
164 case audioMasterWantMidi:
165 SHOW_CALLBACK ("audioMasterWantMidi");
166 // <value> is a filter which is currently ignored
167 if (plug && plug->get_info() != NULL) {
168 plug->get_info()->n_inputs.set_midi (1);
172 case audioMasterGetTime:
173 SHOW_CALLBACK ("audioMasterGetTime");
174 newflags = kVstNanosValid | kVstAutomationWriting | kVstAutomationReading;
176 timeinfo->nanoSeconds = g_get_monotonic_time () * 1000;
178 if (plug && session) {
179 samplepos_t now = plug->transport_sample();
181 timeinfo->samplePos = now;
182 timeinfo->sampleRate = session->sample_rate();
184 if (value & (kVstTempoValid)) {
185 const Tempo& t (session->tempo_map().tempo_at_sample (now));
186 timeinfo->tempo = t.quarter_notes_per_minute ();
187 newflags |= (kVstTempoValid);
189 if (value & (kVstTimeSigValid)) {
190 const MeterSection& ms (session->tempo_map().meter_section_at_sample (now));
191 timeinfo->timeSigNumerator = ms.divisions_per_bar ();
192 timeinfo->timeSigDenominator = ms.note_divisor ();
193 newflags |= (kVstTimeSigValid);
195 if ((value & (kVstPpqPosValid)) || (value & (kVstBarsValid))) {
196 Timecode::BBT_Time bbt;
199 bbt = session->tempo_map().bbt_at_sample_rt (now);
202 /* exact quarter note */
203 double ppqBar = session->tempo_map().quarter_note_at_bbt_rt (bbt);
204 /* quarter note at sample position (not rounded to note subdivision) */
205 double ppqPos = session->tempo_map().quarter_note_at_sample_rt (now);
206 if (value & (kVstPpqPosValid)) {
207 timeinfo->ppqPos = ppqPos;
208 newflags |= kVstPpqPosValid;
211 if (value & (kVstBarsValid)) {
212 timeinfo->barStartPos = ppqBar;
213 newflags |= kVstBarsValid;
221 if (value & (kVstSmpteValid)) {
224 session->timecode_time (now, t);
226 timeinfo->smpteOffset = (t.hours * t.rate * 60.0 * 60.0) +
227 (t.minutes * t.rate * 60.0) +
228 (t.seconds * t.rate) +
232 timeinfo->smpteOffset *= 80.0; /* VST spec is 1/80th samples */
234 if (session->timecode_drop_frames()) {
235 if (session->timecode_frames_per_second() == 30.0) {
236 timeinfo->smpteFrameRate = 5;
238 timeinfo->smpteFrameRate = 4; /* 29.97 assumed, thanks VST */
241 if (session->timecode_frames_per_second() == 24.0) {
242 timeinfo->smpteFrameRate = 0;
243 } else if (session->timecode_frames_per_second() == 24.975) {
244 timeinfo->smpteFrameRate = 2;
245 } else if (session->timecode_frames_per_second() == 25.0) {
246 timeinfo->smpteFrameRate = 1;
248 timeinfo->smpteFrameRate = 3; /* 30 fps */
251 newflags |= (kVstSmpteValid);
254 if (session->actively_recording ()) {
255 newflags |= kVstTransportRecording;
258 if (plug->transport_speed () != 0.0f) {
259 newflags |= kVstTransportPlaying;
262 if (session->get_play_loop ()) {
263 newflags |= kVstTransportCycleActive;
264 Location * looploc = session->locations ()->auto_loop_location ();
266 timeinfo->cycleStartPos = session->tempo_map ().quarter_note_at_sample_rt (looploc->start ());
267 timeinfo->cycleEndPos = session->tempo_map ().quarter_note_at_sample_rt (looploc->end ());
269 newflags |= kVstCyclePosValid;
274 timeinfo->samplePos = 0;
275 timeinfo->sampleRate = AudioEngine::instance()->sample_rate();
278 if ((timeinfo->flags & (kVstTransportPlaying | kVstTransportRecording | kVstTransportCycleActive))
280 (newflags & (kVstTransportPlaying | kVstTransportRecording | kVstTransportCycleActive)))
282 newflags |= kVstTransportChanged;
285 timeinfo->flags = newflags;
286 return (intptr_t) timeinfo;
288 case audioMasterProcessEvents:
289 SHOW_CALLBACK ("audioMasterProcessEvents");
290 // VstEvents* in <ptr>
291 if (plug && plug->midi_buffer()) {
292 VstEvents* v = (VstEvents*)ptr;
293 for (int n = 0 ; n < v->numEvents; ++n) {
294 VstMidiEvent *vme = (VstMidiEvent*) (v->events[n]->dump);
295 if (vme->type == kVstMidiType) {
296 plug->midi_buffer()->push_back(vme->deltaSamples, 3, (uint8_t*)vme->midiData);
302 case audioMasterSetTime:
303 SHOW_CALLBACK ("audioMasterSetTime");
304 // VstTimenfo* in <ptr>, filter in <value>, not supported
307 case audioMasterTempoAt:
308 SHOW_CALLBACK ("audioMasterTempoAt");
309 // returns tempo (in bpm * 10000) at sample sample location passed in <value>
311 const Tempo& t (session->tempo_map().tempo_at_sample (value));
312 return t.quarter_notes_per_minute() * 1000;
318 case audioMasterGetNumAutomatableParameters:
319 SHOW_CALLBACK ("audioMasterGetNumAutomatableParameters");
322 case audioMasterGetParameterQuantization:
323 SHOW_CALLBACK ("audioMasterGetParameterQuantization");
324 // returns the integer value for +1.0 representation,
325 // or 1 if full single float precision is maintained
326 // in automation. parameter index in <value> (-1: all, any)
329 case audioMasterIOChanged:
330 SHOW_CALLBACK ("audioMasterIOChanged");
331 // numInputs and/or numOutputs has changed
334 case audioMasterNeedIdle:
335 SHOW_CALLBACK ("audioMasterNeedIdle");
336 // plug needs idle calls (outside its editor window)
338 plug->state()->wantIdle = 1;
342 case audioMasterSizeWindow:
343 SHOW_CALLBACK ("audioMasterSizeWindow");
344 if (plug && plug->state()) {
345 if (plug->state()->width != index || plug->state()->height != value) {
346 plug->state()->width = index;
347 plug->state()->height = value;
349 printf ("audioMasterSizeWindow %d %d\n", plug->state()->width, plug->state()->height);
351 plug->VSTSizeWindow (); /* EMIT SIGNAL */
356 case audioMasterGetSampleRate:
357 SHOW_CALLBACK ("audioMasterGetSampleRate");
359 return session->sample_rate();
363 case audioMasterGetBlockSize:
364 SHOW_CALLBACK ("audioMasterGetBlockSize");
366 return session->get_block_size();
370 case audioMasterGetInputLatency:
371 SHOW_CALLBACK ("audioMasterGetInputLatency");
374 case audioMasterGetOutputLatency:
375 SHOW_CALLBACK ("audioMasterGetOutputLatency");
378 case audioMasterGetPreviousPlug:
379 SHOW_CALLBACK ("audioMasterGetPreviousPlug");
380 // input pin in <value> (-1: first to come), returns cEffect*
383 case audioMasterGetNextPlug:
384 SHOW_CALLBACK ("audioMasterGetNextPlug");
385 // output pin in <value> (-1: first to come), returns cEffect*
388 case audioMasterWillReplaceOrAccumulate:
389 SHOW_CALLBACK ("audioMasterWillReplaceOrAccumulate");
390 // returns: 0: not supported, 1: replace, 2: accumulate
393 case audioMasterGetCurrentProcessLevel:
394 SHOW_CALLBACK ("audioMasterGetCurrentProcessLevel");
395 // returns: 0: not supported,
396 // 1: currently in user thread (gui)
397 // 2: currently in audio thread (where process is called)
398 // 3: currently in 'sequencer' thread (midi, timer etc)
399 // 4: currently offline processing and thus in user thread
400 // other: not defined, but probably pre-empting user thread.
403 case audioMasterGetAutomationState:
404 SHOW_CALLBACK ("audioMasterGetAutomationState");
405 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
409 case audioMasterOfflineStart:
410 SHOW_CALLBACK ("audioMasterOfflineStart");
413 case audioMasterOfflineRead:
414 SHOW_CALLBACK ("audioMasterOfflineRead");
415 // ptr points to offline structure, see below. return 0: error, 1 ok
418 case audioMasterOfflineWrite:
419 SHOW_CALLBACK ("audioMasterOfflineWrite");
423 case audioMasterOfflineGetCurrentPass:
424 SHOW_CALLBACK ("audioMasterOfflineGetCurrentPass");
427 case audioMasterOfflineGetCurrentMetaPass:
428 SHOW_CALLBACK ("audioMasterOfflineGetCurrentMetaPass");
431 case audioMasterSetOutputSampleRate:
432 SHOW_CALLBACK ("audioMasterSetOutputSampleRate");
433 // for variable i/o, sample rate in <opt>
436 case audioMasterGetSpeakerArrangement:
437 SHOW_CALLBACK ("audioMasterGetSpeakerArrangement");
438 // (long)input in <value>, output in <ptr>
441 case audioMasterGetVendorString:
442 SHOW_CALLBACK ("audioMasterGetVendorString");
443 // fills <ptr> with a string identifying the vendor (max 64 char)
444 strcpy ((char*) ptr, "Linux Audio Systems");
447 case audioMasterGetProductString:
448 SHOW_CALLBACK ("audioMasterGetProductString");
449 // fills <ptr> with a string with product name (max 64 char)
450 strcpy ((char*) ptr, PROGRAM_NAME);
453 case audioMasterGetVendorVersion:
454 SHOW_CALLBACK ("audioMasterGetVendorVersion");
455 // returns vendor-specific version
458 case audioMasterVendorSpecific:
459 SHOW_CALLBACK ("audioMasterVendorSpecific");
460 // no definition, vendor specific handling
463 case audioMasterSetIcon:
464 SHOW_CALLBACK ("audioMasterSetIcon");
465 // void* in <ptr>, format not defined yet
468 case audioMasterCanDo:
469 SHOW_CALLBACK ("audioMasterCanDo");
470 // string in ptr, (const char*)ptr
471 for (int i = 0; i < vst_can_do_string_count; i++) {
472 if (! strcmp(vst_can_do_strings[i], (const char*)ptr)) {
478 case audioMasterGetLanguage:
479 SHOW_CALLBACK ("audioMasterGetLanguage");
483 case audioMasterOpenWindow:
484 SHOW_CALLBACK ("audioMasterOpenWindow");
485 // returns platform specific ptr
488 case audioMasterCloseWindow:
489 SHOW_CALLBACK ("audioMasterCloseWindow");
490 // close window, platform specific handle in <ptr>
493 case audioMasterGetDirectory:
494 SHOW_CALLBACK ("audioMasterGetDirectory");
495 // get plug directory, FSSpec on MAC, else char*
498 case audioMasterUpdateDisplay:
499 SHOW_CALLBACK ("audioMasterUpdateDisplay");
500 // something has changed, update 'multi-fx' display
501 /* TODO: consider emitting ParameterChangedExternally() for each ctrl input */
503 session->set_dirty ();
507 case audioMasterBeginEdit:
508 SHOW_CALLBACK ("audioMasterBeginEdit");
509 // begin of automation session (when mouse down), parameter index in <index>
510 if (plug && plug->plugin_insert ()) {
511 boost::shared_ptr<AutomationControl> ac = plug->plugin_insert ()->automation_control (Evoral::Parameter (PluginAutomation, 0, index));
513 ac->start_touch (ac->session().transport_sample());
518 case audioMasterEndEdit:
519 SHOW_CALLBACK ("audioMasterEndEdit");
520 // end of automation session (when mouse up), parameter index in <index>
521 if (plug && plug->plugin_insert ()) {
522 boost::shared_ptr<AutomationControl> ac = plug->plugin_insert ()->automation_control (Evoral::Parameter (PluginAutomation, 0, index));
524 ac->stop_touch (ac->session().transport_sample());
529 case audioMasterOpenFileSelector:
530 SHOW_CALLBACK ("audioMasterOpenFileSelector");
531 // open a fileselector window with VstFileSelect* in <ptr>
535 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("VST master dispatcher: undefed: %1\n", opcode));