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.

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