You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

885 lines
27KB

  1. /* SpiralPlugin
  2. * Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
  3. * LADSPA Plugin by Nicolas Noble <nicolas@nobis-crew.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #include <cstdio>
  20. #include <cmath>
  21. #include <cstring>
  22. #include <dlfcn.h>
  23. #include <vector>
  24. #include <algorithm>
  25. #include <FL/fl_draw.h>
  26. #include <FL/fl_draw.H>
  27. #include "LADSPAPluginGUI.h"
  28. #include "LADSPAInfo.h"
  29. static const int GUI_COLOUR = 179;
  30. static const int GUIBG_COLOUR = 144;
  31. static const int GUIBG2_COLOUR = 145;
  32. LADSPAPluginGUI::LADSPAPluginGUI(int w, int h,
  33. LADSPAPlugin *o,
  34. ChannelHandler *ch,
  35. const HostInfo *Info,
  36. const vector<LADSPAInfo::PluginEntry> &PVec) :
  37. SpiralPluginGUI(w,h,o,ch)
  38. {
  39. m_PluginList = PVec;
  40. int Width=20;
  41. int Height=100;
  42. // Get maximum input port count
  43. m_GUICH->GetData("GetMaxInputPortCount",&(m_MaxInputPortCount));
  44. // Set up buffers for data transfer via ChannelHandler
  45. m_InputPortNames = (char *)malloc(256 * m_MaxInputPortCount);
  46. m_InputPortSettings = (PortSettings *)malloc(sizeof(PortSettings) * m_MaxInputPortCount);
  47. m_InputPortValues = (PortValues *)calloc(m_MaxInputPortCount, sizeof(PortValues));
  48. m_InputPortDefaults = (float *)calloc(m_MaxInputPortCount, sizeof(float));
  49. if (!(m_InputPortNames && m_InputPortSettings &&
  50. m_InputPortValues && m_InputPortDefaults)) {
  51. cerr<<"Memory allocation error\n"<<endl;
  52. }
  53. // Set up widgets
  54. m_NameLabel = new Fl_Box(10,20,480,15,"None");
  55. m_NameLabel->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
  56. m_NameLabel->labelcolor(GUI_COLOUR);
  57. m_NameLabel->labelsize(12);
  58. add(m_NameLabel);
  59. m_MakerLabel = new Fl_Box(10,40,480,15,"None");
  60. m_MakerLabel->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
  61. m_MakerLabel->labelcolor(GUI_COLOUR);
  62. m_MakerLabel->labelsize(12);
  63. add(m_MakerLabel);
  64. m_Tab = new Fl_Tabs(5,60,490,255,"");
  65. m_Tab->callback((Fl_Callback *)cb_TabChange);
  66. add(m_Tab);
  67. m_ControlGroup = new Fl_Group(0,80,490,255,"Control");
  68. m_ControlGroup->labelsize(12);
  69. m_ControlScroll = new Fl_Scroll(10,85,480,210,"");
  70. m_ControlScroll->align(FL_ALIGN_TOP_LEFT);
  71. m_ControlScroll->type(Fl_Scroll::VERTICAL);
  72. m_ControlScroll->box(FL_DOWN_BOX);
  73. m_ControlGroup->add(m_ControlScroll);
  74. m_ControlPack = new Fl_Pack(5,90,460,50,"");
  75. m_ControlScroll->add(m_ControlPack);
  76. m_SetupGroup = new Fl_Group(0,80,490,255,"Setup");
  77. m_SetupGroup->labelsize(12);
  78. m_Browser = new Fl_Choice(50,85,440,22,"Plugin:");
  79. m_Browser->labelsize(12);
  80. m_Browser->textsize(12);
  81. m_Browser->callback((Fl_Callback *)cb_Select);
  82. m_Browser->add("(None)");
  83. for (vector<LADSPAInfo::PluginEntry>::iterator i=m_PluginList.begin();
  84. i!=m_PluginList.end(); i++)
  85. {
  86. unsigned long len = i->Name.length();
  87. unsigned long esc_count = 0;
  88. const char *tmp = i->Name.c_str();
  89. char *dest;
  90. for (unsigned long c = 0; c < len; c++) {
  91. if (tmp[c] == '/') esc_count++;
  92. }
  93. dest = (char *)malloc(len + 1 + esc_count);
  94. if (dest) {
  95. unsigned long d = 0;
  96. for (unsigned long c = 0; c < len; c++, d++) {
  97. if (tmp[c] == '/' || tmp[c] == '|') {
  98. dest[d] = '\\';
  99. d++;
  100. dest[d] = tmp[c];
  101. } else {
  102. dest[d] = tmp[c];
  103. }
  104. }
  105. dest[len + esc_count] = '\0';
  106. m_Browser->add(dest);
  107. free(dest);
  108. }
  109. }
  110. m_Browser->value(0);
  111. m_SetupGroup->add(m_Browser);
  112. m_InputScroll = new Fl_Scroll(10,130,480,145);
  113. m_InputScroll->labelsize(12);
  114. m_InputScroll->align(FL_ALIGN_TOP_LEFT);
  115. m_InputScroll->type(Fl_Scroll::VERTICAL);
  116. m_InputScroll->box(FL_DOWN_BOX);
  117. m_InputPack = new Fl_Pack(5,135,460,26,"");
  118. m_InputScroll->add(m_InputPack);
  119. m_SetupGroup->add(m_InputScroll);
  120. m_ValueLabel = new Fl_Box(15,115,60,15,"Value");
  121. m_ValueLabel->labelsize(12);
  122. m_SetupGroup->add(m_ValueLabel);
  123. m_DefaultLabel = new Fl_Box(77,115,60,15,"Default");
  124. m_DefaultLabel->labelsize(12);
  125. m_SetupGroup->add(m_DefaultLabel);
  126. m_MinLabel = new Fl_Box(139,115,60,15,"Min");
  127. m_MinLabel->labelsize(12);
  128. m_SetupGroup->add(m_MinLabel);
  129. m_MaxLabel = new Fl_Box(201,115,60,15,"Max");
  130. m_MaxLabel->labelsize(12);
  131. m_SetupGroup->add(m_MaxLabel);
  132. m_ClampLabel = new Fl_Box(280,115,10,15,"Clamp?");
  133. m_ClampLabel->labelsize(12);
  134. m_SetupGroup->add(m_ClampLabel);
  135. m_PortLabel = new Fl_Box(325,115,60,15,"Port Name");
  136. m_PortLabel->labelsize(12);
  137. m_SetupGroup->add(m_PortLabel);
  138. m_UpdateInputs = new Fl_Check_Button(10,282,120,25,"Update input values?");
  139. m_UpdateInputs->labelsize(12);
  140. m_UpdateInputs->value(true);
  141. m_UpdateInputs->callback((Fl_Callback *)cb_UpdateInputs);
  142. m_SetupGroup->add(m_UpdateInputs);
  143. m_Tab->add(m_ControlGroup);
  144. m_Tab->add(m_SetupGroup);
  145. m_Tab->value(m_SetupGroup);
  146. m_TabIndex = 1;
  147. m_PortIndex = 0;
  148. end();
  149. }
  150. LADSPAPluginGUI::~LADSPAPluginGUI(void)
  151. {
  152. if (m_InputPortNames) free(m_InputPortNames);
  153. if (m_InputPortSettings) free(m_InputPortSettings);
  154. if (m_InputPortValues) free(m_InputPortValues);
  155. if (m_InputPortDefaults) free(m_InputPortDefaults);
  156. Fl::check();
  157. }
  158. // Rearrange knobs depending on connections
  159. // Knobs corresponding to connected ports are hidden,
  160. // the rest are shown
  161. void LADSPAPluginGUI::UpdateDefaultAdjustControls(void)
  162. {
  163. int column = 0;
  164. // First, clear out all groups in Pack
  165. // We need to remove all the knobs first, or they'll go
  166. // with the group. Which would be bad.
  167. while (m_ControlPack->children() > 0) {
  168. Fl_Group *Group = (Fl_Group *)m_ControlPack->child(0);
  169. while (Group->children() > 0) {
  170. Fl_Knob *Knob = (Fl_Knob *)Group->child(0);
  171. Group->remove(Knob);
  172. }
  173. m_ControlPack->remove(Group);
  174. }
  175. Fl_Group *NewGroup = new Fl_Group(0,0,460,65,"");
  176. NewGroup->box(FL_FLAT_BOX);
  177. m_ControlPack->add(NewGroup);
  178. for (unsigned long p = 0; p < m_InputPortCount; p++)
  179. {
  180. if (!m_InputPortValues[p].Connected) {
  181. m_PortDefaultAdjust[p]->position(50 + column * 105, 0);
  182. m_PortDefaultAdjust[p]->show();
  183. NewGroup->add(m_PortDefaultAdjust[p]);
  184. column++;
  185. if ((column > 3) && (p < m_InputPortCount - 1)) {
  186. NewGroup = new Fl_Group(0,0,460,65,"");
  187. NewGroup->box(FL_FLAT_BOX);
  188. m_ControlPack->add(NewGroup);
  189. column = 0;
  190. }
  191. } else {
  192. m_PortDefaultAdjust[p]->hide();
  193. }
  194. }
  195. m_ControlScroll->redraw();
  196. }
  197. // This lot is only done on patch load
  198. void LADSPAPluginGUI::UpdateValues(SpiralPlugin *o)
  199. {
  200. LADSPAPlugin* Plugin = (LADSPAPlugin*)o;
  201. SetPluginIndex(Plugin->GetPluginIndex());
  202. SetName(Plugin->GetName());
  203. SetMaker(Plugin->GetMaker());
  204. SetTabIndex(Plugin->GetTabIndex());
  205. SetUpdateInputs(Plugin->GetUpdateInputs());
  206. m_InputPortCount = Plugin->GetInputPortCount();
  207. const char *name;
  208. PortSettings settings;
  209. float defolt;
  210. for (unsigned long p = 0; p < m_InputPortCount; p++) {
  211. name = Plugin->GetInputPortName(p);
  212. settings = Plugin->GetInputPortSettings(p);
  213. defolt = Plugin->GetInputPortDefault(p);
  214. AddPortInfo(name);
  215. SetPortSettings(p, settings.Min, settings.Max, settings.Clamp, defolt);
  216. SetDefaultAdjust(p);
  217. }
  218. UpdateDefaultAdjustControls();
  219. m_PortIndex = m_InputPortCount;
  220. }
  221. // ****************************************************************************
  222. // ** Protected Member Functions **
  223. // ****************************************************************************
  224. const string LADSPAPluginGUI::GetHelpText(const string &loc)
  225. {
  226. // if (loc == "DE") {
  227. // } else if (loc == "FR") {
  228. // } else {
  229. // Default to English?
  230. return string("LADSPA Plugin\n")
  231. + "\n"
  232. + "This plugin allows you to use any LADSPA plugin in SSM.\n"
  233. + "\n"
  234. + "It grows or shrinks the device GUI to allow you to connect\n"
  235. + "up the ports as any other native SSM plugin, so you can\n"
  236. + "seamlessly use the plugins as part of your layouts.\n"
  237. + "\n"
  238. + "The GUI window has two tabbed sections, Control and Setup.\n"
  239. + "\n"
  240. + "Setup is used to choose which LADSPA plugin to use, and\n"
  241. + "allows you to configure port information.\n"
  242. + "\n"
  243. + "Once you have chosen a plugin, a row will appear for each\n"
  244. + "input port:\n"
  245. + "\n"
  246. + "Value\n"
  247. + " The value being input to the port from a connection.\n"
  248. + "Default\n"
  249. + " The value used as input if there is no connection. If"
  250. + " the port is connected, the default will use the value.\n"
  251. + " Upon disconnection, it will retain the last value\n"
  252. + " received.\n"
  253. + "Min, Max\n"
  254. + " The range of values to scale a connected signal to,\n"
  255. + " assuming the signal is in the range -1.0 to +1.0.\n"
  256. + "Clamp\n"
  257. + " Whether to scale inputs - if unchecked, the input is\n"
  258. + " not scaled."
  259. + "Port Name"
  260. + " The name of the port, as supplied by the plugin.\n"
  261. + "\n"
  262. + "The Control tab will display a control knob for each port\n"
  263. + "that is not connected. This allows adjustment of input\n"
  264. + "directly.";
  265. // }
  266. }
  267. // ****************************************************************************
  268. // ** Private Member Functions **
  269. // ****************************************************************************
  270. void LADSPAPluginGUI::SetTabIndex(int index)
  271. {
  272. m_TabIndex = index;
  273. if (m_TabIndex == 0) {
  274. m_Tab->value(m_ControlGroup);
  275. } else {
  276. m_Tab->value(m_SetupGroup);
  277. }
  278. }
  279. void LADSPAPluginGUI::SetUpdateInputs(bool state)
  280. {
  281. m_UpdateInputState = state;
  282. m_UpdateInputs->value(m_UpdateInputState);
  283. }
  284. void LADSPAPluginGUI::SetPluginIndex(unsigned long n)
  285. {
  286. m_PluginIndex = n;
  287. m_Browser->value(m_PluginIndex);
  288. }
  289. void LADSPAPluginGUI::SetName(const char *s)
  290. {
  291. m_NameLabel->label(s);
  292. }
  293. void LADSPAPluginGUI::SetMaker(const char *s)
  294. {
  295. char temp[256];
  296. unsigned int len = strlen(s);
  297. strncpy(temp, s, len);
  298. // If this has got an "@" in it FLTK thinks it's a special character not an E.mail address
  299. int t=0;
  300. for (unsigned int f=0; f<len; f++) {
  301. if (t==255) break;
  302. if (temp[f]=='@') m_Maker[t++]='@';
  303. m_Maker[t++]=temp[f];
  304. }
  305. m_Maker[t]=0;
  306. m_MakerLabel->label (m_Maker);
  307. }
  308. void LADSPAPluginGUI::SetPortSettings(unsigned long n, float min, float max, bool clamp, float defolt)
  309. {
  310. char temp[256];
  311. sprintf(temp,"%.4f",min);
  312. m_PortMin[n]->value(temp);
  313. sprintf(temp,"%.4f",max);
  314. m_PortMax[n]->value(temp);
  315. sprintf(temp, "%d",clamp);
  316. m_PortClamp[n]->value(atoi(temp));
  317. sprintf(temp, "%.4f",defolt);
  318. m_PortDefault[n]->value(temp);
  319. }
  320. void LADSPAPluginGUI::SetDefaultAdjust(unsigned long n)
  321. {
  322. // Set default adjust knob
  323. float min = atof(m_PortMin[n]->value());
  324. float max = atof(m_PortMax[n]->value());
  325. float def = atof(m_PortDefault[n]->value());
  326. float value = ((max - min) > 0.0f) ? (def - min) / (max - min) : 0.5f;
  327. m_PortDefaultAdjust[n]->value(value);
  328. }
  329. void LADSPAPluginGUI::AddPortInfo(const char *Info)
  330. {
  331. Fl_Group* NewGroup = new Fl_Group(0,0,460,24,"");
  332. NewGroup->box(FL_FLAT_BOX);
  333. m_InputPack->add(NewGroup);
  334. // Value
  335. Fl_Output* NewOutput = new Fl_Output(10,0,60,18,"");
  336. NewOutput->value(0);
  337. NewOutput->textsize(10);
  338. NewOutput->color(FL_BACKGROUND_COLOR);
  339. NewOutput->readonly(1);
  340. NewGroup->add(NewOutput);
  341. m_PortValue.push_back(NewOutput);
  342. // Fixed Value/Default
  343. Fl_Input* NewInput = new Fl_Input(72,0,60,18,"");
  344. NewInput->value(0);
  345. NewInput->textsize(10);
  346. NewInput->callback((Fl_Callback *)cb_Default);
  347. NewGroup->add(NewInput);
  348. m_PortDefault.push_back(NewInput);
  349. // Min
  350. NewInput = new Fl_Input(134,0,60,18,"");
  351. NewInput->value(0);
  352. NewInput->textsize(10);
  353. NewInput->callback((Fl_Callback *)cb_Min);
  354. NewGroup->add(NewInput);
  355. m_PortMin.push_back(NewInput);
  356. // Max
  357. NewInput = new Fl_Input(196,0,60,18,"");
  358. NewInput->value(0);
  359. NewInput->textsize(10);
  360. NewInput->callback((Fl_Callback *)cb_Max);
  361. NewGroup->add(NewInput);
  362. m_PortMax.push_back(NewInput);
  363. // Clamp
  364. Fl_Check_Button* NewCheckButton = new Fl_Check_Button(265,0,10,18,"");
  365. NewCheckButton->value(0);
  366. NewCheckButton->callback((Fl_Callback *)cb_Clamp);
  367. NewGroup->add(NewCheckButton);
  368. m_PortClamp.push_back(NewCheckButton);
  369. // Port Name
  370. Fl_Box* NewText = new Fl_Box(320,0,10,18,"");
  371. NewText->label(Info);
  372. NewText->labelsize(10);
  373. NewText->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
  374. NewGroup->add(NewText);
  375. NewGroup->redraw();
  376. m_InputPack->redraw();
  377. m_InputScroll->redraw();
  378. // Control knobs - these aren't displayed yet, as their display will depend
  379. // on what is connected. All that is decided in UpdateControlKnobs()
  380. int len = strlen(Info);
  381. len -= 5; // Get rid of (CV), (AU) bit
  382. len = len > 20 ? 20 : len; // Truncate to fit
  383. char *label = (char *)malloc(len + 1);
  384. if (label)
  385. {
  386. strncpy(label, Info, len);
  387. label[len] = '\0';
  388. }
  389. m_PortDefaultAdjustLabels.push_back(label);
  390. Fl_Knob* NewKnob = new Fl_Knob(0,0,40,40,"");
  391. NewKnob->label(m_PortDefaultAdjustLabels[m_PortDefaultAdjustLabels.size() - 1]);
  392. NewKnob->labelsize(10);
  393. NewKnob->color(GUI_COLOUR);
  394. NewKnob->maximum(1.0f);
  395. NewKnob->step(0.001f);
  396. NewKnob->callback((Fl_Callback *)cb_DefaultAdjust);
  397. NewKnob->hide();
  398. m_PortDefaultAdjust.push_back(NewKnob);
  399. }
  400. // This is done all the time
  401. void LADSPAPluginGUI::Update(void)
  402. {
  403. char temp[256];
  404. bool state_changed = false;
  405. m_GUICH->GetData("GetInputPortCount", &(m_InputPortCount));
  406. m_GUICH->GetData("GetInputPortValues", m_InputPortValues);
  407. m_GUICH->GetData("GetInputPortDefaults", m_InputPortDefaults);
  408. // Need to show that a connection is present
  409. // regardless of Refresh being set
  410. for (unsigned long p = 0; p < m_InputPortCount; p++) {
  411. // Check if plugin connect state is different to GUI state
  412. // A readonly default implies connection
  413. if ((m_InputPortValues[p].Connected &&
  414. !(m_PortDefault[p]->readonly())) ||
  415. (m_PortDefault[p]->readonly() &&
  416. !(m_InputPortValues[p].Connected))) {
  417. if (m_InputPortValues[p].Connected) {
  418. // Disable
  419. m_PortDefault[p]->readonly(1);
  420. m_PortDefault[p]->color(FL_BACKGROUND_COLOR);
  421. } else {
  422. // Enable
  423. m_PortDefault[p]->readonly(0);
  424. m_PortDefault[p]->color(FL_BACKGROUND2_COLOR);
  425. }
  426. sprintf(temp,"%.4f", m_InputPortDefaults[p]);
  427. m_PortDefault[p]->value(temp);
  428. SetDefaultAdjust(p);
  429. m_PortDefault[p]->redraw();
  430. state_changed = true;
  431. }
  432. // Only update values if Refresh is set
  433. if (m_UpdateInputs->value()) {
  434. sprintf(temp,"%.4f", m_InputPortValues[p].Value);
  435. m_PortValue[p]->value(temp);
  436. if (m_InputPortValues[p].Connected) {
  437. sprintf(temp,"%.4f", m_InputPortDefaults[p]);
  438. m_PortDefault[p]->value(temp);
  439. }
  440. }
  441. }
  442. // If a connection has been added/removed, we need to
  443. // rearrange the knobs
  444. if (state_changed) UpdateDefaultAdjustControls();
  445. }
  446. void LADSPAPluginGUI::ClearPlugin(void)
  447. {
  448. m_PluginIndex = 0;
  449. m_InputPortCount = 0;
  450. m_PortIndex = 0;
  451. m_GUICH->SetCommand(LADSPAPlugin::CLEARPLUGIN);
  452. m_GUICH->Wait();
  453. // Clear out port info, and refresh
  454. m_InputScroll->remove(m_InputPack);
  455. delete m_InputPack;
  456. m_InputPack = new Fl_Pack(x()+5,y()+135,460,26,"");
  457. m_InputScroll->add(m_InputPack);
  458. // Oh, and the knobs...
  459. m_ControlScroll->remove(m_ControlPack);
  460. delete m_ControlPack;
  461. m_ControlPack = new Fl_Pack(x()+5,y()+90,460,50,"");
  462. m_ControlScroll->add(m_ControlPack);
  463. m_PortValue.clear();
  464. m_PortMin.clear();
  465. m_PortMax.clear();
  466. m_PortClamp.clear();
  467. m_PortDefault.clear();
  468. m_PortDefaultAdjust.clear();
  469. for (vector<char *>::iterator i = m_PortDefaultAdjustLabels.begin();
  470. i != m_PortDefaultAdjustLabels.end(); i++)
  471. {
  472. if (*i) free (*i);
  473. }
  474. m_PortDefaultAdjustLabels.clear();
  475. }
  476. void LADSPAPluginGUI::SelectPlugin(void)
  477. {
  478. // Now get the new values to populate GUI controls
  479. m_GUICH->GetData("GetName", m_Name);
  480. m_GUICH->GetData("GetMaker", m_Maker);
  481. m_GUICH->GetData("GetInputPortCount", &(m_InputPortCount));
  482. m_GUICH->GetData("GetInputPortNames", m_InputPortNames);
  483. m_GUICH->GetData("GetInputPortSettings", m_InputPortSettings);
  484. m_GUICH->GetData("GetInputPortDefaults", m_InputPortDefaults);
  485. SetName((const char *)m_Name);
  486. SetMaker((const char *)m_Maker);
  487. for (unsigned long p = 0; p < m_InputPortCount; p++) {
  488. AddPortInfo((const char *)(m_InputPortNames + p * 256));
  489. SetPortSettings(p, m_InputPortSettings[p].Min,
  490. m_InputPortSettings[p].Max,
  491. m_InputPortSettings[p].Clamp,
  492. m_InputPortDefaults[p]);
  493. SetDefaultAdjust(p);
  494. }
  495. UpdateDefaultAdjustControls();
  496. m_PortIndex = m_InputPortCount;
  497. redraw();
  498. }
  499. // ****************************************************************************
  500. // ** Widget Callback Functions **
  501. // ****************************************************************************
  502. inline void LADSPAPluginGUI::cb_TabChange_i(Fl_Tabs *o)
  503. {
  504. m_TabIndex = o->find(o->value());
  505. m_GUICH->SetData("SetTabIndex", &m_TabIndex);
  506. m_GUICH->SetCommand(LADSPAPlugin::SETTABINDEX);
  507. }
  508. void LADSPAPluginGUI::cb_TabChange(Fl_Tabs *o)
  509. { // GUI
  510. ((LADSPAPluginGUI*)(o->parent()))->cb_TabChange_i(o);
  511. }
  512. inline void LADSPAPluginGUI::cb_Select_i(Fl_Choice* o)
  513. {
  514. ClearPlugin();
  515. m_PluginIndex = o->value();
  516. if (m_PluginIndex != 0) {
  517. // Plugin selected
  518. m_GUICH->SetData("SetPluginIndex",&m_PluginIndex);
  519. m_GUICH->SetCommand(LADSPAPlugin::SELECTPLUGIN);
  520. m_GUICH->Wait();
  521. }
  522. SelectPlugin();
  523. // redraw();
  524. }
  525. void LADSPAPluginGUI::cb_Select(Fl_Choice* o)
  526. { // Group Tab GUI
  527. ((LADSPAPluginGUI*)(o->parent()->parent()->parent()))->cb_Select_i(o);
  528. }
  529. inline void LADSPAPluginGUI::cb_UpdateInputs_i(Fl_Check_Button* o)
  530. {
  531. m_UpdateInputState = (bool)(o->value());
  532. m_GUICH->SetData("SetUpdateInputs", &m_UpdateInputState);
  533. m_GUICH->SetCommand(LADSPAPlugin::SETUPDATEINPUTS);
  534. }
  535. void LADSPAPluginGUI::cb_UpdateInputs(Fl_Check_Button* o)
  536. { // Group Tab GUI
  537. ((LADSPAPluginGUI*)(o->parent()->parent()->parent()))->cb_UpdateInputs_i(o);
  538. }
  539. inline void LADSPAPluginGUI::cb_Default_i(Fl_Input* o)
  540. {
  541. // Which Default was changed?
  542. bool do_search = false;
  543. if (m_PortIndex == m_PortDefault.size()) { do_search = true; }
  544. if (!do_search) { do_search = (o != (m_PortDefault[m_PortIndex])) ? true : false; }
  545. if (do_search) {
  546. // Only bother to re-query if it is different from last one changed
  547. vector<Fl_Input *>::iterator i = std::find(m_PortDefault.begin(),
  548. m_PortDefault.end(),
  549. o);
  550. m_PortIndex = distance(m_PortDefault.begin(), i);
  551. }
  552. m_Default = atof(o->value());
  553. m_Min = atof(m_PortMin[m_PortIndex]->value());
  554. m_Max = atof(m_PortMax[m_PortIndex]->value());
  555. // If default is out of [Min, Max] range, stretch range
  556. if (m_Default < m_Min) {
  557. m_PortMin[m_PortIndex]->value(m_PortDefault[m_PortIndex]->value());
  558. m_PortMin[m_PortIndex]->redraw();
  559. } else if (m_Default > m_Max) {
  560. m_PortMax[m_PortIndex]->value(m_PortDefault[m_PortIndex]->value());
  561. m_PortMax[m_PortIndex]->redraw();
  562. }
  563. // Pass value to plugin
  564. m_GUICH->SetData("SetInputPortIndex", &m_PortIndex);
  565. m_GUICH->SetData("SetInputPortDefault", &m_Default);
  566. m_GUICH->SetCommand(LADSPAPlugin::SETDEFAULT);
  567. // Set Default Adjust knob to corresponding position
  568. SetDefaultAdjust(m_PortIndex);
  569. }
  570. void LADSPAPluginGUI::cb_Default(Fl_Input* o)
  571. { // Group Pack Scroll Group Tab GUI
  572. ((LADSPAPluginGUI*)(o->parent()->parent()->parent()->parent()->parent()->parent()))->cb_Default_i(o);
  573. }
  574. inline void LADSPAPluginGUI::cb_Min_i(Fl_Input* o)
  575. {
  576. // Which Min was changed?
  577. bool do_search = false;
  578. if (m_PortIndex == m_PortMin.size()) { do_search = true; }
  579. if (!do_search) { do_search = (o != (m_PortMin[m_PortIndex])) ? true : false; }
  580. if (do_search) {
  581. // Only bother to re-query if it is different from last one changed
  582. vector<Fl_Input *>::iterator i = std::find(m_PortMin.begin(),
  583. m_PortMin.end(),
  584. o);
  585. m_PortIndex = distance(m_PortMin.begin(), i);
  586. }
  587. // Pass value to plugin
  588. m_GUICH->SetData("SetInputPortIndex", &m_PortIndex);
  589. // Check that min is really min and max is really max
  590. m_Min = atof(o->value());
  591. m_Max = atof(m_PortMax[m_PortIndex]->value());
  592. if (m_Min > m_Max) {
  593. // Swap min and max (need to set max as well)
  594. float min = m_Min;
  595. m_Min = m_Max;
  596. m_Max = min;
  597. m_GUICH->SetData("SetInputPortMax", &m_Max);
  598. m_GUICH->SetCommand(LADSPAPlugin::SETMAX);
  599. m_GUICH->Wait();
  600. // Swap displayed min and max
  601. char temp[256];
  602. strncpy(temp, m_PortMin[m_PortIndex]->value(), 256);
  603. m_PortMin[m_PortIndex]->value(m_PortMax[m_PortIndex]->value());
  604. m_PortMax[m_PortIndex]->value(temp);
  605. m_PortMin[m_PortIndex]->redraw();
  606. m_PortMax[m_PortIndex]->redraw();
  607. }
  608. m_GUICH->SetData("SetInputPortMin", &m_Min);
  609. m_GUICH->SetCommand(LADSPAPlugin::SETMIN);
  610. // Clip default to range
  611. m_Default = atof(m_PortDefault[m_PortIndex]->value());
  612. if (m_Default < m_Min) {
  613. m_Default = m_Min;
  614. m_GUICH->SetData("SetInputPortDefault",&m_Default);
  615. m_GUICH->Wait();
  616. m_GUICH->SetCommand(LADSPAPlugin::SETDEFAULT);
  617. // Print to displayed default
  618. char temp[256];
  619. sprintf(temp, "%.4f", m_Default);
  620. m_PortDefault[m_PortIndex]->value(temp);
  621. m_PortDefault[m_PortIndex]->redraw();
  622. }
  623. // Reposition Default Adjust knob to reflect new range
  624. SetDefaultAdjust(m_PortIndex);
  625. }
  626. void LADSPAPluginGUI::cb_Min(Fl_Input* o)
  627. { // Group Pack Scroll Group Tab GUI
  628. ((LADSPAPluginGUI*)(o->parent()->parent()->parent()->parent()->parent()->parent()))->cb_Min_i(o);
  629. }
  630. inline void LADSPAPluginGUI::cb_Max_i(Fl_Input* o)
  631. {
  632. // Which Max was changed?
  633. bool do_search = false;
  634. if (m_PortIndex == m_PortMax.size()) { do_search = true; }
  635. if (!do_search) { do_search = (o != (m_PortMax[m_PortIndex])) ? true : false; }
  636. if (do_search) {
  637. // Only bother to re-query if it is different from last one changed
  638. vector<Fl_Input *>::iterator i = std::find(m_PortMax.begin(),
  639. m_PortMax.end(),
  640. o);
  641. m_PortIndex = distance(m_PortMax.begin(), i);
  642. }
  643. // Pass value to plugin
  644. m_GUICH->SetData("SetInputPortIndex", &m_PortIndex);
  645. // Check that min is really min and max is really max
  646. m_Max = atof(o->value());
  647. m_Min = atof(m_PortMin[m_PortIndex]->value());
  648. if (m_Min > m_Max) {
  649. // Swap min and max (need to set max as well)
  650. float max = m_Min;
  651. m_Min = m_Max;
  652. m_Max = max;
  653. m_GUICH->SetData("SetInputPortMin", &m_Min);
  654. m_GUICH->SetCommand(LADSPAPlugin::SETMIN);
  655. m_GUICH->Wait();
  656. // Swap displayed min and max
  657. char temp[256];
  658. strncpy(temp, m_PortMax[m_PortIndex]->value(), 256);
  659. m_PortMax[m_PortIndex]->value(m_PortMin[m_PortIndex]->value());
  660. m_PortMin[m_PortIndex]->value(temp);
  661. m_PortMax[m_PortIndex]->redraw();
  662. m_PortMin[m_PortIndex]->redraw();
  663. }
  664. m_GUICH->SetData("SetInputPortMax", &m_Max);
  665. m_GUICH->SetCommand(LADSPAPlugin::SETMAX);
  666. // Clip default to range
  667. m_Default = atof(m_PortDefault[m_PortIndex]->value());
  668. if (m_Default > m_Max) {
  669. m_Default = m_Max;
  670. m_GUICH->SetData("SetInputPortDefault",&m_Default);
  671. m_GUICH->Wait();
  672. m_GUICH->SetCommand(LADSPAPlugin::SETDEFAULT);
  673. // Print to displayed default
  674. char temp[256];
  675. sprintf(temp, "%.4f", m_Default);
  676. m_PortDefault[m_PortIndex]->value(temp);
  677. m_PortDefault[m_PortIndex]->redraw();
  678. }
  679. // Reposition Default Adjust knob to reflect new range
  680. SetDefaultAdjust(m_PortIndex);
  681. }
  682. void LADSPAPluginGUI::cb_Max(Fl_Input* o)
  683. { // Group Pack Scroll Group Tab GUI
  684. ((LADSPAPluginGUI*)(o->parent()->parent()->parent()->parent()->parent()->parent()))->cb_Max_i(o);
  685. }
  686. inline void LADSPAPluginGUI::cb_Clamp_i(Fl_Check_Button* o)
  687. {
  688. // Which Clamp was changed?
  689. bool do_search = false;
  690. if (m_PortIndex == m_PortClamp.size()) { do_search = true; }
  691. if (!do_search) { do_search = (o != (m_PortClamp[m_PortIndex])) ? true : false; }
  692. if (do_search) {
  693. // Only bother to re-query if it is different from last one changed
  694. vector<Fl_Check_Button *>::iterator i = std::find(m_PortClamp.begin(),
  695. m_PortClamp.end(),
  696. o);
  697. m_PortIndex = distance(m_PortClamp.begin(), i);
  698. }
  699. m_Clamp = (bool)(o->value());
  700. // Pass value to plugin
  701. m_GUICH->SetData("SetInputPortIndex", &m_PortIndex);
  702. m_GUICH->SetData("SetInputPortClamp", &m_Clamp);
  703. m_GUICH->SetCommand(LADSPAPlugin::SETCLAMP);
  704. }
  705. void LADSPAPluginGUI::cb_Clamp(Fl_Check_Button* o)
  706. { // Group Pack Scroll Group Tab GUI
  707. ((LADSPAPluginGUI*)(o->parent()->parent()->parent()->parent()->parent()->parent()))->cb_Clamp_i(o);
  708. }
  709. inline void LADSPAPluginGUI::cb_DefaultAdjust_i(Fl_Knob *o)
  710. {
  711. // First, find which knob is being adjusted
  712. bool do_search = false;
  713. if (m_PortIndex == m_PortDefaultAdjust.size()) { do_search = true; }
  714. if (!do_search) { do_search = (o != (m_PortDefaultAdjust[m_PortIndex])) ? true : false; }
  715. if (do_search) {
  716. // Only bother to re-query knob if it is different from last one adjusted
  717. vector<Fl_Knob *>::iterator i = std::find(m_PortDefaultAdjust.begin(),
  718. m_PortDefaultAdjust.end(),
  719. o);
  720. m_PortIndex = distance(m_PortDefaultAdjust.begin(), i);
  721. }
  722. m_Default = o->value();
  723. // Convert knob value [0.0, 1.0] to value in Min, Max range
  724. float min = atof(m_PortMin[m_PortIndex]->value());
  725. float max = atof(m_PortMax[m_PortIndex]->value());
  726. m_Default = ((max - min) > 0.0f) ? min + (max - min) * m_Default : min;
  727. // Pass value to plugin
  728. m_GUICH->SetData("SetInputPortIndex", &m_PortIndex);
  729. m_GUICH->SetData("SetInputPortDefault", &m_Default);
  730. m_GUICH->SetCommand(LADSPAPlugin::SETDEFAULT);
  731. // Copy to Default field in Port Setup list
  732. char temp[256];
  733. sprintf(temp, "%.4f", m_Default);
  734. m_PortDefault[m_PortIndex]->value(temp);
  735. }
  736. void LADSPAPluginGUI::cb_DefaultAdjust(Fl_Knob *o)
  737. { // Group Pack Scroll Group Tab GUI
  738. ((LADSPAPluginGUI*)(o->parent()->parent()->parent()->parent()->parent()->parent()))->cb_DefaultAdjust_i(o);
  739. }