/[svn]/gigedit/trunk/src/paramedit.cpp
ViewVC logotype

Annotation of /gigedit/trunk/src/paramedit.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1138 - (hide annotations) (download)
Sat Mar 31 09:33:40 2007 UTC (17 years ago) by persson
File size: 9052 byte(s)
* reworked instrument properties dialog - properties can now be edited
* code cleanup: removed the pointer to member usage in paramedit as it
  just made things more complicated

1 persson 1100 /*
2     * Copyright (C) 2006, 2007 Andreas Persson
3     *
4     * This program is free software; you can redistribute it and/or
5     * modify it under the terms of the GNU General Public License as
6     * published by the Free Software Foundation; either version 2, or (at
7     * your option) any later version.
8     *
9     * This program is distributed in the hope that it will be useful, but
10     * WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12     * General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with program; see the file COPYING. If not, write to the Free
16     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17     * 02110-1301 USA.
18     */
19    
20     #include "paramedit.h"
21    
22 persson 1138 bool update_gui;
23    
24 persson 1100 namespace {
25     const char* const controlChangeTexts[] = {
26     "none", "channelaftertouch", "velocity",
27     0,
28     "modwheel", // "Modulation Wheel or Lever",
29     "breath", // "Breath Controller",
30     0,
31     "foot", // "Foot Controller",
32     "portamentotime", // "Portamento Time",
33     0, 0, 0, 0, 0, 0,
34     "effect1", // "Effect Control 1",
35     "effect2", // "Effect Control 2",
36     0, 0,
37     "genpurpose1", // "General Purpose Controller 1",
38     "genpurpose2", // "General Purpose Controller 2",
39     "genpurpose3", // "General Purpose Controller 3",
40     "genpurpose4", // "General Purpose Controller 4",
41     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43     0, 0, 0, 0, 0, 0,
44     "sustainpedal", // "Damper Pedal on/off (Sustain)",
45     "portamento", // "Portamento On/Off",
46     "sostenuto", // "Sustenuto On/Off",
47     "softpedal", // "Soft Pedal On/Off",
48     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49     "genpurpose5", // "General Purpose Controller 5",
50     "genpurpose6", // "General Purpose Controller 6",
51     "genpurpose7", // "General Purpose Controller 7",
52     "genpurpose8", // "General Purpose Controller 8",
53     0, 0, 0, 0, 0, 0, 0,
54     "effect1depth", // "Effects 1 Depth",
55     "effect2depth", // "Effects 2 Depth",
56     "effect3depth", // "Effects 3 Depth",
57     "effect4depth", // "Effects 4 Depth",
58     "effect5depth", // "Effects 5 Depth"
59     };
60     }
61    
62     LabelWidget::LabelWidget(char* labelText, Gtk::Widget& widget) :
63     label(Glib::ustring(labelText) + ":"),
64     widget(widget)
65     {
66     label.set_alignment(Gtk::ALIGN_LEFT);
67     }
68    
69     void LabelWidget::set_sensitive(bool sensitive)
70     {
71     label.set_sensitive(sensitive);
72     widget.set_sensitive(sensitive);
73     }
74    
75 persson 1138 NumEntry::NumEntry(char* labelText, double lower, double upper,
76     int decimals) :
77     adjust(lower, lower, upper, 1, 10),
78     scale(adjust),
79     spinbutton(adjust),
80     LabelWidget(labelText, box)
81     {
82     spinbutton.set_digits(decimals);
83     scale.set_draw_value(false);
84     box.pack_start(spinbutton, Gtk::PACK_SHRINK);
85     box.add(scale);
86     }
87    
88 persson 1100 NumEntryGain::NumEntryGain(char* labelText,
89 persson 1138 double lower, double upper,
90     int decimals, double coeff) :
91     NumEntry(labelText, lower, upper, decimals),
92     coeff(coeff)
93 persson 1100 {
94     spinbutton.signal_value_changed().connect(
95     sigc::mem_fun(*this, &NumEntryGain::value_changed));
96     }
97    
98     void NumEntryGain::value_changed()
99     {
100 persson 1138 if (ptr && update_gui) {
101     *ptr = int32_t(spinbutton.get_value() * coeff);
102 persson 1100 }
103     }
104    
105 persson 1138 void NumEntryGain::set_ptr(int32_t* ptr)
106 persson 1100 {
107 persson 1138 this->ptr = 0;
108     bool plus6 = *ptr < 0;
109     set_value(plus6 ? 0 : *ptr / coeff);
110 persson 1117 set_sensitive(!plus6);
111 persson 1138 this->ptr = ptr;
112 persson 1100 }
113    
114    
115 persson 1138 BoolEntryPlus6::BoolEntryPlus6(char* labelText, NumEntryGain& eGain, int32_t plus6value) :
116 persson 1117 LabelWidget(labelText, checkbutton),
117 persson 1138 eGain(eGain),
118     plus6value(plus6value)
119 persson 1117 {
120     checkbutton.signal_toggled().connect(
121     sigc::mem_fun(*this, &BoolEntryPlus6::value_changed));
122     }
123    
124     void BoolEntryPlus6::value_changed()
125     {
126 persson 1138 if (ptr && update_gui) {
127 persson 1117 bool plus6 = checkbutton.get_active();
128     if (plus6) {
129     eGain.set_value(0);
130 persson 1138 *ptr = plus6value;
131 persson 1117 } else {
132 persson 1138 if (*ptr < 0) {
133     *ptr = 0;
134 persson 1117 }
135     }
136     eGain.set_sensitive(!plus6);
137     }
138     }
139    
140 persson 1138 void BoolEntryPlus6::set_ptr(int32_t* ptr)
141 persson 1117 {
142 persson 1138 this->ptr = 0;
143     checkbutton.set_active(*ptr < 0);
144     this->ptr = ptr;
145 persson 1117 }
146    
147 persson 1100 NumEntryPermille::NumEntryPermille(char* labelText,
148     double lower, double upper, int decimals) :
149 persson 1138 NumEntry(labelText, lower, upper, decimals)
150 persson 1100 {
151     spinbutton.signal_value_changed().connect(
152     sigc::mem_fun(*this, &NumEntryPermille::value_changed));
153     }
154    
155     void NumEntryPermille::value_changed()
156     {
157 persson 1138 if (ptr && update_gui) {
158     *ptr = uint16_t(spinbutton.get_value() * 10 + 0.5);
159 persson 1100 }
160     }
161    
162 persson 1138 void NumEntryPermille::set_ptr(uint16_t* ptr)
163 persson 1100 {
164 persson 1138 this->ptr = 0;
165     set_value(*ptr / 10.0);
166     this->ptr = ptr;
167 persson 1100 }
168    
169    
170 persson 1138 NoteEntry::NoteEntry(char* labelText) :
171     NumEntryTemp<uint8_t>(labelText)
172 persson 1100 {
173     spinbutton.signal_input().connect(
174     sigc::mem_fun(*this, &NoteEntry::on_input));
175     spinbutton.signal_output().connect(
176     sigc::mem_fun(*this, &NoteEntry::on_output));
177     }
178    
179     const char* notes[] = {
180     "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"
181     };
182    
183    
184     // Convert the Entry text to a number
185     int NoteEntry::on_input(double* new_value)
186     {
187     const char* str = spinbutton.get_text().c_str();
188    
189     int i;
190     for (i = 11 ; i >= 0 ; i--) {
191     if (strncmp(str, notes[i], strlen(notes[i])) == 0) break;
192     }
193     if (i >= 0) {
194     char* endptr;
195     long x = strtol(str + strlen(notes[i]), &endptr, 10);
196     if (endptr != str + strlen(notes[i])) {
197     *new_value = i + (x + 1) * 12;
198     return true;
199     }
200     }
201     return Gtk::INPUT_ERROR;
202     }
203    
204     // Convert the Adjustment position to text
205     bool NoteEntry::on_output()
206     {
207     int x = int(spinbutton.get_adjustment()->get_value());
208     char buf[10];
209     sprintf(buf, "%s%d", notes[x % 12], x / 12 - 1);
210     spinbutton.set_text(buf);
211     return true;
212     }
213    
214 persson 1138 ChoiceEntryLeverageCtrl::ChoiceEntryLeverageCtrl(char* labelText) :
215 persson 1100 align(0, 0, 0, 0),
216 persson 1138 LabelWidget(labelText, align)
217 persson 1100 {
218     for (int i = 0 ; i < 99 ; i++) {
219     if (controlChangeTexts[i]) {
220     combobox.append_text(controlChangeTexts[i]);
221     }
222     }
223     combobox.signal_changed().connect(
224     sigc::mem_fun(*this, &ChoiceEntryLeverageCtrl::value_changed));
225     align.add(combobox);
226     }
227    
228     void ChoiceEntryLeverageCtrl::value_changed()
229     {
230 persson 1138 if (ptr && update_gui) {
231 persson 1100 int rowno = combobox.get_active_row_number();
232     switch (rowno)
233     {
234     case -1:
235     break;
236     case 0:
237 persson 1138 ptr->type = gig::leverage_ctrl_t::type_none;
238 persson 1100 break;
239     case 1:
240 persson 1138 ptr->type = gig::leverage_ctrl_t::type_channelaftertouch;
241 persson 1100 break;
242     case 2:
243 persson 1138 ptr->type = gig::leverage_ctrl_t::type_velocity;
244 persson 1100 break;
245     default:
246 persson 1138 ptr->type = gig::leverage_ctrl_t::type_controlchange;
247 persson 1100 int x = 3;
248     for (int cc = 0 ; cc < 96 ; cc++) {
249     if (controlChangeTexts[cc + 3]) {
250     if (rowno == x) {
251 persson 1138 ptr->controller_number = cc;
252 persson 1100 break;
253     }
254     x++;
255     }
256     }
257     break;
258     }
259     }
260     }
261    
262 persson 1138 void ChoiceEntryLeverageCtrl::set_ptr(gig::leverage_ctrl_t* ptr)
263 persson 1100 {
264 persson 1138 this->ptr = 0;
265 persson 1100 int x;
266 persson 1138 switch (ptr->type)
267 persson 1100 {
268     case gig::leverage_ctrl_t::type_none:
269     x = 0;
270     break;
271     case gig::leverage_ctrl_t::type_channelaftertouch:
272     x = 1;
273     break;
274     case gig::leverage_ctrl_t::type_velocity:
275     x = 2;
276     break;
277     case gig::leverage_ctrl_t::type_controlchange:
278     x = -1;
279     for (int cc = 0 ; cc < 96 ; cc++) {
280     if (controlChangeTexts[cc + 3]) {
281     x++;
282 persson 1138 if (ptr->controller_number == cc) {
283 persson 1100 x += 3;
284     break;
285     }
286     }
287     }
288     break;
289     default:
290     x = -1;
291     break;
292     }
293     combobox.set_active(x);
294 persson 1138 this->ptr = ptr;
295 persson 1100 }
296 persson 1138
297    
298     BoolEntry::BoolEntry(char* labelText) :
299     LabelWidget(labelText, checkbutton)
300     {
301     checkbutton.signal_toggled().connect(
302     sigc::mem_fun(*this, &BoolEntry::value_changed));
303     }
304    
305     void BoolEntry::value_changed()
306     {
307     if (ptr && update_gui) {
308     *ptr = checkbutton.get_active();
309     }
310     }
311    
312     void BoolEntry::set_ptr(bool* ptr)
313     {
314     this->ptr = 0;
315     checkbutton.set_active(*ptr);
316     this->ptr = ptr;
317     }
318    
319    
320     StringEntry::StringEntry(char* labelText) :
321     LabelWidget(labelText, entry)
322     {
323     entry.signal_changed().connect(
324     sigc::mem_fun(*this, &StringEntry::value_changed));
325     }
326    
327     void StringEntry::value_changed()
328     {
329     if (ptr && update_gui) {
330     *ptr = entry.get_text();
331     }
332     }
333    
334     void StringEntry::set_ptr(gig::String* ptr)
335     {
336     this->ptr = 0;
337     entry.set_text(*ptr);
338     this->ptr = ptr;
339     }

  ViewVC Help
Powered by ViewVC