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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1225 - (hide annotations) (download)
Sun Jun 10 10:56:11 2007 UTC (16 years, 10 months ago) by schoenebeck
File size: 9146 byte(s)
moved gigedit sources from src/ -> src/gigedit/

1 schoenebeck 1225 /*
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     bool update_gui;
23    
24     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(const 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     NumEntry::NumEntry(const 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     NumEntryGain::NumEntryGain(const char* labelText,
89     double lower, double upper,
90     int decimals, double coeff) :
91     NumEntry(labelText, lower, upper, decimals),
92     coeff(coeff)
93     {
94     spinbutton.signal_value_changed().connect(
95     sigc::mem_fun(*this, &NumEntryGain::value_changed));
96     }
97    
98     void NumEntryGain::value_changed()
99     {
100     if (ptr && update_gui) {
101     *ptr = int32_t(spinbutton.get_value() * coeff);
102     }
103     }
104    
105     void NumEntryGain::set_ptr(int32_t* ptr)
106     {
107     this->ptr = 0;
108     bool plus6 = *ptr < 0;
109     set_value(plus6 ? 0 : *ptr / coeff);
110     set_sensitive(!plus6);
111     this->ptr = ptr;
112     }
113    
114    
115     BoolEntryPlus6::BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value) :
116     LabelWidget(labelText, checkbutton),
117     eGain(eGain),
118     plus6value(plus6value)
119     {
120     checkbutton.signal_toggled().connect(
121     sigc::mem_fun(*this, &BoolEntryPlus6::value_changed));
122     }
123    
124     void BoolEntryPlus6::value_changed()
125     {
126     if (ptr && update_gui) {
127     bool plus6 = checkbutton.get_active();
128     if (plus6) {
129     eGain.set_value(0);
130     *ptr = plus6value;
131     } else {
132     if (*ptr < 0) {
133     *ptr = 0;
134     }
135     }
136     eGain.set_sensitive(!plus6);
137     }
138     }
139    
140     void BoolEntryPlus6::set_ptr(int32_t* ptr)
141     {
142     this->ptr = 0;
143     checkbutton.set_active(*ptr < 0);
144     this->ptr = ptr;
145     }
146    
147     NumEntryPermille::NumEntryPermille(const char* labelText,
148     double lower, double upper, int decimals) :
149     NumEntry(labelText, lower, upper, decimals)
150     {
151     spinbutton.signal_value_changed().connect(
152     sigc::mem_fun(*this, &NumEntryPermille::value_changed));
153     }
154    
155     void NumEntryPermille::value_changed()
156     {
157     if (ptr && update_gui) {
158     *ptr = uint16_t(spinbutton.get_value() * 10 + 0.5);
159     }
160     }
161    
162     void NumEntryPermille::set_ptr(uint16_t* ptr)
163     {
164     this->ptr = 0;
165     set_value(*ptr / 10.0);
166     this->ptr = ptr;
167     }
168    
169    
170     NoteEntry::NoteEntry(const char* labelText) :
171     NumEntryTemp<uint8_t>(labelText)
172     {
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     ChoiceEntryLeverageCtrl::ChoiceEntryLeverageCtrl(const char* labelText) :
215     align(0, 0, 0, 0),
216     LabelWidget(labelText, align)
217     {
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     if (ptr && update_gui) {
231     int rowno = combobox.get_active_row_number();
232     switch (rowno)
233     {
234     case -1:
235     break;
236     case 0:
237     ptr->type = gig::leverage_ctrl_t::type_none;
238     break;
239     case 1:
240     ptr->type = gig::leverage_ctrl_t::type_channelaftertouch;
241     break;
242     case 2:
243     ptr->type = gig::leverage_ctrl_t::type_velocity;
244     break;
245     default:
246     ptr->type = gig::leverage_ctrl_t::type_controlchange;
247     int x = 3;
248     for (int cc = 0 ; cc < 96 ; cc++) {
249     if (controlChangeTexts[cc + 3]) {
250     if (rowno == x) {
251     ptr->controller_number = cc;
252     break;
253     }
254     x++;
255     }
256     }
257     break;
258     }
259     }
260     }
261    
262     void ChoiceEntryLeverageCtrl::set_ptr(gig::leverage_ctrl_t* ptr)
263     {
264     this->ptr = 0;
265     int x;
266     switch (ptr->type)
267     {
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     if (ptr->controller_number == cc) {
283     x += 3;
284     break;
285     }
286     }
287     }
288     break;
289     default:
290     x = -1;
291     break;
292     }
293     combobox.set_active(x);
294     this->ptr = ptr;
295     }
296    
297    
298     BoolEntry::BoolEntry(const char* labelText) :
299     LabelWidget(labelText, checkbutton),
300     checkbutton(labelText),
301     ptr(0)
302     {
303     checkbutton.signal_toggled().connect(
304     sigc::mem_fun(*this, &BoolEntry::value_changed));
305     }
306    
307     void BoolEntry::value_changed()
308     {
309     if (ptr && update_gui) {
310     *ptr = checkbutton.get_active();
311     }
312     }
313    
314     void BoolEntry::set_ptr(bool* ptr)
315     {
316     this->ptr = 0;
317     checkbutton.set_active(*ptr);
318     this->ptr = ptr;
319     }
320    
321    
322     StringEntry::StringEntry(const char* labelText) :
323     LabelWidget(labelText, entry)
324     {
325     entry.signal_changed().connect(
326     sigc::mem_fun(*this, &StringEntry::value_changed));
327     }
328    
329     void StringEntry::value_changed()
330     {
331     if (ptr && update_gui) {
332     *ptr = entry.get_text();
333     }
334     }
335    
336     void StringEntry::set_ptr(gig::String* ptr)
337     {
338     this->ptr = 0;
339     entry.set_text(*ptr);
340     this->ptr = ptr;
341     }

  ViewVC Help
Powered by ViewVC