1 /* SpiralSynth
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
19 #include "PatchBankGUI.h"
20 #include "../SpiralSound/Output.h"
21
PatchBankGUI()22 PatchBankGUI::PatchBankGUI() : m_CurrentPatch(0)
23 {
24 // bit of a hack
25 for (int n=0; n<NPSEL; n++)
26 m_PatchList[n]=n;
27 }
28
CreateGUI(int xoff,int yoff,char * name)29 void PatchBankGUI::CreateGUI(int xoff, int yoff, char *name)
30 {
31 Fl_Group* o = GUIPatchBankGroup = new Fl_Group(xoff, yoff, 775, 40, name);
32 o->type(1);
33 o->box(FL_UP_BOX);
34 o->labeltype(FL_ENGRAVED_LABEL);
35 o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
36 o->user_data((void*)(this));
37
38 for(int n=0; n<NPSEL; n++)
39 {
40 Patch[n] = new Fl_Button(85+xoff+(32*n), 5+yoff, 29, 29);
41 Patch[n]->type(0);
42 Patch[n]->color(SpiralInfo::GUI_COLOUR+(n%5-2));
43 Patch[n]->selection_color(SpiralInfo::GUI_COLOUR);
44 Patch[n]->callback((Fl_Callback*)cb_Patch,(void*)&m_PatchList[n]);
45 }
46
47 Num = new Fl_Value_Output(xoff+5, yoff+18, 25, 20);
48 Num->value(0);
49
50 Select = new Fl_Knob(xoff+728, yoff+1, 37, 37);
51 Select->color(SpiralInfo::GUI_COLOUR);
52 Select->type(Fl_Knob::LINELIN);
53 Select->cursor(50);
54 Select->labelsize(10);
55 Select->maximum(4);
56 Select->step(1);
57 Select->value(0);
58 Select->scaleticks(5);
59 Select->callback((Fl_Callback*)cb_Select);
60
61 Save = new Fl_Button(35+xoff, 18+yoff, 40, 10, "Save");
62 Save->type(1);
63 Save->labelsize(10);
64 Save->selection_color(SpiralInfo::GUI_COLOUR);
65 Save->callback((Fl_Callback*)cb_Save);
66
67 Rand = new Fl_Button(35+xoff, 28+yoff, 40, 10, "Rand");
68 Rand->labelsize(10);
69 Rand->selection_color(SpiralInfo::GUI_COLOUR);
70 Rand->callback((Fl_Callback*)cb_Rand);
71
72 o->end();
73
74 }
75
GetOutput()76 int PatchBankGUI::GetOutput()
77 {
78 static int Last=-1;
79
80 if (Last!=m_CurrentPatch)
81 {
82 Last=m_CurrentPatch;
83 if (m_CurrentPatch>-1) Num->value(m_CurrentPatch);
84 int t=m_CurrentPatch;
85 if (m_CurrentPatch==-2) m_CurrentPatch=-1;
86 return t;
87 }
88
89 return -1;
90 }
91
IsSaving()92 bool PatchBankGUI::IsSaving()
93 {
94 int t=Save->value();
95 if (t)
96 {
97 Save->value(0);
98 }
99 return t;
100 }
101
102 //// Callbacks ////
103
cb_Patch_i(Fl_Button * o,void * v)104 inline void PatchBankGUI::cb_Patch_i(Fl_Button* o, void* v)
105 { m_CurrentPatch=(*(int*)(v))+(int)(Select->value()*20); }
cb_Patch(Fl_Button * o,void * v)106 void PatchBankGUI::cb_Patch(Fl_Button* o, void* v)
107 { ((PatchBankGUI*)(o->parent()->user_data()))->cb_Patch_i(o,v); }
108
cb_Select_i(Fl_Knob * o,void * v)109 inline void PatchBankGUI::cb_Select_i(Fl_Knob* o, void* v)
110 {}
cb_Select(Fl_Knob * o,void * v)111 void PatchBankGUI::cb_Select(Fl_Knob* o, void* v)
112 { ((PatchBankGUI*)(o->parent()->user_data()))->cb_Select_i(o,v); }
113
cb_Save_i(Fl_Button * o,void * v)114 inline void PatchBankGUI::cb_Save_i(Fl_Button* o, void* v)
115 {m_CurrentPatch=-1;}
cb_Save(Fl_Button * o,void * v)116 void PatchBankGUI::cb_Save(Fl_Button* o, void* v)
117 { ((PatchBankGUI*)(o->parent()->user_data()))->cb_Save_i(o,v); }
118
cb_Rand_i(Fl_Button * o,void * v)119 inline void PatchBankGUI::cb_Rand_i(Fl_Button* o, void* v)
120 {m_CurrentPatch=-2;}
cb_Rand(Fl_Button * o,void * v)121 void PatchBankGUI::cb_Rand(Fl_Button* o, void* v)
122 { ((PatchBankGUI*)(o->parent()->user_data()))->cb_Rand_i(o,v); }
123