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.

300 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 <stdio.h>
  19. #include "SeqSelectorPluginGUI.h"
  20. #include <FL/fl_draw.h>
  21. #include <FL/fl_draw.H>
  22. #include <FL/Fl_Box.H>
  23. ////////////////////////////////////////////
  24. CountLine::CountLine (int n, Fl_Color col) :
  25. Fl_Group(0,0,250,14,"")
  26. {
  27. box(FL_FLAT_BOX);
  28. if (n%4==0) color (col);
  29. // if (n%8==0) color (col2);
  30. m_Num=n;
  31. sprintf(m_Count,"%d",n);
  32. Fl_Box *Num = new Fl_Box(5,2,30,20,m_Count);
  33. Num->labelsize(10);
  34. Num->labeltype(FL_ENGRAVED_LABEL);
  35. Num->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
  36. add(Num);
  37. m_Flasher = new Fl_LED_Button (15, -3, 20, 20, "");
  38. m_Flasher->selection_color (FL_RED);
  39. add (m_Flasher);
  40. for (int n=0; n<NUM_VALUES; n++)
  41. {
  42. m_Counter[n] = new Fl_Counter(30+n*25, 2, 25, 12, "");
  43. m_Counter[n]->labelsize(8);
  44. m_Counter[n]->textsize(8);
  45. m_Counter[n]->type(FL_SIMPLE_COUNTER);
  46. m_Counter[n]->step(1);
  47. m_Counter[n]->value(0);
  48. add(m_Counter[n]);
  49. }
  50. end();
  51. redraw();
  52. }
  53. CountLine::~CountLine()
  54. {
  55. }
  56. void CountLine::SetVal(int n, float val)
  57. {
  58. // range check
  59. assert(n>=0 && n<8);
  60. m_Counter[n]->value(val);
  61. }
  62. float CountLine::GetVal(int n)
  63. {
  64. // range check
  65. assert(n>=0 && n<8);
  66. return m_Counter[n]->value();
  67. }
  68. int CountLine::handle(int event)
  69. {
  70. int temp = Fl_Group::handle(event);
  71. if (event==FL_PUSH)
  72. {
  73. for(int n=0; n<NUM_VALUES; n++)
  74. {
  75. m_GUICH->Set("Line",m_Num);
  76. m_GUICH->Set("Num",n);
  77. m_GUICH->Set("Val",(int)GetVal(n));
  78. m_GUICH->SetCommand(SeqSelectorPlugin::SET_VAL);
  79. m_GUICH->Wait();
  80. }
  81. }
  82. return temp;
  83. }
  84. ////////////////////////////////////////////
  85. SeqSelectorPluginGUI::SeqSelectorPluginGUI(int w, int h,SeqSelectorPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  86. SpiralPluginGUI(w,h,o,ch)
  87. {
  88. m_Colour = (Fl_Color)Info->GUI_COLOUR;
  89. //m_Colour2 = (Fl_Color)Info->SCOPE_BG_COLOUR;
  90. m_Scroll = new Fl_Scroll(0, 20, w, h-50, "");
  91. m_Scroll->type(Fl_Scroll::VERTICAL_ALWAYS);
  92. m_Scroll->box(FL_NO_BOX);
  93. m_Scroll->position(0,0);
  94. add(m_Scroll);
  95. m_Main = new Fl_Pack(0,20,w,h-50,"");
  96. m_Main->box(FL_NO_BOX);
  97. m_Scroll->add(m_Main);
  98. m_New = new Fl_Button(5,h-25,50,20,"New");
  99. m_New->labelsize(10);
  100. m_New->callback((Fl_Callback*)cb_New);
  101. add(m_New);
  102. m_Delete = new Fl_Button(60,h-25,50,20,"Delete");
  103. m_Delete->labelsize(10);
  104. m_Delete->callback((Fl_Callback*)cb_Delete);
  105. add(m_Delete);
  106. m_Begin = new Fl_Counter(115,h-28,50,15,"Begin");
  107. m_Begin->labelsize(10);
  108. m_Begin->type(FL_SIMPLE_COUNTER);
  109. m_Begin->step(1);
  110. m_Begin->value(0);
  111. m_Begin->callback((Fl_Callback*)cb_Begin);
  112. add(m_Begin);
  113. m_End = new Fl_Counter(175,h-28,50,15,"End");
  114. m_End->labelsize(10);
  115. m_End->type(FL_SIMPLE_COUNTER);
  116. m_End->step(1);
  117. m_End->value(0);
  118. m_End->callback((Fl_Callback*)cb_End);
  119. add(m_End);
  120. m_UseRange = new Fl_Button(230,h-25,55,20,"UseRange");
  121. m_UseRange->labelsize(10);
  122. m_UseRange->type(1);
  123. m_UseRange->value(0);
  124. m_UseRange->callback((Fl_Callback*)cb_UseRange);
  125. add(m_UseRange);
  126. end();
  127. }
  128. float SeqSelectorPluginGUI::GetVal(int l, int v)
  129. {
  130. int c=0;
  131. list<CountLine*>::iterator i = m_LineVec.end();
  132. do
  133. {
  134. i--;
  135. if (l==c) return (*i)->GetVal(v);
  136. c++;
  137. }
  138. while (i!=m_LineVec.begin());
  139. return 0;
  140. }
  141. void SeqSelectorPluginGUI::AddLine(int* Val)
  142. {
  143. CountLine *NewLine = new CountLine(m_LineVec.size(), m_Colour/*1, m_Colour2*/);
  144. NewLine->m_GUICH = m_GUICH;
  145. // copy the last line
  146. list<CountLine*>::iterator i=m_LineVec.begin();
  147. if (Val)
  148. {
  149. for (int n=0; n<NUM_VALUES; n++)
  150. {
  151. NewLine->SetVal(n,Val[n]);
  152. }
  153. }
  154. else
  155. {
  156. if (m_LineVec.size()>0)
  157. {
  158. for (int n=0; n<NUM_VALUES; n++)
  159. {
  160. NewLine->SetVal(n,(*i)->GetVal(n));
  161. }
  162. }
  163. }
  164. m_Main->add(NewLine);
  165. m_LineVec.push_front(NewLine);
  166. redraw();
  167. Fl::check();
  168. }
  169. void SeqSelectorPluginGUI::RemoveLine()
  170. {
  171. list<CountLine*>::iterator i=m_LineVec.begin();
  172. if (m_LineVec.size()>0)
  173. {
  174. m_Main->remove(*i);
  175. delete(*i);
  176. m_LineVec.erase(i);
  177. m_Main->redraw();
  178. m_Scroll->redraw();
  179. }
  180. }
  181. void SeqSelectorPluginGUI::Update()
  182. {
  183. int p=m_GUICH->GetInt("Pos");
  184. if (m_LastLight!=p)
  185. {
  186. m_LastLight=p;
  187. SetLED(p);
  188. }
  189. }
  190. void SeqSelectorPluginGUI::SetLED(int n)
  191. {
  192. int c=0;
  193. if (m_LineVec.empty()) return;
  194. list<CountLine*>::iterator i = m_LineVec.end();
  195. do
  196. {
  197. i--;
  198. if (n==c) (*i)->SetLED(true);
  199. else (*i)->SetLED(false);
  200. c++;
  201. }
  202. while (i!=m_LineVec.begin());
  203. }
  204. void SeqSelectorPluginGUI::UpdateValues(SpiralPlugin *o)
  205. {
  206. SeqSelectorPlugin *Plugin = (SeqSelectorPlugin *)o;
  207. int c=Plugin->m_Lines.size();
  208. for (int n=0; n<c; n++)
  209. {
  210. int temp[8];
  211. for (int i=0; i<8; i++) temp[i]=Plugin->m_Lines[n].Value[i];
  212. AddLine(temp);
  213. }
  214. }
  215. inline void SeqSelectorPluginGUI::cb_New_i(Fl_Button* o, void* v)
  216. {
  217. AddLine();
  218. m_GUICH->SetCommand(SeqSelectorPlugin::ADD_LINE);
  219. }
  220. void SeqSelectorPluginGUI::cb_New(Fl_Button* o, void* v)
  221. { ((SeqSelectorPluginGUI*)(o->parent()))->cb_New_i(o,v); }
  222. inline void SeqSelectorPluginGUI::cb_Delete_i(Fl_Button* o, void* v)
  223. {
  224. RemoveLine();
  225. m_GUICH->SetCommand(SeqSelectorPlugin::REM_LINE);
  226. }
  227. void SeqSelectorPluginGUI::cb_Delete(Fl_Button* o, void* v)
  228. { ((SeqSelectorPluginGUI*)(o->parent()))->cb_Delete_i(o,v); }
  229. inline void SeqSelectorPluginGUI::cb_Begin_i(Fl_Counter* o, void* v)
  230. {
  231. m_GUICH->Set("Line",(int)o->value());
  232. m_GUICH->SetCommand(SeqSelectorPlugin::SET_BEGIN);
  233. }
  234. void SeqSelectorPluginGUI::cb_Begin(Fl_Counter* o, void* v)
  235. { ((SeqSelectorPluginGUI*)(o->parent()))->cb_Begin_i(o,v); }
  236. inline void SeqSelectorPluginGUI::cb_End_i(Fl_Counter* o, void* v)
  237. {
  238. m_GUICH->Set("Line",(int)o->value());
  239. m_GUICH->SetCommand(SeqSelectorPlugin::SET_END);
  240. }
  241. void SeqSelectorPluginGUI::cb_End(Fl_Counter* o, void* v)
  242. { ((SeqSelectorPluginGUI*)(o->parent()))->cb_End_i(o,v); }
  243. inline void SeqSelectorPluginGUI::cb_UseRange_i(Fl_Button* o, void* v)
  244. {
  245. m_GUICH->Set("Val",(int)o->value());
  246. m_GUICH->SetCommand(SeqSelectorPlugin::RANGE);
  247. }
  248. void SeqSelectorPluginGUI::cb_UseRange(Fl_Button* o, void* v)
  249. { ((SeqSelectorPluginGUI*)(o->parent()))->cb_UseRange_i(o,v); }
  250. const string SeqSelectorPluginGUI::GetHelpText(const string &loc){
  251. return string("")
  252. + "The SeqSelector is designed to allow you to syncronise and select up\n"
  253. + "to 8 Sequencer or Matrix patterns into tracks. When the SeqSelector\n"
  254. + "recieves a trigger (which could come from a master pattern, or a clock\n"
  255. + "oscillator) it will briefly flash the next set of values to its outputs,\n"
  256. + "triggering the next patterns on it's slave sequencers or matrix plugins.\n\n"
  257. + "You can also specify a loop, which will be used if the \"use range\"\n"
  258. + "button is activated. This is useful for auditioning sections of a track.";
  259. }