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.

292 lines
8.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 "MatrixPluginGUI.h"
  19. #include <FL/fl_draw.h>
  20. #include <FL/fl_draw.H>
  21. #include <FL/fl_file_chooser.h>
  22. static const int GUI_COLOUR = 179;
  23. static const int GUIBG_COLOUR = 144;
  24. static const int GUIBG2_COLOUR = 145;
  25. ////////////////////////////////////////////
  26. MatrixPluginGUI::MatrixPluginGUI(int w, int h,MatrixPlugin *o,const HostInfo *Info) :
  27. SpiralPluginGUI(w,h,o)
  28. {
  29. m_Plugin=o;
  30. //size_range(10,10);
  31. m_NoteCut = new Fl_Button (5, h-30, 85, 20,"NoteCut");
  32. m_NoteCut->type(1);
  33. m_NoteCut->labelsize(10);
  34. m_NoteCut->value(0);
  35. m_NoteCut->callback((Fl_Callback*)cb_NoteCut);
  36. add(m_NoteCut);
  37. m_Pattern = new Fl_Counter(5, 20, 40, 20, "Pattern");
  38. m_Pattern->labelsize(10);
  39. m_Pattern->type(FL_SIMPLE_COUNTER);
  40. m_Pattern->step(1);
  41. m_Pattern->value(0);
  42. m_Pattern->callback((Fl_Callback*)cb_Pattern);
  43. add(m_Pattern);
  44. m_Length = new Fl_Counter(5, 55, 40, 20, "Length");
  45. m_Length->labelsize(10);
  46. m_Length->type(FL_SIMPLE_COUNTER);
  47. m_Length->step(1);
  48. m_Length->value(64);
  49. m_Length->callback((Fl_Callback*)cb_Length);
  50. add(m_Length);
  51. m_Speed = new Fl_Knob (50, 60, 40, 40, "Speed");
  52. m_Speed->color(GUI_COLOUR);
  53. m_Speed->type(Fl_Knob::DOTLIN);
  54. m_Speed->labelsize(10);
  55. m_Speed->maximum(200);
  56. m_Speed->step(0.01);
  57. m_Speed->value(1.0);
  58. m_Speed->callback((Fl_Callback*)cb_Speed);
  59. add(m_Speed);
  60. m_SpeedVal = new Fl_Counter (5, 125, 85, 20, "");
  61. m_SpeedVal->labelsize(10);
  62. m_SpeedVal->value(10);
  63. m_SpeedVal->type(FL_SIMPLE_COUNTER);
  64. m_SpeedVal->step(1);
  65. m_SpeedVal->callback((Fl_Callback*)cb_Speed);
  66. add(m_SpeedVal);
  67. m_Octave = new Fl_Counter(5, 90, 40, 20, "Octave");
  68. m_Octave->labelsize(10);
  69. m_Octave->type(FL_SIMPLE_COUNTER);
  70. m_Octave->step(1);
  71. m_Octave->value(0);
  72. m_Octave->callback((Fl_Callback*)cb_Octave);
  73. add(m_Octave);
  74. m_CopyBtn = new Fl_Button (5, 150, 40, 20, "Copy");
  75. m_CopyBtn->labelsize (10);
  76. m_CopyBtn->callback ((Fl_Callback*)cb_CopyBtn);
  77. add (m_CopyBtn);
  78. m_PasteBtn = new Fl_Button (50, 150, 40, 20, "Paste");
  79. m_PasteBtn->labelsize (10);
  80. m_PasteBtn->deactivate();
  81. m_PasteBtn->callback ((Fl_Callback*)cb_PasteBtn);
  82. add (m_PasteBtn);
  83. m_ClearBtn = new Fl_Button (5, 175, 85, 20, "Clear");
  84. m_ClearBtn->labelsize (10);
  85. m_ClearBtn->callback ((Fl_Callback*)cb_ClearBtn);
  86. add (m_ClearBtn);
  87. m_TransUpBtn = new Fl_Button (5, 200, 40, 20, "Up");
  88. m_TransUpBtn->labelsize (10);
  89. m_TransUpBtn->callback ((Fl_Callback*)cb_TransUpBtn);
  90. add (m_TransUpBtn);
  91. m_TransDnBtn = new Fl_Button (50, 200, 40, 20, "Down");
  92. m_TransDnBtn->labelsize (10);
  93. m_TransDnBtn->callback ((Fl_Callback*)cb_TransDnBtn);
  94. add (m_TransDnBtn);
  95. m_TransLbl = new Fl_Box (5, 216, 85, 20, "Transpose");
  96. m_TransLbl->labelsize(10);
  97. add (m_TransLbl);
  98. int xoff=95;
  99. int yoff=40;
  100. int butsize=7;
  101. int n=0;
  102. for(int x=0; x<MATX; x++)
  103. for(int y=0; y<MATY; y++)
  104. {
  105. Numbers[n]=n;
  106. m_Matrix[x][y] = new Fl_Button(xoff+x*butsize,yoff+y*butsize,butsize+1,butsize+1,"");
  107. m_Matrix[x][y]->type(1);
  108. m_Matrix[x][y]->box(FL_BORDER_BOX);
  109. if ((x%8)==0) m_Matrix[x][y]->color(FL_WHITE);
  110. else m_Matrix[x][y]->color(FL_GRAY);
  111. m_Matrix[x][y]->selection_color(FL_BLACK);
  112. m_Matrix[x][y]->callback((Fl_Callback*)cb_Matrix,(void*)&Numbers[n]);
  113. add(m_Matrix[x][y]);
  114. n++;
  115. }
  116. xoff=93;
  117. for(int x=0; x<MATX; x++)
  118. {
  119. m_Flash[x] = new Fl_LED_Button(xoff+x*butsize,20,15,15,"");
  120. m_Flash[x]->selection_color(FL_WHITE);
  121. add(m_Flash[x]);
  122. }
  123. end();
  124. }
  125. void MatrixPluginGUI::UpdateValues()
  126. {
  127. m_Pattern->value(m_Plugin->GetCurrent());
  128. m_Length->value(m_Plugin->GetPattern()->Length);
  129. m_Speed->value(m_Plugin->GetPattern()->Speed);
  130. m_SpeedVal->value((int)m_Speed->value());
  131. m_Octave->value(m_Plugin->GetPattern()->Octave);
  132. for(int x=0; x<MATX; x++)
  133. for(int y=0; y<MATY; y++)
  134. {
  135. m_Matrix[x][y]->value(m_Plugin->GetPattern()->Matrix[x][y]);
  136. }
  137. if (m_Plugin->CanTransposeUp()) m_TransUpBtn->activate(); else m_TransUpBtn->deactivate();
  138. if (m_Plugin->CanTransposeDown()) m_TransDnBtn->activate(); else m_TransDnBtn->deactivate();
  139. }
  140. void MatrixPluginGUI::SetLED(int n)
  141. {
  142. for (int i=0; i<MATX; i++)
  143. {
  144. m_Flash[i]->value(false);
  145. }
  146. m_Flash[n]->value(true);
  147. }
  148. inline void MatrixPluginGUI::cb_NoteCut_i(Fl_Button* o, void* v)
  149. {
  150. m_Plugin->SetNoteCut(o->value());
  151. }
  152. void MatrixPluginGUI::cb_NoteCut(Fl_Button* o, void* v)
  153. { ((MatrixPluginGUI*)(o->parent()))->cb_NoteCut_i(o,v);}
  154. inline void MatrixPluginGUI::cb_Matrix_i(Fl_Button* o, void* v)
  155. {
  156. m_Plugin->GetPattern()->Matrix[*(int*)v/MATY][*(int*)v%MATY]=o->value();
  157. UpdateValues();
  158. }
  159. void MatrixPluginGUI::cb_Matrix(Fl_Button* o, void* v)
  160. { ((MatrixPluginGUI*)(o->parent()))->cb_Matrix_i(o,v);}
  161. inline void MatrixPluginGUI::cb_Pattern_i(Fl_Counter* o, void* v)
  162. {
  163. if (o->value()<0) o->value(0);
  164. if (o->value()>NUM_PATTERNS-1) o->value(NUM_PATTERNS-1);
  165. m_Plugin->SetCurrent((int)o->value());
  166. UpdateValues();
  167. }
  168. void MatrixPluginGUI::cb_Pattern(Fl_Counter* o, void* v)
  169. { ((MatrixPluginGUI*)(o->parent()))->cb_Pattern_i(o,v);}
  170. inline void MatrixPluginGUI::cb_Length_i(Fl_Counter* o, void* v)
  171. {
  172. if (o->value()<1) o->value(1);
  173. if (o->value()>64) o->value(64);
  174. m_Plugin->GetPattern()->Length=(int)o->value();
  175. }
  176. void MatrixPluginGUI::cb_Length(Fl_Counter* o, void* v)
  177. { ((MatrixPluginGUI*)(o->parent()))->cb_Length_i(o,v);}
  178. inline void MatrixPluginGUI::cb_Speed_i(Fl_Knob* o, void* v)
  179. {
  180. // Round off value, but it should be a float for tweaking
  181. float value=o->value()+((int)o->value()-o->value());
  182. m_Plugin->GetPattern()->Speed=o->value();
  183. m_SpeedVal->value(value);
  184. }
  185. void MatrixPluginGUI::cb_Speed(Fl_Knob* o, void* v)
  186. { ((MatrixPluginGUI*)(o->parent()))->cb_Speed_i(o,v);}
  187. inline void MatrixPluginGUI::cb_Octave_i(Fl_Counter* o, void* v)
  188. {
  189. if (o->value()<0) o->value(0);
  190. if (o->value()>6) o->value(6);
  191. m_Plugin->GetPattern()->Octave=(int)o->value();
  192. }
  193. void MatrixPluginGUI::cb_Octave(Fl_Counter* o, void* v)
  194. { ((MatrixPluginGUI*)(o->parent()))->cb_Octave_i(o,v);}
  195. inline void MatrixPluginGUI::cb_SpeedVal_i (Fl_Counter* o, void* v)
  196. {
  197. m_Speed->value (o->value());
  198. m_Plugin->GetPattern()->Speed = (float)o->value() * 0.1;
  199. }
  200. void MatrixPluginGUI::cb_SpeedVal (Fl_Counter* o, void* v)
  201. {
  202. ((MatrixPluginGUI*)(o->parent())) -> cb_SpeedVal_i (o, v);
  203. }
  204. inline void MatrixPluginGUI::cb_CopyBtn_i (Fl_Button* o, void* v)
  205. {
  206. m_PasteBtn->activate();
  207. m_Plugin->CopyPattern();
  208. }
  209. void MatrixPluginGUI::cb_CopyBtn (Fl_Button* o, void* v)
  210. {
  211. ((MatrixPluginGUI*)(o->parent())) -> cb_CopyBtn_i (o, v);
  212. }
  213. inline void MatrixPluginGUI::cb_PasteBtn_i (Fl_Button* o, void* v)
  214. {
  215. m_Plugin->PastePattern();
  216. UpdateValues();
  217. }
  218. void MatrixPluginGUI::cb_PasteBtn (Fl_Button* o, void* v)
  219. {
  220. ((MatrixPluginGUI*)(o->parent())) -> cb_PasteBtn_i (o, v);
  221. }
  222. inline void MatrixPluginGUI::cb_ClearBtn_i (Fl_Button* o, void* v)
  223. {
  224. m_Plugin->ClearPattern();
  225. UpdateValues();
  226. }
  227. void MatrixPluginGUI::cb_ClearBtn (Fl_Button* o, void* v)
  228. {
  229. ((MatrixPluginGUI*)(o->parent())) -> cb_ClearBtn_i (o, v);
  230. }
  231. inline void MatrixPluginGUI::cb_TransUpBtn_i (Fl_Button* o, void* v)
  232. {
  233. m_Plugin->TransposeUp();
  234. UpdateValues();
  235. }
  236. void MatrixPluginGUI::cb_TransUpBtn (Fl_Button* o, void* v)
  237. {
  238. ((MatrixPluginGUI*)(o->parent())) -> cb_TransUpBtn_i (o, v);
  239. }
  240. inline void MatrixPluginGUI::cb_TransDnBtn_i (Fl_Button* o, void* v)
  241. {
  242. m_Plugin->TransposeDown();
  243. UpdateValues();
  244. }
  245. void MatrixPluginGUI::cb_TransDnBtn (Fl_Button* o, void* v)
  246. {
  247. ((MatrixPluginGUI*)(o->parent())) -> cb_TransDnBtn_i (o, v);
  248. }