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.

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