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.

259 lines
7.2KB

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