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.

288 lines
8.0KB

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