~ubuntu-branches/ubuntu/oneiric/muse/oneiric

« back to all changes in this revision

Viewing changes to muse/osc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2010-11-17 21:43:38 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20101117214338-1hvfl7oo2dsqnvrb
Tags: 1.1-0ubuntu1
* New upstream release (LP: #668631)
* Switch to dpkg-source 3.0 (quilt) format
* Switch to dh7 short form
* debian/rules:
  - added --enable-dssi and --enable-osc to conf flags for dssi support
  - added -ljackserver to LDFLAGS to fix a FTBFS because of --as-needed
* debian/control:
  - added build build dependency on liblo-dev and dssi-dev for dssi support
  - bump Standards-version to 3.9.1. No changes required.
* debian/muse.desktop, debian/muse.xpm: dropped as desktop file and icon is
  now shipped upstream.
* fix-desktop-categories.patch: fix Categories tag in upstream desktop file
* 10_es_locale_fix.dpatch: refreshed and converted to quilt as
  fix_es_locale.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//  MusE
 
3
//  Linux Music Editor
 
4
//  $Id: osc.cpp,v 1.0.0.0 2010/04/22 03:39:58 terminator356 Exp $
 
5
//
 
6
//  Copyright (C) 1999-2010 by Werner Schweer and others
 
7
//  OSC module added by Tim.
 
8
//
 
9
//  This program is free software; you can redistribute it and/or modify
 
10
//  it under the terms of the GNU General Public License version 2.
 
11
//
 
12
//  This program is distributed in the hope that it will be useful,
 
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
//  GNU General Public License for more details.
 
16
//
 
17
//  You should have received a copy of the GNU General Public License
 
18
//  along with this program; if not, write to the Free Software
 
19
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
20
//=============================================================================
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#ifdef OSC_SUPPORT
 
25
 
 
26
// Turn on debugging messages
 
27
//#define OSC_DEBUG 
 
28
 
 
29
#include <string.h>
 
30
//#include <signal.h>
 
31
//#include <dlfcn.h>
 
32
#include <stdlib.h>
 
33
#include <sys/stat.h>
 
34
#include <errno.h>
 
35
//#include <dssi.h>
 
36
//#include <alsa/asoundlib.h>
 
37
#include <qt.h>
 
38
#include <qdir.h>
 
39
#include <qstring.h>
 
40
#include <qstringlist.h>
 
41
#include <qfileinfo.h>
 
42
//#include <qpopupmenu.h>
 
43
#include <qprocess.h>
 
44
#include <qtimer.h>
 
45
#include <lo/lo.h>
 
46
 
 
47
#ifdef DSSI_SUPPORT
 
48
#include "dssihost.h"
 
49
#endif
 
50
 
 
51
#include "stringparam.h"
 
52
#include "plugin.h"
 
53
#include "track.h"
 
54
#include "song.h"
 
55
#include "synth.h"
 
56
//#include "audio.h"
 
57
//#include "jackaudio.h"
 
58
//#include "midi.h"
 
59
//#include "midiport.h"
 
60
//#include "al/al.h"
 
61
//#include "al/xml.h"
 
62
//#include "xml.h"
 
63
//#include "midictrl.h"
 
64
//#include "ladspaplugin.h"
 
65
 
 
66
#include "app.h"
 
67
#include "globals.h"
 
68
#include "globaldefs.h"
 
69
//#include "al/dsp.h"
 
70
 
 
71
static lo_server_thread serverThread = 0;
 
72
///static char osc_path_tmp[1024];
 
73
static char* url = 0;
 
74
static bool oscServerRunning = false;
 
75
 
 
76
//---------------------------------------------------------
 
77
//   oscError
 
78
//---------------------------------------------------------
 
79
 
 
80
static void oscError(int num, const char *msg, const char *path)
 
81
      {
 
82
      fprintf(stderr, "MusE: liblo server error %d in path %s: %s\n",
 
83
          num, path, msg);
 
84
      }
 
85
 
 
86
//---------------------------------------------------------
 
87
//   oscDebugHandler
 
88
//---------------------------------------------------------
 
89
 
 
90
static int oscDebugHandler(const char* path, const char* types, lo_arg** argv,
 
91
   int argc, void*, void*)
 
92
      {
 
93
      printf("MusE: got unhandled OSC message:\n   path: <%s>\n", path);
 
94
      for (int i = 0; i < argc; i++) {
 
95
            printf("   arg %d '%c' ", i, types[i]);
 
96
            lo_arg_pp(lo_type(types[i]), argv[i]);
 
97
            printf("\n");
 
98
            }
 
99
      return 1;
 
100
      }
 
101
 
 
102
//---------------------------------------------------------
 
103
//   oscMessageHandler
 
104
//---------------------------------------------------------
 
105
 
 
106
int oscMessageHandler(const char* path, const char* types, lo_arg** argv,
 
107
   int argc, void* data, void* user_data)
 
108
{
 
109
  const char* p = path;
 
110
  
 
111
  #ifdef OSC_DEBUG 
 
112
  if(argc) 
 
113
  {
 
114
      printf("oscMessageHandler: path:%s argc:%d\n", path, argc);
 
115
      for(int i = 0; i < argc; ++i) 
 
116
      {
 
117
        printf(" ");
 
118
        lo_arg_pp((lo_type)types[i], argv[i]);
 
119
      }
 
120
      printf("\n");
 
121
  } 
 
122
  else 
 
123
  {
 
124
      printf("%s\n", path);
 
125
      printf("oscMessageHandler: no args, path:%s\n", path);
 
126
  }
 
127
  #endif  
 
128
    
 
129
  bool isSynth = false;
 
130
  
 
131
  #ifdef DSSI_SUPPORT
 
132
  if(strncmp(p, "/dssi_synth/", 12) == 0)
 
133
  {
 
134
    isSynth = true;
 
135
    p += 12;
 
136
  }
 
137
  else
 
138
  #endif
 
139
  if(strncmp(p, "/ladspa_efx/", 12) == 0)
 
140
  {
 
141
    p += 12;
 
142
  }
 
143
  else
 
144
    return oscDebugHandler(path, types, argv, argc, data, user_data);
 
145
 
 
146
  TrackList* tl = song->tracks();
 
147
  
 
148
 
 
149
  #ifdef OSC_DEBUG 
 
150
  if(isSynth)
 
151
    fprintf(stderr, "oscMessageHandler: got message for dssi synth...\n");
 
152
  else  
 
153
    fprintf(stderr, "oscMessageHandler: got message for ladspa effect...\n");
 
154
  #endif
 
155
    
 
156
  // FIXME: Slowdowns: Shouldn't need these retries but they are needed, only upon creation of the synth. 
 
157
  // Need to fix the real source of the problem! The instance is taking too long to appear after creation.
 
158
  //
 
159
  ///for(int retry = 0; retry < 5000; ++retry) 
 
160
  {
 
161
    ///#ifdef OSC_DEBUG 
 
162
    ///fprintf(stderr, "oscMessageHandler: search retry number:%d ...\n", retry);
 
163
    ///#endif
 
164
    
 
165
    //if(_uiOscPath)
 
166
    //  break;
 
167
  
 
168
    #ifdef DSSI_SUPPORT
 
169
    if(isSynth)
 
170
    {
 
171
      // Message is meant for a dssi synth. Check dssi synth instances...
 
172
      SynthIList* sl = song->syntis();
 
173
      for(iSynthI si = sl->begin(); si != sl->end(); ++si) 
 
174
      {
 
175
        SynthI* synti = *si;
 
176
        
 
177
        #ifdef OSC_DEBUG 
 
178
        fprintf(stderr, "oscMessageHandler: searching for:%s checking synth instance:%s\n", p, synti->name().latin1());
 
179
        #endif
 
180
        
 
181
        const char* sub = strstr(p, synti->name().latin1());
 
182
        if(sub == NULL) 
 
183
          continue;
 
184
        
 
185
        //DssiSynthIF* instance = (DssiSynthIF*)synti->sif();
 
186
        DssiSynthIF* instance = dynamic_cast<DssiSynthIF*>(synti->sif());
 
187
        if(!instance)
 
188
          break;
 
189
          
 
190
        p = sub + strlen(synti->name().latin1());
 
191
        
 
192
        if (*p != '/' || *(p + 1) == 0)
 
193
        {
 
194
          fprintf(stderr, "oscMessageHandler error: synth: end of path or no /\n");
 
195
          return oscDebugHandler(path, types, argv, argc, data, user_data);
 
196
        }
 
197
              
 
198
        ++p;
 
199
  
 
200
        #ifdef OSC_DEBUG 
 
201
        fprintf(stderr, "oscMessageHandler: synth track:%s method:%s\n", synti->name().latin1(), p);
 
202
        #endif
 
203
        
 
204
        OscIF& oscif = instance->oscIF();
 
205
        
 
206
        if (!strcmp(p, "configure") && argc == 2 && !strcmp(types, "ss"))
 
207
              return oscif.oscConfigure(argv);
 
208
        else if (!strcmp(p, "control") && argc == 2 && !strcmp(types, "if"))
 
209
              return oscif.oscControl(argv);
 
210
        else if (!strcmp(p, "midi") && argc == 1 && !strcmp(types, "m"))
 
211
              return oscif.oscMidi(argv);
 
212
        else if (!strcmp(p, "program") && argc == 2 && !strcmp(types, "ii"))
 
213
              return oscif.oscProgram(argv);
 
214
        else if (!strcmp(p, "update") && argc == 1 && !strcmp(types, "s"))
 
215
              return oscif.oscUpdate(argv);
 
216
        else if (!strcmp(p, "exiting") && argc == 0)
 
217
              return oscif.oscExiting(argv);
 
218
        return oscDebugHandler(path, types, argv, argc, data, user_data);
 
219
      }
 
220
    }
 
221
    else
 
222
    #endif //DSSI_SUPPORT
 
223
    // Message is meant for a ladspa effect. Check all ladspa effect instances...
 
224
    for(ciTrack it = tl->begin(); it != tl->end(); ++it) 
 
225
    {
 
226
      if((*it)->isMidiTrack())
 
227
        continue;
 
228
        
 
229
      Pipeline* efxPipe = ((AudioTrack*)*it)->efxPipe();
 
230
      if(efxPipe)
 
231
      {
 
232
        for(ciPluginI ip = efxPipe->begin(); ip != efxPipe->end(); ++ip)
 
233
        {
 
234
          PluginI* instance = *ip;
 
235
          if(!instance)
 
236
            continue;
 
237
          
 
238
          #ifdef OSC_DEBUG 
 
239
          fprintf(stderr, "oscMessageHandler: searching for:%s checking effect instance:%s label:%s lib:%s\n", 
 
240
                  p, instance->name().latin1(), instance->label().latin1(), instance->lib().latin1());
 
241
          #endif
 
242
          
 
243
          //const char* sub = strstr(p, instance->name().latin1());
 
244
          const char* sub = strstr(p, instance->label().latin1());
 
245
          if(sub == NULL) 
 
246
            continue;
 
247
            
 
248
          Plugin* plugin = instance->plugin();
 
249
          if(!plugin)
 
250
            break;
 
251
          
 
252
          //p = sub + strlen(instance->name().latin1());
 
253
          p = sub + strlen(instance->label().latin1());
 
254
          
 
255
          if (*p != '/' || *(p + 1) == 0)
 
256
          {
 
257
            fprintf(stderr, "oscMessageHandler: error: effect: end of path or no /\n");
 
258
            return oscDebugHandler(path, types, argv, argc, data, user_data);
 
259
          }
 
260
                
 
261
          ++p;
 
262
    
 
263
          #ifdef OSC_DEBUG 
 
264
          //fprintf(stderr, "oscMessageHandler: effect:%s method:%s\n", instance->name().latin1(), p);
 
265
          fprintf(stderr, "oscMessageHandler: effect:%s method:%s\n", instance->label().latin1(), p);
 
266
          #endif
 
267
          
 
268
          OscIF& oscif = instance->oscIF();
 
269
          
 
270
          if (!strcmp(p, "configure") && argc == 2 && !strcmp(types, "ss"))
 
271
                return oscif.oscConfigure(argv);
 
272
          else if (!strcmp(p, "control") && argc == 2 && !strcmp(types, "if"))
 
273
                return oscif.oscControl(argv);
 
274
          else if (!strcmp(p, "midi") && argc == 1 && !strcmp(types, "m"))
 
275
                return oscif.oscMidi(argv);
 
276
          else if (!strcmp(p, "program") && argc == 2 && !strcmp(types, "ii"))
 
277
                return oscif.oscProgram(argv);
 
278
          else if (!strcmp(p, "update") && argc == 1 && !strcmp(types, "s"))
 
279
                return oscif.oscUpdate(argv);
 
280
          else if (!strcmp(p, "exiting") && argc == 0)
 
281
                return oscif.oscExiting(argv);
 
282
          return oscDebugHandler(path, types, argv, argc, data, user_data);
 
283
        }
 
284
      }
 
285
    }
 
286
      
 
287
    ///usleep(1000);
 
288
  }
 
289
  
 
290
  fprintf(stderr, "oscMessageHandler: timeout error: no synth or effect instance found for given path\n");
 
291
  return oscDebugHandler(path, types, argv, argc, data, user_data);
 
292
}
 
293
 
 
294
 
 
295
//---------------------------------------------------------
 
296
//   initOSC
 
297
//---------------------------------------------------------
 
298
 
 
299
void initOSC()
 
300
{
 
301
  if(url)
 
302
    free(url);
 
303
  url = 0;
 
304
    
 
305
  // Create OSC thread
 
306
  // Only if not created yet. 
 
307
  if(!serverThread)
 
308
  {
 
309
    serverThread = lo_server_thread_new(0, oscError);
 
310
    if(!serverThread)
 
311
    {
 
312
      printf("initOSC() Failed to create OSC server!\n");
 
313
      return;
 
314
    }
 
315
  }  
 
316
  
 
317
  ///snprintf(osc_path_tmp, 31, "/dssi");
 
318
  // Test: Clear the temp path:
 
319
  //snprintf(osc_path_tmp, 31, "");
 
320
  
 
321
  ///char* tmp = lo_server_thread_get_url(serverThread);
 
322
  
 
323
  url = lo_server_thread_get_url(serverThread);
 
324
  if(!url)
 
325
  {
 
326
    lo_server_thread_free(serverThread);
 
327
    printf("initOSC() Failed to get OSC server thread url !\n");
 
328
    return;
 
329
  }
 
330
  
 
331
  ///url = (char *)malloc(strlen(tmp) + strlen(osc_path_tmp));
 
332
  //url = (char *)malloc(strlen(tmp));
 
333
  
 
334
  ///sprintf(url, "%s%s", tmp, osc_path_tmp + 1);
 
335
  //sprintf(url, "%s", tmp, osc_path_tmp + 1);
 
336
  
 
337
  ///free(tmp);
 
338
  
 
339
  lo_method meth = 0;
 
340
  meth = lo_server_thread_add_method(serverThread, 0, 0, oscMessageHandler, 0);
 
341
  if(!meth)
 
342
  {
 
343
    printf("initOSC() Failed to add oscMessageHandler method to OSC server!\n");
 
344
    // Does not return a value.
 
345
    lo_server_thread_free(serverThread);
 
346
    serverThread = 0;
 
347
    free(url);
 
348
    url = 0;
 
349
    return;
 
350
  }
 
351
  
 
352
  // Does not return a value.
 
353
  lo_server_thread_start(serverThread);
 
354
}
 
355
 
 
356
//---------------------------------------------------------
 
357
//   exitOSC
 
358
//---------------------------------------------------------
 
359
 
 
360
void exitOSC()
 
361
{
 
362
  oscServerRunning = false;  
 
363
  if(serverThread)
 
364
  {
 
365
    // Does not return a value.
 
366
    lo_server_thread_stop(serverThread);
 
367
    lo_server_thread_free(serverThread);
 
368
  }  
 
369
  serverThread = 0;
 
370
}
 
371
 
 
372
//---------------------------------------------------------
 
373
//   startOSC
 
374
//---------------------------------------------------------
 
375
 
 
376
void startOSC()
 
377
{
 
378
  if(serverThread)
 
379
    // Does not return a value.
 
380
    lo_server_thread_start(serverThread);
 
381
  oscServerRunning = true;  
 
382
}
 
383
 
 
384
//---------------------------------------------------------
 
385
//   stopOSC
 
386
//---------------------------------------------------------
 
387
 
 
388
void stopOSC()
 
389
{
 
390
  if(serverThread)
 
391
    // Does not return a value.
 
392
    lo_server_thread_stop(serverThread);
 
393
  oscServerRunning = false;  
 
394
}
 
395
        
 
396
 
 
397
 
 
398
//---------------------------------------------------------
 
399
//   OscControlFifo
 
400
//    put
 
401
//    return true on fifo overflow
 
402
//---------------------------------------------------------
 
403
 
 
404
bool OscControlFifo::put(const OscControlValue& event)
 
405
      {
 
406
      if (size < OSC_FIFO_SIZE) {
 
407
            fifo[wIndex] = event;
 
408
            wIndex = (wIndex + 1) % OSC_FIFO_SIZE;
 
409
            // q_atomic_increment(&size);
 
410
            ++size;
 
411
            return false;
 
412
            }
 
413
      return true;
 
414
      }
 
415
 
 
416
//---------------------------------------------------------
 
417
//   get
 
418
//---------------------------------------------------------
 
419
 
 
420
OscControlValue OscControlFifo::get()
 
421
      {
 
422
      OscControlValue event(fifo[rIndex]);
 
423
      rIndex = (rIndex + 1) % OSC_FIFO_SIZE;
 
424
      // q_atomic_decrement(&size);
 
425
      --size;
 
426
      return event;
 
427
      }
 
428
 
 
429
//---------------------------------------------------------
 
430
//   peek
 
431
//---------------------------------------------------------
 
432
 
 
433
const OscControlValue& OscControlFifo::peek(int n)
 
434
      {
 
435
      int idx = (rIndex + n) % OSC_FIFO_SIZE;
 
436
      return fifo[idx];
 
437
      }
 
438
 
 
439
//---------------------------------------------------------
 
440
//   remove
 
441
//---------------------------------------------------------
 
442
 
 
443
void OscControlFifo::remove()
 
444
      {
 
445
      rIndex = (rIndex + 1) % OSC_FIFO_SIZE;
 
446
      // q_atomic_decrement(&size);
 
447
      --size;
 
448
      }
 
449
 
 
450
 
 
451
 
 
452
//---------------------------------------------------------
 
453
//   OscIF
 
454
//   Open Sound Control Interface
 
455
//---------------------------------------------------------
 
456
 
 
457
OscIF::OscIF()
 
458
{
 
459
  //_oscPluginI = 0;
 
460
  
 
461
  //#ifdef DSSI_SUPPORT
 
462
  //_oscSynthIF = 0;
 
463
  //#endif
 
464
  
 
465
  _uiOscTarget = 0;
 
466
  _uiOscSampleRatePath = 0;
 
467
  _uiOscShowPath = 0;
 
468
  _uiOscControlPath = 0;
 
469
  _uiOscConfigurePath = 0;
 
470
  _uiOscProgramPath = 0;
 
471
  _uiOscPath = 0;
 
472
  //guiPid = -1;
 
473
  _oscGuiQProc = 0;
 
474
  _oscGuiVisible = false;
 
475
  
 
476
  _oscControlFifos = 0;
 
477
}
 
478
 
 
479
OscIF::~OscIF()
 
480
{
 
481
  //if (guiPid != -1)
 
482
  //      kill(guiPid, SIGHUP);
 
483
  if(_oscGuiQProc)
 
484
  {
 
485
    if(_oscGuiQProc->isRunning())
 
486
    {
 
487
      #ifdef OSC_DEBUG 
 
488
      printf("OscIF::~OscIF terminating _oscGuiQProc\n");
 
489
      #endif
 
490
      
 
491
      //_oscGuiQProc->kill();
 
492
      // "This tries to terminate the process the nice way. If the process is still running after 5 seconds, 
 
493
      //  it terminates the process the hard way. The timeout should be chosen depending on the time the 
 
494
      //  process needs to do all its cleanup: use a higher value if the process is likely to do a lot of 
 
495
      //  computation or I/O on cleanup."           
 
496
      _oscGuiQProc->tryTerminate();
 
497
      QTimer::singleShot( 5000, _oscGuiQProc, SLOT( kill() ) );          
 
498
    }  
 
499
    //delete _oscGuiQProc;
 
500
  }
 
501
      
 
502
  if(_uiOscTarget)
 
503
    lo_address_free(_uiOscTarget);
 
504
  if(_uiOscSampleRatePath)
 
505
    free(_uiOscSampleRatePath);
 
506
  if(_uiOscShowPath)
 
507
    free(_uiOscShowPath);
 
508
  if(_uiOscControlPath)
 
509
    free(_uiOscControlPath);
 
510
  if(_uiOscConfigurePath)
 
511
    free(_uiOscConfigurePath);
 
512
  if(_uiOscProgramPath)
 
513
    free(_uiOscProgramPath);
 
514
  if(_uiOscPath)
 
515
    free(_uiOscPath);
 
516
    
 
517
  if(_oscControlFifos)
 
518
    delete[] _oscControlFifos;
 
519
}
 
520
 
 
521
//---------------------------------------------------------
 
522
//   oscFifo
 
523
//---------------------------------------------------------
 
524
 
 
525
OscControlFifo* OscIF::oscFifo(unsigned long i) const
 
526
{
 
527
  if(!_oscControlFifos)
 
528
    return 0;
 
529
  return &_oscControlFifos[i];
 
530
}
 
531
 
 
532
//---------------------------------------------------------
 
533
//   oscUpdate
 
534
//---------------------------------------------------------
 
535
 
 
536
int OscIF::oscUpdate(lo_arg **argv)
 
537
{
 
538
      const char *purl = (char *)&argv[0]->s;
 
539
 
 
540
      if(_uiOscTarget)
 
541
        lo_address_free(_uiOscTarget);
 
542
      _uiOscTarget = 0;  
 
543
      char* host   = lo_url_get_hostname(purl);
 
544
      char* port   = lo_url_get_port(purl);
 
545
      _uiOscTarget = lo_address_new(host, port);
 
546
      free(host);
 
547
      free(port);
 
548
      if(!_uiOscTarget)
 
549
        return 0;
 
550
        
 
551
      if (_uiOscPath)
 
552
            free(_uiOscPath);
 
553
      _uiOscPath = lo_url_get_path(purl);
 
554
      int pl = strlen(_uiOscPath);
 
555
 
 
556
      if(_uiOscSampleRatePath)
 
557
        free(_uiOscSampleRatePath);
 
558
      _uiOscSampleRatePath = (char *)malloc(pl + 14);
 
559
      sprintf(_uiOscSampleRatePath, "%s/sample-rate", _uiOscPath);
 
560
        
 
561
      if (_uiOscControlPath)
 
562
            free(_uiOscControlPath);
 
563
      _uiOscControlPath = (char *)malloc(pl + 10);
 
564
      sprintf(_uiOscControlPath, "%s/control", _uiOscPath);
 
565
 
 
566
      if (_uiOscConfigurePath)
 
567
            free(_uiOscConfigurePath);
 
568
      _uiOscConfigurePath = (char *)malloc(pl + 12);
 
569
      sprintf(_uiOscConfigurePath, "%s/configure", _uiOscPath);
 
570
 
 
571
      if (_uiOscProgramPath)
 
572
            free(_uiOscProgramPath);
 
573
      _uiOscProgramPath = (char *)malloc(pl + 10);
 
574
      sprintf(_uiOscProgramPath, "%s/program", _uiOscPath);
 
575
 
 
576
      if (_uiOscShowPath)
 
577
            free(_uiOscShowPath);
 
578
      _uiOscShowPath = (char *)malloc(pl + 10);
 
579
      sprintf(_uiOscShowPath, "%s/show", _uiOscPath);
 
580
 
 
581
      /* At this point a more substantial host might also call
 
582
      * configure() on the UI to set any state that it had remembered
 
583
      * for the plugin instance.  But we don't remember state for
 
584
      * plugin instances (see our own configure() implementation in
 
585
      * osc_configure_handler), and so we have nothing to send except
 
586
      * the optional project directory.
 
587
      */
 
588
 
 
589
      #ifdef OSC_DEBUG 
 
590
      printf("OscIF::oscUpdate: _uiOscTarget:%p\n", _uiOscTarget);
 
591
      if(url)
 
592
        printf(" server url:%s\n", url);
 
593
      else  
 
594
        printf(" no server url!\n");
 
595
      printf(" update path:%s\n", purl);
 
596
      printf(" _uiOscPath:%s\n", _uiOscPath);
 
597
      printf(" _uiOscSampleRatePath:%s\n", _uiOscSampleRatePath);
 
598
      printf(" _uiOscConfigurePath:%s\n", _uiOscConfigurePath);
 
599
      printf(" _uiOscProgramPath:%s\n", _uiOscProgramPath);
 
600
      printf(" _uiOscControlPath:%s\n",_uiOscControlPath);
 
601
      printf(" _uiOscShowPath:%s\n", _uiOscShowPath);
 
602
      printf(" museProject:%s\n", museProject.latin1());
 
603
      #endif
 
604
      
 
605
      // Send sample rate.
 
606
      lo_send(_uiOscTarget, _uiOscSampleRatePath, "i", sampleRate);
 
607
      
 
608
      // Send project directory.
 
609
      //lo_send(_uiOscTarget, _uiOscConfigurePath, "ss",
 
610
      //   DSSI_PROJECT_DIRECTORY_KEY, museProject.latin1());  // song->projectPath()
 
611
      
 
612
      // Done in sub-classes.
 
613
      /*
 
614
      #ifdef DSSI_SUPPORT
 
615
      //lo_send(_uiOscTarget, _uiOscConfigurePath, "ss",
 
616
         //DSSI_PROJECT_DIRECTORY_KEY, song->projectPath().toAscii().data());
 
617
      lo_send(_uiOscTarget, _uiOscConfigurePath, "ss",
 
618
         DSSI_PROJECT_DIRECTORY_KEY, museProject.latin1());
 
619
      
 
620
      if(_oscSynthIF)
 
621
      {
 
622
        for(ciStringParamMap r = _oscSynthIF->synthI->_stringParamMap.begin(); r != synti->_stringParamMap.end(); ++r) 
 
623
        {
 
624
          rv = 0;
 
625
          rv = dssi->configure(handle, r->first.c_str(), r->second.c_str());
 
626
          if(rv)
 
627
          {
 
628
            fprintf(stderr, "MusE: Warning: plugin config key: %s value: %s \"%s\"\n", r->first.c_str(), r->second.c_str(), rv);
 
629
            free(rv);
 
630
          }  
 
631
        }          
 
632
      }  
 
633
      #endif
 
634
      */
 
635
      
 
636
      /*
 
637
      char uiOscGuiPath[strlen(_uiOscPath)+6];
 
638
      sprintf(uiOscGuiPath, "%s/%s", _uiOscPath, "show");
 
639
      
 
640
      #ifdef OSC_DEBUG 
 
641
      printf("OscIF::oscUpdate Sending show uiOscGuiPath:%s\n", uiOscGuiPath);
 
642
      #endif
 
643
      
 
644
      lo_send(_uiOscTarget, uiOscGuiPath, "");
 
645
      
 
646
      sprintf(uiOscGuiPath, "%s/%s", _uiOscPath, "hide");
 
647
      
 
648
      #ifdef OSC_DEBUG 
 
649
      printf("OscIF::oscUpdate Sending hide uiOscGuiPath:%s\n", uiOscGuiPath);
 
650
      #endif
 
651
      
 
652
      lo_send(_uiOscTarget, uiOscGuiPath, "");
 
653
      */
 
654
      
 
655
#if 0
 
656
      /* Send current bank/program  (-FIX- another race...) */
 
657
      if (instance->pendingProgramChange < 0) {
 
658
            unsigned long bank = instance->currentBank;
 
659
            unsigned long program = instance->currentProgram;
 
660
            instance->uiNeedsProgramUpdate = 0;
 
661
            if (instance->uiTarget) {
 
662
                  lo_send(instance->uiTarget, instance->ui_osc_program_path, "ii", bank, program);
 
663
                  }
 
664
            }
 
665
 
 
666
      /* Send control ports */
 
667
      for (i = 0; i < instance->plugin->controlIns; i++) {
 
668
            int in = i + instance->firstControlIn;
 
669
            int port = pluginControlInPortNumbers[in];
 
670
            lo_send(instance->uiTarget, instance->ui_osc_control_path, "if", port,
 
671
               pluginControlIns[in]);
 
672
            /* Avoid overloading the GUI if there are lots and lots of ports */
 
673
            if ((i+1) % 50 == 0)
 
674
                  usleep(300000);
 
675
            }
 
676
#endif
 
677
      return 0;
 
678
}
 
679
 
 
680
//---------------------------------------------------------
 
681
//   oscExiting
 
682
//---------------------------------------------------------
 
683
 
 
684
int OscIF::oscExiting(lo_arg**)
 
685
{
 
686
      // The gui is gone now, right?
 
687
      _oscGuiVisible = false;
 
688
      
 
689
      if(_oscGuiQProc)
 
690
      {
 
691
        if(_oscGuiQProc->isRunning())
 
692
        {
 
693
          #ifdef OSC_DEBUG 
 
694
          printf("OscIF::oscExiting terminating _oscGuiQProc\n");
 
695
          #endif
 
696
          
 
697
          //_oscGuiQProc->kill();
 
698
          // "This tries to terminate the process the nice way. If the process is still running after 5 seconds, 
 
699
          //  it terminates the process the hard way. The timeout should be chosen depending on the time the 
 
700
          //  process needs to do all its cleanup: use a higher value if the process is likely to do a lot of 
 
701
          //  computation or I/O on cleanup."           
 
702
          _oscGuiQProc->tryTerminate();
 
703
          QTimer::singleShot( 5000, _oscGuiQProc, SLOT( kill() ) );          
 
704
        }  
 
705
        //delete _oscGuiQProc;
 
706
      }
 
707
          
 
708
      if(_uiOscTarget)
 
709
        lo_address_free(_uiOscTarget);
 
710
      _uiOscTarget = 0;  
 
711
      if(_uiOscSampleRatePath)
 
712
        free(_uiOscSampleRatePath);
 
713
      _uiOscSampleRatePath = 0;  
 
714
      if(_uiOscShowPath)
 
715
        free(_uiOscShowPath);
 
716
      _uiOscShowPath = 0;  
 
717
      if(_uiOscControlPath)
 
718
        free(_uiOscControlPath);
 
719
      _uiOscControlPath = 0;  
 
720
      if(_uiOscConfigurePath)
 
721
        free(_uiOscConfigurePath);
 
722
      _uiOscConfigurePath = 0;  
 
723
      if(_uiOscProgramPath)
 
724
        free(_uiOscProgramPath);
 
725
      _uiOscProgramPath = 0;  
 
726
      if(_uiOscPath)
 
727
        free(_uiOscPath);
 
728
      _uiOscPath = 0;  
 
729
        
 
730
      //if(_oscControlFifos)
 
731
      //  delete[] _oscControlFifos;
 
732
      
 
733
      //const DSSI_Descriptor* dssi = synth->dssi;
 
734
      //const LADSPA_Descriptor* ld = dssi->LADSPA_Plugin;
 
735
      //if(ld->deactivate) 
 
736
      //  ld->deactivate(handle);
 
737
      
 
738
      /*
 
739
      if (_uiOscPath == 0) {
 
740
            printf("OscIF::oscExiting(): no _uiOscPath\n");
 
741
            return 1;
 
742
            }
 
743
      char uiOscGuiPath[strlen(_uiOscPath)+6];
 
744
        
 
745
      sprintf(uiOscGuiPath, "%s/%s", _uiOscPath, "quit");
 
746
      #ifdef OSC_DEBUG 
 
747
      printf("OscIF::oscExiting(): sending quit to uiOscGuiPath:%s\n", uiOscGuiPath);
 
748
      #endif
 
749
      
 
750
      lo_send(_uiOscTarget, uiOscGuiPath, "");
 
751
      */
 
752
      
 
753
#if 0
 
754
      int i;
 
755
 
 
756
      if (verbose) {
 
757
            printf("MusE: OSC: got exiting notification for instance %d\n",
 
758
               instance->number);
 
759
            }
 
760
 
 
761
      if (instance->plugin) {
 
762
 
 
763
            /*!!! No, this isn't safe -- plugins deactivated in this way
 
764
              would still be included in a run_multiple_synths call unless
 
765
              we re-jigged the instance array at the same time -- leave it
 
766
              for now
 
767
            if (instance->plugin->descriptor->LADSPA_Plugin->deactivate) {
 
768
                  instance->plugin->descriptor->LADSPA_Plugin->deactivate
 
769
                     (instanceHandles[instance->number]);
 
770
                  }
 
771
            */
 
772
            /* Leave this flag though, as we need it to determine when to exit */
 
773
            instance->inactive = 1;
 
774
            }
 
775
 
 
776
      /* Do we have any plugins left running? */
 
777
 
 
778
      for (i = 0; i < instance_count; ++i) {
 
779
            if (!instances[i].inactive)
 
780
                  return 0;
 
781
            }
 
782
 
 
783
      if (verbose) {
 
784
            printf("MusE: That was the last remaining plugin, exiting...\n");
 
785
            }
 
786
      exiting = 1;
 
787
#endif
 
788
      return 0;
 
789
}
 
790
 
 
791
//---------------------------------------------------------
 
792
//   oscSendProgram
 
793
//---------------------------------------------------------
 
794
 
 
795
void OscIF::oscSendProgram(unsigned long prog, unsigned long bank)
 
796
{
 
797
  if(_uiOscTarget && _uiOscProgramPath)
 
798
    lo_send(_uiOscTarget, _uiOscProgramPath, "ii", bank, prog);
 
799
}
 
800
 
 
801
//---------------------------------------------------------
 
802
//   oscSendControl
 
803
//---------------------------------------------------------
 
804
 
 
805
void OscIF::oscSendControl(unsigned long dssiPort, float v)
 
806
{
 
807
  if(_uiOscTarget && _uiOscControlPath)
 
808
    lo_send(_uiOscTarget, _uiOscControlPath, "if", dssiPort, v);
 
809
}
 
810
 
 
811
//---------------------------------------------------------
 
812
//   oscSendConfigure
 
813
//---------------------------------------------------------
 
814
 
 
815
void OscIF::oscSendConfigure(const char *key, const char *val)
 
816
 
817
  if(_uiOscTarget && _uiOscConfigurePath)
 
818
    lo_send(_uiOscTarget, _uiOscConfigurePath, "ss", key, val);
 
819
}
 
820
 
 
821
//---------------------------------------------------------
 
822
//   oscInitGui
 
823
//---------------------------------------------------------
 
824
 
 
825
//bool OscIF::oscInitGui()
 
826
bool OscIF::oscInitGui(const QString& typ, const QString& baseName, const QString& name, 
 
827
                       const QString& label, const QString& filePath, const QString& dirPath)
 
828
{
 
829
      // Are we already running? We don't want to allow another process do we...
 
830
      if((_oscGuiQProc != 0) && (_oscGuiQProc->isRunning()))
 
831
        return true;
 
832
        
 
833
      if(!url)
 
834
      {  
 
835
        fprintf(stderr, "OscIF::oscInitGui no server url!\n");
 
836
        return false;
 
837
      }
 
838
            
 
839
      //
 
840
      //  start gui
 
841
      //
 
842
      //static char oscUrl[1024];
 
843
      //char oscUrl[1024];
 
844
      QString oscUrl;
 
845
      
 
846
      /*
 
847
      QString typ; 
 
848
      QString baseName;
 
849
      QString name;
 
850
      QString label;
 
851
      QString filePath;
 
852
      QString dirPath;
 
853
      #ifdef DSSI_SUPPORT
 
854
      if(_oscSynthIF)
 
855
      {
 
856
        //snprintf(oscUrl, 1024, "%s/%s", url, synti->name().toAscii().data());
 
857
        //snprintf(oscUrl, 1024, "%s/%s", url, synti->name().ascii());
 
858
        //snprintf(oscUrl, 1024, "%s/%s/%s", url, synth->info.baseName().ascii(), synti->name().ascii());
 
859
        typ = QT_TR_NOOP("dssi_synth");
 
860
        baseName = _oscSynthIF->dssiSynth()->baseName(false);
 
861
        label = _oscSynthIF->dssiSynthI()->name();
 
862
        name = _oscSynthIF->dssiSynth()->name();
 
863
        
 
864
        dirPath = _oscSynthIF->dssiSynth()->dirPath(false);
 
865
        filePath = _oscSynthIF->dssiSynth()->filePath();
 
866
      }
 
867
      else  
 
868
      #endif
 
869
      if(_oscPluginI)
 
870
      {
 
871
        typ = QT_TR_NOOP("ladspa_efx");
 
872
        baseName = _oscPluginI->plugin()->lib(false);
 
873
        //name = _oscPluginI->name();
 
874
        name = _oscPluginI->plugin()->label();
 
875
        label = _oscPluginI->label();
 
876
        
 
877
        dirPath = _oscPluginI->plugin()->dirPath(false);
 
878
        //dirPath.replace("ladspa", "dssi", true);
 
879
        
 
880
        filePath = _oscPluginI->plugin()->filePath();
 
881
        //filePath.replace("ladspa", "dssi", true);
 
882
      }
 
883
      else
 
884
        return false;
 
885
      */
 
886
      
 
887
      //snprintf(oscUrl, 1024, "%s/%s/%s", url, baseName.ascii(), name.ascii());
 
888
      //snprintf(oscUrl, 1024, "%s%s/%s/%s", url, typ.latin1(), baseName.latin1(), name.latin1());
 
889
      //oscUrl = QString("%1%2/%3/%4").arg(QString(QT_TR_NOOP(url))).arg(typ).arg(baseName).arg(name);
 
890
      oscUrl = QString("%1%2/%3/%4").arg(QString(QT_TR_NOOP(url))).arg(typ).arg(baseName).arg(label);
 
891
      
 
892
      //QString guiPath(info.path() + "/" + info.baseName());
 
893
      //QString guiPath(synth->info.dirPath() + "/" + synth->info.baseName());
 
894
      QString guiPath(dirPath + "/" + baseName);
 
895
 
 
896
      #ifdef OSC_DEBUG 
 
897
      fprintf(stderr, "OscIF::oscInitGui guiPath:%s\n", guiPath.latin1());
 
898
      #endif
 
899
      
 
900
      QDir guiDir(guiPath, "*", QDir::Unsorted, QDir::Files);
 
901
      if (guiDir.exists()) 
 
902
      {
 
903
            //const QFileInfoList list = guiDir.entryInfoList();
 
904
            QStringList list = guiDir.entryList();
 
905
            
 
906
            //for (int i = 0; i < list.size(); ++i) {
 
907
            for (unsigned int i = 0; i < list.count(); ++i) 
 
908
            {
 
909
                
 
910
                //QFileInfo fi = list.at(i);
 
911
                QFileInfo fi(guiPath + QString("/") + list[i]);
 
912
                  
 
913
                  QString gui(fi.filePath());
 
914
                  if (gui.contains('_') == 0)
 
915
                        continue;
 
916
                  struct stat buf;
 
917
                  
 
918
                  //if (stat(gui.toAscii().data(), &buf)) {
 
919
                  if (stat(gui.latin1(), &buf)) {
 
920
                  
 
921
                        perror("stat failed");
 
922
                        continue;
 
923
                        }
 
924
 
 
925
                  #ifdef OSC_DEBUG 
 
926
                  fprintf(stderr, "OscIF::oscInitGui  %s %s %s %s\n",
 
927
                      //fi.filePath().toAscii().data(),
 
928
                      //fi.fileName().toAscii().data(),
 
929
                      fi.filePath().latin1(),
 
930
                      //fi.fileName().ascii(),
 
931
                      
 
932
                      oscUrl.latin1(),
 
933
                      
 
934
                      //synth->info.filePath().ascii(),
 
935
                      filePath.latin1(),
 
936
                      
 
937
                      //name().toAscii().data(),
 
938
                      //synth->name().ascii());
 
939
                      name.latin1());
 
940
                  #endif
 
941
                      
 
942
                  if ((S_ISREG(buf.st_mode) || S_ISLNK(buf.st_mode)) &&
 
943
                     (buf.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) 
 
944
                  {
 
945
                        // Changed by T356.
 
946
                        // fork + execlp were causing the processes to remain after closing gui, requiring manual kill.
 
947
                        // Changed to QProcess, works OK now. 
 
948
                        //if((guiPid = fork()) == 0) 
 
949
                        {
 
950
                              // No QProcess created yet? Do it now. Only once per SynthIF instance. Exists until parent destroyed.
 
951
                              if(_oscGuiQProc == 0)
 
952
                                _oscGuiQProc = new QProcess(muse);                        
 
953
                              
 
954
                              // Don't forget this, he he...
 
955
                              _oscGuiQProc->clearArguments();
 
956
                              
 
957
                              _oscGuiQProc->addArgument(fi.filePath());
 
958
                              //_oscGuiQProc->addArgument(fi.fileName()); // No conventional 'Arg0' here.
 
959
                              //_oscGuiQProc->addArgument(QString(oscUrl));
 
960
                              _oscGuiQProc->addArgument(oscUrl);
 
961
                              //_oscGuiQProc->addArgument(synth->info.filePath());
 
962
                              _oscGuiQProc->addArgument(filePath);
 
963
                              //_oscGuiQProc->addArgument(synth->name());
 
964
                              _oscGuiQProc->addArgument(name);
 
965
                              _oscGuiQProc->addArgument(QString("channel-1"));
 
966
                              
 
967
                              #ifdef OSC_DEBUG 
 
968
                              fprintf(stderr, "OscIF::oscInitGui starting QProcess\n");
 
969
                              #endif
 
970
                                
 
971
                              if(_oscGuiQProc->start() == TRUE)
 
972
                              {
 
973
                                #ifdef OSC_DEBUG 
 
974
                                fprintf(stderr, "OscIF::oscInitGui started QProcess\n");
 
975
                                #endif
 
976
                                
 
977
                                //guiPid = _oscGuiQProc->processIdentifier();
 
978
                              }
 
979
                              else
 
980
                              {
 
981
                              
 
982
                                /*
 
983
                                execlp(
 
984
                                        //fi.filePath().toAscii().data(),
 
985
                                        //fi.fileName().toAscii().data(),
 
986
                                        fi.filePath().ascii(),
 
987
                                        fi.fileName().ascii(),
 
988
                                        
 
989
                                        oscUrl,
 
990
                                        
 
991
                                        //info.filePath().toAscii().data(),
 
992
                                        //name().toAscii().data(),
 
993
                                        synth->info.filePath().ascii(),
 
994
                                        synth->name().ascii(),
 
995
                                        
 
996
                                        "channel 1", (void*)0);
 
997
                                */
 
998
                                        
 
999
                                fprintf(stderr, "exec %s %s %s %s failed: %s\n",
 
1000
                                        //fi.filePath().toAscii().data(),
 
1001
                                        //fi.fileName().toAscii().data(),
 
1002
                                        fi.filePath().latin1(),
 
1003
                                        fi.fileName().latin1(),
 
1004
                                        
 
1005
                                        oscUrl.latin1(),
 
1006
                                        
 
1007
                                        //name().toAscii().data(),
 
1008
                                        //synth->name().ascii(),
 
1009
                                        name.latin1(),
 
1010
                                        
 
1011
                                        strerror(errno));
 
1012
                                        
 
1013
                                // It's Ok, Keep going. So nothing happens. So what. The timeout in showGui will just leave.
 
1014
                                // Maybe it's a 'busy' issue somewhere - allow to try again later + save work now.
 
1015
                                //exit(1);
 
1016
                                
 
1017
                              }
 
1018
                              
 
1019
                              #ifdef OSC_DEBUG 
 
1020
                              fprintf(stderr, "OscIF::oscInitGui after QProcess\n");
 
1021
                              #endif
 
1022
                        }
 
1023
                  }
 
1024
            }
 
1025
            //synth->_hasGui = true;
 
1026
      }
 
1027
      else {
 
1028
            printf("OscIF::oscInitGui %s: no dir for gui found: %s\n",
 
1029
               //name().toAscii().data(), guiPath.toAscii().data());
 
1030
               //synth->name().ascii(), guiPath.ascii());
 
1031
               name.latin1(), guiPath.latin1());
 
1032
            
 
1033
            //synth->_hasGui = false;
 
1034
            }
 
1035
            
 
1036
  return true;          
 
1037
}
 
1038
 
 
1039
 
 
1040
//---------------------------------------------------------
 
1041
//   oscShowGui
 
1042
//---------------------------------------------------------
 
1043
 
 
1044
void OscIF::oscShowGui(bool v)
 
1045
{
 
1046
      #ifdef OSC_DEBUG 
 
1047
      printf("OscIF::oscShowGui(): v:%d visible:%d\n", v, oscGuiVisible());
 
1048
      #endif
 
1049
      
 
1050
      if (v == oscGuiVisible())
 
1051
            return;
 
1052
      
 
1053
      //if(guiPid == -1)
 
1054
      if((_oscGuiQProc == 0) || (!_oscGuiQProc->isRunning()))
 
1055
      {
 
1056
        // We need an indicator that update was called - update must have been called to get new path etc...
 
1057
        // If the process is not running this path is invalid, right?
 
1058
        if(_uiOscPath)
 
1059
          free(_uiOscPath);
 
1060
        _uiOscPath = 0;  
 
1061
          
 
1062
        #ifdef OSC_DEBUG
 
1063
        printf("OscIF::oscShowGui(): No QProcess or process not running. Starting gui...\n");
 
1064
        #endif
 
1065
        
 
1066
        if(!oscInitGui())
 
1067
        {
 
1068
          printf("OscIF::oscShowGui(): failed to initialize gui on oscInitGui()\n");
 
1069
          return;
 
1070
        }  
 
1071
      }  
 
1072
      
 
1073
      //for (int i = 0; i < 5; ++i) {
 
1074
      for (int i = 0; i < 10; ++i) {    // Give it a wee bit more time?
 
1075
            if (_uiOscPath)
 
1076
                  break;
 
1077
            sleep(1);
 
1078
            }
 
1079
      if (_uiOscPath == 0) {
 
1080
            printf("OscIF::oscShowGui(): no _uiOscPath. Error: Timeout - synth gui did not start within 10 seconds.\n");
 
1081
            return;
 
1082
            }
 
1083
      
 
1084
      char uiOscGuiPath[strlen(_uiOscPath)+6];
 
1085
      sprintf(uiOscGuiPath, "%s/%s", _uiOscPath, v ? "show" : "hide");
 
1086
      
 
1087
      #ifdef OSC_DEBUG 
 
1088
      printf("OscIF::oscShowGui(): Sending show/hide uiOscGuiPath:%s\n", uiOscGuiPath);
 
1089
      #endif
 
1090
      
 
1091
      lo_send(_uiOscTarget, uiOscGuiPath, "");
 
1092
      _oscGuiVisible = v;
 
1093
}
 
1094
 
 
1095
//---------------------------------------------------------
 
1096
//   oscGuiVisible
 
1097
//---------------------------------------------------------
 
1098
 
 
1099
bool OscIF::oscGuiVisible() const
 
1100
{
 
1101
  return _oscGuiVisible;
 
1102
}
 
1103
 
 
1104
#ifdef DSSI_SUPPORT
 
1105
 
 
1106
//---------------------------------------------------------
 
1107
//   OscDssiIF::
 
1108
//   oscSetSynthIF
 
1109
//---------------------------------------------------------
 
1110
 
 
1111
//void OscIF::oscSetSynthIF(DssiSynthIF* s) 
 
1112
void OscDssiIF::oscSetSynthIF(DssiSynthIF* s)
 
1113
 
1114
  _oscSynthIF = s;
 
1115
  if(_oscControlFifos)
 
1116
    delete[] _oscControlFifos;
 
1117
  _oscControlFifos = 0;
 
1118
    
 
1119
  if(_oscSynthIF && _oscSynthIF->dssiSynth())
 
1120
  {
 
1121
    unsigned long ports = _oscSynthIF->dssiSynth()->inControls();
 
1122
    _oscControlFifos = new OscControlFifo[ports];  
 
1123
  }  
 
1124
}
 
1125
 
 
1126
//---------------------------------------------------------
 
1127
//   oscUpdate
 
1128
//---------------------------------------------------------
 
1129
 
 
1130
int OscDssiIF::oscUpdate(lo_arg **argv)
 
1131
{
 
1132
      // Make sure to call base method.
 
1133
      OscIF::oscUpdate(argv);
 
1134
      
 
1135
      // Send sample rate. No, done in base class.
 
1136
      //lo_send(_uiOscTarget, _uiOscSampleRatePath, "i", sampleRate);
 
1137
      
 
1138
      // Send project directory. No, done in DssiSynthIF.
 
1139
      //lo_send(_uiOscTarget, _uiOscConfigurePath, "ss",
 
1140
      //   DSSI_PROJECT_DIRECTORY_KEY, museProject.latin1());  // song->projectPath()
 
1141
      
 
1142
      if(_oscSynthIF)
 
1143
        _oscSynthIF->oscUpdate();
 
1144
      
 
1145
      /*
 
1146
      if(_oscSynthIF)
 
1147
      {
 
1148
        // Send current string configuration parameters.
 
1149
        StringParamMap& map = _oscSynthIF->dssiSynthI()->stringParameters();
 
1150
        int i = 0;
 
1151
        for(ciStringParamMap r = map.begin(); r != map.end(); ++r) 
 
1152
        {
 
1153
          lo_send(_uiOscTarget, _uiOscConfigurePath, "ss", r->first.c_str(), r->second.c_str());
 
1154
          // Avoid overloading the GUI if there are lots and lots of params. 
 
1155
          if((i+1) % 50 == 0)
 
1156
            usleep(300000);
 
1157
          ++i;      
 
1158
        }  
 
1159
        
 
1160
        // Send current bank and program.
 
1161
        unsigned long bank, prog;
 
1162
        _oscSynthIF->dssiSynthI()->currentProg(&prog, &bank, 0);
 
1163
        lo_send(_uiOscTarget, _uiOscProgramPath, "ii", bank, prog);
 
1164
        
 
1165
        // Send current control values.
 
1166
        unsigned long ports = _oscSynthIF->dssiSynth()->inControls();
 
1167
        for(unsigned long i = 0; i < ports; ++i) 
 
1168
        {
 
1169
          unsigned long k = _oscSynthIF->dssiSynth()->inControlPortIdx(i);
 
1170
          lo_send(_uiOscTarget, _uiOscControlPath, "if", k, _oscSynthIF->getParameter(i));
 
1171
          // Avoid overloading the GUI if there are lots and lots of ports. 
 
1172
          if((i+1) % 50 == 0)
 
1173
            usleep(300000);
 
1174
        }
 
1175
      }  
 
1176
      */
 
1177
      
 
1178
      /*
 
1179
      char uiOscGuiPath[strlen(_uiOscPath)+6];
 
1180
      sprintf(uiOscGuiPath, "%s/%s", _uiOscPath, "show");
 
1181
      
 
1182
      #ifdef OSC_DEBUG 
 
1183
      printf("OscIF::oscUpdate Sending show uiOscGuiPath:%s\n", uiOscGuiPath);
 
1184
      #endif
 
1185
      
 
1186
      lo_send(_uiOscTarget, uiOscGuiPath, "");
 
1187
      
 
1188
      sprintf(uiOscGuiPath, "%s/%s", _uiOscPath, "hide");
 
1189
      
 
1190
      #ifdef OSC_DEBUG 
 
1191
      printf("OscIF::oscUpdate Sending hide uiOscGuiPath:%s\n", uiOscGuiPath);
 
1192
      #endif
 
1193
      
 
1194
      lo_send(_uiOscTarget, uiOscGuiPath, "");
 
1195
      */
 
1196
      
 
1197
#if 0
 
1198
      /* Send current bank/program  (-FIX- another race...) */
 
1199
      if (instance->pendingProgramChange < 0) {
 
1200
            unsigned long bank = instance->currentBank;
 
1201
            unsigned long program = instance->currentProgram;
 
1202
            instance->uiNeedsProgramUpdate = 0;
 
1203
            if (instance->uiTarget) {
 
1204
                  lo_send(instance->uiTarget, instance->ui_osc_program_path, "ii", bank, program);
 
1205
                  }
 
1206
            }
 
1207
 
 
1208
      /* Send control ports */
 
1209
      for (i = 0; i < instance->plugin->controlIns; i++) {
 
1210
            int in = i + instance->firstControlIn;
 
1211
            int port = pluginControlInPortNumbers[in];
 
1212
            lo_send(instance->uiTarget, instance->ui_osc_control_path, "if", port,
 
1213
               pluginControlIns[in]);
 
1214
            /* Avoid overloading the GUI if there are lots and lots of ports */
 
1215
            if ((i+1) % 50 == 0)
 
1216
                  usleep(300000);
 
1217
            }
 
1218
#endif
 
1219
      return 0;
 
1220
}
 
1221
 
 
1222
 
 
1223
//---------------------------------------------------------
 
1224
//   oscConfigure
 
1225
//---------------------------------------------------------
 
1226
 
 
1227
int OscDssiIF::oscConfigure(lo_arg** argv)
 
1228
{
 
1229
  //OscIF::oscConfigure(argv);
 
1230
  
 
1231
  if(_oscSynthIF)
 
1232
    _oscSynthIF->oscConfigure((const char*)&argv[0]->s, (const char*)&argv[1]->s);
 
1233
  return 0;
 
1234
}
 
1235
 
 
1236
//---------------------------------------------------------
 
1237
//   oscMidi
 
1238
//---------------------------------------------------------
 
1239
 
 
1240
int OscDssiIF::oscMidi(lo_arg** argv)
 
1241
{
 
1242
  //OscIF::oscMidi(argv);
 
1243
  
 
1244
  if(_oscSynthIF)
 
1245
    _oscSynthIF->oscMidi(argv[0]->m[1], argv[0]->m[2], argv[0]->m[3]);
 
1246
  
 
1247
  return 0;
 
1248
}
 
1249
 
 
1250
//---------------------------------------------------------
 
1251
//   oscProgram
 
1252
//---------------------------------------------------------
 
1253
 
 
1254
int OscDssiIF::oscProgram(lo_arg** argv)
 
1255
{
 
1256
  //OscIF::oscProgram(argv);
 
1257
  
 
1258
  if(_oscSynthIF)
 
1259
    _oscSynthIF->oscProgram(argv[1]->i, argv[0]->i);
 
1260
  
 
1261
  return 0;
 
1262
}
 
1263
 
 
1264
//---------------------------------------------------------
 
1265
//   oscControl
 
1266
//---------------------------------------------------------
 
1267
 
 
1268
int OscDssiIF::oscControl(lo_arg** argv)
 
1269
{
 
1270
  //OscIF::oscControl(argv);
 
1271
  
 
1272
  int port = argv[0]->i;
 
1273
  if(port < 0)
 
1274
    return 0;
 
1275
    
 
1276
  if(_oscSynthIF)
 
1277
    _oscSynthIF->oscControl(argv[0]->i, argv[1]->f);
 
1278
  
 
1279
  return 0;
 
1280
}
 
1281
 
 
1282
//---------------------------------------------------------
 
1283
//   oscInitGui
 
1284
//---------------------------------------------------------
 
1285
bool OscDssiIF::oscInitGui()
 
1286
{
 
1287
  if(!_oscSynthIF)
 
1288
    return false;
 
1289
    
 
1290
  return OscIF::oscInitGui(QT_TR_NOOP("dssi_synth"), _oscSynthIF->dssiSynth()->baseName(false), 
 
1291
                           _oscSynthIF->dssiSynth()->name(), _oscSynthIF->dssiSynthI()->name(), 
 
1292
                           _oscSynthIF->dssiSynth()->filePath(), _oscSynthIF->dssiSynth()->dirPath(false));
 
1293
}
 
1294
      
 
1295
#endif   // DSSI_SUPPORT
 
1296
      
 
1297
 
 
1298
//---------------------------------------------------------
 
1299
//   OscEffectIF::
 
1300
//   oscSetPluginI
 
1301
//---------------------------------------------------------
 
1302
 
 
1303
void OscEffectIF::oscSetPluginI(PluginI* s)
 
1304
 
1305
  _oscPluginI = s; 
 
1306
  if(_oscControlFifos)
 
1307
    delete[] _oscControlFifos;
 
1308
  _oscControlFifos = 0;
 
1309
    
 
1310
  if(_oscPluginI && _oscPluginI->plugin())
 
1311
  {
 
1312
    unsigned long ports = _oscPluginI->plugin()->controlInPorts();
 
1313
    _oscControlFifos = new OscControlFifo[ports];  
 
1314
  }  
 
1315
}
 
1316
 
 
1317
//---------------------------------------------------------
 
1318
//   oscUpdate
 
1319
//---------------------------------------------------------
 
1320
 
 
1321
int OscEffectIF::oscUpdate(lo_arg** argv)
 
1322
{
 
1323
  // Make sure to call base method.
 
1324
  OscIF::oscUpdate(argv);
 
1325
  
 
1326
  // Send project directory. No, done in PluginI.
 
1327
  //lo_send(_uiOscTarget, _uiOscConfigurePath, "ss",
 
1328
  //   DSSI_PROJECT_DIRECTORY_KEY, museProject.latin1());  // song->projectPath()
 
1329
  
 
1330
  if(_oscPluginI)
 
1331
    _oscPluginI->oscUpdate();
 
1332
  
 
1333
  return 0;
 
1334
}
 
1335
 
 
1336
//---------------------------------------------------------
 
1337
//   oscConfigure
 
1338
//---------------------------------------------------------
 
1339
 
 
1340
int OscEffectIF::oscConfigure(lo_arg** argv)
 
1341
{
 
1342
  //OscIF::oscConfigure(argv);
 
1343
  
 
1344
  if(_oscPluginI)
 
1345
    _oscPluginI->oscConfigure((const char*)&argv[0]->s, (const char*)&argv[1]->s);
 
1346
  
 
1347
  return 0;
 
1348
}
 
1349
 
 
1350
//---------------------------------------------------------
 
1351
//   oscControl
 
1352
//---------------------------------------------------------
 
1353
 
 
1354
int OscEffectIF::oscControl(lo_arg** argv)
 
1355
{
 
1356
  //OscIF::oscControl(argv);
 
1357
  
 
1358
  int port = argv[0]->i;
 
1359
  if(port < 0)
 
1360
    return 0;
 
1361
    
 
1362
  if(_oscPluginI)
 
1363
    _oscPluginI->oscControl(argv[0]->i, argv[1]->f);
 
1364
  
 
1365
  return 0;
 
1366
}
 
1367
 
 
1368
//---------------------------------------------------------
 
1369
//   oscInitGui
 
1370
//---------------------------------------------------------
 
1371
bool OscEffectIF::oscInitGui()
 
1372
{
 
1373
  if(!_oscPluginI)
 
1374
    return false;
 
1375
    
 
1376
  return OscIF::oscInitGui(QT_TR_NOOP("ladspa_efx"), _oscPluginI->plugin()->lib(false), 
 
1377
                           _oscPluginI->plugin()->label(), _oscPluginI->label(), 
 
1378
                           _oscPluginI->plugin()->filePath(), _oscPluginI->plugin()->dirPath(false));
 
1379
}
 
1380
      
 
1381
 
 
1382
#else //OSC_SUPPORT
 
1383
void initOSC() {}
 
1384
void exitOSC() {}
 
1385
 
 
1386
#endif