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.

203 lines
5.5KB

  1. /* SpiralPlugin
  2. * Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "JackPluginGUI.h"
  19. #include <FL/fl_draw.h>
  20. #include <FL/fl_file_chooser.H>
  21. #include <FL/Fl_Hold_Browser.H>
  22. static const int GUI_COLOUR = 179;
  23. static const int GUIBG_COLOUR = 144;
  24. static const int GUIBG2_COLOUR = 145;
  25. static int Numbers[255];
  26. ////////////////////////////////////////////////////////////////////////
  27. int OptionsList(const vector<string> &List)
  28. {
  29. Fl_Double_Window *Win = new Fl_Double_Window(300,300);
  30. Fl_Button *Ok = new Fl_Button(10,275,40,20,"Ok");
  31. Ok->labelsize(10);
  32. Fl_Button *Cancel = new Fl_Button(50,275,40,20,"Cancel");
  33. Cancel->labelsize(10);
  34. Fl_Hold_Browser* Browser = new Fl_Hold_Browser(5,5,290,265,"");
  35. for (vector<string>::const_iterator i = List.begin();
  36. i!=List.end(); i++)
  37. {
  38. Browser->add(i->c_str());
  39. }
  40. Win->show();
  41. int Choice=-1;
  42. for (;;)
  43. {
  44. Fl::wait();
  45. Fl_Widget* o = Fl::readqueue();
  46. if (o==Ok || o==Browser)
  47. {
  48. Choice=Browser->value();
  49. Win->hide();
  50. delete Win;
  51. break;
  52. }
  53. if (o==Cancel)
  54. {
  55. Choice=-1;
  56. Win->hide();
  57. delete Win;
  58. break;
  59. }
  60. if (o==Win) break;
  61. }
  62. return Choice;
  63. }
  64. ////////////////////////////////////////////////////////////////////////
  65. JackPluginGUI::JackPluginGUI(int w, int h,JackPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  66. SpiralPluginGUI(w,h,o,ch)
  67. {
  68. for (int n=0; n<255; n++) Numbers[n]=n;
  69. m_Indicator = new Fl_LED_Button(85,17,30,30,"");
  70. m_Indicator->value(0);
  71. m_Indicator->color(FL_RED);
  72. m_Attach = new Fl_Button(5,50,190,20,"Attach");
  73. m_Attach->type(0);
  74. m_Attach->labelsize(10);
  75. m_Attach->callback((Fl_Callback*)cb_Attach);
  76. m_Detach = new Fl_Button(5,70,190,20,"Detach");
  77. m_Detach->type(0);
  78. m_Detach->labelsize(10);
  79. m_Detach->callback((Fl_Callback*)cb_Detach);
  80. int yoff=90;
  81. for (int n=0; n<NUM_OUTPUTS; n++)
  82. {
  83. sprintf(m_OutputName[n],"Output %d",n);
  84. m_OutputLabel[n] = new Fl_Box(5,n*40+yoff,95,20,m_OutputName[n]);
  85. m_OutputLabel[n]->labelsize(10);
  86. m_OutputLabel[n]->labeltype(FL_ENGRAVED_LABEL);
  87. m_OutputButton[n] = new Fl_Button(5,n*40+yoff+20,95,20,"None yet");
  88. m_OutputButton[n]->labelsize(10);
  89. m_OutputButton[n]->callback((Fl_Callback*)cb_OutputConnect,&Numbers[n]);
  90. }
  91. for (int n=0; n<NUM_INPUTS; n++)
  92. {
  93. sprintf(m_InputName[n],"Input %d",n);
  94. m_InputLabel[n] = new Fl_Box(100,n*40+yoff,95,20,m_InputName[n]);
  95. m_InputLabel[n]->labelsize(10);
  96. m_InputLabel[n]->labeltype(FL_ENGRAVED_LABEL);
  97. m_InputButton[n] = new Fl_Button(100,n*40+yoff+20,95,20,"None yet");
  98. m_InputButton[n]->labelsize(10);
  99. m_InputButton[n]->callback((Fl_Callback*)cb_InputConnect,&Numbers[n]);
  100. }
  101. end();
  102. }
  103. void JackPluginGUI::UpdateValues(SpiralPlugin *o)
  104. {
  105. }
  106. void JackPluginGUI::draw()
  107. {
  108. SpiralPluginGUI::draw();
  109. m_Indicator->value(m_GUICH->GetBool("Connected"));
  110. };
  111. //// Callbacks ////
  112. inline void JackPluginGUI::cb_Attach_i(Fl_Button* o, void* v)
  113. {
  114. m_GUICH->SetCommand(JackPlugin::ATTACH);
  115. }
  116. void JackPluginGUI::cb_Attach(Fl_Button* o, void* v)
  117. { ((JackPluginGUI*)(o->parent()))->cb_Attach_i(o,v);}
  118. inline void JackPluginGUI::cb_Detach_i(Fl_Button* o, void* v)
  119. {
  120. m_GUICH->SetCommand(JackPlugin::DETACH);
  121. }
  122. void JackPluginGUI::cb_Detach(Fl_Button* o, void* v)
  123. { ((JackPluginGUI*)(o->parent()))->cb_Detach_i(o,v);}
  124. inline void JackPluginGUI::cb_OutputConnect_i(Fl_Button* o, void* v)
  125. {
  126. m_GUICH->SetCommand(JackPlugin::UPDATE_NAMES);
  127. m_GUICH->Wait();
  128. // bit of a hack for multithreaded safety
  129. int ninputs=m_GUICH->GetInt("NumOutputPortNames");
  130. char inputs[MAX_INPUTPORTS][256];
  131. m_GUICH->GetData("InputPortNames",inputs);
  132. vector<string> Inputs;
  133. for (int n=0; n<ninputs; n++) Inputs.push_back(inputs[n]);
  134. int choice=OptionsList(Inputs);
  135. // connect this plugin's output to a jack input
  136. if (choice>0)
  137. {
  138. m_GUICH->Set("Num",(*(int*)v));
  139. m_GUICH->SetData("Port",inputs[choice-1]);
  140. m_GUICH->SetCommand(JackPlugin::CONNECTOUTPUT);
  141. o->label(inputs[choice-1]);
  142. o->redraw();
  143. }
  144. }
  145. void JackPluginGUI::cb_OutputConnect(Fl_Button* o, void* v)
  146. { ((JackPluginGUI*)(o->parent()))->cb_OutputConnect_i(o,v);}
  147. inline void JackPluginGUI::cb_InputConnect_i(Fl_Button* o, void* v)
  148. {
  149. m_GUICH->SetCommand(JackPlugin::UPDATE_NAMES);
  150. m_GUICH->Wait();
  151. // bit of a hack for multithreaded safety
  152. int noutputs=m_GUICH->GetInt("NumOutputPortNames");
  153. char outputs[MAX_OUTPUTPORTS][256];
  154. m_GUICH->GetData("OutputPortNames",outputs);
  155. vector<string> Outputs;
  156. for (int n=0; n<noutputs; n++) Outputs.push_back(outputs[n]);
  157. int choice=OptionsList(Outputs);
  158. // connect this plugin's input to a jack output
  159. if (choice>0)
  160. {
  161. m_GUICH->Set("Num",(*(int*)v));
  162. m_GUICH->SetData("Port",outputs[choice-1]);
  163. m_GUICH->SetCommand(JackPlugin::CONNECTINPUT);
  164. o->label(outputs[choice-1]);
  165. o->redraw();
  166. }
  167. }
  168. void JackPluginGUI::cb_InputConnect(Fl_Button* o, void* v)
  169. { ((JackPluginGUI*)(o->parent()))->cb_InputConnect_i(o,v);}