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.

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