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.

857 lines
26KB

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