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.
24 #include <fst/vestige/aeffectx.h>
26 #include <ardour/session.h>
27 #include <ardour/tempo.h>
28 #include <ardour/vst_plugin.h>
32 #undef DEBUG_CALLBACKS
34 #ifdef DEBUG_CALLBACKS
35 #define SHOW_CALLBACK printf
37 #define SHOW_CALLBACK(...)
40 using namespace ARDOUR;
42 long Session::vst_callback (AEffect* effect,
49 static VstTimeInfo _timeInfo;
54 if (effect && effect->user) {
55 plug = (VSTPlugin*) (effect->user);
56 session = &plug->session();
57 SHOW_CALLBACK ("am callback %d, opcode = %ld, plugin = \"%s\" ", pthread_self(), opcode, plug->name());
61 SHOW_CALLBACK ("am callback %d, opcode = %ld", pthread_self(), opcode);
66 case audioMasterAutomate:
67 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
68 // index, value, returns 0
70 effect->setParameter (effect, index, opt);
74 case audioMasterVersion:
75 SHOW_CALLBACK ("amc: audioMasterVersion\n");
76 // vst version, currently 2 (0 for older)
79 case audioMasterCurrentId:
80 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
81 // returns the unique id of a plug that's currently
86 SHOW_CALLBACK ("amc: audioMasterIdle\n");
87 // call application idle routine (this will
88 // call effEditIdle for all open editors too)
90 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
94 case audioMasterPinConnected:
95 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
96 // inquire if an input or output is beeing connected;
97 // index enumerates input or output counting from zero:
98 // value is 0 for input and != 0 otherwise. note: the
99 // return value is 0 for <true> such that older versions
100 // will always return true.
103 case audioMasterWantMidi:
104 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
105 // <value> is a filter which is currently ignored
108 case audioMasterGetTime:
109 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
110 // returns const VstTimeInfo* (or 0 if not supported)
111 // <value> should contain a mask indicating which fields are required
112 // (see valid masks above), as some items may require extensive
114 memset(&_timeInfo, 0, sizeof(_timeInfo));
116 _timeInfo.samplePos = session->transport_frame();
117 _timeInfo.sampleRate = session->frame_rate();
120 if (value & (kVstTempoValid)) {
121 const Tempo& t (session->tempo_map().tempo_at (session->transport_frame()));
122 _timeInfo.tempo = t.beats_per_minute ();
123 _timeInfo.flags |= (kVstTempoValid);
125 if (value & (kVstBarsValid)) {
126 const Meter& m (session->tempo_map().meter_at (session->transport_frame()));
127 _timeInfo.timeSigNumerator = m.beats_per_bar ();
128 _timeInfo.timeSigDenominator = m.note_divisor ();
129 _timeInfo.flags |= (kVstBarsValid);
132 if (session->transport_speed() != 0.0f) {
133 _timeInfo.flags |= kVstTransportPlaying;
137 return (long)&_timeInfo;
139 case audioMasterProcessEvents:
140 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
141 // VstEvents* in <ptr>
144 case audioMasterSetTime:
145 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
146 // VstTimenfo* in <ptr>, filter in <value>, not supported
148 case audioMasterTempoAt:
149 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
150 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
152 const Tempo& t (session->tempo_map().tempo_at (value));
153 return t.beats_per_minute() * 1000;
159 case audioMasterGetNumAutomatableParameters:
160 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
163 case audioMasterGetParameterQuantization:
164 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
165 // returns the integer value for +1.0 representation,
166 // or 1 if full single float precision is maintained
167 // in automation. parameter index in <value> (-1: all, any)
170 case audioMasterIOChanged:
171 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
172 // numInputs and/or numOutputs has changed
175 case audioMasterNeedIdle:
176 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
177 // plug needs idle calls (outside its editor window)
180 case audioMasterSizeWindow:
181 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
182 // index: width, value: height
185 case audioMasterGetSampleRate:
186 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
189 case audioMasterGetBlockSize:
190 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
193 case audioMasterGetInputLatency:
194 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
197 case audioMasterGetOutputLatency:
198 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
201 case audioMasterGetPreviousPlug:
202 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
203 // input pin in <value> (-1: first to come), returns cEffect*
206 case audioMasterGetNextPlug:
207 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
208 // output pin in <value> (-1: first to come), returns cEffect*
210 case audioMasterWillReplaceOrAccumulate:
211 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
212 // returns: 0: not supported, 1: replace, 2: accumulate
215 case audioMasterGetCurrentProcessLevel:
216 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
217 // returns: 0: not supported,
218 // 1: currently in user thread (gui)
219 // 2: currently in audio thread (where process is called)
220 // 3: currently in 'sequencer' thread (midi, timer etc)
221 // 4: currently offline processing and thus in user thread
222 // other: not defined, but probably pre-empting user thread.
225 case audioMasterGetAutomationState:
226 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
227 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
231 case audioMasterOfflineStart:
232 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
233 case audioMasterOfflineRead:
234 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
235 // ptr points to offline structure, see below. return 0: error, 1 ok
238 case audioMasterOfflineWrite:
239 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
243 case audioMasterOfflineGetCurrentPass:
244 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
245 case audioMasterOfflineGetCurrentMetaPass:
246 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
249 case audioMasterSetOutputSampleRate:
250 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
251 // for variable i/o, sample rate in <opt>
254 case audioMasterGetSpeakerArrangement:
255 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
256 // (long)input in <value>, output in <ptr>
259 case audioMasterGetVendorString:
260 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
261 // fills <ptr> with a string identifying the vendor (max 64 char)
262 strcpy ((char*) ptr, "Linux Audio Systems");
265 case audioMasterGetProductString:
266 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
267 // fills <ptr> with a string with product name (max 64 char)
268 strcpy ((char*) ptr, "Ardour");
271 case audioMasterGetVendorVersion:
272 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
273 // returns vendor-specific version
276 case audioMasterVendorSpecific:
277 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
278 // no definition, vendor specific handling
281 case audioMasterSetIcon:
282 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
283 // void* in <ptr>, format not defined yet
286 case audioMasterCanDo:
287 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
288 // string in ptr, see below
291 case audioMasterGetLanguage:
292 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
296 case audioMasterOpenWindow:
297 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
298 // returns platform specific ptr
301 case audioMasterCloseWindow:
302 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
303 // close window, platform specific handle in <ptr>
306 case audioMasterGetDirectory:
307 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
308 // get plug directory, FSSpec on MAC, else char*
311 case audioMasterUpdateDisplay:
312 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
313 // something has changed, update 'multi-fx' display
315 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
319 case audioMasterBeginEdit:
320 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
321 // begin of automation session (when mouse down), parameter index in <index>
324 case audioMasterEndEdit:
325 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
326 // end of automation session (when mouse up), parameter index in <index>
329 case audioMasterOpenFileSelector:
330 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
331 // open a fileselector window with VstFileSelect* in <ptr>
335 SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode);