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

« back to all changes in this revision

Viewing changes to muse/plugin.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:
18
18
#include <qlabel.h>
19
19
#include <qsignalmapper.h>
20
20
#include <qpushbutton.h>
 
21
#include <qscrollview.h>
21
22
#include <qlistview.h>
22
23
#include <qtoolbar.h>
23
24
#include <qtoolbutton.h>
24
25
#include <qwhatsthis.h>
25
26
#include <qcheckbox.h>
26
27
#include <qtooltip.h>
27
 
#include <qwidgetfactory.h>
 
28
//#include <qwidgetfactory.h>
28
29
#include <qfile.h>
29
30
#include <qobjectlist.h>
30
31
#include <qcombobox.h>
49
50
#include "audio.h"
50
51
#include "al/dsp.h"
51
52
 
52
 
#define PLUGIN_DEBUGIN 0
 
53
#include "config.h"
 
54
 
 
55
// Turn on debugging messages.
 
56
//#define PLUGIN_DEBUGIN 
53
57
 
54
58
PluginList plugins;
55
59
 
 
60
/*
56
61
static const char* preset_file_pattern[] = {
57
 
      QT_TR_NOOP("presets (*.pre *.pre.gz *.pre.bz2)"),
58
 
      QT_TR_NOOP("All Files (*)"),
59
 
      0
60
 
      };
 
62
      QT_TR_NOOP("Presets (*.pre *.pre.gz *.pre.bz2)"),
 
63
      QT_TR_NOOP("All Files (*)"),
 
64
      0
 
65
      };
 
66
 
 
67
static const char* preset_file_save_pattern[] = {
 
68
      QT_TR_NOOP("Presets (*.pre)"),
 
69
      QT_TR_NOOP("gzip compressed presets (*.pre.gz)"),
 
70
      QT_TR_NOOP("bzip2 compressed presets (*.pre.bz2)"),
 
71
      QT_TR_NOOP("All Files (*)"),
 
72
      0
 
73
      };
 
74
*/
61
75
 
62
76
int PluginDialog::selectedPlugType = 0;
63
77
QStringList PluginDialog::sortItems = QStringList();
82
96
  //bool isint = desc & LADSPA_HINT_INTEGER;
83
97
  MidiController::ControllerType t = midiControllerType(ctlnum);
84
98
  
85
 
  // Added by Tim. p3.3.12
86
 
  if(PLUGIN_DEBUGIN)
87
 
    printf("ladspa2MidiControlValues: ctlnum:%d ladspa port:%d has default?:%d default:%f\n", ctlnum, port, hasdef, fdef);
 
99
  #ifdef PLUGIN_DEBUGIN 
 
100
  printf("ladspa2MidiControlValues: ctlnum:%d ladspa port:%d has default?:%d default:%f\n", ctlnum, port, hasdef, fdef);
 
101
  #endif
88
102
  
89
103
  if(desc & LADSPA_HINT_TOGGLED) 
90
104
  {
91
 
    // Added by Tim. p3.3.12
92
 
    if(PLUGIN_DEBUGIN)
93
 
      printf("ladspa2MidiControlValues: has LADSPA_HINT_TOGGLED\n");
 
105
    #ifdef PLUGIN_DEBUGIN 
 
106
    printf("ladspa2MidiControlValues: has LADSPA_HINT_TOGGLED\n");
 
107
    #endif
94
108
    
95
109
    *min = 0;
96
110
    *max = 1;
101
115
  float m = 1.0;
102
116
  if(desc & LADSPA_HINT_SAMPLE_RATE)
103
117
  {
104
 
    // Added by Tim. p3.3.12
105
 
    if(PLUGIN_DEBUGIN)
106
 
      printf("ladspa2MidiControlValues: has LADSPA_HINT_SAMPLE_RATE\n");
 
118
    #ifdef PLUGIN_DEBUGIN 
 
119
    printf("ladspa2MidiControlValues: has LADSPA_HINT_SAMPLE_RATE\n");
 
120
    #endif
107
121
    
108
122
    m = float(sampleRate);
109
123
  }  
110
124
  
111
125
  if(desc & LADSPA_HINT_BOUNDED_BELOW)
112
126
  {
113
 
    // Added by Tim. p3.3.12
114
 
    if(PLUGIN_DEBUGIN)
115
 
      printf("ladspa2MidiControlValues: has LADSPA_HINT_BOUNDED_BELOW\n");
 
127
    #ifdef PLUGIN_DEBUGIN 
 
128
    printf("ladspa2MidiControlValues: has LADSPA_HINT_BOUNDED_BELOW\n");
 
129
    #endif
116
130
    
117
131
    fmin =  range.LowerBound * m;
118
132
  }  
121
135
  
122
136
  if(desc & LADSPA_HINT_BOUNDED_ABOVE)
123
137
  {  
124
 
    // Added by Tim. p3.3.12
125
 
    if(PLUGIN_DEBUGIN)
126
 
      printf("ladspa2MidiControlValues: has LADSPA_HINT_BOUNDED_ABOVE\n");
 
138
    #ifdef PLUGIN_DEBUGIN 
 
139
    printf("ladspa2MidiControlValues: has LADSPA_HINT_BOUNDED_ABOVE\n");
 
140
    #endif
127
141
    
128
142
    fmax =  range.UpperBound * m;
129
143
  }  
138
152
  int ctlmn = 0;
139
153
  int ctlmx = 127;
140
154
  
141
 
  // Added by Tim. p3.3.12
142
 
  if(PLUGIN_DEBUGIN)
143
 
    printf("ladspa2MidiControlValues: port min:%f max:%f \n", fmin, fmax);
 
155
  #ifdef PLUGIN_DEBUGIN 
 
156
  printf("ladspa2MidiControlValues: port min:%f max:%f \n", fmin, fmax);
 
157
  #endif
144
158
  
145
159
  //bool isneg = (fmin < 0.0);
146
160
  bool isneg = (imin < 0);
196
210
  // Is it an integer control?
197
211
  if(desc & LADSPA_HINT_INTEGER)
198
212
  {
199
 
    // Added by Tim. p3.3.12
200
 
    if(PLUGIN_DEBUGIN)
201
 
      printf("ladspa2MidiControlValues: has LADSPA_HINT_INTEGER\n");
 
213
    #ifdef PLUGIN_DEBUGIN 
 
214
    printf("ladspa2MidiControlValues: has LADSPA_HINT_INTEGER\n");
 
215
    #endif
202
216
  
203
217
    // If the upper or lower limit is beyond the controller limits, just scale the whole range to fit.
204
218
    // We could get fancy by scaling only the negative or positive domain, or each one separately, but no...
240
254
  float normdef = fdef / frng;
241
255
  fdef = normdef * fctlrng;
242
256
  
243
 
  // FIXME: TODO: Incorrect... Arrrrgh... My brain hurts... Fix this somewhat more trivial stuff later....
 
257
  // FIXME: TODO: Incorrect... Fix this somewhat more trivial stuff later....
244
258
  
245
259
  *def = (int)lrint(fdef) + bias;
246
260
 
247
 
  // Added by Tim. p3.3.12
248
 
  if(PLUGIN_DEBUGIN)
249
 
    printf("ladspa2MidiControlValues: setting default:%d\n", *def);
 
261
  #ifdef PLUGIN_DEBUGIN 
 
262
  printf("ladspa2MidiControlValues: setting default:%d\n", *def);
 
263
  #endif
250
264
  
251
265
  return hasdef;
252
266
}      
272
286
  //bool isint = desc & LADSPA_HINT_INTEGER;
273
287
  MidiController::ControllerType t = midiControllerType(ctlnum);
274
288
  
275
 
  // Added by Tim. p3.3.12
276
 
  if(PLUGIN_DEBUGIN)
277
 
    printf("midi2LadspaValue: ctlnum:%d ladspa port:%d val:%d\n", ctlnum, port, val);
 
289
  #ifdef PLUGIN_DEBUGIN 
 
290
  printf("midi2LadspaValue: ctlnum:%d ladspa port:%d val:%d\n", ctlnum, port, val);
 
291
  #endif
278
292
  
279
293
  float m = 1.0;
280
294
  if(desc & LADSPA_HINT_SAMPLE_RATE)
281
295
  {
282
 
    // Added by Tim. p3.3.12
283
 
    if(PLUGIN_DEBUGIN)
284
 
      printf("midi2LadspaValue: has LADSPA_HINT_SAMPLE_RATE\n");
 
296
    #ifdef PLUGIN_DEBUGIN 
 
297
    printf("midi2LadspaValue: has LADSPA_HINT_SAMPLE_RATE\n");
 
298
    #endif
285
299
    
286
300
    m = float(sampleRate);
287
301
  }  
288
302
  
289
303
  if(desc & LADSPA_HINT_BOUNDED_BELOW)
290
304
  {
291
 
    // Added by Tim. p3.3.12
292
 
    if(PLUGIN_DEBUGIN)
293
 
      printf("midi2LadspaValue: has LADSPA_HINT_BOUNDED_BELOW\n");
 
305
    #ifdef PLUGIN_DEBUGIN 
 
306
    printf("midi2LadspaValue: has LADSPA_HINT_BOUNDED_BELOW\n");
 
307
    #endif
294
308
    
295
309
    fmin =  range.LowerBound * m;
296
310
  }  
299
313
  
300
314
  if(desc & LADSPA_HINT_BOUNDED_ABOVE)
301
315
  {  
302
 
    // Added by Tim. p3.3.12
303
 
    if(PLUGIN_DEBUGIN)
304
 
      printf("midi2LadspaValue: has LADSPA_HINT_BOUNDED_ABOVE\n");
 
316
    #ifdef PLUGIN_DEBUGIN 
 
317
    printf("midi2LadspaValue: has LADSPA_HINT_BOUNDED_ABOVE\n");
 
318
    #endif
305
319
    
306
320
    fmax =  range.UpperBound * m;
307
321
  }  
315
329
 
316
330
  if(desc & LADSPA_HINT_TOGGLED) 
317
331
  {
318
 
    // Added by Tim. p3.3.12
319
 
    if(PLUGIN_DEBUGIN)
320
 
      printf("midi2LadspaValue: has LADSPA_HINT_TOGGLED\n");
 
332
    #ifdef PLUGIN_DEBUGIN 
 
333
    printf("midi2LadspaValue: has LADSPA_HINT_TOGGLED\n");
 
334
    #endif
321
335
    
322
336
    if(val > 0)
323
337
      return fmax;
328
342
  int ctlmn = 0;
329
343
  int ctlmx = 127;
330
344
  
331
 
  // Added by Tim. p3.3.12
332
 
  if(PLUGIN_DEBUGIN)
333
 
    printf("midi2LadspaValue: port min:%f max:%f \n", fmin, fmax);
 
345
  #ifdef PLUGIN_DEBUGIN 
 
346
  printf("midi2LadspaValue: port min:%f max:%f \n", fmin, fmax);
 
347
  #endif
334
348
  
335
349
  //bool isneg = (fmin < 0.0);
336
350
  bool isneg = (imin < 0);
395
409
      ret = fmin;
396
410
    if(ret > fmax)
397
411
      ret = fmax;
398
 
    // Added by Tim. p3.3.12
399
 
    if(PLUGIN_DEBUGIN)
400
 
      printf("midi2LadspaValue: has LADSPA_HINT_INTEGER returning:%f\n", ret);
401
 
  
 
412
    #ifdef PLUGIN_DEBUGIN 
 
413
    printf("midi2LadspaValue: has LADSPA_HINT_INTEGER returning:%f\n", ret);
 
414
    #endif
 
415
    
402
416
    return ret;  
403
417
  }
404
418
  
415
429
  
416
430
  float ret = normval * frng + fmin;
417
431
  
418
 
  // Added by Tim. p3.3.12
419
 
  if(PLUGIN_DEBUGIN)
420
 
    printf("midi2LadspaValue: float returning:%f\n", ret);
 
432
  #ifdef PLUGIN_DEBUGIN 
 
433
  printf("midi2LadspaValue: float returning:%f\n", ret);
 
434
  #endif
421
435
  
422
436
  return ret;
423
437
}      
564
578
//   Plugin
565
579
//---------------------------------------------------------
566
580
 
567
 
Plugin::Plugin(QFileInfo* f,
568
 
   LADSPA_Descriptor_Function df, const LADSPA_Descriptor* d, bool ip)
569
 
   : fi(*f), ladspa(df), plugin(d)
570
 
      {
571
 
      _inPlaceCapable = ip;
 
581
Plugin::Plugin(QFileInfo* f, const LADSPA_Descriptor* d, bool isDssi)
 
582
{
 
583
  _isDssi = isDssi;
 
584
  #ifdef DSSI_SUPPORT
 
585
  dssi_descr = NULL;
 
586
  #endif
 
587
  
 
588
  fi = *f;
 
589
  plugin = NULL;
 
590
  ladspa = NULL;
 
591
  _handle = 0;
 
592
  _references = 0;
 
593
  _instNo     = 0;
 
594
  _label = QString(d->Label); 
 
595
  _name = QString(d->Name); 
 
596
  _uniqueID = d->UniqueID; 
 
597
  _maker = QString(d->Maker); 
 
598
  _copyright = QString(d->Copyright); 
 
599
  
 
600
  _portCount = d->PortCount;
 
601
  //_portDescriptors = 0;
 
602
  //if(_portCount)
 
603
  //  _portDescriptors = new LADSPA_PortDescriptor[_portCount];
 
604
  
 
605
  
 
606
  _inports = 0;
 
607
  _outports = 0;
 
608
  _controlInPorts = 0;
 
609
  _controlOutPorts = 0;
 
610
  for(unsigned long k = 0; k < _portCount; ++k) 
 
611
  {
 
612
    LADSPA_PortDescriptor pd = d->PortDescriptors[k];
 
613
    //_portDescriptors[k] = pd;
 
614
    if(pd & LADSPA_PORT_AUDIO)
 
615
    {
 
616
      if(pd & LADSPA_PORT_INPUT)
 
617
        ++_inports;
 
618
      else
 
619
      if(pd & LADSPA_PORT_OUTPUT)
 
620
        ++_outports;
 
621
    }    
 
622
    else
 
623
    if(pd & LADSPA_PORT_CONTROL)
 
624
    {
 
625
      if(pd & LADSPA_PORT_INPUT)
 
626
        ++_controlInPorts;
 
627
      else
 
628
      if(pd & LADSPA_PORT_OUTPUT)
 
629
        ++_controlOutPorts;
 
630
    }    
 
631
  }
 
632
  
 
633
  _inPlaceCapable = !LADSPA_IS_INPLACE_BROKEN(d->Properties);
 
634
  
 
635
  // By T356. Blacklist vst plugins in-place configurable for now. At one point they 
 
636
  //   were working with in-place here, but not now, and RJ also reported they weren't working.
 
637
  // Fixes problem with vst plugins not working or feeding back loudly.
 
638
  // I can only think of two things that made them stop working:
 
639
  // 1): I switched back from Jack-2 to Jack-1
 
640
  // 2): I changed winecfg audio to use Jack instead of ALSA.
 
641
  // Will test later...
 
642
  // Possibly the first one because under Mandriva2007.1 (Jack-1), no matter how hard I tried, 
 
643
  //  the same problem existed. It may have been when using Jack-2 with Mandriva2009 that they worked.
 
644
  // Apparently the plugins are lying about their in-place capability.
 
645
  // Quote:
 
646
  /* Property LADSPA_PROPERTY_INPLACE_BROKEN indicates that the plugin
 
647
    may cease to work correctly if the host elects to use the same data
 
648
    location for both input and output (see connect_port()). This
 
649
    should be avoided as enabling this flag makes it impossible for
 
650
    hosts to use the plugin to process audio `in-place.' */
 
651
  // Examination of all my ladspa and vst synths and effects plugins showed only one - 
 
652
  //  EnsembleLite (EnsLite VST) has the flag set, but it is a vst synth and is not involved here!
 
653
  // Yet many (all?) ladspa vst effect plugins exhibit this problem.  
 
654
  // Changed by Tim. p3.3.14
 
655
  if ((_inports != _outports) || (fi.baseName(true) == QString("dssi-vst") && !config.vstInPlace))
 
656
        _inPlaceCapable = false;
 
657
}
 
658
 
 
659
Plugin::~Plugin()
 
660
{
 
661
  //if(_portDescriptors)
 
662
  //  delete[] _portDescriptors;
 
663
}
 
664
  
 
665
//---------------------------------------------------------
 
666
//   incReferences
 
667
//---------------------------------------------------------
 
668
 
 
669
int Plugin::incReferences(int val)
 
670
{
 
671
  #ifdef PLUGIN_DEBUGIN 
 
672
  fprintf(stderr, "Plugin::incReferences _references:%d val:%d\n", _references, val);
 
673
  #endif
 
674
  
 
675
  int newref = _references + val;
 
676
  
 
677
  if(newref == 0) 
 
678
  {
 
679
    _references = 0;
 
680
    if(_handle)
 
681
    {
 
682
      #ifdef PLUGIN_DEBUGIN 
 
683
      fprintf(stderr, "Plugin::incReferences no more instances, closing library\n");
 
684
      #endif
 
685
      
 
686
      dlclose(_handle);
 
687
    }
 
688
    
 
689
    _handle = 0;
 
690
    ladspa = NULL;
 
691
    plugin = NULL;
 
692
    rpIdx.clear();
 
693
    
 
694
    #ifdef DSSI_SUPPORT
 
695
    dssi_descr = NULL;
 
696
    #endif
 
697
    
 
698
    return 0;
 
699
  }
 
700
    
 
701
  //if(_references == 0) 
 
702
  if(_handle == 0) 
 
703
  {
 
704
    //_references = 0;
 
705
    _handle = dlopen(fi.filePath().latin1(), RTLD_NOW);
 
706
    //handle = dlopen(fi.absFilePath().latin1(), RTLD_NOW);
 
707
    
 
708
    if(_handle == 0) 
 
709
    {
 
710
      fprintf(stderr, "Plugin::incReferences dlopen(%s) failed: %s\n",
 
711
              fi.filePath().latin1(), dlerror());
 
712
              //fi.absFilePath().latin1(), dlerror());
 
713
      return 0;
 
714
    }
 
715
    
 
716
    #ifdef DSSI_SUPPORT
 
717
    DSSI_Descriptor_Function dssi = (DSSI_Descriptor_Function)dlsym(_handle, "dssi_descriptor");
 
718
    if(dssi)
 
719
    {
 
720
      const DSSI_Descriptor* descr;
 
721
      for(int i = 0;; ++i) 
 
722
      {
 
723
        descr = dssi(i);
 
724
        if(descr == NULL)
 
725
          break;
 
726
        
 
727
        QString label(descr->LADSPA_Plugin->Label);
 
728
        // Listing effect plugins only while excluding synths:
 
729
        // Do exactly what dssi-vst.cpp does for listing ladspa plugins.
 
730
        //if(label == _name &&
 
731
        if(label == _label &&
 
732
          !descr->run_synth &&
 
733
          !descr->run_synth_adding &&
 
734
          !descr->run_multiple_synths &&
 
735
          !descr->run_multiple_synths_adding) 
 
736
        {  
 
737
          _isDssi = true;
 
738
          ladspa = NULL;
 
739
          dssi_descr = descr;
 
740
          plugin = descr->LADSPA_Plugin;
 
741
          break;
 
742
        }
 
743
      }  
 
744
    }
 
745
    else
 
746
    #endif // DSSI_SUPPORT   
 
747
    {
 
748
      LADSPA_Descriptor_Function ladspadf = (LADSPA_Descriptor_Function)dlsym(_handle, "ladspa_descriptor");
 
749
      if(ladspadf)
 
750
      {
 
751
        const LADSPA_Descriptor* descr;
 
752
        for(int i = 0;; ++i) 
 
753
        {
 
754
          descr = ladspadf(i);
 
755
          if(descr == NULL)
 
756
            break;
 
757
          
 
758
          QString label(descr->Label);
 
759
          //if(label == _name)
 
760
          if(label == _label)
 
761
          {  
 
762
            _isDssi = false;
 
763
            ladspa = ladspadf;
 
764
            plugin = descr;
 
765
            
 
766
            #ifdef DSSI_SUPPORT
 
767
            dssi_descr = NULL;
 
768
            #endif
 
769
            
 
770
            break;
 
771
          }
 
772
        }  
 
773
      }
 
774
    }    
 
775
    
 
776
    if(plugin != NULL)
 
777
    {
 
778
      //_instNo     = 0;
 
779
      _name = QString(plugin->Name); 
 
780
      _uniqueID = plugin->UniqueID; 
 
781
      _maker = QString(plugin->Maker); 
 
782
      _copyright = QString(plugin->Copyright); 
 
783
      
 
784
      //if(_portDescriptors)
 
785
      //  delete[] _portDescriptors;
 
786
      //_portDescriptors = 0;  
 
787
      _portCount = plugin->PortCount;
 
788
      //if(_portCount)
 
789
      //  _portDescriptors = new LADSPA_PortDescriptor[_portCount];
 
790
        
572
791
      _inports = 0;
573
792
      _outports = 0;
574
 
      for (unsigned k = 0; k < d->PortCount; ++k) {
575
 
            LADSPA_PortDescriptor pd = d->PortDescriptors[k];
576
 
            if (pd &  LADSPA_PORT_CONTROL)
577
 
                  continue;
578
 
            if (pd &  LADSPA_PORT_INPUT)
579
 
                  ++_inports;
580
 
            else
581
 
                  ++_outports;
582
 
            }
583
 
      
584
 
      // By T356. Blacklist vst plugins in-place configurable for now. At one point they 
585
 
      //   were working with in-place here, but not now, and RJ also reported they weren't working.
586
 
      // Fixes problem with vst plugins not working or feeding back loudly.
587
 
      // I can only think of two things that made them stop working:
588
 
      // 1): I switched back from Jack-2 to Jack-1
589
 
      // 2): I changed winecfg audio to use Jack instead of ALSA.
590
 
      // Will test later...
591
 
      // Possibly the first one because under Mandriva2007.1 (Jack-1), no matter how hard I tried, 
592
 
      //  the same problem existed. It may have been when using Jack-2 with Mandriva2009 that they worked.
593
 
      // Apparently the plugins are lying about their in-place capability.
594
 
      // Quote:
595
 
      /* Property LADSPA_PROPERTY_INPLACE_BROKEN indicates that the plugin
596
 
        may cease to work correctly if the host elects to use the same data
597
 
        location for both input and output (see connect_port()). This
598
 
        should be avoided as enabling this flag makes it impossible for
599
 
        hosts to use the plugin to process audio `in-place.' */
600
 
      // Examination of all my ladspa and vst synths and effects plugins showed only one - 
601
 
      //  EnsembleLite (EnsLite VST) has the flag set, but it is a vst synth and is not involved here!
602
 
      // Yet many (all?) ladspa vst effect plugins exhibit this problem.  
603
 
      // Changed by Tim. p3.3.14
604
 
      if ((_inports != _outports) || (f->baseName(true) == QString("dssi-vst") && !config.vstInPlace))
 
793
      _controlInPorts = 0;
 
794
      _controlOutPorts = 0;
 
795
      for(unsigned long k = 0; k < _portCount; ++k) 
 
796
      {
 
797
        LADSPA_PortDescriptor pd = plugin->PortDescriptors[k];
 
798
        //_portDescriptors[k] = pd;
 
799
        if(pd & LADSPA_PORT_AUDIO)
 
800
        {
 
801
          if(pd & LADSPA_PORT_INPUT)
 
802
            ++_inports;
 
803
          else
 
804
          if(pd & LADSPA_PORT_OUTPUT)
 
805
            ++_outports;
 
806
          
 
807
          rpIdx.push_back((unsigned long)-1);
 
808
        }    
 
809
        else
 
810
        if(pd & LADSPA_PORT_CONTROL)
 
811
        {
 
812
          if(pd & LADSPA_PORT_INPUT)
 
813
          {
 
814
            rpIdx.push_back(_controlInPorts);
 
815
            ++_controlInPorts;
 
816
          }  
 
817
          else
 
818
          if(pd & LADSPA_PORT_OUTPUT)
 
819
          {
 
820
            rpIdx.push_back((unsigned long)-1);
 
821
            ++_controlOutPorts;
 
822
          }  
 
823
        }    
 
824
      }
 
825
      
 
826
      _inPlaceCapable = !LADSPA_IS_INPLACE_BROKEN(plugin->Properties);
 
827
      
 
828
      // Blacklist vst plugins in-place configurable for now. 
 
829
      if ((_inports != _outports) || (fi.baseName(true) == QString("dssi-vst") && !config.vstInPlace))
605
830
            _inPlaceCapable = false;
606
 
      
607
 
      _references = 0;
608
 
      _instNo     = 0;
609
 
      }
 
831
    }
 
832
  }      
 
833
        
 
834
  if(plugin == NULL)
 
835
  {
 
836
    dlclose(_handle);
 
837
    _handle = 0;
 
838
    _references = 0;
 
839
    fprintf(stderr, "Plugin::incReferences Error: %s no plugin!\n", fi.filePath().latin1()); 
 
840
    return 0;
 
841
  }
 
842
        
 
843
  _references = newref;
 
844
  
 
845
  //QString guiPath(info.dirPath() + "/" + info.baseName());
 
846
  //QDir guiDir(guiPath, "*", QDir::Unsorted, QDir::Files);
 
847
  //_hasGui = guiDir.exists();
 
848
  
 
849
  return _references;
 
850
}
610
851
 
611
852
//---------------------------------------------------------
612
853
//   range
613
854
//---------------------------------------------------------
614
855
 
615
 
void Plugin::range(int i, float* min, float* max) const
 
856
void Plugin::range(unsigned long i, float* min, float* max) const
616
857
      {
617
858
      LADSPA_PortRangeHint range = plugin->PortRangeHints[i];
618
859
      LADSPA_PortRangeHintDescriptor desc = range.HintDescriptor;
639
880
//   defaultValue
640
881
//---------------------------------------------------------
641
882
 
642
 
double Plugin::defaultValue(unsigned int port) const
 
883
double Plugin::defaultValue(unsigned long port) const
643
884
{
644
885
    if(port >= plugin->PortCount) 
645
886
      return 0.0;
686
927
//---------------------------------------------------------
687
928
 
688
929
static void loadPluginLib(QFileInfo* fi)
689
 
      {
690
 
      void* handle = dlopen(fi->filePath().ascii(), RTLD_NOW);
691
 
      if (handle == 0) {
692
 
            fprintf(stderr, "dlopen(%s) failed: %s\n",
693
 
              fi->filePath().ascii(), dlerror());
694
 
            return;
695
 
            }
696
 
      LADSPA_Descriptor_Function ladspa = (LADSPA_Descriptor_Function)dlsym(handle, "ladspa_descriptor");
 
930
{
 
931
  void* handle = dlopen(fi->filePath().ascii(), RTLD_NOW);
 
932
  if (handle == 0) {
 
933
        fprintf(stderr, "dlopen(%s) failed: %s\n",
 
934
          fi->filePath().ascii(), dlerror());
 
935
        return;
 
936
        }
697
937
 
698
 
      if (!ladspa) {
699
 
            const char *txt = dlerror();
700
 
            if (txt) {
701
 
                  fprintf(stderr,
702
 
                        "Unable to find ladspa_descriptor() function in plugin "
703
 
                        "library file \"%s\": %s.\n"
704
 
                        "Are you sure this is a LADSPA plugin file?\n",
705
 
                        fi->filePath().ascii(),
706
 
                        txt);
707
 
                  }
708
 
                  dlclose(handle);
709
 
                  return;
710
 
            }
711
 
      const LADSPA_Descriptor* descr;
712
 
      for (int i = 0;; ++i) {
713
 
            descr = ladspa(i);
714
 
            if (descr == NULL)
715
 
                  break;
716
 
            
717
 
            // Make sure it doesn't already exist.
718
 
            if(plugins.find(fi->baseName(true), QString(descr->Label)) != 0)
719
 
              continue;
720
 
            
721
 
            LADSPA_Properties properties = descr->Properties;
722
 
            int ai = 0;
723
 
            int ao = 0;
724
 
            for (unsigned k = 0; k < descr->PortCount; ++k) {
725
 
                  LADSPA_PortDescriptor pd = descr->PortDescriptors[k];
726
 
                  if (pd &  LADSPA_PORT_CONTROL)
727
 
                        continue;
728
 
                  if (pd &  LADSPA_PORT_INPUT)
729
 
                        ++ai;
730
 
                  else
731
 
                        ++ao;
732
 
                  }
733
 
            bool inPlaceBroken = LADSPA_IS_INPLACE_BROKEN(properties);
734
 
            
735
 
            plugins.add(fi, ladspa, descr, !inPlaceBroken);
736
 
            }
737
 
      }
 
938
  #ifdef DSSI_SUPPORT
 
939
  DSSI_Descriptor_Function dssi = (DSSI_Descriptor_Function)dlsym(handle, "dssi_descriptor");
 
940
  if(dssi)
 
941
  {
 
942
    const DSSI_Descriptor* descr;
 
943
    for (int i = 0;; ++i) 
 
944
    {
 
945
      descr = dssi(i);
 
946
      if (descr == 0)
 
947
            break;
 
948
      
 
949
      // Listing effect plugins only while excluding synths:
 
950
      // Do exactly what dssi-vst.cpp does for listing ladspa plugins.
 
951
      if(!descr->run_synth &&
 
952
        !descr->run_synth_adding &&
 
953
        !descr->run_multiple_synths &&
 
954
        !descr->run_multiple_synths_adding) 
 
955
      {
 
956
        // Make sure it doesn't already exist.
 
957
        if(plugins.find(fi->baseName(true), QString(descr->LADSPA_Plugin->Label)) != 0)
 
958
          continue;
 
959
        
 
960
        #ifdef PLUGIN_DEBUGIN 
 
961
        fprintf(stderr, "loadPluginLib: dssi effect name:%s inPlaceBroken:%d\n", descr->LADSPA_Plugin->Name, LADSPA_IS_INPLACE_BROKEN(descr->LADSPA_Plugin->Properties));
 
962
        #endif
 
963
      
 
964
        //LADSPA_Properties properties = descr->LADSPA_Plugin->Properties;
 
965
        //bool inPlaceBroken = LADSPA_IS_INPLACE_BROKEN(properties);
 
966
        //plugins.add(fi, descr, !inPlaceBroken);
 
967
        plugins.add(fi, descr->LADSPA_Plugin, true);
 
968
      }
 
969
    }      
 
970
  }
 
971
  else
 
972
  #endif
 
973
  {
 
974
    LADSPA_Descriptor_Function ladspa = (LADSPA_Descriptor_Function)dlsym(handle, "ladspa_descriptor");
 
975
    if(!ladspa) 
 
976
    {
 
977
      const char *txt = dlerror();
 
978
      if(txt) 
 
979
      {
 
980
        fprintf(stderr,
 
981
              "Unable to find ladspa_descriptor() function in plugin "
 
982
              "library file \"%s\": %s.\n"
 
983
              "Are you sure this is a LADSPA plugin file?\n",
 
984
              fi->filePath().ascii(),
 
985
              txt);
 
986
      }
 
987
      dlclose(handle);
 
988
      return;
 
989
    }
 
990
    
 
991
    const LADSPA_Descriptor* descr;
 
992
    for (int i = 0;; ++i) 
 
993
    {
 
994
      descr = ladspa(i);
 
995
      if (descr == NULL)
 
996
            break;
 
997
      
 
998
      // Make sure it doesn't already exist.
 
999
      if(plugins.find(fi->baseName(true), QString(descr->Label)) != 0)
 
1000
        continue;
 
1001
      
 
1002
      #ifdef PLUGIN_DEBUGIN 
 
1003
      fprintf(stderr, "loadPluginLib: ladspa effect name:%s inPlaceBroken:%d\n", descr->Name, LADSPA_IS_INPLACE_BROKEN(descr->Properties));
 
1004
      #endif
 
1005
      
 
1006
      //LADSPA_Properties properties = descr->Properties;
 
1007
      //bool inPlaceBroken = LADSPA_IS_INPLACE_BROKEN(properties);
 
1008
      //plugins.add(fi, ladspa, descr, !inPlaceBroken);
 
1009
      plugins.add(fi, descr);
 
1010
    }
 
1011
  }  
 
1012
  
 
1013
  dlclose(handle);
 
1014
}
738
1015
 
739
1016
//---------------------------------------------------------
740
1017
//   loadPluginDir
764
1041
      {
765
1042
      loadPluginDir(museGlobalLib + QString("/plugins"));
766
1043
 
 
1044
      const char* p = 0;
 
1045
      
 
1046
      // Take care of DSSI plugins first...
 
1047
      #ifdef DSSI_SUPPORT
 
1048
      const char* dssiPath = getenv("DSSI_PATH");
 
1049
      if (dssiPath == 0)
 
1050
            dssiPath = "/usr/local/lib64/dssi:/usr/lib64/dssi:/usr/local/lib/dssi:/usr/lib/dssi";
 
1051
      p = dssiPath;
 
1052
      while (*p != '\0') {
 
1053
            const char* pe = p;
 
1054
            while (*pe != ':' && *pe != '\0')
 
1055
                  pe++;
 
1056
 
 
1057
            int n = pe - p;
 
1058
            if (n) {
 
1059
                  char* buffer = new char[n + 1];
 
1060
                  strncpy(buffer, p, n);
 
1061
                  buffer[n] = '\0';
 
1062
                  loadPluginDir(QString(buffer));
 
1063
                  delete[] buffer;
 
1064
                  }
 
1065
            p = pe;
 
1066
            if (*p == ':')
 
1067
                  p++;
 
1068
            }
 
1069
      #endif
 
1070
      
 
1071
      // Now do LADSPA plugins...
767
1072
      const char* ladspaPath = getenv("LADSPA_PATH");
768
1073
      if (ladspaPath == 0)
769
1074
            ladspaPath = "/usr/local/lib64/ladspa:/usr/lib64/ladspa:/usr/local/lib/ladspa:/usr/lib/ladspa";
770
 
 
771
 
      const char* p = ladspaPath;
 
1075
      p = ladspaPath;
 
1076
      
 
1077
      if(debugMsg)
 
1078
        fprintf(stderr, "loadPluginLib: ladspa path:%s\n", ladspaPath);
 
1079
      
772
1080
      while (*p != '\0') {
773
1081
            const char* pe = p;
774
1082
            while (*pe != ':' && *pe != '\0')
779
1087
                  char* buffer = new char[n + 1];
780
1088
                  strncpy(buffer, p, n);
781
1089
                  buffer[n] = '\0';
 
1090
                  if(debugMsg)
 
1091
                    fprintf(stderr, "loadPluginLib: loading ladspa dir:%s\n", buffer);
 
1092
                  
782
1093
                  loadPluginDir(QString(buffer));
783
1094
                  delete[] buffer;
784
1095
                  }
974
1285
}
975
1286
 
976
1287
//---------------------------------------------------------
 
1288
//   isDssiPlugin
 
1289
//---------------------------------------------------------
 
1290
 
 
1291
bool Pipeline::isDssiPlugin(int idx) const
 
1292
{
 
1293
  PluginI* p = (*this)[idx];
 
1294
  if(p)
 
1295
    return p->isDssiPlugin();
 
1296
        
 
1297
  return false;               
 
1298
}
 
1299
 
 
1300
//---------------------------------------------------------
977
1301
//   showGui
978
1302
//---------------------------------------------------------
979
1303
 
985
1309
      }
986
1310
 
987
1311
//---------------------------------------------------------
 
1312
//   showNativeGui
 
1313
//---------------------------------------------------------
 
1314
 
 
1315
void Pipeline::showNativeGui(int idx, bool flag)
 
1316
      {
 
1317
      #ifdef OSC_SUPPORT
 
1318
      PluginI* p = (*this)[idx];
 
1319
      if (p)
 
1320
            p->oscIF().oscShowGui(flag);
 
1321
      #endif      
 
1322
      }
 
1323
 
 
1324
//---------------------------------------------------------
988
1325
//   deleteGui
989
1326
//---------------------------------------------------------
990
1327
 
1020
1357
      }
1021
1358
 
1022
1359
//---------------------------------------------------------
 
1360
//   nativeGuiVisible
 
1361
//---------------------------------------------------------
 
1362
 
 
1363
bool Pipeline::nativeGuiVisible(int idx)
 
1364
      {
 
1365
      PluginI* p = (*this)[idx];
 
1366
      if (p)
 
1367
            return p->nativeGuiVisible();
 
1368
      return false;
 
1369
      }
 
1370
 
 
1371
//---------------------------------------------------------
1023
1372
//   apply
1024
1373
//---------------------------------------------------------
1025
1374
 
1034
1383
      //for (int i = 0; i < ports; ++i)
1035
1384
      //      buffer2[i] = data + i * nframes;
1036
1385
 
 
1386
      // p3.3.41
 
1387
      //fprintf(stderr, "Pipeline::apply data: nframes:%ld %e %e %e %e\n", nframes, buffer1[0][0], buffer1[0][1], buffer1[0][2], buffer1[0][3]);
 
1388
      
1037
1389
      bool swap = false;
1038
1390
 
1039
1391
      for (iPluginI ip = begin(); ip != end(); ++ip) {
1067
1419
                  //memcpy(buffer1[i], buffer[i], sizeof(float) * nframes);
1068
1420
                  AL::dsp->cpy(buffer1[i], buffer[i], nframes);
1069
1421
      }
 
1422
      
 
1423
      // p3.3.41
 
1424
      //fprintf(stderr, "Pipeline::apply after data: nframes:%ld %e %e %e %e\n", nframes, buffer1[0][0], buffer1[0][1], buffer1[0][2], buffer1[0][3]);
 
1425
      
1070
1426
}
1071
1427
 
1072
1428
//---------------------------------------------------------
1079
1435
      instances         = 0;
1080
1436
      handle            = 0;
1081
1437
      controls          = 0;
 
1438
      controlsOut       = 0;
1082
1439
      controlPorts      = 0;
 
1440
      controlOutPorts   = 0;
1083
1441
      _gui              = 0;
1084
1442
      _on               = true;
1085
1443
      initControlValues = false;
 
1444
      _showNativeGuiPending = false;
1086
1445
      }
1087
1446
 
1088
1447
PluginI::PluginI()
1089
1448
      {
1090
1449
      _id = -1;
1091
1450
      _track = 0;
 
1451
      
1092
1452
      init();
1093
1453
      }
1094
1454
 
1104
1464
            }
1105
1465
      if (_gui)
1106
1466
            delete _gui;
 
1467
      if (controlsOut)
 
1468
            delete[] controlsOut;
1107
1469
      if (controls)
1108
 
            delete controls;
 
1470
            delete[] controls;
1109
1471
      if (handle)
1110
 
            delete handle;
 
1472
            delete[] handle;
1111
1473
      }
1112
1474
 
1113
1475
//---------------------------------------------------------
1125
1487
 
1126
1488
void PluginI::updateControllers()
1127
1489
{
 
1490
  if(!_track)
 
1491
    return;
 
1492
    
1128
1493
  for(int i = 0; i < controlPorts; ++i) 
1129
 
    audio->msgSetPluginCtrlVal(this, genACnum(_id, i), controls[i].val);
 
1494
    //audio->msgSetPluginCtrlVal(this, genACnum(_id, i), controls[i].val);
 
1495
    // p3.3.43
 
1496
    audio->msgSetPluginCtrlVal(_track, genACnum(_id, i), controls[i].val);
1130
1497
}
1131
1498
  
1132
1499
//---------------------------------------------------------
1143
1510
//---------------------------------------------------------
1144
1511
 
1145
1512
void PluginI::setChannels(int c)
1146
 
      {
1147
 
      if (channel == c)
1148
 
            return;
1149
 
      int ni = c / _plugin->outports();
1150
 
      if (ni == 0)
1151
 
            ni = 1;
 
1513
{
 
1514
      // p3.3.41 Removed
 
1515
      //if (channel == c)
 
1516
      //      return;
 
1517
      
 
1518
      // p3.3.41
 
1519
      channel = c;
 
1520
      
 
1521
      //int ni = c / _plugin->outports();
 
1522
      //if (ni == 0)
 
1523
      //      ni = 1;
 
1524
      // p3.3.41 Some plugins have zero out ports, causing exception with the above line.
 
1525
      // Also, pick the least number of ins or outs, and base the number of instances on that.
 
1526
      unsigned long ins = _plugin->inports();
 
1527
      unsigned long outs = _plugin->outports();
 
1528
      /*
 
1529
      unsigned long minports = ~0ul;
 
1530
      if(outs && outs < minports)
 
1531
        minports = outs;
 
1532
      if(ins && ins < minports)
 
1533
        minports = ins;
 
1534
      if(minports == ~0ul)
 
1535
        minports = 1;
 
1536
      int ni = c / minports;
 
1537
      */
 
1538
      int ni = 1;
 
1539
      if(outs)
 
1540
        ni = c / outs;
 
1541
      else
 
1542
      if(ins)
 
1543
        ni = c / ins;
 
1544
      
 
1545
      if(ni < 1)
 
1546
        ni = 1;
 
1547
      
1152
1548
      if (ni == instances)
1153
1549
            return;
1154
 
      channel = c;
 
1550
      
 
1551
      // p3.3.41 Moved above.
 
1552
      //channel = c;
1155
1553
 
1156
1554
      // remove old instances:
1157
1555
      deactivate();
1158
 
      delete handle;
 
1556
      delete[] handle;
1159
1557
      instances = ni;
1160
1558
      handle    = new LADSPA_Handle[instances];
1161
1559
      for (int i = 0; i < instances; ++i) {
1162
1560
            handle[i] = _plugin->instantiate();
1163
 
            if (handle[i] == 0) {
 
1561
            if (handle[i] == NULL) {
1164
1562
                  printf("cannot instantiate instance %d\n", i);
1165
1563
                  return;
1166
1564
                  }
1167
1565
            }
 
1566
      
1168
1567
      int curPort = 0;
1169
 
      int ports   = _plugin->ports();
1170
 
      for (int k = 0; k < ports; ++k) {
 
1568
      int curOutPort = 0;
 
1569
      unsigned long ports   = _plugin->ports();
 
1570
      for (unsigned long k = 0; k < ports; ++k) 
 
1571
      {
1171
1572
            LADSPA_PortDescriptor pd = _plugin->portd(k);
1172
 
            if (pd & LADSPA_PORT_CONTROL) {
1173
 
                  for (int i = 0; i < instances; ++i)
1174
 
                        _plugin->connectPort(handle[i], k, &controls[curPort].val);
1175
 
                  controls[curPort].idx = k;
1176
 
                  ++curPort;
 
1573
            if (pd & LADSPA_PORT_CONTROL) 
 
1574
            {
 
1575
                  if(pd & LADSPA_PORT_INPUT) 
 
1576
                  {
 
1577
                    for (int i = 0; i < instances; ++i)
 
1578
                          _plugin->connectPort(handle[i], k, &controls[curPort].val);
 
1579
                    controls[curPort].idx = k;
 
1580
                    ++curPort;
 
1581
                  }
 
1582
                  else  
 
1583
                  if(pd & LADSPA_PORT_OUTPUT) 
 
1584
                  {
 
1585
                    for (int i = 0; i < instances; ++i)
 
1586
                          _plugin->connectPort(handle[i], k, &controlsOut[curOutPort].val);
 
1587
                    controlsOut[curOutPort].idx = k;
 
1588
                    ++curOutPort;
1177
1589
                  }
1178
1590
            }
 
1591
      }
 
1592
      
1179
1593
      activate();
1180
 
      }
 
1594
}
1181
1595
 
1182
1596
//---------------------------------------------------------
1183
1597
//   defaultValue
1192
1606
  return _plugin->defaultValue(controls[param].idx);
1193
1607
}
1194
1608
 
 
1609
LADSPA_Handle Plugin::instantiate() 
 
1610
{
 
1611
  LADSPA_Handle h = plugin->instantiate(plugin, sampleRate);
 
1612
  if(h == NULL)
 
1613
  {
 
1614
    fprintf(stderr, "Plugin::instantiate() Error: plugin:%s instantiate failed!\n", plugin->Label); 
 
1615
    return NULL;
 
1616
  }
 
1617
  
 
1618
  //QString guiPath(info.dirPath() + "/" + info.baseName());
 
1619
  //QDir guiDir(guiPath, "*", QDir::Unsorted, QDir::Files);
 
1620
  //_hasGui = guiDir.exists();
 
1621
  
 
1622
  return h;
 
1623
}
 
1624
 
1195
1625
//---------------------------------------------------------
1196
1626
//   initPluginInstance
1197
1627
//    return true on error
1200
1630
bool PluginI::initPluginInstance(Plugin* plug, int c)
1201
1631
      {
1202
1632
      channel = c;
1203
 
      if (plug == 0) {
1204
 
            printf("initPluginInstance: zero plugin\n");
1205
 
            return true;
1206
 
            }
 
1633
      if(plug == 0) 
 
1634
      {
 
1635
        printf("initPluginInstance: zero plugin\n");
 
1636
        return true;
 
1637
      }
1207
1638
      _plugin = plug;
 
1639
      
1208
1640
      _plugin->incReferences(1);
1209
1641
 
 
1642
      #ifdef OSC_SUPPORT
 
1643
      _oscif.oscSetPluginI(this);      
 
1644
      #endif
 
1645
      
1210
1646
      QString inst("-" + QString::number(_plugin->instNo()));
1211
1647
      _name  = _plugin->name() + inst;
1212
1648
      _label = _plugin->label() + inst;
1213
1649
 
1214
 
      instances = channel/plug->outports();
1215
 
      if (instances < 1)
1216
 
            instances = 1;
 
1650
      //instances = channel/plug->outports();
 
1651
      // p3.3.41 Some plugins have zero out ports, causing exception with the above line.
 
1652
      // Also, pick the least number of ins or outs, and base the number of instances on that.
 
1653
      unsigned long ins = plug->inports();
 
1654
      unsigned long outs = plug->outports();
 
1655
      /*
 
1656
      unsigned long minports = ~0ul;
 
1657
      if(outs && outs < minports)
 
1658
        minports = outs;
 
1659
      if(ins && ins < minports)
 
1660
        minports = ins;
 
1661
      if(minports == ~0ul)
 
1662
        minports = 1;
 
1663
      instances = channel / minports;
 
1664
      if(instances < 1)
 
1665
        instances = 1;
 
1666
      */  
 
1667
      if(outs)
 
1668
      {
 
1669
        instances = channel / outs;
 
1670
        if(instances < 1)
 
1671
          instances = 1;
 
1672
      }
 
1673
      else
 
1674
      if(ins)
 
1675
      {
 
1676
        instances = channel / ins;
 
1677
        if(instances < 1)
 
1678
          instances = 1;
 
1679
      }
 
1680
      else
 
1681
        instances = 1;
 
1682
        
1217
1683
      handle = new LADSPA_Handle[instances];
1218
 
      for (int i = 0; i < instances; ++i) {
1219
 
            handle[i] = _plugin->instantiate();
1220
 
            if (handle[i] == 0)
1221
 
                  return true;
1222
 
            }
 
1684
      for(int i = 0; i < instances; ++i) 
 
1685
      {
 
1686
        #ifdef PLUGIN_DEBUGIN 
 
1687
        fprintf(stderr, "PluginI::initPluginInstance instance:%d\n", i);
 
1688
        #endif
 
1689
        
 
1690
        handle[i] = _plugin->instantiate();
 
1691
        //if (handle[i] == 0)
 
1692
        if(handle[i] == NULL)
 
1693
          return true;
 
1694
      }
1223
1695
 
 
1696
      unsigned long ports = _plugin->ports();
 
1697
      
1224
1698
      controlPorts = 0;
1225
 
      int ports    = _plugin->ports();
1226
 
 
1227
 
      for (int k = 0; k < ports; ++k) {
1228
 
            LADSPA_PortDescriptor pd = _plugin->portd(k);
1229
 
            if (pd & LADSPA_PORT_CONTROL)
1230
 
                  ++controlPorts;
1231
 
            }
1232
 
      controls = new Port[controlPorts];
1233
 
      int i = 0;
1234
 
      for (int k = 0; k < ports; ++k) {
1235
 
            LADSPA_PortDescriptor pd = _plugin->portd(k);
1236
 
            if (pd & LADSPA_PORT_CONTROL) {
1237
 
                  double val = _plugin->defaultValue(k);
1238
 
                  controls[i].val    = val;
1239
 
                  controls[i].tmpVal = val;
1240
 
                  controls[i].enCtrl  = true;
1241
 
                  controls[i].en2Ctrl = true;
1242
 
                  ++i;
1243
 
                  }
1244
 
            }
1245
 
      int curPort = 0;
1246
 
      for (int k = 0; k < ports; ++k) {
1247
 
            LADSPA_PortDescriptor pd = _plugin->portd(k);
1248
 
            if (pd & LADSPA_PORT_CONTROL) {
1249
 
                  for (int i = 0; i < instances; ++i)
1250
 
                        _plugin->connectPort(handle[i], k, &controls[curPort].val);
1251
 
                  controls[curPort].idx = k;
1252
 
                  ++curPort;
1253
 
                  }
1254
 
            }
 
1699
      controlOutPorts = 0;
 
1700
      
 
1701
      for(unsigned long k = 0; k < ports; ++k) 
 
1702
      {
 
1703
        LADSPA_PortDescriptor pd = _plugin->portd(k);
 
1704
        if(pd & LADSPA_PORT_CONTROL)
 
1705
        {
 
1706
          if(pd & LADSPA_PORT_INPUT)
 
1707
            ++controlPorts;
 
1708
          else    
 
1709
          if(pd & LADSPA_PORT_OUTPUT)
 
1710
            ++controlOutPorts;
 
1711
        }      
 
1712
      }
 
1713
      
 
1714
      controls    = new Port[controlPorts];
 
1715
      controlsOut = new Port[controlOutPorts];
 
1716
      
 
1717
      int i  = 0;
 
1718
      int ii = 0;
 
1719
      for(unsigned long k = 0; k < ports; ++k) 
 
1720
      {
 
1721
        LADSPA_PortDescriptor pd = _plugin->portd(k);
 
1722
        if(pd & LADSPA_PORT_CONTROL) 
 
1723
        {
 
1724
          if(pd & LADSPA_PORT_INPUT)
 
1725
          {
 
1726
            double val = _plugin->defaultValue(k);
 
1727
            controls[i].val    = val;
 
1728
            controls[i].tmpVal = val;
 
1729
            controls[i].enCtrl  = true;
 
1730
            controls[i].en2Ctrl = true;
 
1731
            ++i;
 
1732
          }
 
1733
          else
 
1734
          if(pd & LADSPA_PORT_OUTPUT)
 
1735
          {
 
1736
            //double val = _plugin->defaultValue(k);
 
1737
            controlsOut[ii].val     = 0.0;
 
1738
            controlsOut[ii].tmpVal  = 0.0;
 
1739
            controlsOut[ii].enCtrl  = false;
 
1740
            controlsOut[ii].en2Ctrl = false;
 
1741
            ++ii;
 
1742
          }
 
1743
        }
 
1744
      }
 
1745
      unsigned long curPort = 0;
 
1746
      unsigned long curOutPort = 0;
 
1747
      for(unsigned long k = 0; k < ports; ++k) 
 
1748
      {
 
1749
        LADSPA_PortDescriptor pd = _plugin->portd(k);
 
1750
        if(pd & LADSPA_PORT_CONTROL) 
 
1751
        {
 
1752
          if(pd & LADSPA_PORT_INPUT)
 
1753
          {
 
1754
            for(int i = 0; i < instances; ++i)
 
1755
              _plugin->connectPort(handle[i], k, &controls[curPort].val);
 
1756
            controls[curPort].idx = k;
 
1757
            ++curPort;
 
1758
          }
 
1759
          else
 
1760
          if(pd & LADSPA_PORT_OUTPUT)
 
1761
          {
 
1762
            for(int i = 0; i < instances; ++i)
 
1763
              _plugin->connectPort(handle[i], k, &controlsOut[curOutPort].val);
 
1764
            controlsOut[curOutPort].idx = k;
 
1765
            ++curOutPort;
 
1766
          }
 
1767
        }
 
1768
      }
1255
1769
      activate();
1256
1770
      return false;
1257
1771
      }
1264
1778
      {
1265
1779
      int port = 0;
1266
1780
      for (int i = 0; i < instances; ++i) {
1267
 
            for (int k = 0; k < _plugin->ports(); ++k) {
 
1781
            for (unsigned long k = 0; k < _plugin->ports(); ++k) {
1268
1782
                  if (isAudioIn(k)) {
1269
1783
                        _plugin->connectPort(handle[i], k, src[port]);
1270
1784
                        port = (port + 1) % ports;
1273
1787
            }
1274
1788
      port = 0;
1275
1789
      for (int i = 0; i < instances; ++i) {
1276
 
            for (int k = 0; k < _plugin->ports(); ++k) {
 
1790
            for (unsigned long k = 0; k < _plugin->ports(); ++k) {
1277
1791
                  if (isAudioOut(k)) {
1278
1792
                        _plugin->connectPort(handle[i], k, dst[port]);
1279
1793
                        port = (port + 1) % ports;  // overwrite output?
1287
1801
      }
1288
1802
 
1289
1803
//---------------------------------------------------------
 
1804
//   deactivate
 
1805
//---------------------------------------------------------
 
1806
 
 
1807
void PluginI::deactivate()
 
1808
      {
 
1809
      for (int i = 0; i < instances; ++i) {
 
1810
            _plugin->deactivate(handle[i]);
 
1811
            _plugin->cleanup(handle[i]);
 
1812
            }
 
1813
      }
 
1814
 
 
1815
//---------------------------------------------------------
 
1816
//   activate
 
1817
//---------------------------------------------------------
 
1818
 
 
1819
void PluginI::activate()
 
1820
      {
 
1821
      for (int i = 0; i < instances; ++i)
 
1822
            _plugin->activate(handle[i]);
 
1823
      if (initControlValues) {
 
1824
            for (int i = 0; i < controlPorts; ++i) {
 
1825
                  controls[i].val = controls[i].tmpVal;
 
1826
                  }
 
1827
            }
 
1828
      else {
 
1829
            //
 
1830
            // get initial control values from plugin
 
1831
            //
 
1832
            for (int i = 0; i < controlPorts; ++i) {
 
1833
                  controls[i].tmpVal = controls[i].val;
 
1834
                  }
 
1835
            }
 
1836
      }
 
1837
 
 
1838
//---------------------------------------------------------
1290
1839
//   setControl
1291
1840
//    set plugin instance controller value by name
1292
1841
//---------------------------------------------------------
1311
1860
void PluginI::writeConfiguration(int level, Xml& xml)
1312
1861
      {
1313
1862
      xml.tag(level++, "plugin file=\"%s\" label=\"%s\" channel=\"%d\"",
1314
 
         _plugin->lib().latin1(), _plugin->label().latin1(), instances * _plugin->inports());
 
1863
         //_plugin->lib().latin1(), _plugin->label().latin1(), instances * _plugin->inports());
 
1864
         // p3.3.41
 
1865
         //_plugin->lib().latin1(), _plugin->label().latin1(), channel);
 
1866
         Xml::xmlString(_plugin->lib()).latin1(), Xml::xmlString(_plugin->label()).latin1(), channel);
 
1867
         
1315
1868
      for (int i = 0; i < controlPorts; ++i) {
1316
1869
            int idx = controls[i].idx;
1317
1870
            QString s("control name=\"%1\" val=\"%2\" /");
1318
 
            xml.tag(level, s.arg(_plugin->portName(idx)).arg(controls[i].tmpVal).latin1());
 
1871
            //xml.tag(level, s.arg(_plugin->portName(idx)).arg(controls[i].tmpVal).latin1());
 
1872
            xml.tag(level, s.arg(Xml::xmlString(_plugin->portName(idx)).latin1()).arg(controls[i].tmpVal).latin1());
1319
1873
            }
1320
1874
      if (_on == false)
1321
1875
            xml.intTag(level, "on", _on);
1323
1877
            xml.intTag(level, "gui", 1);
1324
1878
            xml.geometryTag(level, "geometry", _gui);
1325
1879
            }
 
1880
      if (nativeGuiVisible()) {
 
1881
            xml.intTag(level, "nativegui", 1);
 
1882
            // TODO:
 
1883
            //xml.geometryTag(level, "nativegeometry", ?);
 
1884
            }
1326
1885
      xml.tag(level--, "/plugin");
1327
1886
      }
1328
1887
 
1379
1938
      QString file;
1380
1939
      QString label;
1381
1940
      if (!readPreset)
1382
 
            instances = 1;
 
1941
            //instances = 1;
 
1942
            // p3.3.41
 
1943
            channel = 1;
1383
1944
 
1384
1945
      for (;;) {
1385
1946
            Xml::Token token(xml.parse());
1391
1952
                  case Xml::TagStart:
1392
1953
                        if (!readPreset && _plugin == 0) {
1393
1954
                              _plugin = plugins.find(file, label);
1394
 
                              if (_plugin && initPluginInstance(_plugin, instances)) {
 
1955
                              
 
1956
                              //if (_plugin && initPluginInstance(_plugin, instances)) {
 
1957
                              // p3.3.41
 
1958
                              if (_plugin && initPluginInstance(_plugin, channel)) {
1395
1959
                                    _plugin = 0;
1396
1960
                                    xml.parse1();
1397
1961
                                    break;
1408
1972
                              bool flag = xml.parseInt();
1409
1973
                              showGui(flag);
1410
1974
                              }
 
1975
                        else if (tag == "nativegui") {
 
1976
                              // We can't tell OSC to show the native plugin gui 
 
1977
                              //  until the parent track is added to the lists.
 
1978
                              // OSC needs to find the plugin in the track lists.
 
1979
                              // Use this 'pending' flag so it gets done later.
 
1980
                              _showNativeGuiPending = xml.parseInt();
 
1981
                              }
1411
1982
                        else if (tag == "geometry") {
1412
1983
                              QRect r(readGeometry(xml, tag));
1413
1984
                              if (_gui) {
1438
2009
                              }
1439
2010
                        else if (tag == "channel") {
1440
2011
                              if (!readPreset)
1441
 
                                    instances = xml.s2().toInt();
 
2012
                                    //instances = xml.s2().toInt();
 
2013
                                    // p3.3.41
 
2014
                                    channel = xml.s2().toInt();
1442
2015
                              }
1443
2016
                        break;
1444
2017
                  case Xml::TagEnd:
1447
2020
                                    _plugin = plugins.find(file, label);
1448
2021
                                    if (_plugin == 0)
1449
2022
                                          return true;
1450
 
                                    if (initPluginInstance(_plugin, instances))
 
2023
                                    
 
2024
                                    //if (initPluginInstance(_plugin, instances))
 
2025
                                    // p3.3.41
 
2026
                                    if (initPluginInstance(_plugin, channel))
1451
2027
                                          return true;
1452
2028
                                    }
1453
2029
                              if (_gui)
1503
2079
      }
1504
2080
 
1505
2081
//---------------------------------------------------------
 
2082
//   showNativeGui
 
2083
//---------------------------------------------------------
 
2084
 
 
2085
void PluginI::showNativeGui()
 
2086
{
 
2087
  #ifdef OSC_SUPPORT
 
2088
  if (_plugin) 
 
2089
  {
 
2090
        if (_oscif.oscGuiVisible())
 
2091
                _oscif.oscShowGui(false);
 
2092
        else
 
2093
                _oscif.oscShowGui(true);
 
2094
  }
 
2095
  #endif
 
2096
  _showNativeGuiPending = false;  
 
2097
}
 
2098
 
 
2099
void PluginI::showNativeGui(bool flag)
 
2100
{
 
2101
  #ifdef OSC_SUPPORT
 
2102
  if(_plugin) 
 
2103
  {
 
2104
    _oscif.oscShowGui(flag);
 
2105
  }  
 
2106
  #endif
 
2107
  _showNativeGuiPending = false;  
 
2108
}
 
2109
 
 
2110
//---------------------------------------------------------
 
2111
//   nativeGuiVisible
 
2112
//---------------------------------------------------------
 
2113
 
 
2114
bool PluginI::nativeGuiVisible()
 
2115
{
 
2116
  #ifdef OSC_SUPPORT
 
2117
  return _oscif.oscGuiVisible();
 
2118
  #endif    
 
2119
  
 
2120
  return false;
 
2121
}
 
2122
 
 
2123
//---------------------------------------------------------
1506
2124
//   makeGui
1507
2125
//---------------------------------------------------------
1508
2126
 
1548
2166
//---------------------------------------------------------
1549
2167
 
1550
2168
void PluginI::apply(int n)
1551
 
      {
1552
 
      if(automation && _track && _track->automationType() != AUTO_OFF && _id != -1)
1553
 
      {
1554
 
        for(int i = 0; i < controlPorts; ++i)
1555
 
        {
1556
 
          if( controls[i].enCtrl && controls[i].en2Ctrl )
1557
 
            controls[i].tmpVal = _track->pluginCtrlVal(genACnum(_id, i));
1558
 
        }  
1559
 
      }      
1560
 
      
1561
 
      for (int i = 0; i < controlPorts; ++i)
1562
 
            controls[i].val = controls[i].tmpVal;
 
2169
{
 
2170
      // Process control value changes.
 
2171
      //if(automation && _track && _track->automationType() != AUTO_OFF && _id != -1)
 
2172
      //{
 
2173
      //  for(int i = 0; i < controlPorts; ++i)
 
2174
      //  {
 
2175
      //    if( controls[i].enCtrl && controls[i].en2Ctrl )
 
2176
      //      controls[i].tmpVal = _track->pluginCtrlVal(genACnum(_id, i));
 
2177
      //  }  
 
2178
      //}      
 
2179
      
 
2180
      unsigned long ctls = controlPorts;
 
2181
      for(unsigned long k = 0; k < ctls; ++k)
 
2182
      {
 
2183
        // First, update the temporary value if needed...
 
2184
        
 
2185
        #ifdef OSC_SUPPORT
 
2186
        // Process OSC gui input control fifo events.
 
2187
        // It is probably more important that these are processed so that they take precedence over all other
 
2188
        //  events because OSC + DSSI/DSSI-VST are fussy about receiving feedback via these control ports, from GUI changes.
 
2189
        
 
2190
        OscControlFifo* cfifo = _oscif.oscFifo(k);
 
2191
        //if(!cfifo)
 
2192
        //  continue;
 
2193
          
 
2194
        // If there are 'events' in the fifo, get exactly one 'event' per control per process cycle...
 
2195
        //if(!cfifo->isEmpty()) 
 
2196
        if(cfifo && !cfifo->isEmpty()) 
 
2197
        {
 
2198
          OscControlValue v = cfifo->get();  
 
2199
          
 
2200
          #ifdef PLUGIN_DEBUGIN
 
2201
          fprintf(stderr, "PluginI::apply OscControlFifo event input control number:%ld value:%f\n", k, v.value);
 
2202
          #endif
 
2203
          
 
2204
          // Set the ladspa control port value.
 
2205
          controls[k].tmpVal = v.value;
 
2206
          
 
2207
          // Need to update the automation value, otherwise it overwrites later with the last automation value.
 
2208
          if(_track && _id != -1)
 
2209
          {
 
2210
            // Since we are now in the audio thread context, there's no need to send a message,
 
2211
            //  just modify directly.
 
2212
            //audio->msgSetPluginCtrlVal(this, genACnum(_id, k), controls[k].val);
 
2213
            // p3.3.43
 
2214
            //audio->msgSetPluginCtrlVal(_track, genACnum(_id, k), controls[k].val);
 
2215
            _track->setPluginCtrlVal(genACnum(_id, k), v.value);
 
2216
            
 
2217
            // Record automation.
 
2218
            // NO! Take care of this immediately in the OSC control handler, because we don't want 
 
2219
            //  the silly delay associated with processing the fifo one-at-a-time here.
 
2220
            
 
2221
            //AutomationType at = _track->automationType();
 
2222
            // TODO: Taken from our native gui control handlers. 
 
2223
            // This may need modification or may cause problems - 
 
2224
            //  we don't have the luxury of access to the dssi gui controls !
 
2225
            //if(at == AUTO_WRITE || (audio->isPlaying() && at == AUTO_TOUCH))
 
2226
            //  enableController(k, false);
 
2227
            //_track->recordAutomation(id, v.value);
 
2228
          }  
 
2229
        }
 
2230
        else
 
2231
        #endif // OSC_SUPPORT
 
2232
        {
 
2233
          // Process automation control value.
 
2234
          if(automation && _track && _track->automationType() != AUTO_OFF && _id != -1)
 
2235
          {
 
2236
            if(controls[k].enCtrl && controls[k].en2Ctrl )
 
2237
              controls[k].tmpVal = _track->pluginCtrlVal(genACnum(_id, k));
 
2238
          }      
 
2239
        }
 
2240
        
 
2241
        // Now update the actual value from the temporary value...
 
2242
        controls[k].val = controls[k].tmpVal;
 
2243
      }  
 
2244
      
 
2245
      //for (int i = 0; i < controlPorts; ++i)
 
2246
      //      controls[i].val = controls[i].tmpVal;
 
2247
      
1563
2248
      for (int i = 0; i < instances; ++i)
 
2249
      {
 
2250
            // p3.3.41
 
2251
            //fprintf(stderr, "PluginI::apply handle %d\n", i);
1564
2252
            _plugin->apply(handle[i], n);
1565
 
      }
 
2253
      }      
 
2254
      }
 
2255
 
 
2256
//---------------------------------------------------------
 
2257
//   oscConfigure
 
2258
//---------------------------------------------------------
 
2259
 
 
2260
#ifdef OSC_SUPPORT
 
2261
int Plugin::oscConfigure(LADSPA_Handle handle, const char* key, const char* value)
 
2262
      {
 
2263
      #ifdef PLUGIN_DEBUGIN 
 
2264
      printf("Plugin::oscConfigure effect plugin label:%s key:%s value:%s\n", plugin->Label, key, value);
 
2265
      #endif
 
2266
      
 
2267
      #ifdef DSSI_SUPPORT
 
2268
      if(!dssi_descr || !dssi_descr->configure)
 
2269
            return 0;
 
2270
 
 
2271
      if (!strncmp(key, DSSI_RESERVED_CONFIGURE_PREFIX,
 
2272
         strlen(DSSI_RESERVED_CONFIGURE_PREFIX))) {
 
2273
            fprintf(stderr, "Plugin::oscConfigure OSC: UI for plugin '%s' attempted to use reserved configure key \"%s\", ignoring\n",
 
2274
               plugin->Label, key);
 
2275
               
 
2276
            return 0;
 
2277
            }
 
2278
 
 
2279
      char* message = dssi_descr->configure(handle, key, value);
 
2280
      if (message) {
 
2281
            printf("Plugin::oscConfigure on configure '%s' '%s', plugin '%s' returned error '%s'\n",
 
2282
               //key, value, synti->name().toAscii().data(), message);
 
2283
               key, value, plugin->Label, message);
 
2284
            
 
2285
            free(message);
 
2286
            }
 
2287
 
 
2288
      // also call back on UIs for plugins other than the one
 
2289
      // that requested this:
 
2290
      // if (n != instance->number && instances[n].uiTarget) {
 
2291
      //      lo_send(instances[n].uiTarget,
 
2292
      //      instances[n].ui_osc_configure_path, "ss", key, value);
 
2293
      //      }
 
2294
 
 
2295
      // configure invalidates bank and program information, so
 
2296
      //  we should do this again now: 
 
2297
      //queryPrograms();
 
2298
      
 
2299
      #endif // DSSI_SUPPORT
 
2300
      
 
2301
      return 0;
 
2302
}
 
2303
      
 
2304
//---------------------------------------------------------
 
2305
//   oscConfigure
 
2306
//---------------------------------------------------------
 
2307
 
 
2308
int PluginI::oscConfigure(const char *key, const char *value)
 
2309
      {
 
2310
      if(!_plugin)
 
2311
        return 0;
 
2312
 
 
2313
      // This is pretty much the simplest legal implementation of
 
2314
      // configure in a DSSI host. 
 
2315
 
 
2316
      // The host has the option to remember the set of (key,value)
 
2317
      // pairs associated with a particular instance, so that if it
 
2318
      // wants to restore the "same" instance on another occasion it can
 
2319
      // just call configure() on it for each of those pairs and so
 
2320
      // restore state without any input from a GUI.  Any real-world GUI
 
2321
      // host will probably want to do that.  This host doesn't have any
 
2322
      // concept of restoring an instance from one run to the next, so
 
2323
      // we don't bother remembering these at all. 
 
2324
 
 
2325
      //const char *key = (const char *)&argv[0]->s;
 
2326
      //const char *value = (const char *)&argv[1]->s;
 
2327
 
 
2328
      #ifdef PLUGIN_DEBUGIN 
 
2329
      printf("PluginI::oscConfigure effect plugin name:%s label:%s key:%s value:%s\n", _name.latin1(), _label.latin1(), key, value);
 
2330
      #endif
 
2331
      
 
2332
      #ifdef DSSI_SUPPORT
 
2333
      // FIXME: Don't think this is right, should probably do as example shows below.
 
2334
      for(int i = 0; i < instances; ++i)
 
2335
        _plugin->oscConfigure(handle[i], key, value);
 
2336
      
 
2337
      // also call back on UIs for plugins other than the one
 
2338
      // that requested this:
 
2339
      // if (n != instance->number && instances[n].uiTarget) {
 
2340
      //      lo_send(instances[n].uiTarget,
 
2341
      //      instances[n].ui_osc_configure_path, "ss", key, value);
 
2342
      //      }
 
2343
 
 
2344
      // configure invalidates bank and program information, so
 
2345
      //  we should do this again now: 
 
2346
      //queryPrograms();
 
2347
      #endif // DSSI_SUPPORT
 
2348
      
 
2349
      return 0;
 
2350
}
 
2351
      
 
2352
//---------------------------------------------------------
 
2353
//   oscUpdate
 
2354
//---------------------------------------------------------
 
2355
 
 
2356
int PluginI::oscUpdate()
 
2357
{
 
2358
      #ifdef DSSI_SUPPORT
 
2359
      // Send project directory.
 
2360
      _oscif.oscSendConfigure(DSSI_PROJECT_DIRECTORY_KEY, museProject.latin1());  // song->projectPath()
 
2361
      #endif
 
2362
      
 
2363
      /*
 
2364
      // Send current string configuration parameters.
 
2365
      StringParamMap& map = synti->stringParameters();
 
2366
      int i = 0;
 
2367
      for(ciStringParamMap r = map.begin(); r != map.end(); ++r) 
 
2368
      {
 
2369
        _oscIF.oscSendConfigure(r->first.c_str(), r->second.c_str());
 
2370
        // Avoid overloading the GUI if there are lots and lots of params. 
 
2371
        if((i+1) % 50 == 0)
 
2372
          usleep(300000);
 
2373
        ++i;      
 
2374
      }  
 
2375
      
 
2376
      // Send current bank and program.
 
2377
      unsigned long bank, prog;
 
2378
      synti->currentProg(&prog, &bank, 0);
 
2379
      _oscIF.oscSendProgram(prog, bank);
 
2380
      
 
2381
      // Send current control values.
 
2382
      unsigned long ports = synth->_controlInPorts;
 
2383
      for(unsigned long i = 0; i < ports; ++i) 
 
2384
      {
 
2385
        unsigned long k = synth->pIdx(i);
 
2386
        _oscIF.oscSendControl(k, controls[i]);
 
2387
        // Avoid overloading the GUI if there are lots and lots of ports. 
 
2388
        if((i+1) % 50 == 0)
 
2389
          usleep(300000);
 
2390
      }
 
2391
      
 
2392
      */
 
2393
      
 
2394
      return 0;
 
2395
}
 
2396
 
 
2397
//---------------------------------------------------------
 
2398
//   oscControl
 
2399
//---------------------------------------------------------
 
2400
 
 
2401
int PluginI::oscControl(unsigned long port, float value)
 
2402
{
 
2403
  //int port = argv[0]->i;
 
2404
  //LADSPA_Data value = argv[1]->f;
 
2405
 
 
2406
  #ifdef PLUGIN_DEBUGIN  
 
2407
  printf("PluginI::oscControl received oscControl port:%ld val:%f\n", port, value);
 
2408
  #endif
 
2409
  
 
2410
  //int controlPorts = synth->_controller;
 
2411
  
 
2412
  //if(port >= controlPorts)
 
2413
  //if(port < 0 || port >= _plugin->rpIdx.size())
 
2414
  //{
 
2415
    //fprintf(stderr, "DssiSynthIF::oscControl: port number:%d is out of range of number of ports:%d\n", port, controlPorts);
 
2416
  //  fprintf(stderr, "PluginI::oscControl: port number:%d is out of range of index list size:%d\n", port, _plugin->rpIdx.size());
 
2417
  //  return 0;
 
2418
  //}
 
2419
  
 
2420
  // Convert from DSSI port number to control input port index.
 
2421
  //unsigned long cport = _plugin->rpIdx[port];
 
2422
  unsigned long cport = _plugin->port2InCtrl(port);
 
2423
    
 
2424
  if((int)cport == -1)
 
2425
  {
 
2426
    fprintf(stderr, "PluginI::oscControl: port number:%ld is not a control input\n", port);
 
2427
    return 0;
 
2428
  }
 
2429
  
 
2430
  // (From DSSI module).
 
2431
  // p3.3.39 Set the DSSI control input port's value.
 
2432
  // Observations: With a native DSSI synth like LessTrivialSynth, the native GUI's controls do not change the sound at all
 
2433
  //  ie. they don't update the DSSI control port values themselves. 
 
2434
  // Hence in response to the call to this oscControl, sent by the native GUI, it is required to that here.
 
2435
///  controls[cport].val = value;
 
2436
  // DSSI-VST synths however, unlike DSSI synths, DO change their OWN sound in response to their gui controls.
 
2437
  // AND this function is called ! 
 
2438
  // Despite the descrepency we are STILL required to update the DSSI control port values here 
 
2439
  //  because dssi-vst is WAITING FOR A RESPONSE! (A CHANGE in the control port value). 
 
2440
  // It will output something like "...4 events expected..." and count that number down as 4 actual control port value CHANGES
 
2441
  //  are done here in response. Normally it says "...0 events expected..." when MusE is the one doing the DSSI control changes.
 
2442
  // TODO: May need FIFOs on each control(!) so that the control changes get sent one per process cycle! 
 
2443
  // Observed countdown not actually going to zero upon string of changes.
 
2444
  // Try this ...
 
2445
  OscControlFifo* cfifo = _oscif.oscFifo(cport); 
 
2446
  if(cfifo)
 
2447
  {
 
2448
    OscControlValue cv;
 
2449
    //cv.idx = cport;
 
2450
    cv.value = value;
 
2451
    if(cfifo->put(cv))
 
2452
    {
 
2453
      fprintf(stderr, "PluginI::oscControl: fifo overflow: in control number:%ld\n", cport);
 
2454
    }
 
2455
  }
 
2456
   
 
2457
  // Record automation:
 
2458
  // Take care of this immediately, because we don't want the silly delay associated with 
 
2459
  //  processing the fifo one-at-a-time in the apply().
 
2460
  // NOTE: Ahh crap! We don't receive control events until the user RELEASES a control !
 
2461
  // So the events all arrive at once when the user releases a control.
 
2462
  // That makes this pretty useless... But what the heck...
 
2463
  if(_track && _id != -1)
 
2464
  {
 
2465
    int id = genACnum(_id, cport);
 
2466
    AutomationType at = _track->automationType();
 
2467
  
 
2468
    // TODO: Taken from our native gui control handlers. 
 
2469
    // This may need modification or may cause problems - 
 
2470
    //  we don't have the luxury of access to the dssi gui controls !
 
2471
    if(at == AUTO_WRITE || (audio->isPlaying() && at == AUTO_TOUCH))
 
2472
      enableController(cport, false);
 
2473
      
 
2474
    _track->recordAutomation(id, value);
 
2475
  } 
 
2476
   
 
2477
  /*
 
2478
  const DSSI_Descriptor* dssi = synth->dssi;
 
2479
  const LADSPA_Descriptor* ld = dssi->LADSPA_Plugin;
 
2480
  
 
2481
  ciMidiCtl2LadspaPort ip = synth->port2MidiCtlMap.find(cport);
 
2482
  if(ip != synth->port2MidiCtlMap.end())
 
2483
  {
 
2484
    // TODO: TODO: Update midi MusE's midi controller knobs, sliders, boxes etc with a call to the midi port's setHwCtrlState() etc.
 
2485
    // But first we need a ladspa2MidiValue() function!  ... 
 
2486
    //
 
2487
    //
 
2488
    //float val = ladspa2MidiValue(ld, i, ?, ?); 
 
2489
  
 
2490
  }
 
2491
  */
 
2492
 
 
2493
#if 0
 
2494
      int port = argv[0]->i;
 
2495
      LADSPA_Data value = argv[1]->f;
 
2496
 
 
2497
      if (port < 0 || port > instance->plugin->descriptor->LADSPA_Plugin->PortCount) {
 
2498
            fprintf(stderr, "MusE: OSC: %s port number (%d) is out of range\n",
 
2499
               instance->friendly_name, port);
 
2500
            return 0;
 
2501
            }
 
2502
      if (instance->pluginPortControlInNumbers[port] == -1) {
 
2503
            fprintf(stderr, "MusE: OSC: %s port %d is not a control in\n",
 
2504
               instance->friendly_name, port);
 
2505
            return 0;
 
2506
            }
 
2507
      pluginControlIns[instance->pluginPortControlInNumbers[port]] = value;
 
2508
      if (verbose) {
 
2509
            printf("MusE: OSC: %s port %d = %f\n",
 
2510
               instance->friendly_name, port, value);
 
2511
            }
 
2512
#endif
 
2513
      return 0;
 
2514
      }
 
2515
 
 
2516
#endif // OSC_SUPPORT
 
2517
 
1566
2518
 
1567
2519
//---------------------------------------------------------
1568
2520
//   PluginDialog
1692
2644
//---------------------------------------------------------
1693
2645
 
1694
2646
void PluginDialog::fillPlugs(int nbr)
1695
 
      {
1696
 
      pList->clear();
1697
 
      for (iPlugin i = plugins.begin(); i != plugins.end(); ++i) {
1698
 
        int ai = 0;
1699
 
        int ao = 0;
1700
 
        int ci = 0;
1701
 
        int co = 0;
1702
 
        for (int k = 0; k < i->ports(); ++k) {
1703
 
          LADSPA_PortDescriptor pd = i->portd(k);
1704
 
          if (pd &  LADSPA_PORT_CONTROL) {
1705
 
              if (pd &  LADSPA_PORT_INPUT)
1706
 
                  ++ci;
1707
 
              else
1708
 
                  ++co;
1709
 
                  }
1710
 
          else {
1711
 
              if (pd &  LADSPA_PORT_INPUT)
1712
 
                  ++ai;
1713
 
              else
1714
 
                  ++ao;
1715
 
                  }
1716
 
              }
 
2647
{
 
2648
  pList->clear();
 
2649
  for(iPlugin i = plugins.begin(); i != plugins.end(); ++i) 
 
2650
  {
 
2651
    /*
 
2652
    int ai = 0;
 
2653
    int ao = 0;
 
2654
    int ci = 0;
 
2655
    int co = 0;
 
2656
    for(unsigned long k = 0; k < i->ports(); ++k) 
 
2657
    {
 
2658
      LADSPA_PortDescriptor pd = i->portd(k);
 
2659
      if(pd & LADSPA_PORT_CONTROL) 
 
2660
      {
 
2661
        if(pd & LADSPA_PORT_INPUT)
 
2662
          ++ci;
 
2663
        else
 
2664
        if(pd & LADSPA_PORT_OUTPUT)
 
2665
          ++co;
 
2666
      }
 
2667
      else 
 
2668
      if(pd & LADSPA_PORT_AUDIO) 
 
2669
      {
 
2670
        if(pd & LADSPA_PORT_INPUT)
 
2671
          ++ai;
 
2672
        else
 
2673
        if(pd & LADSPA_PORT_OUTPUT)
 
2674
          ++ao;
 
2675
      }
 
2676
    }
 
2677
    */
 
2678
    int ai = i->inports();
 
2679
    int ao = i->outports();
 
2680
    int ci = i->controlInPorts();
 
2681
    int co = i->controlOutPorts();
1717
2682
    
1718
 
          bool addFlag = false;
1719
 
          switch(nbr)
1720
 
              {
1721
 
              case 0: // stereo & mono
1722
 
                if ((ai == 1 || ai == 2) && (ao == 1 || ao ==2))
1723
 
                  {
1724
 
                  addFlag = true;
1725
 
                  }
1726
 
                break;
1727
 
              case 1: // stereo
1728
 
                if ((ai == 1 || ai == 2) &&  ao ==2)
1729
 
                  {
1730
 
                  addFlag = true;
1731
 
                  }
1732
 
                break;
1733
 
              case 2: // mono
1734
 
                if (ai == 1  && ao == 1)
1735
 
                  {
1736
 
                  addFlag = true;
1737
 
                  }
1738
 
                break;
1739
 
              case 3: // all
1740
 
                  addFlag = true;
1741
 
                break;
1742
 
              }
1743
 
          if (addFlag)
1744
 
              {
1745
 
              QListViewItem* item = new QListViewItem(pList,
1746
 
              i->lib(),
1747
 
              i->label(),
1748
 
              i->name(),
1749
 
              QString().setNum(ai),
1750
 
              QString().setNum(ao),
1751
 
              QString().setNum(ci),
1752
 
              QString().setNum(co),
1753
 
              QString().setNum(i->inPlaceCapable())
1754
 
              );
1755
 
              item->setText(8, QString().setNum(i->id()));
1756
 
              item->setText(9, i->maker());
1757
 
              item->setText(10, i->copyright());
1758
 
            }
1759
 
          }
1760
 
        selectedPlugType = nbr;
1761
 
        }
 
2683
    bool addFlag = false;
 
2684
    switch(nbr)
 
2685
    {
 
2686
        case 0: // stereo & mono
 
2687
          if ((ai == 1 || ai == 2) && (ao == 1 || ao ==2))
 
2688
            {
 
2689
            addFlag = true;
 
2690
            }
 
2691
          break;
 
2692
        case 1: // stereo
 
2693
          if ((ai == 1 || ai == 2) &&  ao ==2)
 
2694
            {
 
2695
            addFlag = true;
 
2696
            }
 
2697
          break;
 
2698
        case 2: // mono
 
2699
          if (ai == 1  && ao == 1)
 
2700
            {
 
2701
            addFlag = true;
 
2702
            }
 
2703
          break;
 
2704
        case 3: // all
 
2705
            addFlag = true;
 
2706
          break;
 
2707
    }
 
2708
    if(addFlag)
 
2709
    {
 
2710
      QListViewItem* item = new QListViewItem(pList,
 
2711
        i->lib(),
 
2712
        i->label(),
 
2713
        i->name(),
 
2714
        QString().setNum(ai),
 
2715
        QString().setNum(ao),
 
2716
        QString().setNum(ci),
 
2717
        QString().setNum(co),
 
2718
        QString().setNum(i->inPlaceCapable())
 
2719
      );
 
2720
      item->setText(8, QString().setNum(i->id()));
 
2721
      item->setText(9, i->maker());
 
2722
      item->setText(10, i->copyright());
 
2723
    }
 
2724
  }
 
2725
  selectedPlugType = nbr;
 
2726
}
1762
2727
 
1763
2728
void PluginDialog::fillPlugs(const QString &sortValue)
1764
 
      {
1765
 
      pList->clear();
1766
 
      for (iPlugin i = plugins.begin(); i != plugins.end(); ++i) {
1767
 
        int ai = 0;
1768
 
        int ao = 0;
1769
 
        int ci = 0;
1770
 
        int co = 0;
1771
 
        for (int k = 0; k < i->ports(); ++k) {
1772
 
          LADSPA_PortDescriptor pd = i->portd(k);
1773
 
          if (pd &  LADSPA_PORT_CONTROL) {
1774
 
              if (pd &  LADSPA_PORT_INPUT)
1775
 
                  ++ci;
1776
 
              else
1777
 
                  ++co;
1778
 
                  }
1779
 
          else {
1780
 
              if (pd &  LADSPA_PORT_INPUT)
1781
 
                  ++ai;
1782
 
              else
1783
 
                  ++ao;
1784
 
                  }
1785
 
              }
1786
 
    
1787
 
          bool addFlag = false;
1788
 
          
1789
 
          if (i->label().lower().contains(sortValue.lower()))
1790
 
                addFlag = true;
1791
 
          else if (i->name().lower().contains(sortValue.lower()))
1792
 
                addFlag = true;
1793
 
          if (addFlag)
1794
 
              {
1795
 
              QListViewItem* item = new QListViewItem(pList,
1796
 
              i->lib(),
1797
 
              i->label(),
1798
 
              i->name(),
1799
 
              QString().setNum(ai),
1800
 
              QString().setNum(ao),
1801
 
              QString().setNum(ci),
1802
 
              QString().setNum(co),
1803
 
              QString().setNum(i->inPlaceCapable())
1804
 
              );
1805
 
              item->setText(8, QString().setNum(i->id()));
1806
 
              item->setText(9, i->maker());
1807
 
              item->setText(10, i->copyright());
1808
 
              }
1809
 
          }
1810
 
      }
 
2729
{
 
2730
  pList->clear();
 
2731
  for(iPlugin i = plugins.begin(); i != plugins.end(); ++i) 
 
2732
  {
 
2733
    /*
 
2734
    int ai = 0;
 
2735
    int ao = 0;
 
2736
    int ci = 0;
 
2737
    int co = 0;
 
2738
    for(unsigned long k = 0; k < i->ports(); ++k) 
 
2739
    {
 
2740
      LADSPA_PortDescriptor pd = i->portd(k);
 
2741
      if(pd & LADSPA_PORT_CONTROL) 
 
2742
      {
 
2743
        if(pd & LADSPA_PORT_INPUT)
 
2744
          ++ci;
 
2745
        else
 
2746
        if(pd & LADSPA_PORT_OUTPUT)
 
2747
          ++co;
 
2748
      }
 
2749
      else 
 
2750
      if(pd & LADSPA_PORT_AUDIO) 
 
2751
      {
 
2752
        if(pd & LADSPA_PORT_INPUT)
 
2753
          ++ai;
 
2754
        else
 
2755
        if(pd & LADSPA_PORT_OUTPUT)
 
2756
          ++ao;
 
2757
      }
 
2758
    }
 
2759
    */
 
2760
    int ai = i->inports();
 
2761
    int ao = i->outports();
 
2762
    int ci = i->controlInPorts();
 
2763
    int co = i->controlOutPorts();
 
2764
    
 
2765
    bool addFlag = false;
 
2766
    
 
2767
    if(i->label().lower().contains(sortValue.lower()))
 
2768
      addFlag = true;
 
2769
    else
 
2770
    if(i->name().lower().contains(sortValue.lower()))
 
2771
      addFlag = true;
 
2772
    if(addFlag)
 
2773
    {
 
2774
      QListViewItem* item = new QListViewItem(pList,
 
2775
        i->lib(),
 
2776
        i->label(),
 
2777
        i->name(),
 
2778
        QString().setNum(ai),
 
2779
        QString().setNum(ao),
 
2780
        QString().setNum(ci),
 
2781
        QString().setNum(co),
 
2782
        QString().setNum(i->inPlaceCapable())
 
2783
      );
 
2784
      item->setText(8, QString().setNum(i->id()));
 
2785
      item->setText(9, i->maker());
 
2786
      item->setText(10, i->copyright());
 
2787
    }
 
2788
  }
 
2789
}
1811
2790
 
1812
2791
//---------------------------------------------------------
1813
2792
//   getPlugin
1821
2800
      return 0;
1822
2801
      }
1823
2802
 
1824
 
//---------------------------------------------------------
1825
 
//   deactivate
1826
 
//---------------------------------------------------------
1827
 
 
1828
 
void PluginI::deactivate()
1829
 
      {
1830
 
      for (int i = 0; i < instances; ++i) {
1831
 
            _plugin->deactivate(handle[i]);
1832
 
            _plugin->cleanup(handle[i]);
1833
 
            }
1834
 
      }
1835
 
 
1836
 
//---------------------------------------------------------
1837
 
//   activate
1838
 
//---------------------------------------------------------
1839
 
 
1840
 
void PluginI::activate()
1841
 
      {
1842
 
      for (int i = 0; i < instances; ++i)
1843
 
            _plugin->activate(handle[i]);
1844
 
      if (initControlValues) {
1845
 
            for (int i = 0; i < controlPorts; ++i) {
1846
 
                  controls[i].val = controls[i].tmpVal;
1847
 
                  }
1848
 
            }
1849
 
      else {
1850
 
            //
1851
 
            // get initial control values from plugin
1852
 
            //
1853
 
            for (int i = 0; i < controlPorts; ++i) {
1854
 
                  controls[i].tmpVal = controls[i].val;
1855
 
                  }
1856
 
            }
1857
 
      }
1858
 
 
1859
2803
const char* presetOpenText = "<img source=\"fileopen\"> "
1860
2804
      "Click this button to load a saved <em>preset</em>.";
1861
2805
const char* presetSaveText = "Click this button to save curent parameter "
1866
2810
//   PluginGui
1867
2811
//---------------------------------------------------------
1868
2812
 
1869
 
PluginGui::PluginGui(PluginI* p)
 
2813
//PluginGui::PluginGui(PluginI* p)
 
2814
// p3.3.43
 
2815
PluginGui::PluginGui(PluginIBase* p)
1870
2816
   : QMainWindow(0)
1871
2817
      {
1872
2818
      gw     = 0;
1903
2849
      QWhatsThis::add(fileSave, tr(presetSaveText));
1904
2850
 
1905
2851
      QString id;
1906
 
      id.setNum(plugin->plugin()->id());
 
2852
      //id.setNum(plugin->plugin()->id());
 
2853
      id.setNum(plugin->pluginID());
1907
2854
      QString name(museGlobalShare + QString("/plugins/") + id + QString(".ui"));
1908
2855
      QFile uifile(name);
1909
2856
      if (uifile.exists()) {
2004
2951
              updateValues(); // otherwise the GUI won't have valid data
2005
2952
            }
2006
2953
      else {
2007
 
            mw = new QWidget(this);
2008
 
            setCentralWidget(mw);
 
2954
            //mw = new QWidget(this);
 
2955
            //setCentralWidget(mw);
 
2956
            // p3.4.43
 
2957
            view = new QScrollView(this);
 
2958
            setCentralWidget(view);
 
2959
            mw = new QWidget(view);
 
2960
            view->setResizePolicy(QScrollView::AutoOneFit);
 
2961
            //view->setVScrollBarMode(QScrollView::AlwaysOff);
 
2962
            view->addChild(mw);
 
2963
            
2009
2964
            QGridLayout* grid = new QGridLayout(mw);
2010
2965
            grid->setSpacing(2);
2011
2966
 
2012
2967
            int n  = plugin->parameters();
2013
2968
            params = new GuiParam[n];
2014
2969
 
2015
 
            resize(280, n*20+30);
 
2970
            // Changed p3.3.43
 
2971
            //resize(280, n*20+30);
 
2972
            //int nh = n*20+40;
 
2973
            //if(nh > 760)
 
2974
            //  nh = 760;
 
2975
            //resize(280, nh);
2016
2976
 
2017
2977
            //int style       = Slider::BgTrough | Slider::BgSlot;
2018
2978
            QFontMetrics fm = fontMetrics();
2051
3011
                  if (LADSPA_IS_HINT_TOGGLED(range.HintDescriptor)) {
2052
3012
                        params[i].type = GuiParam::GUI_SWITCH;
2053
3013
                        CheckBox* cb = new CheckBox(mw, i, "param");
 
3014
                        cb->setId(i);
2054
3015
                        cb->setText(QString(plugin->paramName(i)));
2055
3016
                        cb->setChecked(plugin->param(i) != 0.0);
2056
3017
                        cb->setFixedHeight(h);
2108
3069
                        connect(params[i].actuator, SIGNAL(checkboxRightClicked(const QPoint &, int)), SLOT(ctrlRightClicked(const QPoint &, int)));
2109
3070
                        }
2110
3071
                  }
 
3072
            // p3.3.43
 
3073
            resize(280, height());
 
3074
            
2111
3075
            grid->setColStretch(2, 10);
2112
3076
            }
2113
3077
      connect(heartBeatTimer, SIGNAL(timeout()), SLOT(heartBeat()));
2141
3105
void PluginGui::ctrlPressed(int param)
2142
3106
{
2143
3107
      AutomationType at = AUTO_OFF;
2144
 
      AudioTrack* track = 0;
2145
 
      if(plugin->track())
2146
 
      {
2147
 
        track = plugin->track();
 
3108
      AudioTrack* track = plugin->track();
 
3109
      if(track)
2148
3110
        at = track->automationType();
2149
 
      }  
2150
3111
            
2151
3112
      if(at != AUTO_OFF)
2152
3113
        plugin->enableController(param, false);
2167
3128
              val = rint(val);
2168
3129
        plugin->setParam(param, val);
2169
3130
        ((DoubleLabel*)params[param].label)->setValue(val);
2170
 
        audio->msgSetPluginCtrlVal(((PluginI*)plugin), id, val);
 
3131
        
 
3132
        // p3.3.43
 
3133
        //audio->msgSetPluginCtrlVal(((PluginI*)plugin), id, val);
 
3134
        
2171
3135
        if(track)
 
3136
        {
 
3137
          // p3.3.43
 
3138
          audio->msgSetPluginCtrlVal(track, id, val);
 
3139
          
2172
3140
          track->startAutoRecord(id, val);
 
3141
        }  
2173
3142
      }       
2174
3143
      else if(params[param].type == GuiParam::GUI_SWITCH)
2175
3144
      {
2176
3145
        double val = (double)((CheckBox*)params[param].actuator)->isChecked();
2177
3146
        plugin->setParam(param, val);
2178
 
        audio->msgSetPluginCtrlVal(((PluginI*)plugin), id, val);
 
3147
        
 
3148
        // p3.3.43
 
3149
        //audio->msgSetPluginCtrlVal(((PluginI*)plugin), id, val);
 
3150
        
2179
3151
        if(track)
 
3152
        {
 
3153
          // p3.3.43
 
3154
          audio->msgSetPluginCtrlVal(track, id, val);
 
3155
          
2180
3156
          track->startAutoRecord(id, val);
 
3157
        }  
2181
3158
      }       
2182
3159
}
2183
3160
 
2188
3165
void PluginGui::ctrlReleased(int param)
2189
3166
{
2190
3167
      AutomationType at = AUTO_OFF;
2191
 
      AudioTrack* track = 0;
2192
 
      if(plugin->track())
2193
 
      {
2194
 
        track = plugin->track();
 
3168
      AudioTrack* track = plugin->track();
 
3169
      if(track)
2195
3170
        at = track->automationType();
2196
 
      }  
2197
3171
        
2198
3172
      // Special for switch - don't enable controller until transport stopped.
2199
3173
      if(at != AUTO_WRITE && ((params[param].type != GuiParam::GUI_SWITCH
2231
3205
{
2232
3206
  int id = plugin->id();
2233
3207
  if(id != -1)
2234
 
    song->execAutomationCtlPopup((AudioTrack*)plugin->track(), p, genACnum(id, param));
 
3208
    //song->execAutomationCtlPopup((AudioTrack*)plugin->track(), p, genACnum(id, param));
 
3209
    song->execAutomationCtlPopup(plugin->track(), p, genACnum(id, param));
2235
3210
}
2236
3211
 
2237
3212
//---------------------------------------------------------
2239
3214
//---------------------------------------------------------
2240
3215
 
2241
3216
void PluginGui::sliderChanged(double val, int param)
2242
 
      {
 
3217
{
2243
3218
      AutomationType at = AUTO_OFF;
2244
 
      AudioTrack* track = 0;
2245
 
      if(plugin->track())
2246
 
      {
2247
 
        track = plugin->track();
 
3219
      AudioTrack* track = plugin->track();
 
3220
      if(track)
2248
3221
        at = track->automationType();
2249
 
      }  
2250
3222
      
2251
3223
      if(at == AUTO_WRITE || (audio->isPlaying() && at == AUTO_TOUCH))
2252
3224
        plugin->enableController(param, false);
2265
3237
        return;
2266
3238
      id = genACnum(id, param);
2267
3239
          
2268
 
      audio->msgSetPluginCtrlVal(((PluginI*)plugin), id, val);
 
3240
      // p3.3.43
 
3241
      //audio->msgSetPluginCtrlVal(((PluginI*)plugin), id, val);
2269
3242
          
2270
3243
      if(track)
 
3244
      {
 
3245
        // p3.3.43
 
3246
        audio->msgSetPluginCtrlVal(track, id, val);
 
3247
        
2271
3248
        track->recordAutomation(id, val);
2272
 
      }
 
3249
      }  
 
3250
}
2273
3251
 
2274
3252
//---------------------------------------------------------
2275
3253
//   labelChanged
2276
3254
//---------------------------------------------------------
2277
3255
 
2278
3256
void PluginGui::labelChanged(double val, int param)
2279
 
      {
 
3257
{
2280
3258
      AutomationType at = AUTO_OFF;
2281
 
      AudioTrack* track = 0;
2282
 
      if(plugin->track())
2283
 
      {
2284
 
        track = plugin->track();
 
3259
      AudioTrack* track = plugin->track();
 
3260
      if(track)
2285
3261
        at = track->automationType();
2286
 
      }  
2287
3262
      
2288
3263
      if(at == AUTO_WRITE || (audio->isPlaying() && at == AUTO_TOUCH))
2289
3264
        plugin->enableController(param, false);
2303
3278
        return;
2304
3279
      
2305
3280
      id = genACnum(id, param);
2306
 
      audio->msgSetPluginCtrlVal(((PluginI*)plugin), id, val);
 
3281
      
 
3282
      // p3.3.43
 
3283
      //audio->msgSetPluginCtrlVal(((PluginI*)plugin), id, val);
 
3284
      
2307
3285
      if(track)
 
3286
      {
 
3287
        // p3.3.43
 
3288
        audio->msgSetPluginCtrlVal(track, id, val);
 
3289
        
2308
3290
        track->startAutoRecord(id, val);
2309
 
      }
 
3291
      }  
 
3292
}
2310
3293
 
2311
3294
//---------------------------------------------------------
2312
3295
//   load
2315
3298
void PluginGui::load()
2316
3299
      {
2317
3300
      QString s("presets/plugins/");
2318
 
      s += plugin->plugin()->label();
 
3301
      //s += plugin->plugin()->label();
 
3302
      s += plugin->pluginLabel();
2319
3303
      s += "/";
2320
3304
 
2321
3305
      QString fn = getOpenFileName(s, preset_file_pattern,
2379
3363
void PluginGui::save()
2380
3364
      {
2381
3365
      QString s("presets/plugins/");
2382
 
      s += plugin->plugin()->label();
 
3366
      //s += plugin->plugin()->label();
 
3367
      s += plugin->pluginLabel();
2383
3368
      s += "/";
2384
3369
 
2385
 
      QString fn = getSaveFileName(s, preset_file_pattern, this,
 
3370
      //QString fn = getSaveFileName(s, preset_file_pattern, this,
 
3371
      QString fn = getSaveFileName(s, preset_file_save_pattern, this,
2386
3372
        tr("MusE: save preset"));
2387
3373
      if (fn.isEmpty())
2388
3374
            return;
2503
3489
                            }      
2504
3490
                            if(((Slider*)(gp->actuator))->value() != sv)
2505
3491
                            {
2506
 
                              // Added by Tim. p3.3.6
2507
3492
                              //printf("PluginGui::updateControls slider\n");
2508
3493
                              
2509
3494
                              gp->label->blockSignals(true);
2522
3507
                            bool v = (int)plugin->track()->pluginCtrlVal(genACnum(plugin->id(), i));
2523
3508
                            if(((CheckBox*)(gp->actuator))->isChecked() != v)
2524
3509
                            {
2525
 
                              // Added by Tim. p3.3.6
2526
3510
                              //printf("PluginGui::updateControls switch\n");
2527
3511
                              
2528
3512
                              ((CheckBox*)(gp->actuator))->blockSignals(true);
2545
3529
                                double v = plugin->track()->pluginCtrlVal(genACnum(plugin->id(), param));
2546
3530
                                if(((Slider*)widget)->value() != v)
2547
3531
                                {
2548
 
                                  // Added by Tim. p3.3.6
2549
3532
                                  //printf("PluginGui::updateControls slider\n");
2550
3533
                              
2551
3534
                                  ((Slider*)widget)->blockSignals(true);
2560
3543
                                double v = plugin->track()->pluginCtrlVal(genACnum(plugin->id(), param));
2561
3544
                                if(((DoubleLabel*)widget)->value() != v)
2562
3545
                                {
2563
 
                                  // Added by Tim. p3.3.6
2564
3546
                                  //printf("PluginGui::updateControls label\n");
2565
3547
                              
2566
3548
                                  ((DoubleLabel*)widget)->blockSignals(true);
2575
3557
                                bool b = (bool) plugin->track()->pluginCtrlVal(genACnum(plugin->id(), param));
2576
3558
                                if(((QCheckBox*)widget)->isChecked() != b)
2577
3559
                                {
2578
 
                                  // Added by Tim. p3.3.6
2579
3560
                                  //printf("PluginGui::updateControls checkbox\n");
2580
3561
                              
2581
3562
                                  ((QCheckBox*)widget)->blockSignals(true);
2590
3571
                                int n = (int) plugin->track()->pluginCtrlVal(genACnum(plugin->id(), param));
2591
3572
                                if(((QComboBox*)widget)->currentItem() != n)
2592
3573
                                {
2593
 
                                  // Added by Tim. p3.3.6
2594
3574
                                  //printf("PluginGui::updateControls combobox\n");
2595
3575
                              
2596
3576
                                  ((QComboBox*)widget)->blockSignals(true);
2609
3589
//---------------------------------------------------------
2610
3590
 
2611
3591
void PluginGui::guiParamChanged(int idx)
2612
 
      {
 
3592
{
2613
3593
      QWidget* w = gw[idx].widget;
2614
3594
      int param  = gw[idx].param;
2615
3595
      int type   = gw[idx].type;
2616
3596
 
2617
3597
      AutomationType at = AUTO_OFF;
2618
 
      AudioTrack* track = 0;
2619
 
      if(plugin->track())
2620
 
      {
2621
 
        track = plugin->track();
 
3598
      AudioTrack* track = plugin->track();
 
3599
      if(track)
2622
3600
        at = track->automationType();
2623
 
      }  
2624
3601
      
2625
3602
      if(at == AUTO_WRITE || (audio->isPlaying() && at == AUTO_TOUCH))
2626
3603
        plugin->enableController(param, false);
2663
3640
            }
2664
3641
      
2665
3642
      int id = plugin->id();
2666
 
      if(id != -1)
2667
 
        {
 
3643
      if(track && id != -1)
 
3644
      {
2668
3645
          id = genACnum(id, param);
2669
 
          audio->msgSetPluginCtrlVal(((PluginI*)plugin), id, val);
2670
 
          if(track)
2671
 
          {
 
3646
          
 
3647
          // p3.3.43
 
3648
          //audio->msgSetPluginCtrlVal(((PluginI*)plugin), id, val);
 
3649
          
 
3650
          //if(track)
 
3651
          //{
 
3652
            // p3.3.43
 
3653
            audio->msgSetPluginCtrlVal(track, id, val);
 
3654
            
2672
3655
            switch(type) 
2673
3656
            {
2674
3657
               case GuiWidgets::DOUBLE_LABEL:
2679
3662
                 track->recordAutomation(id, val);
2680
3663
               break;  
2681
3664
            }  
2682
 
          }  
2683
 
        } 
 
3665
          //}  
 
3666
      } 
2684
3667
      plugin->setParam(param, val);
2685
 
      }
 
3668
}
2686
3669
 
2687
3670
//---------------------------------------------------------
2688
3671
//   guiParamPressed
2693
3676
      int param  = gw[idx].param;
2694
3677
 
2695
3678
      AutomationType at = AUTO_OFF;
2696
 
      AudioTrack* track = 0;
2697
 
      if(plugin->track())
2698
 
      {
2699
 
        track = plugin->track();
 
3679
      AudioTrack* track = plugin->track();
 
3680
      if(track)
2700
3681
        at = track->automationType();
2701
 
      }  
2702
3682
      
2703
3683
      if(at != AUTO_OFF)
2704
3684
        plugin->enableController(param, false);
2737
3717
      int type   = gw[idx].type;
2738
3718
      
2739
3719
      AutomationType at = AUTO_OFF;
2740
 
      AudioTrack* track = 0;
2741
 
      if(plugin->track())
2742
 
      {
2743
 
        track = plugin->track();
 
3720
      AudioTrack* track = plugin->track();
 
3721
      if(track)
2744
3722
        at = track->automationType();
2745
 
      }  
2746
3723
      
2747
3724
      // Special for switch - don't enable controller until transport stopped.
2748
3725
      if(at != AUTO_WRITE && (type != GuiWidgets::QCHECKBOX
2785
3762
      QWidget *w = gw[idx].widget;
2786
3763
      
2787
3764
      AutomationType at = AUTO_OFF;
2788
 
      AudioTrack* track = 0;
2789
 
      if(plugin->track())
2790
 
      {
2791
 
        track = plugin->track();
 
3765
      AudioTrack* track = plugin->track();
 
3766
      if(track)
2792
3767
        at = track->automationType();
2793
 
      }  
2794
3768
      
2795
3769
      int id = plugin->id();
2796
3770
      
2804
3778
      
2805
3779
      double val = ((Slider*)w)->value();
2806
3780
      plugin->setParam(param, val);
2807
 
      audio->msgSetPluginCtrlVal(((PluginI*)plugin), id, val);
 
3781
      
 
3782
      //audio->msgSetPluginCtrlVal(((PluginI*)plugin), id, val);
 
3783
      // p3.3.43
 
3784
      audio->msgSetPluginCtrlVal(track, id, val);
 
3785
      
2808
3786
      track->startAutoRecord(id, val);
2809
3787
      
2810
3788
      // Needed so that paging a slider updates a label or other buddy control.
2840
3818
      QWidget *w = gw[idx].widget;
2841
3819
      
2842
3820
      AutomationType at = AUTO_OFF;
2843
 
      AudioTrack* track = 0;
2844
 
      if(plugin->track())
2845
 
      {
2846
 
        track = plugin->track();
 
3821
      AudioTrack* track = plugin->track();
 
3822
      if(track)
2847
3823
        at = track->automationType();
2848
 
      }  
2849
3824
      
2850
3825
      if(at != AUTO_WRITE || (!audio->isPlaying() && at == AUTO_TOUCH))
2851
3826
        plugin->enableController(param, true);
2870
3845
  int param  = gw[idx].param;
2871
3846
  int id = plugin->id();
2872
3847
  if(id != -1)
2873
 
    song->execAutomationCtlPopup((AudioTrack*)plugin->track(), p, genACnum(id, param));
 
3848
    //song->execAutomationCtlPopup((AudioTrack*)plugin->track(), p, genACnum(id, param));
 
3849
    song->execAutomationCtlPopup(plugin->track(), p, genACnum(id, param));
2874
3850
}
 
3851
 
 
3852
//---------------------------------------------------------
 
3853
//   PluginWidgetFactory
 
3854
//---------------------------------------------------------
 
3855
 
 
3856
QWidget* PluginWidgetFactory::createWidget(const QString& className, QWidget* parent, const char* name) const
 
3857
{
 
3858
  if(className == "DoubleLabel")
 
3859
    return new DoubleLabel(parent, name); 
 
3860
  if(className == "Slider")
 
3861
    return new Slider(parent, name); 
 
3862
  return 0;  
 
3863
};
 
3864