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.

470 lines
14KB

  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. static const char NoteText[12][3] = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
  26. ////////////////////////////////////////////
  27. Fl_MatrixButton::Fl_MatrixButton(int x, int y, int w, int h, char* n) :
  28. Fl_Button(x,y,w,h,n),
  29. m_Volume(NULL),
  30. cb_VolChange(NULL),
  31. cb_context(NULL)
  32. {
  33. m_SliderHidden=true;
  34. m_VolVal=255;
  35. }
  36. int Fl_MatrixButton::handle(int event)
  37. {
  38. if (value()==true && event==FL_PUSH && Fl::event_button()==3)
  39. {
  40. if (m_SliderHidden)
  41. {
  42. m_Volume = new Fl_Slider(x(),y()+h(),w(),50,"");
  43. m_Volume->type(4);
  44. m_Volume->selection_color(GUI_COLOUR);
  45. m_Volume->maximum(255);
  46. m_Volume->step(1);
  47. m_Volume->value(255-m_VolVal);
  48. m_Volume->user_data((void*)this);
  49. m_Volume->callback((Fl_Callback*)cb_Vol);
  50. m_Volume->show();
  51. parent()->add(m_Volume);
  52. parent()->redraw();
  53. m_SliderHidden=false;
  54. }
  55. else
  56. {
  57. m_Volume->hide();
  58. m_VolVal=255-m_Volume->value();
  59. parent()->remove(m_Volume);
  60. parent()->redraw();
  61. m_Volume=NULL;
  62. m_SliderHidden=true;
  63. }
  64. return 1;
  65. }
  66. if (event==FL_PUSH && Fl::event_button()==1 && !m_SliderHidden)
  67. {
  68. m_Volume->hide();
  69. m_VolVal=255-m_Volume->value();
  70. parent()->remove(m_Volume);
  71. parent()->redraw();
  72. m_Volume=NULL;
  73. m_SliderHidden=true;
  74. }
  75. if (Fl::event_button()!=3) return Fl_Button::handle(event);
  76. return 1;
  77. }
  78. inline void Fl_MatrixButton::cb_Vol_i(Fl_Slider* o, void* v)
  79. {
  80. m_VolVal=255-m_Volume->value();
  81. fl_color((char)m_VolVal,(char)m_VolVal,255);
  82. selection_color(fl_color());
  83. if (cb_VolChange) cb_VolChange(this,cb_context);
  84. redraw();
  85. }
  86. void Fl_MatrixButton::cb_Vol(Fl_Slider* o, void* v)
  87. { ((Fl_MatrixButton*)(o->user_data()))->cb_Vol_i(o,v);}
  88. ////////////////////////////////////////////
  89. MatrixPluginGUI::MatrixPluginGUI(int w, int h,MatrixPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  90. SpiralPluginGUI(w,h,o,ch),
  91. m_LastLight(0)
  92. {
  93. //size_range(10,10);
  94. m_NoteCut = new Fl_Button (5, h-30, 85, 20,"NoteCut");
  95. m_NoteCut->type(1);
  96. m_NoteCut->labelsize(10);
  97. m_NoteCut->value(0);
  98. m_NoteCut->callback((Fl_Callback*)cb_NoteCut);
  99. add(m_NoteCut);
  100. m_Pattern = new Fl_Counter(5, 20, 40, 20, "View");
  101. m_Pattern->labelsize(10);
  102. m_Pattern->type(FL_SIMPLE_COUNTER);
  103. m_Pattern->step(1);
  104. m_Pattern->value(0);
  105. m_Pattern->callback((Fl_Callback*)cb_Pattern);
  106. add(m_Pattern);
  107. m_PlayPattern = new Fl_Counter(50, 20, 40, 20, "Play");
  108. m_PlayPattern->labelsize(10);
  109. m_PlayPattern->type(FL_SIMPLE_COUNTER);
  110. m_PlayPattern->step(1);
  111. m_PlayPattern->value(0);
  112. m_PlayPattern->callback((Fl_Callback*)cb_PlayPattern);
  113. add(m_PlayPattern);
  114. m_Length = new Fl_Counter(5, 55, 40, 20, "Length");
  115. m_Length->labelsize(10);
  116. m_Length->type(FL_SIMPLE_COUNTER);
  117. m_Length->step(1);
  118. m_Length->value(64);
  119. m_Length->callback((Fl_Callback*)cb_Length);
  120. add(m_Length);
  121. m_Speed = new Fl_Knob (50, 60, 40, 40, "Speed");
  122. m_Speed->color(GUI_COLOUR);
  123. m_Speed->type(Fl_Knob::DOTLIN);
  124. m_Speed->labelsize(10);
  125. m_Speed->maximum(200);
  126. m_Speed->step(0.01);
  127. m_Speed->value(1.0);
  128. m_Speed->callback((Fl_Callback*)cb_Speed);
  129. add(m_Speed);
  130. m_SpeedVal = new Fl_Counter (5, 125, 85, 20, "");
  131. m_SpeedVal->labelsize(10);
  132. m_SpeedVal->value(10);
  133. m_SpeedVal->type(FL_SIMPLE_COUNTER);
  134. m_SpeedVal->step(1);
  135. m_SpeedVal->callback((Fl_Callback*)cb_Speed);
  136. add(m_SpeedVal);
  137. m_Octave = new Fl_Counter(5, 90, 40, 20, "Octave");
  138. m_Octave->labelsize(10);
  139. m_Octave->type(FL_SIMPLE_COUNTER);
  140. m_Octave->step(1);
  141. m_Octave->value(0);
  142. m_Octave->callback((Fl_Callback*)cb_Octave);
  143. add(m_Octave);
  144. m_CopyBtn = new Fl_Button (5, 150, 40, 20, "Copy");
  145. m_CopyBtn->labelsize (10);
  146. m_CopyBtn->callback ((Fl_Callback*)cb_CopyBtn);
  147. add (m_CopyBtn);
  148. m_PasteBtn = new Fl_Button (50, 150, 40, 20, "Paste");
  149. m_PasteBtn->labelsize (10);
  150. m_PasteBtn->deactivate();
  151. m_PasteBtn->callback ((Fl_Callback*)cb_PasteBtn);
  152. add (m_PasteBtn);
  153. m_ClearBtn = new Fl_Button (5, 175, 85, 20, "Clear");
  154. m_ClearBtn->labelsize (10);
  155. m_ClearBtn->callback ((Fl_Callback*)cb_ClearBtn);
  156. add (m_ClearBtn);
  157. m_TransUpBtn = new Fl_Button (5, 200, 40, 20, "Up");
  158. m_TransUpBtn->labelsize (10);
  159. m_TransUpBtn->callback ((Fl_Callback*)cb_TransUpBtn);
  160. add (m_TransUpBtn);
  161. m_TransDnBtn = new Fl_Button (50, 200, 40, 20, "Down");
  162. m_TransDnBtn->labelsize (10);
  163. m_TransDnBtn->callback ((Fl_Callback*)cb_TransDnBtn);
  164. add (m_TransDnBtn);
  165. m_TransLbl = new Fl_Box (5, 216, 85, 20, "Transpose");
  166. m_TransLbl->labelsize(10);
  167. add (m_TransLbl);
  168. int xoff=105;
  169. int yoff=40;
  170. int butsize=7;
  171. int n=0;
  172. fl_color(150,150,150);
  173. int markercol=fl_color();
  174. fl_color(170,170,170);
  175. int blcolour=fl_color();
  176. for(int x=0; x<MATX; x++)
  177. for(int y=0; y<MATY; y++)
  178. {
  179. Numbers[n]=n;
  180. m_Matrix[x][y] = new Fl_MatrixButton(xoff+x*butsize,yoff+((MATY-1)*butsize)-(y*butsize),butsize+1,butsize+1,"");
  181. m_Matrix[x][y]->type(1);
  182. m_Matrix[x][y]->box(FL_BORDER_BOX);
  183. if ((x%8)==0) m_Matrix[x][y]->color(markercol);
  184. else if ((y%12)==1 || (y%12)==3 || (y%12)==6 || (y%12)==8 || (y%12)==10) m_Matrix[x][y]->color(blcolour);
  185. else m_Matrix[x][y]->color(FL_GRAY);
  186. m_Matrix[x][y]->selection_color(FL_WHITE);
  187. m_Matrix[x][y]->callback((Fl_Callback*)cb_Matrix,(void*)&Numbers[n]);
  188. m_Matrix[x][y]->SetVolCallback((Fl_Callback*)cb_MatVol,(void*)&Numbers[n]);
  189. add(m_Matrix[x][y]);
  190. n++;
  191. }
  192. yoff=37;
  193. for(int y=0; y<MATY; y++)
  194. {
  195. Fl_Box *box = new Fl_Box(90,yoff+((MATY-1)*butsize)-(y*butsize),15,15,NoteText[y%12]);
  196. box->align(FL_ALIGN_INSIDE|FL_ALIGN_LEFT);
  197. box->labelsize(8);
  198. }
  199. xoff=103;
  200. for(int x=0; x<MATX; x++)
  201. {
  202. m_Flash[x] = new Fl_LED_Button(xoff+x*butsize,20,15,15,"");
  203. m_Flash[x]->selection_color(FL_WHITE);
  204. add(m_Flash[x]);
  205. }
  206. end();
  207. }
  208. void MatrixPluginGUI::Update()
  209. {
  210. int Light=m_GUICH->GetInt("Step");
  211. if (Light!=m_LastLight)
  212. {
  213. m_Flash[Light]->value(1);
  214. m_Flash[m_LastLight]->value(0);
  215. m_LastLight=Light;
  216. }
  217. }
  218. void MatrixPluginGUI::UpdateValues(SpiralPlugin *o)
  219. {
  220. MatrixPlugin *Plugin = (MatrixPlugin*)o;
  221. m_Pattern->value(Plugin->GetCurrent());
  222. m_Length->value(Plugin->GetPattern()->Length);
  223. m_Speed->value(Plugin->GetPattern()->Speed*8);
  224. m_SpeedVal->value((int)m_Speed->value());
  225. m_Octave->value(Plugin->GetPattern()->Octave);
  226. for(int x=0; x<MATX; x++)
  227. for(int y=0; y<MATY; y++)
  228. {
  229. m_Matrix[x][y]->value(Plugin->GetPattern()->Matrix[x][y]);
  230. m_Matrix[x][y]->SetVolume(Plugin->GetPattern()->Volume[x][y]);
  231. }
  232. }
  233. void MatrixPluginGUI::UpdateMatrix()
  234. {
  235. m_GUICH->Wait();
  236. m_GUICH->RequestChannelAndWait("Matrix");
  237. m_GUICH->GetData("Matrix",(void*)m_GUIMatrix);
  238. Pattern *p=&m_GUIMatrix[(int)m_Pattern->value()];
  239. m_Length->value(p->Length);
  240. m_Speed->value(p->Speed*8);
  241. m_SpeedVal->value((int)m_Speed->value());
  242. m_Octave->value(p->Octave);
  243. for(int x=0; x<MATX; x++)
  244. for(int y=0; y<MATY; y++)
  245. {
  246. m_Matrix[x][y]->value(p->Matrix[x][y]);
  247. m_Matrix[x][y]->SetVolume(p->Volume[x][y]);
  248. }
  249. }
  250. inline void MatrixPluginGUI::cb_NoteCut_i(Fl_Button* o, void* v)
  251. {
  252. m_GUICH->Set("NoteCut",o->value());
  253. }
  254. void MatrixPluginGUI::cb_NoteCut(Fl_Button* o, void* v)
  255. { ((MatrixPluginGUI*)(o->parent()))->cb_NoteCut_i(o,v);}
  256. inline void MatrixPluginGUI::cb_Matrix_i(Fl_Button* o, void* v)
  257. {
  258. m_GUICH->Set("X",*(int*)v/MATY);
  259. m_GUICH->Set("Y",*(int*)v%MATY);
  260. if (o->value()) m_GUICH->SetCommand(MatrixPlugin::MAT_ACTIVATE);
  261. else m_GUICH->SetCommand(MatrixPlugin::MAT_DEACTIVATE);
  262. m_GUICH->Wait();
  263. }
  264. void MatrixPluginGUI::cb_Matrix(Fl_Button* o, void* v)
  265. { ((MatrixPluginGUI*)(o->parent()))->cb_Matrix_i(o,v);}
  266. inline void MatrixPluginGUI::cb_MatVol_i(Fl_Button* o, void* v)
  267. {
  268. m_GUICH->Set("X",*(int*)v/MATY);
  269. m_GUICH->Set("Y",*(int*)v%MATY);
  270. m_GUICH->Set("Volume",((Fl_MatrixButton*)o)->GetVolume());
  271. m_GUICH->SetCommand(MatrixPlugin::MAT_VOLUME);
  272. }
  273. void MatrixPluginGUI::cb_MatVol(Fl_Button* o, void* v)
  274. { ((MatrixPluginGUI*)(o->parent()))->cb_MatVol_i(o,v);}
  275. inline void MatrixPluginGUI::cb_Pattern_i(Fl_Counter* o, void* v)
  276. {
  277. if (o->value()<0) o->value(0);
  278. if (o->value()>NUM_PATTERNS-1) o->value(NUM_PATTERNS-1);
  279. m_GUICH->Set("Current",(int)o->value());
  280. UpdateMatrix();
  281. }
  282. void MatrixPluginGUI::cb_Pattern(Fl_Counter* o, void* v)
  283. { ((MatrixPluginGUI*)(o->parent()))->cb_Pattern_i(o,v);}
  284. inline void MatrixPluginGUI::cb_PlayPattern_i(Fl_Counter* o, void* v)
  285. {
  286. if (o->value()<0) o->value(0);
  287. if (o->value()>NUM_PATTERNS-1) o->value(NUM_PATTERNS-1);
  288. m_GUICH->Set("Num",(int)o->value());
  289. m_GUICH->SetCommand(MatrixPlugin::SET_CURRENT);
  290. }
  291. void MatrixPluginGUI::cb_PlayPattern(Fl_Counter* o, void* v)
  292. { ((MatrixPluginGUI*)(o->parent()))->cb_PlayPattern_i(o,v);}
  293. inline void MatrixPluginGUI::cb_Length_i(Fl_Counter* o, void* v)
  294. {
  295. if (o->value()<1) o->value(1);
  296. if (o->value()>64) o->value(64);
  297. m_GUICH->Set("Length",(int)o->value());
  298. m_GUICH->SetCommand(MatrixPlugin::MAT_LENGTH);
  299. }
  300. void MatrixPluginGUI::cb_Length(Fl_Counter* o, void* v)
  301. { ((MatrixPluginGUI*)(o->parent()))->cb_Length_i(o,v);}
  302. inline void MatrixPluginGUI::cb_Speed_i(Fl_Knob* o, void* v)
  303. {
  304. // Round off value, but it should be a float for tweaking
  305. float value=o->value()+((int)o->value()-o->value());
  306. m_SpeedVal->value(value);
  307. m_GUICH->Set("Speed",(float)value/8.0f);
  308. m_GUICH->SetCommand(MatrixPlugin::MAT_SPEED);
  309. }
  310. void MatrixPluginGUI::cb_Speed(Fl_Knob* o, void* v)
  311. { ((MatrixPluginGUI*)(o->parent()))->cb_Speed_i(o,v);}
  312. inline void MatrixPluginGUI::cb_Octave_i(Fl_Counter* o, void* v)
  313. {
  314. if (o->value()<0) o->value(0);
  315. if (o->value()>6) o->value(6);
  316. m_GUICH->Set("Octave",(int)o->value());
  317. m_GUICH->SetCommand(MatrixPlugin::MAT_OCTAVE);
  318. }
  319. void MatrixPluginGUI::cb_Octave(Fl_Counter* o, void* v)
  320. { ((MatrixPluginGUI*)(o->parent()))->cb_Octave_i(o,v);}
  321. inline void MatrixPluginGUI::cb_SpeedVal_i (Fl_Counter* o, void* v)
  322. {
  323. m_Speed->value(o->value());
  324. }
  325. void MatrixPluginGUI::cb_SpeedVal (Fl_Counter* o, void* v)
  326. {
  327. ((MatrixPluginGUI*)(o->parent())) -> cb_SpeedVal_i (o, v);
  328. }
  329. inline void MatrixPluginGUI::cb_CopyBtn_i (Fl_Button* o, void* v)
  330. {
  331. m_PasteBtn->activate();
  332. m_GUICH->SetCommand(MatrixPlugin::COPY);
  333. UpdateMatrix();
  334. }
  335. void MatrixPluginGUI::cb_CopyBtn (Fl_Button* o, void* v)
  336. {
  337. ((MatrixPluginGUI*)(o->parent())) -> cb_CopyBtn_i (o, v);
  338. }
  339. inline void MatrixPluginGUI::cb_PasteBtn_i (Fl_Button* o, void* v)
  340. {
  341. m_GUICH->SetCommand(MatrixPlugin::PASTE);
  342. UpdateMatrix();
  343. }
  344. void MatrixPluginGUI::cb_PasteBtn (Fl_Button* o, void* v)
  345. {
  346. ((MatrixPluginGUI*)(o->parent())) -> cb_PasteBtn_i (o, v);
  347. }
  348. inline void MatrixPluginGUI::cb_ClearBtn_i (Fl_Button* o, void* v)
  349. {
  350. m_GUICH->SetCommand(MatrixPlugin::CLEAR);
  351. UpdateMatrix();
  352. }
  353. void MatrixPluginGUI::cb_ClearBtn (Fl_Button* o, void* v)
  354. {
  355. ((MatrixPluginGUI*)(o->parent())) -> cb_ClearBtn_i (o, v);
  356. }
  357. inline void MatrixPluginGUI::cb_TransUpBtn_i (Fl_Button* o, void* v)
  358. {
  359. m_GUICH->SetCommand(MatrixPlugin::TUP);
  360. UpdateMatrix();
  361. }
  362. void MatrixPluginGUI::cb_TransUpBtn (Fl_Button* o, void* v)
  363. {
  364. ((MatrixPluginGUI*)(o->parent())) -> cb_TransUpBtn_i (o, v);
  365. }
  366. inline void MatrixPluginGUI::cb_TransDnBtn_i (Fl_Button* o, void* v)
  367. {
  368. m_GUICH->SetCommand(MatrixPlugin::TDOWN);
  369. UpdateMatrix();
  370. }
  371. void MatrixPluginGUI::cb_TransDnBtn (Fl_Button* o, void* v)
  372. {
  373. ((MatrixPluginGUI*)(o->parent())) -> cb_TransDnBtn_i (o, v);
  374. }
  375. const string MatrixPluginGUI::GetHelpText(const string &loc){
  376. return string("")
  377. + "This is a matrix style step sequencer for techno purists. Great for\n"
  378. + "drum programming, but also capable of robotic bass and melodies.\n\n"
  379. + "Note events are turned on and off by activating the 64*32 grid of\n"
  380. + "toggle buttons on the GUI. The speed and octave of the notes can be\n"
  381. + "set. The length of the pattern in notes and note cut are also\n"
  382. + "present. The current play position is indicated by the row of LED's\n"
  383. + "along the top of the plugin window. You can copy and paste between\n"
  384. + "different patterns and transpose the notes\n\n"
  385. + "16 triggers are supplied for simultaneous triggering of samples in the\n"
  386. + "sampler plugin (for instance).\n\n"
  387. + "Each Matrix plugin can contain up to 16 different patterns, these are\n"
  388. + "selectable on the plugin GUI, and triggerable by the play trigger CV.\n"
  389. + "This CV input takes a note frequency CV rather than just a trigger,\n"
  390. + "and the bottom 16 notes on the midi scale trigger the 16 patterns.\n"
  391. + "This means that a matrix can trigger another matrix, if set to a much\n"
  392. + "lower speed, and (set to octave 0) the notes trigger the differnt\n"
  393. + "patterns in the slave matrix.\n\n"
  394. + "The external clock input is an important alternative to the matrixes\n"
  395. + "internal clock, it allows you to have multiple matrixes powered from one\n"
  396. + "oscillator clock. To allow you to sync these matrixes, the matrix is\n"
  397. + "provided with a Reset Trigger, which when plugged into the Play Trigger\n"
  398. + "of another matrix, will synch the two so they start at the same clock\n"
  399. + "pulse.";
  400. }