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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1117 - (hide annotations) (download)
Sat Mar 24 13:05:58 2007 UTC (17 years, 1 month ago) by persson
File size: 8366 byte(s)
* added +6dB parameter to DimRegionEdit
* preparations for improved instrument properties dialog

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     namespace {
23     const char* const controlChangeTexts[] = {
24     "none", "channelaftertouch", "velocity",
25     0,
26     "modwheel", // "Modulation Wheel or Lever",
27     "breath", // "Breath Controller",
28     0,
29     "foot", // "Foot Controller",
30     "portamentotime", // "Portamento Time",
31     0, 0, 0, 0, 0, 0,
32     "effect1", // "Effect Control 1",
33     "effect2", // "Effect Control 2",
34     0, 0,
35     "genpurpose1", // "General Purpose Controller 1",
36     "genpurpose2", // "General Purpose Controller 2",
37     "genpurpose3", // "General Purpose Controller 3",
38     "genpurpose4", // "General Purpose Controller 4",
39     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
40     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41     0, 0, 0, 0, 0, 0,
42     "sustainpedal", // "Damper Pedal on/off (Sustain)",
43     "portamento", // "Portamento On/Off",
44     "sostenuto", // "Sustenuto On/Off",
45     "softpedal", // "Soft Pedal On/Off",
46     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47     "genpurpose5", // "General Purpose Controller 5",
48     "genpurpose6", // "General Purpose Controller 6",
49     "genpurpose7", // "General Purpose Controller 7",
50     "genpurpose8", // "General Purpose Controller 8",
51     0, 0, 0, 0, 0, 0, 0,
52     "effect1depth", // "Effects 1 Depth",
53     "effect2depth", // "Effects 2 Depth",
54     "effect3depth", // "Effects 3 Depth",
55     "effect4depth", // "Effects 4 Depth",
56     "effect5depth", // "Effects 5 Depth"
57     };
58     }
59    
60     LabelWidget::LabelWidget(char* labelText, Gtk::Widget& widget) :
61     label(Glib::ustring(labelText) + ":"),
62     widget(widget)
63     {
64     label.set_alignment(Gtk::ALIGN_LEFT);
65     }
66    
67     void LabelWidget::set_sensitive(bool sensitive)
68     {
69     label.set_sensitive(sensitive);
70     widget.set_sensitive(sensitive);
71     }
72    
73     NumEntryGain::NumEntryGain(char* labelText,
74     double lower = 0, double upper = 127,
75     int decimals = 0) :
76     NumEntry<gig::DimensionRegion>(labelText, lower, upper, decimals)
77     {
78     spinbutton.signal_value_changed().connect(
79     sigc::mem_fun(*this, &NumEntryGain::value_changed));
80     }
81    
82     void NumEntryGain::value_changed()
83     {
84     if (dimreg && update_gui) {
85     dimreg->Gain = int32_t(spinbutton.get_value() * -655360.0);
86     }
87     }
88    
89     void NumEntryGain::set_dimreg(gig::DimensionRegion* dimreg)
90     {
91     this->dimreg = 0;
92 persson 1117 bool plus6 = dimreg->Gain < 0;
93     set_value(plus6 ? 0 : dimreg->Gain / -655360.0);
94     set_sensitive(!plus6);
95 persson 1100 this->dimreg = dimreg;
96     }
97    
98    
99 persson 1117 BoolEntryPlus6::BoolEntryPlus6(char* labelText, NumEntryGain& eGain) :
100     LabelWidget(labelText, checkbutton),
101     eGain(eGain)
102     {
103     checkbutton.signal_toggled().connect(
104     sigc::mem_fun(*this, &BoolEntryPlus6::value_changed));
105     }
106    
107     void BoolEntryPlus6::value_changed()
108     {
109     if (dimreg && update_gui) {
110     bool plus6 = checkbutton.get_active();
111     if (plus6) {
112     eGain.set_value(0);
113     dimreg->Gain = 6 * -655360;
114     } else {
115     if (dimreg->Gain < 0) {
116     dimreg->Gain = 0;
117     }
118     }
119     eGain.set_sensitive(!plus6);
120     }
121     }
122    
123     void BoolEntryPlus6::set_dimreg(gig::DimensionRegion* dimreg)
124     {
125     this->dimreg = 0;
126     checkbutton.set_active(dimreg->Gain < 0);
127     this->dimreg = dimreg;
128     }
129    
130 persson 1100 NumEntryPermille::NumEntryPermille(char* labelText,
131     uint16_t gig::DimensionRegion::* param,
132     double lower, double upper, int decimals) :
133     NumEntry<gig::DimensionRegion>(labelText, lower, upper, decimals),
134     param(param)
135     {
136     spinbutton.signal_value_changed().connect(
137     sigc::mem_fun(*this, &NumEntryPermille::value_changed));
138     }
139    
140     void NumEntryPermille::value_changed()
141     {
142     if (dimreg && update_gui) {
143     dimreg->*param = uint16_t(spinbutton.get_value() * 10 + 0.5);
144     }
145     }
146    
147     void NumEntryPermille::set_dimreg(gig::DimensionRegion* dimreg)
148     {
149     this->dimreg = 0;
150     set_value(dimreg->*param / 10.0);
151     this->dimreg = dimreg;
152     }
153    
154    
155     NoteEntry::NoteEntry(char* labelText, uint8_t& (*access)(gig::DimensionRegion*)) :
156     NumEntryX<uint8_t>(labelText, access)
157     {
158     spinbutton.signal_input().connect(
159     sigc::mem_fun(*this, &NoteEntry::on_input));
160     spinbutton.signal_output().connect(
161     sigc::mem_fun(*this, &NoteEntry::on_output));
162     }
163    
164     const char* notes[] = {
165     "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"
166     };
167    
168    
169     // Convert the Entry text to a number
170     int NoteEntry::on_input(double* new_value)
171     {
172     const char* str = spinbutton.get_text().c_str();
173    
174     int i;
175     for (i = 11 ; i >= 0 ; i--) {
176     if (strncmp(str, notes[i], strlen(notes[i])) == 0) break;
177     }
178     if (i >= 0) {
179     char* endptr;
180     long x = strtol(str + strlen(notes[i]), &endptr, 10);
181     if (endptr != str + strlen(notes[i])) {
182     *new_value = i + (x + 1) * 12;
183     return true;
184     }
185     }
186     return Gtk::INPUT_ERROR;
187     }
188    
189     // Convert the Adjustment position to text
190     bool NoteEntry::on_output()
191     {
192     int x = int(spinbutton.get_adjustment()->get_value());
193     char buf[10];
194     sprintf(buf, "%s%d", notes[x % 12], x / 12 - 1);
195     spinbutton.set_text(buf);
196     return true;
197     }
198    
199     ChoiceEntryLeverageCtrl::ChoiceEntryLeverageCtrl(
200     char* labelText,
201     gig::leverage_ctrl_t gig::DimensionRegion::* param) :
202     align(0, 0, 0, 0),
203     LabelWidget(labelText, align),
204     param(param)
205     {
206     for (int i = 0 ; i < 99 ; i++) {
207     if (controlChangeTexts[i]) {
208     combobox.append_text(controlChangeTexts[i]);
209     }
210     }
211     combobox.signal_changed().connect(
212     sigc::mem_fun(*this, &ChoiceEntryLeverageCtrl::value_changed));
213     align.add(combobox);
214     }
215    
216     void ChoiceEntryLeverageCtrl::value_changed()
217     {
218     if (dimreg && update_gui) {
219     int rowno = combobox.get_active_row_number();
220     switch (rowno)
221     {
222     case -1:
223     break;
224     case 0:
225     (dimreg->*param).type = gig::leverage_ctrl_t::type_none;
226     break;
227     case 1:
228     (dimreg->*param).type =
229     gig::leverage_ctrl_t::type_channelaftertouch;
230     break;
231     case 2:
232     (dimreg->*param).type = gig::leverage_ctrl_t::type_velocity;
233     break;
234     default:
235     (dimreg->*param).type = gig::leverage_ctrl_t::type_controlchange;
236     int x = 3;
237     for (int cc = 0 ; cc < 96 ; cc++) {
238     if (controlChangeTexts[cc + 3]) {
239     if (rowno == x) {
240     (dimreg->*param).controller_number = cc;
241     break;
242     }
243     x++;
244     }
245     }
246     break;
247     }
248     }
249     }
250    
251     void ChoiceEntryLeverageCtrl::set_dimreg(gig::DimensionRegion* dimreg)
252     {
253     this->dimreg = 0;
254     gig::leverage_ctrl_t c = dimreg->*param;
255     int x;
256     switch (c.type)
257     {
258     case gig::leverage_ctrl_t::type_none:
259     x = 0;
260     break;
261     case gig::leverage_ctrl_t::type_channelaftertouch:
262     x = 1;
263     break;
264     case gig::leverage_ctrl_t::type_velocity:
265     x = 2;
266     break;
267     case gig::leverage_ctrl_t::type_controlchange:
268     x = -1;
269     for (int cc = 0 ; cc < 96 ; cc++) {
270     if (controlChangeTexts[cc + 3]) {
271     x++;
272     if (c.controller_number == cc) {
273     x += 3;
274     break;
275     }
276     }
277     }
278     break;
279     default:
280     x = -1;
281     break;
282     }
283     combobox.set_active(x);
284     this->dimreg = dimreg;
285     }

  ViewVC Help
Powered by ViewVC