switch to using jack_set_thread_creator() and dont mess with winaudio thread
[fst.git] / audiomaster.c
blobae401f35b01ce495386b3a7cdb588f0976012693
1 /*
2 Copyright (C) 2002 Kjetil S. Matheussen / Notam.
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.
20 #include <stdbool.h>
21 #include <stdio.h>
23 #include "jackvst.h"
24 #include <vestige/aeffectx.h>
25 #include <math.h>
27 /* The following audioMaster opcode handlings are copied
28 * (with a light modification) from the vst tilde source
29 * made by Mark Williamson.
32 //#define DEBUG_CALLBACKS
34 #ifdef DEBUG_CALLBACKS
35 #define SHOW_CALLBACK fst_error
36 #else
37 #define SHOW_CALLBACK(...)
38 #endif
40 extern void queue_midi_message(JackVST* jvst, int status, int d1, int d2, jack_nframes_t delta );
42 long jack_host_callback (struct AEffect* effect,
43 long opcode,
44 long index,
45 long value,
46 void* ptr,
47 float opt)
49 static struct VstTimeInfo _timeInfo;
50 JackVST* jackvst = effect ? ((JackVST*) effect->user) : NULL;
51 jack_position_t jack_pos;
52 jack_transport_state_t tstate;
54 //SHOW_CALLBACK ("am callback, opcode = %d", opcode);
56 switch(opcode){
58 case audioMasterAutomate:
59 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
60 // index, value, returns 0
61 //effect->setParameter (effect, index, opt);
62 if( jackvst && jackvst->midi_learn ) {
63 jackvst->midi_learn_PARAM = index;
65 return 0;
67 case audioMasterVersion:
68 SHOW_CALLBACK ("amc: audioMasterVersion\n");
69 // vst version, currently 2 (0 for older)
70 return 2;
72 case audioMasterCurrentId:
73 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
74 // returns the unique id of a plug that's currently
75 // loading
76 return 0;
78 case audioMasterIdle:
79 SHOW_CALLBACK ("amc: audioMasterIdle\n");
80 // call application idle routine (this will
81 // call effEditIdle for all open editors too)
82 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
83 return 0;
85 case audioMasterPinConnected:
86 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
87 // inquire if an input or output is beeing connected;
88 // index enumerates input or output counting from zero:
89 // value is 0 for input and != 0 otherwise. note: the
90 // return value is 0 for <true> such that older versions
91 // will always return true.
92 return 0;
94 case audioMasterWantMidi:
95 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
96 // <value> is a filter which is currently ignored
97 return 0;
99 case audioMasterGetTime:
100 //SHOW_CALLBACK ("amc: audioMasterGetTime\n");
101 // returns const VstTimeInfo* (or 0 if not supported)
102 // <value> should contain a mask indicating which fields are required
103 // (see valid masks above), as some items may require extensive
104 // conversions
106 //return 0;
108 memset(&_timeInfo, 0, sizeof(_timeInfo));
109 if (jackvst) {
110 tstate = jack_transport_query (jackvst->client, &jack_pos);
112 _timeInfo.samplePos = jack_pos.frame;
113 _timeInfo.sampleRate = jack_pos.frame_rate;
114 _timeInfo.flags = 0;
116 //printf( "get time value=%d\n", value );
117 if (jack_pos.valid & JackPositionBBT) {
118 _timeInfo.tempo = jack_pos.beats_per_minute;
119 _timeInfo.flags |= (kVstTempoValid);
121 if (jack_pos.valid & JackPositionBBT) {
122 _timeInfo.timeSigNumerator = (long) floor (jack_pos.beats_per_bar);
123 _timeInfo.timeSigDenominator = (long) floor (jack_pos.beat_type);
124 _timeInfo.flags |= (kVstBarsValid);
127 if (tstate == JackTransportRolling) {
128 _timeInfo.flags |= (kVstTransportChanged|kVstTransportPlaying);
129 } else {
130 _timeInfo.flags |= (kVstTransportChanged);
133 } else {
134 _timeInfo.samplePos = 0;
135 _timeInfo.sampleRate = 48000;
138 return (long)&_timeInfo;
140 case audioMasterProcessEvents:
141 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
142 // VstEvents* in <ptr>
143 if (jackvst) {
144 int i;
145 long numEvents;
146 VstEvents* events = (VstEvents*)ptr;
148 numEvents = events->numEvents;
149 for (i = 0; i < numEvents; i++) {
150 char* midiData;
151 VstMidiEvent* event = (VstMidiEvent*)events->events[i];
152 //printf( "delta = %d\n", (int) event->deltaFrames );
153 midiData = event->midiData;
154 queue_midi_message(jackvst, midiData[0], midiData[1], midiData[2], event->deltaFrames);
157 return 1;
159 case audioMasterSetTime:
160 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
161 // VstTimenfo* in <ptr>, filter in <value>, not supported
162 return 0;
164 case audioMasterTempoAt:
165 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
166 memset(&_timeInfo, 0, sizeof(_timeInfo));
167 if (jackvst) {
168 tstate = jack_transport_query (jackvst->client, &jack_pos);
169 return jack_pos.beats_per_minute * 10000.0;
171 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
172 return 0;
174 case audioMasterGetNumAutomatableParameters:
175 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
176 return 0;
178 case audioMasterGetParameterQuantization:
179 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
180 // returns the integer value for +1.0 representation,
181 // or 1 if full single float precision is maintained
182 // in automation. parameter index in <value> (-1: all, any)
183 return 0;
185 case audioMasterIOChanged:
186 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
187 // numInputs and/or numOutputs has changed
188 return 0;
190 case audioMasterNeedIdle:
191 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
192 // plug needs idle calls (outside its editor window)
193 if( jackvst )
194 jackvst->fst->wantIdle = 1;
195 return 1;
197 case audioMasterSizeWindow:
198 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
199 // index: width, value: height
200 return 0;
202 case audioMasterGetSampleRate:
203 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
204 if( jackvst )
205 return jack_get_sample_rate( jackvst->client );
207 return 44100;
209 case audioMasterGetBlockSize:
210 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
211 if( jackvst )
212 return jack_get_buffer_size( jackvst->client );
214 return 1024;
216 case audioMasterGetInputLatency:
217 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
218 return 0;
220 case audioMasterGetOutputLatency:
221 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
222 return 0;
224 case audioMasterGetPreviousPlug:
225 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
226 // input pin in <value> (-1: first to come), returns cEffect*
227 return 0;
229 case audioMasterGetNextPlug:
230 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
231 // output pin in <value> (-1: first to come), returns cEffect*
233 case audioMasterWillReplaceOrAccumulate:
234 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
235 // returns: 0: not supported, 1: replace, 2: accumulate
236 return 0;
238 case audioMasterGetCurrentProcessLevel:
239 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
240 // returns: 0: not supported,
241 // 1: currently in user thread (gui)
242 // 2: currently in audio thread (where process is called)
243 // 3: currently in 'sequencer' thread (midi, timer etc)
244 // 4: currently offline processing and thus in user thread
245 // other: not defined, but probably pre-empting user thread.
246 return 0;
248 case audioMasterGetAutomationState:
249 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
250 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
251 // offline
252 return 0;
254 case audioMasterOfflineStart:
255 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
256 case audioMasterOfflineRead:
257 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
258 // ptr points to offline structure, see below. return 0: error, 1 ok
259 return 0;
261 case audioMasterOfflineWrite:
262 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
263 // same as read
264 return 0;
266 case audioMasterOfflineGetCurrentPass:
267 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
268 case audioMasterOfflineGetCurrentMetaPass:
269 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
270 return 0;
272 case audioMasterSetOutputSampleRate:
273 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
274 // for variable i/o, sample rate in <opt>
275 return 0;
277 case audioMasterGetSpeakerArrangement:
278 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
279 // (long)input in <value>, output in <ptr>
280 return 0;
282 case audioMasterGetVendorString:
283 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
284 // fills <ptr> with a string identifying the vendor (max 64 char)
285 strcpy ((char*) ptr, "LAD");
286 return 0;
288 case audioMasterGetProductString:
289 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
290 // fills <ptr> with a string with product name (max 64 char)
291 strcpy ((char*) ptr, "FreeST");
292 return 0;
294 case audioMasterGetVendorVersion:
295 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
296 // returns vendor-specific version
297 return 1000;
299 case audioMasterVendorSpecific:
300 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
301 // no definition, vendor specific handling
302 return 0;
304 case audioMasterSetIcon:
305 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
306 // void* in <ptr>, format not defined yet
307 return 0;
309 case audioMasterCanDo:
310 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
311 // string in ptr, see below
312 return 0;
314 case audioMasterGetLanguage:
315 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
316 // see enum
317 return 0;
319 case audioMasterOpenWindow:
320 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
321 // returns platform specific ptr
322 return 0;
324 case audioMasterCloseWindow:
325 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
326 // close window, platform specific handle in <ptr>
327 return 0;
329 case audioMasterGetDirectory:
330 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
331 // get plug directory, FSSpec on MAC, else char*
332 return 0;
334 case audioMasterUpdateDisplay:
335 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
336 // something has changed, update 'multi-fx' display
337 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
338 return 0;
340 case audioMasterBeginEdit:
341 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
342 // begin of automation session (when mouse down), parameter index in <index>
343 return 0;
345 case audioMasterEndEdit:
346 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
347 // end of automation session (when mouse up), parameter index in <index>
348 return 0;
350 case audioMasterOpenFileSelector:
351 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
352 // open a fileselector window with VstFileSelect* in <ptr>
353 return 0;
355 default:
356 SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode);
357 break;
360 return 0;