File: ladspadialog.cpp

package info (click to toggle)
ams 1.8.7-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,880 kB
  • ctags: 2,171
  • sloc: cpp: 17,793; makefile: 433; sh: 101
file content (207 lines) | stat: -rw-r--r-- 6,852 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <glob.h>
#include <dlfcn.h>
#include <qregexp.h>
#include <qwidget.h>
#include <qstring.h>
#include <qslider.h>
#include <qcheckbox.h>
#include <qlistbox.h>
#include <qlabel.h>
#include <qvbox.h>
#include <qhbox.h>
#include <qframe.h>
#include <qspinbox.h>
#include <qradiobutton.h>
#include <qpushbutton.h>
#include <qlineedit.h>
#include <qlistview.h>
#include <ladspa.h>
#include "ladspadialog.h"
#include "synthdata.h"

LadspaDialog::LadspaDialog(SynthData *p_synthdata, QWidget* parent, const char *name)
                : QVBox(parent, name) {

  char *error;
  QString ladspadir, ladspapath, qs;
  void *so_handle;
  LADSPA_Descriptor_Function ladspa_dsc_func;
  const LADSPA_Descriptor *ladspa_dsc;
  int l1, l2, colon, lastcolon;
  glob_t globbuf;
  QListViewItem *ladspaSetItem;

  setCaption("Ladspa Browser");
  setMargin(10);
  setSpacing(10);
  synthdata = p_synthdata;
  ladspaList = new QListView(this);
  ladspaList->setRootIsDecorated(true);
  ladspaList->addColumn("Available Ladspa Plugins");

  ladspapath.sprintf("%s", getenv("LADSPA_PATH"));
  if (ladspapath.length() < 1) {
    fprintf(stderr, "\nYou did not set the environment variable LADSPA_PATH.\n");
    fprintf(stderr, "Assuming LADSPA_PATH=" LADSPA_PATH "\n");
    ladspapath = LADSPA_PATH;
  } else {
    fprintf(stderr, "LADSPA_PATH: %s\n", ladspapath.latin1());
  }
  colon = -1;
  l2 = 0;
  do {
    lastcolon = colon;
    colon = ladspapath.find(QRegExp(":"), lastcolon + 1);
    if (colon >= 0) {
      ladspadir = ladspapath.mid(lastcolon + 1, colon - lastcolon - 1);
    } else {
      ladspadir = (lastcolon) ? ladspapath.mid(lastcolon + 1, ladspapath.length() - lastcolon - 1)
                              : ladspapath;
    }
//    fprintf(stderr, "Searching for LADSPA plugins in %s\n", ladspadir.latin1());
    ladspadir += "/*.so";
    glob(ladspadir.latin1(), GLOB_MARK, NULL, &globbuf);
    for (l1 = 0; l1 < globbuf.gl_pathc; l1++) {
//      fprintf(stderr, "    found %s\n", globbuf.gl_pathv[l1]);
      if (!(so_handle = dlopen(globbuf.gl_pathv[l1], RTLD_LAZY))) {
        fprintf(stderr, "Error opening shared ladspa object %s.\n", globbuf.gl_pathv[l1]);
        continue;
      }
      ladspa_dsc_func =(LADSPA_Descriptor_Function)dlsym(so_handle, "ladspa_descriptor");
      if ((error = dlerror()) != NULL) {
        fprintf(stderr, "Error accessing ladspa descriptor in %s.\n", globbuf.gl_pathv[l1]);
        continue;
      }
      synthdata->ladspa_dsc_func_list[l2] = ladspa_dsc_func;
      qs.sprintf("%s", globbuf.gl_pathv[l1]);
      synthdata->ladspa_lib_name[l2] = qs.mid(qs.findRev("/") + 1, qs.findRev(".") - qs.findRev("/") - 1);
      l2++;
    }
    globfree(&globbuf);
  } while (colon >= 0);
  l1 = 0;
  while(synthdata->ladspa_dsc_func_list[l1]!=NULL) {
    l2 = 0;
    QListViewItem *ladspaSetItem = new QListViewItem(ladspaList, QString(synthdata->ladspa_lib_name[l1]));
    ladspaSetItem->setSelectable(false);
    while((ladspa_dsc = synthdata->ladspa_dsc_func_list[l1](l2)) != NULL) {
      new QListViewItem(ladspaSetItem, QString(ladspa_dsc->Name));
      l2++;
    }
    l1++;
  }

  QHBox *searchBox = new QHBox(this);
  searchBox->setSpacing(10);
  searchLine = new QLineEdit(searchBox);
  QPushButton *searchButton = new QPushButton("Search", searchBox);
  QObject::connect(searchButton, SIGNAL(clicked()), this, SLOT(searchClicked()));
  QObject::connect(searchLine, SIGNAL(returnPressed()), this, SLOT(searchClicked()));

  QVBox *labelBox = new QVBox(this);
  labelBox->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
  labelBox->setSpacing(5);
  pluginLabel = new QLabel(labelBox);
  pluginLabel->setAlignment(Qt::WordBreak | Qt::AlignLeft);
  pluginMaker = new QLabel(labelBox);
  pluginMaker->setAlignment(Qt::WordBreak | Qt::AlignLeft);
  pluginCopyright = new QLabel(labelBox);
  pluginCopyright->setAlignment(Qt::WordBreak | Qt::AlignLeft);
  QObject::connect(ladspaList, SIGNAL(selectionChanged()), this, SLOT(pluginHighlighted()));

  extCtrlPortsCheck = new QCheckBox("Export control ports as module ports", this);
  QHBox *buttonBox = new QHBox(this);
  QPushButton *insertButton = new QPushButton("Create Plugin", buttonBox);
  QObject::connect(insertButton, SIGNAL(clicked()), this, SLOT(insertClicked()));
  new QWidget(buttonBox);
  QPushButton *insertPolyButton = new QPushButton("Create Poly Plugin", buttonBox);
  QObject::connect(insertPolyButton, SIGNAL(clicked()), this, SLOT(insertPolyClicked()));
}

LadspaDialog::~LadspaDialog() {
}

void LadspaDialog::insertClicked() {

  int index, n;

  if (ladspaList->selectedItem()) {
    if (synthdata->getLadspaIDs(ladspaList->selectedItem()->parent()->text(0),
                                ladspaList->selectedItem()->text(0), &index, &n)) {
      emit createLadspaModule(index, n, false, extCtrlPortsCheck->isChecked());
    }
  }
}

void LadspaDialog::insertPolyClicked() {

  int index, n;

  if (ladspaList->selectedItem()) {
    if (synthdata->getLadspaIDs(ladspaList->selectedItem()->parent()->text(0),
                                ladspaList->selectedItem()->text(0), &index, &n)) {
      emit createLadspaModule(index, n, true, extCtrlPortsCheck->isChecked());
    }
  }
}

void LadspaDialog::pluginHighlighted() {

  const LADSPA_Descriptor *ladspa_dsc;
  int index, n;

  if (ladspaList->selectedItem()) {
    if (synthdata->getLadspaIDs(ladspaList->selectedItem()->parent()->text(0),
                                ladspaList->selectedItem()->text(0), &index, &n)) {
      ladspa_dsc = synthdata->ladspa_dsc_func_list[index](n);
      pluginLabel->setText(QString("Label: ")+QString(ladspa_dsc->Label));
      pluginMaker->setText(QString("Author: ")+QString(ladspa_dsc->Maker));
      pluginCopyright->setText(QString("Copyright: ")+QString(ladspa_dsc->Copyright));
    }
  } else {
    pluginLabel->setText("");
    pluginMaker->setText("");
    pluginCopyright->setText("");
  }
}

void LadspaDialog::searchClicked() {

  QListViewItemIterator it(ladspaList), firstItem(ladspaList);

  while (it.current()) {
    if (it.current()->isSelected()) {
      ++it;
      break;
    }
    ++it;
  }
  if (!it.current()) {
    it = firstItem;
  }
  while (it.current()) {
    if ((it.current()->isSelectable()) && (it.current()->text(0).contains(searchLine->text(), false))) {
      break;
    }
    ++it;
  }
  if (!it.current()) {
    it = firstItem;
    while (it.current()) {
      if ((it.current()->isSelectable()) && (it.current()->text(0).contains(searchLine->text(), false))) {
        break;
      }
      ++it;
    }
  }
  if (it.current()) {
    if (it.current()->isSelectable()) {
      ladspaList->setSelected(it.current(), true);
      it.current()->parent()->setOpen(true);
      ladspaList->ensureVisible(10, it.current()->itemPos());
    }
  }
}