~ubuntu-branches/ubuntu/hardy/lmms/hardy

« back to all changes in this revision

Viewing changes to plugins/vestige/fstserver.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ragwitz
  • Date: 2005-12-22 16:22:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051222162250-key3p7x0212jy6dn
Tags: 0.1.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * fstserver.cpp - XFST-server
 
3
 *
 
4
 * Copyright (c) 2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 
5
 * 
 
6
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU General Public
 
10
 * License as published by the Free Software Foundation; either
 
11
 * version 2 of the License, or (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public
 
19
 * License along with this program (see COPYING); if not, write to the
 
20
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
21
 * Boston, MA 02111-1307, USA.
 
22
 *
 
23
 */
 
24
 
 
25
 
 
26
#include <sys/types.h>
 
27
#include <sys/ipc.h>
 
28
#include <sys/shm.h>
 
29
#include <unistd.h>
 
30
#include <string.h>
 
31
#include <stdio.h>
 
32
#include <stdarg.h>
 
33
 
 
34
#include <vst/aeffectx.h>
 
35
 
 
36
#include <vector>
 
37
#include <map>
 
38
 
 
39
#include "fstserver.h"
 
40
#include "types.h"
 
41
#include "midi.h"
 
42
#include "communication.h"
 
43
 
 
44
char debugout[1024];
 
45
 
 
46
 
 
47
extern "C"
 
48
{
 
49
void wine_shared_premain( void );
 
50
 
 
51
 
 
52
void debugMsg( const char * _str )
 
53
{
 
54
        writeValue<Sint16>( DEBUG_MSG, 1 );
 
55
        writeString( _str, 1 );
 
56
}
 
57
 
 
58
 
 
59
void 
 
60
fst_error (const char *fmt, ...)
 
61
{
 
62
        va_list ap;
 
63
        char buffer[512];
 
64
 
 
65
        va_start (ap, fmt);
 
66
        vsnprintf (buffer, sizeof(buffer), fmt, ap);
 
67
        fst_error_callback (buffer);
 
68
        va_end (ap);
 
69
}
 
70
 
 
71
void 
 
72
default_fst_error_callback (const char *desc)
 
73
{
 
74
        debugMsg(desc);
 
75
}
 
76
 
 
77
void (*fst_error_callback)(const char *desc) = &default_fst_error_callback;
 
78
 
 
79
 
 
80
}
 
81
 
 
82
 
 
83
 
 
84
 
 
85
class VSTPlugin
 
86
{
 
87
public:
 
88
        VSTPlugin( const char * _plugin ) :
 
89
                m_handle( NULL ),
 
90
                m_fst( NULL ),
 
91
                m_plugin( NULL ),
 
92
                m_shm( NULL ),
 
93
                m_inputs( NULL ),
 
94
                m_outputs( NULL )
 
95
        {
 
96
                if( ( m_handle = fst_load( _plugin ) ) == NULL )
 
97
                {
 
98
                        sprintf( debugout, "can't load plugin %s\n", _plugin );
 
99
                        debugMsg( debugout );
 
100
                        return;
 
101
                }
 
102
 
 
103
                if( ( m_fst = fst_instantiate( m_handle, hostCallback,
 
104
                                                        this ) ) == NULL )
 
105
                {
 
106
                        sprintf( debugout, "can't instantiate plugin %s\n",
 
107
                                                                _plugin );
 
108
                        debugMsg( debugout );
 
109
                        return;
 
110
                }
 
111
 
 
112
                m_plugin = m_fst->plugin;
 
113
 
 
114
                /* set program to zero */
 
115
                /* i comment this out because it breaks dfx Geometer
 
116
                 * looks like we cant set programs for it
 
117
                 *
 
118
                m_plugin->dispatcher( m_plugin, effSetProgram, 0, 0, NULL, 0.0f); */
 
119
                // request rate and blocksize
 
120
                writeValue<Sint16>( GET_SAMPLE_RATE );
 
121
                writeValue<Sint16>( GET_BUFFER_SIZE );
 
122
 
 
123
 
 
124
                m_plugin->dispatcher( m_plugin, effMainsChanged, 0, 1, NULL,
 
125
                                                                        0.0f );
 
126
                if( fst_run_editor( m_fst ) )
 
127
                {
 
128
                        sprintf( debugout, "cannot create editor\n" );
 
129
                        debugMsg( debugout );
 
130
                }
 
131
 
 
132
                writeValue<Sint16>( SET_XID );
 
133
                writeValue<Sint32>( fst_get_XID( m_fst ) );
 
134
        }
 
135
 
 
136
        ~VSTPlugin()
 
137
        {
 
138
                writeValue<Sint16>( QUIT_ACK );
 
139
                fst_close( m_fst );
 
140
                fst_unload( m_handle );
 
141
                delete[] m_inputs;
 
142
                delete[] m_outputs;
 
143
                if( m_shm != NULL )
 
144
                {
 
145
                        shmdt( m_shm );
 
146
                }
 
147
        }
 
148
 
 
149
        void process( void )
 
150
        {
 
151
                // first we gonna post all MIDI-events we enqueued so far
 
152
                if( m_midiEvents.size() )
 
153
                {
 
154
                        // since MIDI-events are not received immediately, we
 
155
                        // have to have them stored somewhere even after
 
156
                        // dispatcher-call, so we create static copies of the
 
157
                        // data and post them
 
158
                        static VstEvents events;
 
159
                        static std::vector<VstMidiEvent> cur_events;
 
160
                        cur_events = m_midiEvents;
 
161
                        m_midiEvents.clear();
 
162
                        for( unsigned int i = 0; i < cur_events.size(); ++i )
 
163
                        {
 
164
                                events.events[i] = (VstEvent *) &cur_events[i];
 
165
                        }
 
166
                        events.numEvents = cur_events.size();
 
167
                        events.reserved = 0;
 
168
                        m_plugin->dispatcher( m_fst->plugin, effProcessEvents,
 
169
                                                        0, 0, &events, 0.0f );
 
170
                }
 
171
 
 
172
                // now we're ready to fetch sound from VST-plugin
 
173
 
 
174
                for( int i = 0; i < inputCount(); ++i )
 
175
                {
 
176
                        m_inputs[i] = &m_shm[i * m_blockSize];
 
177
                }
 
178
                for( int i = 0; i < outputCount(); ++i )
 
179
                {
 
180
                        m_outputs[i] = &m_shm[( i + inputCount() ) *
 
181
                                                                m_blockSize];
 
182
                }
 
183
 
 
184
                if( m_fst->plugin->flags & effFlagsCanReplacing )
 
185
                {
 
186
                        m_plugin->processReplacing( m_plugin, m_inputs,
 
187
                                                                m_outputs,
 
188
                                                                m_blockSize );
 
189
                }
 
190
                else
 
191
                {
 
192
                        m_plugin->process( m_plugin, m_inputs, m_outputs,
 
193
                                                                m_blockSize );
 
194
                }
 
195
                writeValue<Sint16>( PROCESS_DONE );
 
196
                // give plugin some idle-time for graphics-update and so on...
 
197
                m_plugin->dispatcher( m_plugin, effEditIdle, 0, 0, NULL, 0 );
 
198
 
 
199
        }
 
200
 
 
201
        void enqueueMidiEvent( const midiEvent & _event,
 
202
                                                const Uint32 _frames_ahead )
 
203
        {
 
204
                VstMidiEvent event;
 
205
 
 
206
                event.type = kVstMidiType;
 
207
                event.byteSize = 24;
 
208
                event.deltaFrames = _frames_ahead;
 
209
                event.flags = 0;
 
210
                event.detune = 0;
 
211
                event.noteLength = 0;
 
212
                event.noteOffset = 0;
 
213
                event.noteOffVelocity = 0;
 
214
                event.reserved1 = 0;
 
215
                event.reserved2 = 0;
 
216
                event.midiData[0] = _event.m_type + _event.m_channel;
 
217
                event.midiData[1] = _event.key();
 
218
                event.midiData[2] = _event.velocity();
 
219
                event.midiData[3] = 0;
 
220
                m_midiEvents.push_back( event );
 
221
        }
 
222
 
 
223
        void setSampleRate( Sint32 _rate )
 
224
        {
 
225
                m_plugin->dispatcher( m_plugin, effSetSampleRate, 0, 0, NULL, 
 
226
                                                            (float) _rate );
 
227
        }
 
228
 
 
229
        void setBlockSize( Uint32 _bsize )
 
230
        {
 
231
                if( _bsize == m_blockSize )
 
232
                {
 
233
                        return;
 
234
                }
 
235
                m_blockSize = _bsize;
 
236
                resizeSharedMemory();
 
237
                m_plugin->dispatcher( m_plugin, effSetBlockSize, 0, _bsize,
 
238
                                                                NULL, 0.0f );
 
239
        }
 
240
 
 
241
        Sint32 vstVersion( void ) const
 
242
        {
 
243
                return( m_plugin->dispatcher( m_plugin,
 
244
                                        effGetVstVersion, 0, 0, NULL, 0.0f ) );
 
245
        }
 
246
 
 
247
        const char * vstName( void ) const
 
248
        {
 
249
                static char buf[32];
 
250
                buf[0] = 0;
 
251
                m_plugin->dispatcher( m_plugin,
 
252
                                        effGetEffectName, 0, 0, buf, 0.0f );
 
253
                buf[31] = 0;
 
254
                return( buf );
 
255
        }
 
256
 
 
257
        const char * vstVendorString( void ) const
 
258
        {
 
259
                static char buf[64];
 
260
                buf[0] = 0;
 
261
                m_plugin->dispatcher( m_plugin,
 
262
                                        effGetVendorString, 0, 0, buf, 0.0f );
 
263
                buf[63] = 0;
 
264
                return( buf );
 
265
        }
 
266
 
 
267
        const char * vstProductString( void ) const
 
268
        {
 
269
                static char buf[64];
 
270
                buf[0] = 0;
 
271
                m_plugin->dispatcher( m_plugin,
 
272
                                        effGetProductString, 0, 0, buf, 0.0f );
 
273
                buf[63] = 0;
 
274
                return( buf );
 
275
        }
 
276
 
 
277
        Uint8 inputCount( void ) const
 
278
        {
 
279
                return( m_plugin->numInputs );
 
280
        }
 
281
 
 
282
        Uint8 outputCount( void ) const
 
283
        {
 
284
                return( m_plugin->numOutputs );
 
285
        }
 
286
 
 
287
        void resizeSharedMemory( void )
 
288
        {
 
289
                delete[] m_inputs;
 
290
                delete[] m_outputs;
 
291
 
 
292
                size_t s = ( inputCount() + outputCount() ) * m_blockSize *
 
293
                                                                sizeof( float );
 
294
                if( m_shm )
 
295
                {
 
296
                        shmdt( m_shm );
 
297
                }
 
298
                int shm_id;
 
299
                Uint16 shm_key = 0;
 
300
                while( ( shm_id = shmget( ++shm_key, s, IPC_CREAT | IPC_EXCL |
 
301
                                                        0666 ) ) == -1 )
 
302
                {
 
303
                }
 
304
                m_shm = (float *) shmat( shm_id, 0, 0 );
 
305
 
 
306
                if( inputCount() > 0 )
 
307
                {
 
308
                        m_inputs = new float * [inputCount()];
 
309
                }
 
310
                if( outputCount() > 0 )
 
311
                {
 
312
                        m_outputs = new float * [outputCount()];
 
313
                }
 
314
 
 
315
                writeValue<Sint16>( SET_INPUT_COUNT );
 
316
                writeValue<Uint8>( inputCount() );
 
317
 
 
318
                writeValue<Sint16>( SET_OUTPUT_COUNT );
 
319
                writeValue<Uint8>( outputCount() );
 
320
 
 
321
                writeValue<Sint16>( SET_SHM_KEY_AND_SIZE );
 
322
                writeValue<Uint16>( shm_key );
 
323
                writeValue<size_t>( s );
 
324
 
 
325
                writeValue<Sint16>( INITIALIZATION_DONE );
 
326
        }
 
327
 
 
328
 
 
329
private:
 
330
        static long hostCallback( AEffect * _effect, long _opcode, long _index,
 
331
                                        long _value, void * _ptr, float _opt );
 
332
 
 
333
        FSTHandle * m_handle;
 
334
        FST * m_fst;
 
335
        AEffect * m_plugin;
 
336
 
 
337
        Uint32 m_blockSize;
 
338
        float * m_shm;
 
339
 
 
340
        float ** m_inputs;
 
341
        float ** m_outputs;
 
342
 
 
343
        std::vector<VstMidiEvent> m_midiEvents;
 
344
 
 
345
} ;
 
346
 
 
347
 
 
348
 
 
349
VSTPlugin * plugin = NULL;
 
350
 
 
351
 
 
352
#define DEBUG_CALLBACKS
 
353
#ifdef DEBUG_CALLBACKS
 
354
#define SHOW_CALLBACK debugMsg
 
355
#else
 
356
#define SHOW_CALLBACK(...)
 
357
#endif
 
358
 
 
359
 
 
360
long VSTPlugin::hostCallback( AEffect * _effect, long _opcode, long _index,
 
361
                                        long _value, void * _ptr, float _opt )
 
362
{
 
363
        static VstTimeInfo _timeInfo;
 
364
/*      sprintf( debugout, "host-callback, opcode = %d\n", (int) _opcode );
 
365
        SHOW_CALLBACK( debugout );*/
 
366
        
 
367
        switch( _opcode )
 
368
        {
 
369
                case audioMasterAutomate:
 
370
                        /*SHOW_CALLBACK( "amc: audioMasterAutomate\n" );*/
 
371
                        // index, value, returns 0
 
372
                        _effect->setParameter( _effect, _index, _opt );
 
373
                        return( 0 );
 
374
 
 
375
                case audioMasterVersion:
 
376
                        SHOW_CALLBACK( "amc: audioMasterVersion\n" );
 
377
                        // vst version, currently 2 (0 for older)
 
378
                        return( 2 );
 
379
 
 
380
                case audioMasterCurrentId:      
 
381
                        SHOW_CALLBACK( "amc: audioMasterCurrentId\n" );
 
382
                        // returns the unique id of a plug that's currently
 
383
                        // loading
 
384
                        return( 0 );
 
385
                
 
386
                case audioMasterIdle:
 
387
                        SHOW_CALLBACK ("amc: audioMasterIdle\n" );
 
388
                        // call application idle routine (this will
 
389
                        // call effEditIdle for all open editors too) 
 
390
                        _effect->dispatcher( _effect, effEditIdle, 0, 0, NULL,
 
391
                                                                        0.0f );
 
392
                        return( 0 );
 
393
 
 
394
                case audioMasterPinConnected:           
 
395
                        SHOW_CALLBACK( "amc: audioMasterPinConnected\n" );
 
396
                        // inquire if an input or output is beeing connected;
 
397
                        // index enumerates input or output counting from zero:
 
398
                        // value is 0 for input and != 0 otherwise. note: the
 
399
                        // return value is 0 for <true> such that older versions
 
400
                        // will always return true.
 
401
                        return( 1 );
 
402
 
 
403
                case audioMasterWantMidi:
 
404
                        SHOW_CALLBACK( "amc: audioMasterWantMidi\n" );
 
405
                        // <value> is a filter which is currently ignored
 
406
                        return( 0 );
 
407
 
 
408
                case audioMasterGetTime:
 
409
                        //SHOW_CALLBACK( "amc: audioMasterGetTime\n" );
 
410
                        // returns const VstTimeInfo* (or 0 if not supported)
 
411
                        // <value> should contain a mask indicating which
 
412
                        // fields are required (see valid masks above), as some
 
413
                        // items may require extensive conversions
 
414
 
 
415
                        memset( &_timeInfo, 0, sizeof( _timeInfo ) );
 
416
 
 
417
                        _timeInfo.samplePos = 0;
 
418
                        // TODO: _timeInfo.sampleRate = mixer::inst()->sampleRate();
 
419
                        _timeInfo.flags = 0;
 
420
                        // TODO: _timeInfo.tempo = songEditor::inst()->getBPM();
 
421
                        _timeInfo.timeSigNumerator = 4;
 
422
                        _timeInfo.timeSigDenominator = 4;
 
423
                        _timeInfo.flags |= ( kVstBarsValid | kVstTempoValid );
 
424
                        _timeInfo.flags |= kVstTransportPlaying;
 
425
 
 
426
                        return( (long)&_timeInfo );
 
427
 
 
428
                case audioMasterProcessEvents:
 
429
                        SHOW_CALLBACK( "amc: audioMasterProcessEvents\n" );
 
430
                        // VstEvents* in <ptr>
 
431
                        return( 0 );
 
432
 
 
433
                case audioMasterSetTime:
 
434
                        SHOW_CALLBACK( "amc: audioMasterSetTime\n" );
 
435
                        // VstTimenfo* in <ptr>, filter in <value>, not
 
436
                        // supported
 
437
 
 
438
                case audioMasterTempoAt:
 
439
                        SHOW_CALLBACK( "amc: audioMasterTempoAt\n" );
 
440
                        // returns tempo (in bpm * 10000) at sample frame
 
441
                        // location passed in <value>
 
442
                        return( 0 );
 
443
 
 
444
                case audioMasterGetNumAutomatableParameters:
 
445
                        SHOW_CALLBACK( "amc: audioMasterGetNumAutomatable"
 
446
                                                        "Parameters\n" );
 
447
                        return( 0 );
 
448
 
 
449
                case audioMasterGetParameterQuantization:       
 
450
                        SHOW_CALLBACK( "amc: audioMasterGetParameter\n"
 
451
                                                        "Quantization\n" );
 
452
                        // returns the integer value for +1.0 representation,
 
453
                        // or 1 if full single float precision is maintained
 
454
                        // in automation. parameter index in <value> (-1: all,
 
455
                        // any)
 
456
                        return( 0 );
 
457
 
 
458
                case audioMasterIOChanged:
 
459
                        plugin->resizeSharedMemory();
 
460
                        SHOW_CALLBACK( "amc: audioMasterIOChanged\n" );
 
461
                        // numInputs and/or numOutputs has changed
 
462
                        return( 0 );
 
463
 
 
464
                case audioMasterNeedIdle:
 
465
                        SHOW_CALLBACK( "amc: audioMasterNeedIdle\n" );
 
466
                        // plug needs idle calls (outside its editor window)
 
467
                        return( 0 );
 
468
 
 
469
                case audioMasterSizeWindow:
 
470
                        // TODO using lmms-main-window-size
 
471
                        SHOW_CALLBACK( "amc: audioMasterSizeWindow\n" );
 
472
                        // index: width, value: height
 
473
                        return( 0 );
 
474
 
 
475
                case audioMasterGetSampleRate:
 
476
                        // TODO using mixer-call
 
477
                        SHOW_CALLBACK( "amc: audioMasterGetSampleRate\n" );
 
478
                        return( 0 );
 
479
 
 
480
                case audioMasterGetBlockSize:
 
481
                        // TODO using mixer-call
 
482
                        SHOW_CALLBACK( "amc: audioMasterGetBlockSize\n" );
 
483
                        return( 0 );
 
484
 
 
485
                case audioMasterGetInputLatency:
 
486
                        // TODO using mixer-call
 
487
                        SHOW_CALLBACK( "amc: audioMasterGetInputLatency\n" );
 
488
                        return( 0 );
 
489
 
 
490
                case audioMasterGetOutputLatency:
 
491
                        // TODO using mixer-call
 
492
                        SHOW_CALLBACK( "amc: audioMasterGetOutputLatency\n" );
 
493
                        return( 0 );
 
494
 
 
495
                case audioMasterGetPreviousPlug:
 
496
                        SHOW_CALLBACK( "amc: audioMasterGetPreviousPlug\n" );
 
497
                        // input pin in <value> (-1: first to come), returns
 
498
                        // cEffect*
 
499
                        return( 0 );
 
500
 
 
501
                case audioMasterGetNextPlug:
 
502
                        SHOW_CALLBACK( "amc: audioMasterGetNextPlug\n" );
 
503
                        // output pin in <value> (-1: first to come), returns
 
504
                        // cEffect*
 
505
                        return( 0 );
 
506
 
 
507
                case audioMasterWillReplaceOrAccumulate:
 
508
                        SHOW_CALLBACK( "amc: audioMasterWillReplaceOr"
 
509
                                                        "Accumulate\n" );
 
510
                        // returns: 0: not supported, 1: replace, 2: accumulate
 
511
                        return( 0 );
 
512
 
 
513
                case audioMasterGetCurrentProcessLevel:
 
514
                        SHOW_CALLBACK( "amc: audioMasterGetCurrentProcess"
 
515
                                                                "Level\n" );
 
516
                        // returns: 0: not supported,
 
517
                        // 1: currently in user thread (gui)
 
518
                        // 2: currently in audio thread (where process is
 
519
                        //    called)
 
520
                        // 3: currently in 'sequencer' thread (midi, timer etc)
 
521
                        // 4: currently offline processing and thus in user
 
522
                        //    thread
 
523
                        // other: not defined, but probably pre-empting user
 
524
                        //        thread.
 
525
                        return( 0 );
 
526
 
 
527
                case audioMasterGetAutomationState:
 
528
                        SHOW_CALLBACK( "amc: audioMasterGetAutomationState\n" );
 
529
                        // returns 0: not supported, 1: off, 2:read, 3:write,
 
530
                        // 4:read/write offline
 
531
                        return( 0 );
 
532
 
 
533
                case audioMasterOfflineStart:
 
534
                        SHOW_CALLBACK( "amc: audioMasterOfflineStart\n" );
 
535
                        return( 0 );
 
536
 
 
537
                case audioMasterOfflineRead:
 
538
                        SHOW_CALLBACK( "amc: audioMasterOfflineRead\n" );
 
539
                        // ptr points to offline structure, see below.
 
540
                        // return 0: error, 1 ok
 
541
                        return( 0 );
 
542
 
 
543
                case audioMasterOfflineWrite:
 
544
                        SHOW_CALLBACK( "amc: audioMasterOfflineWrite\n" );
 
545
                        // same as read
 
546
                        return( 0 );
 
547
 
 
548
                case audioMasterOfflineGetCurrentPass:
 
549
                        SHOW_CALLBACK( "amc: audioMasterOfflineGetCurrent"
 
550
                                                                "Pass\n" );
 
551
                        return( 0 );
 
552
 
 
553
                case audioMasterOfflineGetCurrentMetaPass:
 
554
                        SHOW_CALLBACK( "amc: audioMasterOfflineGetCurrentMeta"
 
555
                                                                "Pass\n");
 
556
                        return( 0 );
 
557
 
 
558
                case audioMasterSetOutputSampleRate:
 
559
                        SHOW_CALLBACK( "amc: audioMasterSetOutputSample"
 
560
                                                                "Rate\n" );
 
561
                        // for variable i/o, sample rate in <opt>
 
562
                        return( 0 );
 
563
 
 
564
                case audioMasterGetSpeakerArrangement:
 
565
                        SHOW_CALLBACK( "amc: audioMasterGetSpeaker"
 
566
                                                        "Arrangement\n" );
 
567
                        // (long)input in <value>, output in <ptr>
 
568
                        return( 0 );
 
569
 
 
570
                case audioMasterGetVendorString:
 
571
                        SHOW_CALLBACK( "amc: audioMasterGetVendorString\n" );
 
572
                        // fills <ptr> with a string identifying the vendor
 
573
                        // (max 64 char)
 
574
                        strcpy( (char *) _ptr, "LAD");
 
575
                        return( 0 );
 
576
 
 
577
                case audioMasterGetProductString:
 
578
                        SHOW_CALLBACK( "amc: audioMasterGetProductString\n" );
 
579
                        // fills <ptr> with a string with product name
 
580
                        // (max 64 char)
 
581
                        strcpy( (char *) _ptr, "XFST-Server" );
 
582
                        return( 0 );
 
583
 
 
584
                case audioMasterGetVendorVersion:
 
585
                        SHOW_CALLBACK( "amc: audioMasterGetVendorVersion\n" );
 
586
                        // TODO
 
587
                        // returns vendor-specific version
 
588
                        return( 1000 );
 
589
 
 
590
                case audioMasterVendorSpecific:
 
591
                        SHOW_CALLBACK( "amc: audioMasterVendorSpecific\n" );
 
592
                        // no definition, vendor specific handling
 
593
                        return( 0 );
 
594
                
 
595
                case audioMasterSetIcon:
 
596
                        SHOW_CALLBACK( "amc: audioMasterSetIcon\n" );
 
597
                        // TODO
 
598
                        // void* in <ptr>, format not defined yet
 
599
                        return( 0 );
 
600
 
 
601
                case audioMasterCanDo:
 
602
                        SHOW_CALLBACK( "amc: audioMasterCanDo\n" );
 
603
                        // string in ptr, see below
 
604
                        return( 0 );
 
605
                
 
606
                case audioMasterGetLanguage:
 
607
                        SHOW_CALLBACK( "amc: audioMasterGetLanguage\n" );
 
608
                        // TODO
 
609
                        // see enum
 
610
                        return( 0 );
 
611
 
 
612
                case audioMasterOpenWindow:
 
613
                        SHOW_CALLBACK( "amc: audioMasterOpenWindow\n" );
 
614
                        // TODO
 
615
                        // returns platform specific ptr
 
616
                        return( 0 );
 
617
                
 
618
                case audioMasterCloseWindow:
 
619
                        SHOW_CALLBACK( "amc: audioMasterCloseWindow\n" );
 
620
                        // TODO
 
621
                        // close window, platform specific handle in <ptr>
 
622
                        return( 0 );
 
623
                
 
624
                case audioMasterGetDirectory:
 
625
                        SHOW_CALLBACK( "amc: audioMasterGetDirectory\n" );
 
626
                        // TODO
 
627
                        // get plug directory, FSSpec on MAC, else char*
 
628
                        return( 0 );
 
629
                
 
630
                case audioMasterUpdateDisplay:
 
631
                        SHOW_CALLBACK( "amc: audioMasterUpdateDisplay\n" );
 
632
                        // something has changed, update 'multi-fx' display
 
633
                        _effect->dispatcher( _effect, effEditIdle, 0, 0, NULL,
 
634
                                                                        0.0f );
 
635
                        return( 0 );
 
636
 
 
637
                case audioMasterBeginEdit:
 
638
                        SHOW_CALLBACK( "amc: audioMasterBeginEdit\n" );
 
639
                        // begin of automation session (when mouse down),       
 
640
                        // parameter index in <index>
 
641
                        return( 0 );
 
642
 
 
643
                case audioMasterEndEdit:
 
644
                        SHOW_CALLBACK( "amc: audioMasterEndEdit\n" );
 
645
                        // end of automation session (when mouse up),
 
646
                        // parameter index in <index>
 
647
                        return( 0 );
 
648
 
 
649
                case audioMasterOpenFileSelector:
 
650
                        SHOW_CALLBACK( "amc: audioMasterOpenFileSelector\n" );
 
651
                        // open a fileselector window with VstFileSelect*
 
652
                        // in <ptr>
 
653
                        return( 0 );
 
654
 
 
655
                default:
 
656
                        sprintf( debugout, "VST master dispatcher: undefed: "
 
657
                                "%d, %d\n", (int) _opcode, effKeysRequired );
 
658
                        SHOW_CALLBACK( debugout );
 
659
                        break;
 
660
        }
 
661
 
 
662
        return( 0 );
 
663
}
 
664
 
 
665
 
 
666
 
 
667
 
 
668
int 
 
669
main( int argc, char * * argv ) 
 
670
{
 
671
        wine_shared_premain();
 
672
 
 
673
        Sint16 cmd;
 
674
        while( ( cmd = readValue<Sint16>() ) != CLOSE_VST_PLUGIN )
 
675
        {
 
676
                switch( cmd )
 
677
                {
 
678
                        case LOAD_VST_PLUGIN:
 
679
                                plugin = new VSTPlugin( readString().c_str() );
 
680
                                break;
 
681
 
 
682
                        case PROCESS:
 
683
                                plugin->process();
 
684
                                break;
 
685
 
 
686
                        case ENQUEUE_MIDI_EVENT:
 
687
                        {
 
688
                                const midiEvent ev = readValue<midiEvent>();
 
689
                                const Uint32 fr_ahead = readValue<Uint32>();
 
690
                                plugin->enqueueMidiEvent( ev, fr_ahead );
 
691
                                break;
 
692
                        }
 
693
 
 
694
                        case SET_SAMPLE_RATE:
 
695
                                plugin->setSampleRate( readValue<Sint32>() );
 
696
                                break;
 
697
 
 
698
 
 
699
                        case SET_BUFFER_SIZE:
 
700
                                plugin->setBlockSize( readValue<Uint32>() );
 
701
                                break;
 
702
 
 
703
                        case GET_VST_VERSION:
 
704
                                writeValue<Sint16>( SET_VST_VERSION );
 
705
                                writeValue<Sint32>( plugin->vstVersion() );
 
706
                                break;
 
707
 
 
708
                        case GET_NAME:
 
709
                                writeValue<Sint16>( SET_NAME );
 
710
                                writeString( plugin->vstName() );
 
711
                                break;
 
712
 
 
713
                        case GET_VENDOR_STRING:
 
714
                                writeValue<Sint16>( SET_VENDOR_STRING );
 
715
                                writeString( plugin->vstVendorString() );
 
716
                                break;
 
717
 
 
718
                        case GET_PRODUCT_STRING:
 
719
                                writeValue<Sint16>( SET_PRODUCT_STRING );
 
720
                                writeString( plugin->vstProductString() );
 
721
                                break;
 
722
 
 
723
                        default:
 
724
                                debugMsg( "unhandled message!" );
 
725
                                break;
 
726
                }
 
727
        }
 
728
 
 
729
        delete plugin;
 
730
 
 
731
        return( 0 );
 
732
 
 
733
}
 
734