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/session.h"
26 #include "ardour/tempo.h"
27 #include "ardour/windows_vst_plugin.h"
28 #include "ardour/vestige/aeffectx.h"
29 #include "ardour/vst_types.h"
33 #define DEBUG_CALLBACKS
34 static int debug_callbacks = -1;
36 #ifdef DEBUG_CALLBACKS
37 #define SHOW_CALLBACK if (debug_callbacks) printf
39 #define SHOW_CALLBACK(...)
42 using namespace ARDOUR;
44 intptr_t Session::vst_callback (
53 static VstTimeInfo _timeInfo;
57 if (debug_callbacks < 0) {
58 debug_callbacks = (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0);
61 if (effect && effect->user) {
62 plug = (VSTPlugin *) (effect->user);
63 session = &plug->session();
65 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self().p, opcode, plug->name());
67 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self(), opcode, plug->name());
73 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self().p, opcode);
75 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self(), opcode);
81 case audioMasterAutomate:
82 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
83 // index, value, returns 0
85 plug->set_parameter (index, opt);
89 case audioMasterVersion:
90 SHOW_CALLBACK ("amc: audioMasterVersion\n");
91 // vst version, currently 2 (0 for older)
94 case audioMasterCurrentId:
95 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
96 // returns the unique id of a plug that's currently
100 case audioMasterIdle:
101 SHOW_CALLBACK ("amc: audioMasterIdle\n");
102 // call application idle routine (this will
103 // call effEditIdle for all open editors too)
105 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
109 case audioMasterPinConnected:
110 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
111 // inquire if an input or output is beeing connected;
112 // index enumerates input or output counting from zero:
113 // value is 0 for input and != 0 otherwise. note: the
114 // return value is 0 for <true> such that older versions
115 // will always return true.
118 case audioMasterWantMidi:
119 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
120 // <value> is a filter which is currently ignored
122 plug->get_info()->n_inputs.set_midi (1);
126 case audioMasterGetTime:
127 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
128 // returns const VstTimeInfo* (or 0 if not supported)
129 // <value> should contain a mask indicating which fields are required
130 // (see valid masks above), as some items may require extensive
132 memset(&_timeInfo, 0, sizeof(_timeInfo));
133 std::cerr << "VST get time callback, value = " << std::hex << value << " index = " << index << std::dec << std::endl;
135 framepos_t now = session->transport_frame();
137 std::cerr << "\t@ " << now << std::endl;
139 _timeInfo.samplePos = now;
140 _timeInfo.sampleRate = session->frame_rate();
143 const TempoMetric& tm (session->tempo_map().metric_at (now));
145 // if (value & (kVstTempoValid)) {
146 const Tempo& t (tm.tempo());
147 _timeInfo.tempo = t.beats_per_minute ();
148 _timeInfo.flags |= (kVstTempoValid);
150 // if (value & (kVstBarsValid)) {
151 const Meter& m (tm.meter());
152 _timeInfo.timeSigNumerator = m.divisions_per_bar ();
153 _timeInfo.timeSigDenominator = m.note_divisor ();
154 _timeInfo.flags |= (kVstTimeSigValid);
156 // if (value & (kVstPpqPosValid)) {
157 Timecode::BBT_Time bbt;
159 session->tempo_map().bbt_time_rt (now, bbt);
161 /* Note that this assumes constant
162 meter/tempo throughout the session. We
163 can do better than this, because
164 progressive rock fans demand it.
166 double ppqBar = double(bbt.bars - 1) * tm.meter().divisions_per_bar();
167 double ppqBeat = double(bbt.beats - 1);
168 double ppqTick = double(bbt.ticks) / Timecode::BBT_Time::ticks_per_beat;
170 _timeInfo.ppqPos = ppqBar + ppqBeat + ppqTick;
171 _timeInfo.flags |= (kVstPpqPosValid);
178 // _timeInfo.barStartPos = ppqBar;
179 // _timeInfo.flags |= kVstBarsValid;
181 if (session->transport_speed() != 0.0f) {
182 _timeInfo.flags |= kVstTransportPlaying;
186 std::cerr << "\ttimeinfo valid = " << std::hex << _timeInfo.flags << std::dec << std::endl;
187 return (long)&_timeInfo;
189 case audioMasterProcessEvents:
190 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
191 // VstEvents* in <ptr>
194 case audioMasterSetTime:
195 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
196 // VstTimenfo* in <ptr>, filter in <value>, not supported
198 case audioMasterTempoAt:
199 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
200 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
202 const Tempo& t (session->tempo_map().tempo_at (value));
203 return t.beats_per_minute() * 1000;
209 case audioMasterGetNumAutomatableParameters:
210 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
213 case audioMasterGetParameterQuantization:
214 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
215 // returns the integer value for +1.0 representation,
216 // or 1 if full single float precision is maintained
217 // in automation. parameter index in <value> (-1: all, any)
220 case audioMasterIOChanged:
221 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
222 // numInputs and/or numOutputs has changed
225 case audioMasterNeedIdle:
226 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
227 // plug needs idle calls (outside its editor window)
229 plug->state()->wantIdle = 1;
233 case audioMasterSizeWindow:
234 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
235 // index: width, value: height
238 case audioMasterGetSampleRate:
239 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
241 return session->frame_rate();
245 case audioMasterGetBlockSize:
246 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
248 return session->get_block_size();
252 case audioMasterGetInputLatency:
253 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
256 case audioMasterGetOutputLatency:
257 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
260 case audioMasterGetPreviousPlug:
261 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
262 // input pin in <value> (-1: first to come), returns cEffect*
265 case audioMasterGetNextPlug:
266 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
267 // output pin in <value> (-1: first to come), returns cEffect*
269 case audioMasterWillReplaceOrAccumulate:
270 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
271 // returns: 0: not supported, 1: replace, 2: accumulate
274 case audioMasterGetCurrentProcessLevel:
275 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
276 // returns: 0: not supported,
277 // 1: currently in user thread (gui)
278 // 2: currently in audio thread (where process is called)
279 // 3: currently in 'sequencer' thread (midi, timer etc)
280 // 4: currently offline processing and thus in user thread
281 // other: not defined, but probably pre-empting user thread.
284 case audioMasterGetAutomationState:
285 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
286 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
290 case audioMasterOfflineStart:
291 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
294 case audioMasterOfflineRead:
295 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
296 // ptr points to offline structure, see below. return 0: error, 1 ok
299 case audioMasterOfflineWrite:
300 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
304 case audioMasterOfflineGetCurrentPass:
305 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
308 case audioMasterOfflineGetCurrentMetaPass:
309 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
312 case audioMasterSetOutputSampleRate:
313 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
314 // for variable i/o, sample rate in <opt>
317 case audioMasterGetSpeakerArrangement:
318 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
319 // (long)input in <value>, output in <ptr>
322 case audioMasterGetVendorString:
323 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
324 // fills <ptr> with a string identifying the vendor (max 64 char)
325 strcpy ((char*) ptr, "Linux Audio Systems");
328 case audioMasterGetProductString:
329 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
330 // fills <ptr> with a string with product name (max 64 char)
331 strcpy ((char*) ptr, PROGRAM_NAME);
334 case audioMasterGetVendorVersion:
335 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
336 // returns vendor-specific version
339 case audioMasterVendorSpecific:
340 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
341 // no definition, vendor specific handling
344 case audioMasterSetIcon:
345 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
346 // void* in <ptr>, format not defined yet
349 case audioMasterCanDo:
350 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
351 // string in ptr, see below
354 case audioMasterGetLanguage:
355 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
359 case audioMasterOpenWindow:
360 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
361 // returns platform specific ptr
364 case audioMasterCloseWindow:
365 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
366 // close window, platform specific handle in <ptr>
369 case audioMasterGetDirectory:
370 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
371 // get plug directory, FSSpec on MAC, else char*
374 case audioMasterUpdateDisplay:
375 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
376 // something has changed, update 'multi-fx' display
378 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
382 case audioMasterBeginEdit:
383 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
384 // begin of automation session (when mouse down), parameter index in <index>
387 case audioMasterEndEdit:
388 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
389 // end of automation session (when mouse up), parameter index in <index>
392 case audioMasterOpenFileSelector:
393 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
394 // open a fileselector window with VstFileSelect* in <ptr>
398 SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode);