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()));
83 timeinfo = &_timeinfo;
84 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4\n",
85 std::hex, (void*) DEBUG_THREAD_SELF,
91 case audioMasterAutomate:
92 SHOW_CALLBACK ("audioMasterAutomate");
93 // index, value, returns 0
95 plug->parameter_changed_externally (index, opt);
99 case audioMasterVersion:
100 SHOW_CALLBACK ("audioMasterVersion");
101 // vst version, currently 2 (0 for older)
104 case audioMasterCurrentId:
105 SHOW_CALLBACK ("audioMasterCurrentId");
106 // returns the unique id of a plug that's currently loading
107 return vst_current_loading_id;
109 case audioMasterIdle:
110 SHOW_CALLBACK ("audioMasterIdle");
111 #ifdef WINDOWS_VST_SUPPORT
112 fst_audio_master_idle();
115 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
119 case audioMasterPinConnected:
120 SHOW_CALLBACK ("audioMasterPinConnected");
121 // inquire if an input or output is beeing connected;
122 // index enumerates input or output counting from zero:
123 // value is 0 for input and != 0 otherwise. note: the
124 // return value is 0 for <true> such that older versions
125 // will always return true.
128 // but ardour always connects all buffers, so we're good
133 if (plug->plugin_insert ()) {
135 const ChanMapping& map (plug->plugin_insert ()->input_map (plug->plugin_number ()));
136 map.get (DataType::AUDIO, index, &valid);
137 return valid ? 0 : 1;
139 if (index < plug->plugin()->numInputs) {
144 #if 0 // investigate, the outputs *are* connected to scratch buffers
145 if (plug->plugin_insert ()) {
147 const ChanMapping& map (plug->plugin_insert ()->output_map (plug->plugin_number ()));
148 map.get (DataType::AUDIO, index, &valid);
149 return valid ? 0 : 1;
152 if (index < plug->plugin()->numOutputs) {
161 case audioMasterWantMidi:
162 SHOW_CALLBACK ("audioMasterWantMidi");
163 // <value> is a filter which is currently ignored
164 if (plug && plug->get_info() != NULL) {
165 plug->get_info()->n_inputs.set_midi (1);
169 case audioMasterGetTime:
170 SHOW_CALLBACK ("audioMasterGetTime");
171 newflags = kVstNanosValid | kVstAutomationWriting | kVstAutomationReading;
173 timeinfo->nanoSeconds = g_get_monotonic_time () * 1000;
175 if (plug && session) {
176 samplepos_t now = plug->transport_sample();
178 timeinfo->samplePos = now;
179 timeinfo->sampleRate = session->sample_rate();
181 if (value & (kVstTempoValid)) {
182 const Tempo& t (session->tempo_map().tempo_at_sample (now));
183 timeinfo->tempo = t.quarter_notes_per_minute ();
184 newflags |= (kVstTempoValid);
186 if (value & (kVstTimeSigValid)) {
187 const MeterSection& ms (session->tempo_map().meter_section_at_sample (now));
188 timeinfo->timeSigNumerator = ms.divisions_per_bar ();
189 timeinfo->timeSigDenominator = ms.note_divisor ();
190 newflags |= (kVstTimeSigValid);
192 if ((value & (kVstPpqPosValid)) || (value & (kVstBarsValid))) {
193 Timecode::BBT_Time bbt;
196 bbt = session->tempo_map().bbt_at_sample_rt (now);
199 /* exact quarter note */
200 double ppqBar = session->tempo_map().quarter_note_at_bbt_rt (bbt);
201 /* quarter note at sample position (not rounded to note subdivision) */
202 double ppqPos = session->tempo_map().quarter_note_at_sample_rt (now);
203 if (value & (kVstPpqPosValid)) {
204 timeinfo->ppqPos = ppqPos;
205 newflags |= kVstPpqPosValid;
208 if (value & (kVstBarsValid)) {
209 timeinfo->barStartPos = ppqBar;
210 newflags |= kVstBarsValid;
218 if (value & (kVstSmpteValid)) {
221 session->timecode_time (now, t);
223 timeinfo->smpteOffset = (t.hours * t.rate * 60.0 * 60.0) +
224 (t.minutes * t.rate * 60.0) +
225 (t.seconds * t.rate) +
229 timeinfo->smpteOffset *= 80.0; /* VST spec is 1/80th samples */
231 if (session->timecode_drop_frames()) {
232 if (session->timecode_frames_per_second() == 30.0) {
233 timeinfo->smpteFrameRate = 5;
235 timeinfo->smpteFrameRate = 4; /* 29.97 assumed, thanks VST */
238 if (session->timecode_frames_per_second() == 24.0) {
239 timeinfo->smpteFrameRate = 0;
240 } else if (session->timecode_frames_per_second() == 24.975) {
241 timeinfo->smpteFrameRate = 2;
242 } else if (session->timecode_frames_per_second() == 25.0) {
243 timeinfo->smpteFrameRate = 1;
245 timeinfo->smpteFrameRate = 3; /* 30 fps */
248 newflags |= (kVstSmpteValid);
251 if (session->actively_recording ()) {
252 newflags |= kVstTransportRecording;
255 if (plug->transport_speed () != 0.0f) {
256 newflags |= kVstTransportPlaying;
259 if (session->get_play_loop ()) {
260 newflags |= kVstTransportCycleActive;
261 Location * looploc = session->locations ()->auto_loop_location ();
263 timeinfo->cycleStartPos = session->tempo_map ().quarter_note_at_sample_rt (looploc->start ());
264 timeinfo->cycleEndPos = session->tempo_map ().quarter_note_at_sample_rt (looploc->end ());
266 newflags |= kVstCyclePosValid;
271 timeinfo->samplePos = 0;
272 timeinfo->sampleRate = AudioEngine::instance()->sample_rate();
275 if ((timeinfo->flags & (kVstTransportPlaying | kVstTransportRecording | kVstTransportCycleActive))
277 (newflags & (kVstTransportPlaying | kVstTransportRecording | kVstTransportCycleActive)))
279 newflags |= kVstTransportChanged;
282 timeinfo->flags = newflags;
283 return (intptr_t) timeinfo;
285 case audioMasterProcessEvents:
286 SHOW_CALLBACK ("audioMasterProcessEvents");
287 // VstEvents* in <ptr>
288 if (plug && plug->midi_buffer()) {
289 VstEvents* v = (VstEvents*)ptr;
290 for (int n = 0 ; n < v->numEvents; ++n) {
291 VstMidiEvent *vme = (VstMidiEvent*) (v->events[n]->dump);
292 if (vme->type == kVstMidiType) {
293 plug->midi_buffer()->push_back(vme->deltaSamples, 3, (uint8_t*)vme->midiData);
299 case audioMasterSetTime:
300 SHOW_CALLBACK ("audioMasterSetTime");
301 // VstTimenfo* in <ptr>, filter in <value>, not supported
304 case audioMasterTempoAt:
305 SHOW_CALLBACK ("audioMasterTempoAt");
306 // returns tempo (in bpm * 10000) at sample sample location passed in <value>
308 const Tempo& t (session->tempo_map().tempo_at_sample (value));
309 return t.quarter_notes_per_minute() * 1000;
315 case audioMasterGetNumAutomatableParameters:
316 SHOW_CALLBACK ("audioMasterGetNumAutomatableParameters");
319 case audioMasterGetParameterQuantization:
320 SHOW_CALLBACK ("audioMasterGetParameterQuantization");
321 // returns the integer value for +1.0 representation,
322 // or 1 if full single float precision is maintained
323 // in automation. parameter index in <value> (-1: all, any)
326 case audioMasterIOChanged:
327 SHOW_CALLBACK ("audioMasterIOChanged");
328 // numInputs and/or numOutputs has changed
331 case audioMasterNeedIdle:
332 SHOW_CALLBACK ("audioMasterNeedIdle");
333 // plug needs idle calls (outside its editor window)
335 plug->state()->wantIdle = 1;
339 case audioMasterSizeWindow:
340 SHOW_CALLBACK ("audioMasterSizeWindow");
341 if (plug && plug->state()) {
342 if (plug->state()->width != index || plug->state()->height != value) {
343 plug->state()->width = index;
344 plug->state()->height = value;
346 printf ("audioMasterSizeWindow %d %d\n", plug->state()->width, plug->state()->height);
348 plug->VSTSizeWindow (); /* EMIT SIGNAL */
353 case audioMasterGetSampleRate:
354 SHOW_CALLBACK ("audioMasterGetSampleRate");
356 return session->sample_rate();
360 case audioMasterGetBlockSize:
361 SHOW_CALLBACK ("audioMasterGetBlockSize");
363 return session->get_block_size();
367 case audioMasterGetInputLatency:
368 SHOW_CALLBACK ("audioMasterGetInputLatency");
371 case audioMasterGetOutputLatency:
372 SHOW_CALLBACK ("audioMasterGetOutputLatency");
375 case audioMasterGetPreviousPlug:
376 SHOW_CALLBACK ("audioMasterGetPreviousPlug");
377 // input pin in <value> (-1: first to come), returns cEffect*
380 case audioMasterGetNextPlug:
381 SHOW_CALLBACK ("audioMasterGetNextPlug");
382 // output pin in <value> (-1: first to come), returns cEffect*
385 case audioMasterWillReplaceOrAccumulate:
386 SHOW_CALLBACK ("audioMasterWillReplaceOrAccumulate");
387 // returns: 0: not supported, 1: replace, 2: accumulate
390 case audioMasterGetCurrentProcessLevel:
391 SHOW_CALLBACK ("audioMasterGetCurrentProcessLevel");
392 // returns: 0: not supported,
393 // 1: currently in user thread (gui)
394 // 2: currently in audio thread (where process is called)
395 // 3: currently in 'sequencer' thread (midi, timer etc)
396 // 4: currently offline processing and thus in user thread
397 // other: not defined, but probably pre-empting user thread.
400 case audioMasterGetAutomationState:
401 SHOW_CALLBACK ("audioMasterGetAutomationState");
402 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
406 case audioMasterOfflineStart:
407 SHOW_CALLBACK ("audioMasterOfflineStart");
410 case audioMasterOfflineRead:
411 SHOW_CALLBACK ("audioMasterOfflineRead");
412 // ptr points to offline structure, see below. return 0: error, 1 ok
415 case audioMasterOfflineWrite:
416 SHOW_CALLBACK ("audioMasterOfflineWrite");
420 case audioMasterOfflineGetCurrentPass:
421 SHOW_CALLBACK ("audioMasterOfflineGetCurrentPass");
424 case audioMasterOfflineGetCurrentMetaPass:
425 SHOW_CALLBACK ("audioMasterOfflineGetCurrentMetaPass");
428 case audioMasterSetOutputSampleRate:
429 SHOW_CALLBACK ("audioMasterSetOutputSampleRate");
430 // for variable i/o, sample rate in <opt>
433 case audioMasterGetSpeakerArrangement:
434 SHOW_CALLBACK ("audioMasterGetSpeakerArrangement");
435 // (long)input in <value>, output in <ptr>
438 case audioMasterGetVendorString:
439 SHOW_CALLBACK ("audioMasterGetVendorString");
440 // fills <ptr> with a string identifying the vendor (max 64 char)
441 strcpy ((char*) ptr, "Linux Audio Systems");
444 case audioMasterGetProductString:
445 SHOW_CALLBACK ("audioMasterGetProductString");
446 // fills <ptr> with a string with product name (max 64 char)
447 strcpy ((char*) ptr, PROGRAM_NAME);
450 case audioMasterGetVendorVersion:
451 SHOW_CALLBACK ("audioMasterGetVendorVersion");
452 // returns vendor-specific version
455 case audioMasterVendorSpecific:
456 SHOW_CALLBACK ("audioMasterVendorSpecific");
457 // no definition, vendor specific handling
460 case audioMasterSetIcon:
461 SHOW_CALLBACK ("audioMasterSetIcon");
462 // void* in <ptr>, format not defined yet
465 case audioMasterCanDo:
466 SHOW_CALLBACK ("audioMasterCanDo");
467 // string in ptr, (const char*)ptr
468 for (int i = 0; i < vst_can_do_string_count; i++) {
469 if (! strcmp(vst_can_do_strings[i], (const char*)ptr)) {
475 case audioMasterGetLanguage:
476 SHOW_CALLBACK ("audioMasterGetLanguage");
480 case audioMasterOpenWindow:
481 SHOW_CALLBACK ("audioMasterOpenWindow");
482 // returns platform specific ptr
485 case audioMasterCloseWindow:
486 SHOW_CALLBACK ("audioMasterCloseWindow");
487 // close window, platform specific handle in <ptr>
490 case audioMasterGetDirectory:
491 SHOW_CALLBACK ("audioMasterGetDirectory");
492 // get plug directory, FSSpec on MAC, else char*
495 case audioMasterUpdateDisplay:
496 SHOW_CALLBACK ("audioMasterUpdateDisplay");
497 // something has changed, update 'multi-fx' display
498 /* TODO: consider emitting ParameterChangedExternally() for each ctrl input */
500 session->set_dirty ();
504 case audioMasterBeginEdit:
505 SHOW_CALLBACK ("audioMasterBeginEdit");
506 // begin of automation session (when mouse down), parameter index in <index>
507 if (plug && plug->plugin_insert ()) {
508 boost::shared_ptr<AutomationControl> ac = plug->plugin_insert ()->automation_control (Evoral::Parameter (PluginAutomation, 0, index));
510 ac->start_touch (ac->session().transport_sample());
515 case audioMasterEndEdit:
516 SHOW_CALLBACK ("audioMasterEndEdit");
517 // end of automation session (when mouse up), parameter index in <index>
518 if (plug && plug->plugin_insert ()) {
519 boost::shared_ptr<AutomationControl> ac = plug->plugin_insert ()->automation_control (Evoral::Parameter (PluginAutomation, 0, index));
521 ac->stop_touch (ac->session().transport_sample());
526 case audioMasterOpenFileSelector:
527 SHOW_CALLBACK ("audioMasterOpenFileSelector");
528 // open a fileselector window with VstFileSelect* in <ptr>
532 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("VST master dispatcher: undefed: %1\n", opcode));