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.

199 lines
5.3KB

  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_Plugin=o;
  70. m_Indicator = new Fl_LED_Button(85,17,30,30,"");
  71. m_Indicator->value(0);
  72. m_Indicator->color(FL_RED);
  73. m_Attach = new Fl_Button(5,50,190,20,"Attach");
  74. m_Attach->type(0);
  75. m_Attach->labelsize(10);
  76. m_Attach->callback((Fl_Callback*)cb_Attach);
  77. m_Detach = new Fl_Button(5,70,190,20,"Detach");
  78. m_Detach->type(0);
  79. m_Detach->labelsize(10);
  80. m_Detach->callback((Fl_Callback*)cb_Detach);
  81. int yoff=90;
  82. for (int n=0; n<NUM_INPUTS; n++)
  83. {
  84. sprintf(m_InputName[n],"Input %d",n);
  85. m_InputLabel[n] = new Fl_Box(100,n*40+yoff,95,20,m_InputName[n]);
  86. m_InputLabel[n]->labelsize(10);
  87. m_InputLabel[n]->labeltype(FL_ENGRAVED_LABEL);
  88. m_InputButton[n] = new Fl_Button(100,n*40+yoff+20,95,20,"None yet");
  89. m_InputButton[n]->labelsize(10);
  90. m_InputButton[n]->callback((Fl_Callback*)cb_InputConnect,&Numbers[n]);
  91. }
  92. for (int n=0; n<NUM_OUTPUTS; n++)
  93. {
  94. sprintf(m_OutputName[n],"Output %d",n);
  95. m_OutputLabel[n] = new Fl_Box(5,n*40+yoff,95,20,m_OutputName[n]);
  96. m_OutputLabel[n]->labelsize(10);
  97. m_OutputLabel[n]->labeltype(FL_ENGRAVED_LABEL);
  98. m_OutputButton[n] = new Fl_Button(5,n*40+yoff+20,95,20,"None yet");
  99. m_OutputButton[n]->labelsize(10);
  100. m_OutputButton[n]->callback((Fl_Callback*)cb_OutputConnect,&Numbers[n]);
  101. }
  102. end();
  103. }
  104. void JackPluginGUI::UpdateValues(SpiralPlugin *o)
  105. {
  106. }
  107. //// Callbacks ////
  108. inline void JackPluginGUI::cb_Attach_i(Fl_Button* o, void* v)
  109. {
  110. m_Plugin->Attach();
  111. }
  112. void JackPluginGUI::cb_Attach(Fl_Button* o, void* v)
  113. { ((JackPluginGUI*)(o->parent()))->cb_Attach_i(o,v);}
  114. inline void JackPluginGUI::cb_Detach_i(Fl_Button* o, void* v)
  115. {
  116. m_Plugin->Detach();
  117. }
  118. void JackPluginGUI::cb_Detach(Fl_Button* o, void* v)
  119. { ((JackPluginGUI*)(o->parent()))->cb_Detach_i(o,v);}
  120. inline void JackPluginGUI::cb_OutputConnect_i(Fl_Button* o, void* v)
  121. {
  122. cerr<<"cb_OutputConnect_i"<<endl;
  123. vector<string> Inputs,Outputs;
  124. m_GUICH->Set("UpdateNames",true);
  125. // bit of a hack for multithreaded safety
  126. int ninputs=m_GUICH->GetInt("NumOutputPortNames"),
  127. int noutputs=m_GUICH->GetInt("NumOutputPortNames");
  128. char **inputs = new char[MAX_INPUTPORTS][256];
  129. char **outputs = new char[MAX_OUTPUTPORTS][256];;
  130. for (int n=0 n<m_GUICH->GetInt("NumInputPortNames"); n++)
  131. {
  132. Inputs.push_back(inputs[n]);
  133. }
  134. for (int n=0 n<m_GUICH->GetInt("NumOutputPortNames"); n++)
  135. {
  136. Inputs.push_back(outputs[n]);
  137. }
  138. delete[] inputs;
  139. delete[] outputs;
  140. // connect this plugin's output to a jack input
  141. int choice=OptionsList(Inputs);
  142. if (choice>0)
  143. {
  144. m_Plugin->ConnectOutput(*(int*)v,Inputs[choice-1]);
  145. o->label(Inputs[choice-1].c_str());
  146. o->redraw();
  147. }
  148. }
  149. void JackPluginGUI::cb_OutputConnect(Fl_Button* o, void* v)
  150. { ((JackPluginGUI*)(o->parent()))->cb_OutputConnect_i(o,v);}
  151. inline void JackPluginGUI::cb_InputConnect_i(Fl_Button* o, void* v)
  152. {
  153. cerr<<"cb_InputConnect_i"<<endl;
  154. vector<string> Inputs,Outputs;
  155. m_Plugin->GetPortNames(Inputs,Outputs);
  156. // connect this plugin's input to a jack output
  157. int choice=OptionsList(Outputs);
  158. if (choice>0)
  159. {
  160. m_Plugin->ConnectInput(*(int*)v,Outputs[choice-1]);
  161. o->label(Outputs[choice-1].c_str());
  162. o->redraw();
  163. }
  164. }
  165. void JackPluginGUI::cb_InputConnect(Fl_Button* o, void* v)
  166. { ((JackPluginGUI*)(o->parent()))->cb_InputConnect_i(o,v);}