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.

250 lines
7.1KB

  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 "JackPlugin.h"
  19. #include "JackPluginGUI.h"
  20. #include <FL/fl_draw.h>
  21. #include <FL/fl_file_chooser.H>
  22. #include <FL/Fl_Hold_Browser.H>
  23. static const int GUI_COLOUR = 179;
  24. static const int GUIBG_COLOUR = 144;
  25. static const int GUIBG2_COLOUR = 145;
  26. static int Numbers[255];
  27. ////////////////////////////////////////////////////////////////////////
  28. int OptionsList(const vector<string> &List)
  29. {
  30. Fl_Double_Window *Win = new Fl_Double_Window(300,300);
  31. Fl_Button *Ok = new Fl_Button(10,275,40,20,"Ok");
  32. Ok->labelsize(10);
  33. Fl_Button *Cancel = new Fl_Button(50,275,40,20,"Cancel");
  34. Cancel->labelsize(10);
  35. Fl_Hold_Browser* Browser = new Fl_Hold_Browser(5,5,290,265,"");
  36. for (vector<string>::const_iterator i = List.begin();
  37. i!=List.end(); i++)
  38. {
  39. Browser->add(i->c_str());
  40. }
  41. Win->show();
  42. int Choice=-1;
  43. for (;;)
  44. {
  45. Fl::wait();
  46. Fl_Widget* o = Fl::readqueue();
  47. if (o==Ok || o==Browser)
  48. {
  49. Choice=Browser->value();
  50. Win->hide();
  51. delete Win;
  52. break;
  53. }
  54. if (o==Cancel)
  55. {
  56. Choice=-1;
  57. Win->hide();
  58. delete Win;
  59. break;
  60. }
  61. if (o==Win) break;
  62. }
  63. return Choice;
  64. }
  65. ////////////////////////////////////////////////////////////////////////
  66. JackPluginGUI::JackPluginGUI(int w, int h,JackPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  67. SpiralPluginGUI(w,h,o,ch)
  68. {
  69. for (int n=0; n<255; n++) Numbers[n]=n;
  70. m_Indicator = new Fl_LED_Button(85,15,30,30,"");
  71. m_Indicator->value(0);
  72. m_Indicator->color(FL_RED);
  73. m_Attach = new Fl_Button(5,40,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,60,190,20,"Detach");
  78. m_Detach->type(0);
  79. m_Detach->labelsize(10);
  80. m_Detach->callback((Fl_Callback*)cb_Detach);
  81. int yoff=80;
  82. for (int n=0; n<NUM_OUTPUTS; n++)
  83. {
  84. sprintf(m_OutputName[n],"Output %d",n);
  85. m_OutputLabel[n] = new Fl_Box(5,n*30+yoff,95,10,m_OutputName[n]);
  86. m_OutputLabel[n]->labelsize(8);
  87. //m_OutputLabel[n]->labeltype(FL_ENGRAVED_LABEL);
  88. m_OutputButton[n] = new Fl_Button(5,n*30+yoff+10,95,20,"None");
  89. m_OutputButton[n]->type(1);
  90. m_OutputButton[n]->labelsize(8);
  91. m_OutputButton[n]->callback((Fl_Callback*)cb_OutputConnect,&Numbers[n]);
  92. }
  93. for (int n=0; n<NUM_INPUTS; n++)
  94. {
  95. sprintf(m_InputName[n],"Input %d",n);
  96. m_InputLabel[n] = new Fl_Box(100,n*30+yoff,95,10,m_InputName[n]);
  97. m_InputLabel[n]->labelsize(8);
  98. //m_InputLabel[n]->labeltype(FL_ENGRAVED_LABEL);
  99. m_InputButton[n] = new Fl_Button(100,n*30+yoff+10,95,20,"None");
  100. m_InputButton[n]->type(1);
  101. m_InputButton[n]->labelsize(8);
  102. m_InputButton[n]->callback((Fl_Callback*)cb_InputConnect,&Numbers[n]);
  103. }
  104. end();
  105. }
  106. void JackPluginGUI::UpdateValues(SpiralPlugin *o)
  107. {
  108. }
  109. void JackPluginGUI::Update()
  110. {
  111. m_Indicator->value(m_GUICH->GetBool("Connected"));
  112. redraw();
  113. }
  114. //// Callbacks ////
  115. inline void JackPluginGUI::cb_Attach_i(Fl_Button* o, void* v)
  116. {
  117. //m_GUICH->SetCommand(JackPlugin::ATTACH);
  118. JackClient::Get()->Attach();
  119. }
  120. void JackPluginGUI::cb_Attach(Fl_Button* o, void* v)
  121. { ((JackPluginGUI*)(o->parent()))->cb_Attach_i(o,v);}
  122. inline void JackPluginGUI::cb_Detach_i(Fl_Button* o, void* v)
  123. {
  124. //m_GUICH->SetCommand(JackPlugin::DETACH);
  125. JackClient::Get()->Detach();
  126. }
  127. void JackPluginGUI::cb_Detach(Fl_Button* o, void* v)
  128. { ((JackPluginGUI*)(o->parent()))->cb_Detach_i(o,v);}
  129. inline void JackPluginGUI::cb_OutputConnect_i(Fl_Button* o, void* v)
  130. {
  131. if (o->value())
  132. {
  133. m_GUICH->SetCommand(JackPlugin::UPDATE_NAMES);
  134. m_GUICH->Wait();
  135. // bit of a hack for multithreaded safety
  136. int ninputs=m_GUICH->GetInt("NumOutputPortNames");
  137. char inputs[MAX_INPUTPORTS][256];
  138. m_GUICH->GetData("InputPortNames",inputs);
  139. vector<string> Inputs;
  140. for (int n=0; n<ninputs; n++) Inputs.push_back(inputs[n]);
  141. int choice=OptionsList(Inputs);
  142. // connect this plugin's output to a jack input
  143. if (choice>0)
  144. {
  145. //m_GUICH->Set("Num",(*(int*)v));
  146. //m_GUICH->SetData("Port",inputs[choice-1]);
  147. //m_GUICH->SetCommand(JackPlugin::CONNECTOUTPUT);
  148. JackClient::Get()->ConnectOutput((*(int*)v),inputs[choice-1]);
  149. o->label(inputs[choice-1]);
  150. o->redraw();
  151. }
  152. }
  153. else
  154. {
  155. JackClient::Get()->DisconnectOutput((*(int*)v));
  156. o->label("None");
  157. o->redraw();
  158. }
  159. }
  160. void JackPluginGUI::cb_OutputConnect(Fl_Button* o, void* v)
  161. { ((JackPluginGUI*)(o->parent()))->cb_OutputConnect_i(o,v);}
  162. inline void JackPluginGUI::cb_InputConnect_i(Fl_Button* o, void* v)
  163. {
  164. if (o->value())
  165. {
  166. m_GUICH->SetCommand(JackPlugin::UPDATE_NAMES);
  167. m_GUICH->Wait();
  168. // bit of a hack for multithreaded safety
  169. int noutputs=m_GUICH->GetInt("NumOutputPortNames");
  170. char outputs[MAX_OUTPUTPORTS][256];
  171. m_GUICH->GetData("OutputPortNames",outputs);
  172. vector<string> Outputs;
  173. for (int n=0; n<noutputs; n++) Outputs.push_back(outputs[n]);
  174. int choice=OptionsList(Outputs);
  175. // connect this plugin's input to a jack output
  176. if (choice>0)
  177. {
  178. //m_GUICH->Set("Num",(*(int*)v));
  179. //m_GUICH->SetData("Port",outputs[choice-1]);
  180. //m_GUICH->SetCommand(JackPlugin::CONNECTINPUT);
  181. JackClient::Get()->ConnectInput((*(int*)v),outputs[choice-1]);
  182. o->label(outputs[choice-1]);
  183. o->redraw();
  184. }
  185. }
  186. else
  187. {
  188. JackClient::Get()->DisconnectInput((*(int*)v));
  189. o->label("None");
  190. o->redraw();
  191. }
  192. }
  193. void JackPluginGUI::cb_InputConnect(Fl_Button* o, void* v)
  194. { ((JackPluginGUI*)(o->parent()))->cb_InputConnect_i(o,v);}
  195. const string JackPluginGUI::GetHelpText(const string &loc){
  196. return string("")
  197. + "JACK is the Jack Audio Connection Kit, and allows multiple Linux audio\n"
  198. + "apps to be connected together and run simultaneously in a low latency.\n"
  199. + "environment.\n\n"
  200. + "This plugin allows you to connect up to 8 inputs and outputs to other\n"
  201. + "JACK apps (providing a server is running)\n"
  202. + "You can use the JackPlugin to connect the ports, or a external program\n"
  203. + "such as the excellent qjackconnect app. Be aware however that if you\n"
  204. + "connect from an external app, the port GUI does not update itself yet.\n"
  205. + "Another problem yet to be fixed is that ssm will get confused if more\n"
  206. + "than one JackPlugin is being used. It's best to use one central\n"
  207. + "JackPlugin at this time.\n\n"
  208. + "When using JACK, make sure the buffer size and samplerate are set to\n"
  209. + "match the JACK server, otherwise glitchy playback, and/or crashes may\n"
  210. + "result";
  211. }