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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1100 - (hide annotations) (download)
Sat Mar 17 09:20:19 2007 UTC (17 years, 1 month ago) by persson
File size: 8043 byte(s)
* code refactoring: dimregion editor and parameter editors extracted
  to separate files.
* loading progress dialog now also shown when filename is given as
  argument

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     set_value(dimreg->Gain / -655360.0);
93     this->dimreg = dimreg;
94     }
95    
96    
97     NumEntryPermille::NumEntryPermille(char* labelText,
98     uint16_t gig::DimensionRegion::* param,
99     double lower, double upper, int decimals) :
100     NumEntry<gig::DimensionRegion>(labelText, lower, upper, decimals),
101     param(param)
102     {
103     spinbutton.signal_value_changed().connect(
104     sigc::mem_fun(*this, &NumEntryPermille::value_changed));
105     }
106    
107     void NumEntryPermille::value_changed()
108     {
109     if (dimreg && update_gui) {
110     dimreg->*param = uint16_t(spinbutton.get_value() * 10 + 0.5);
111     }
112     }
113    
114     void NumEntryPermille::set_dimreg(gig::DimensionRegion* dimreg)
115     {
116     this->dimreg = 0;
117     set_value(dimreg->*param / 10.0);
118     this->dimreg = dimreg;
119     }
120    
121    
122     NoteEntry::NoteEntry(char* labelText, uint8_t& (*access)(gig::DimensionRegion*)) :
123     NumEntryX<uint8_t>(labelText, access)
124     {
125     spinbutton.signal_input().connect(
126     sigc::mem_fun(*this, &NoteEntry::on_input));
127     spinbutton.signal_output().connect(
128     sigc::mem_fun(*this, &NoteEntry::on_output));
129     }
130    
131     const char* notes[] = {
132     "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"
133     };
134    
135    
136     // Convert the Entry text to a number
137     int NoteEntry::on_input(double* new_value)
138     {
139     const char* str = spinbutton.get_text().c_str();
140    
141     int i;
142     for (i = 11 ; i >= 0 ; i--) {
143     if (strncmp(str, notes[i], strlen(notes[i])) == 0) break;
144     }
145     if (i >= 0) {
146     char* endptr;
147     long x = strtol(str + strlen(notes[i]), &endptr, 10);
148     if (endptr != str + strlen(notes[i])) {
149     *new_value = i + (x + 1) * 12;
150     return true;
151     }
152     }
153     return Gtk::INPUT_ERROR;
154     }
155    
156     // Convert the Adjustment position to text
157     bool NoteEntry::on_output()
158     {
159     int x = int(spinbutton.get_adjustment()->get_value());
160     char buf[10];
161     sprintf(buf, "%s%d", notes[x % 12], x / 12 - 1);
162     spinbutton.set_text(buf);
163     return true;
164     }
165    
166     BoolEntry::BoolEntry(char* labelText, bool gig::DimensionRegion::* param) :
167     LabelWidget(labelText, checkbutton),
168     param(param)
169     {
170     checkbutton.signal_toggled().connect(
171     sigc::mem_fun(*this, &BoolEntry::value_changed));
172     }
173    
174     void BoolEntry::value_changed()
175     {
176     if (dimreg && update_gui) {
177     dimreg->*param = checkbutton.get_active();
178     }
179     }
180    
181     void BoolEntry::set_dimreg(gig::DimensionRegion* dimreg)
182     {
183     this->dimreg = 0;
184     checkbutton.set_active(dimreg->*param);
185     this->dimreg = dimreg;
186     }
187    
188     ChoiceEntryLeverageCtrl::ChoiceEntryLeverageCtrl(
189     char* labelText,
190     gig::leverage_ctrl_t gig::DimensionRegion::* param) :
191     align(0, 0, 0, 0),
192     LabelWidget(labelText, align),
193     param(param)
194     {
195     for (int i = 0 ; i < 99 ; i++) {
196     if (controlChangeTexts[i]) {
197     combobox.append_text(controlChangeTexts[i]);
198     }
199     }
200     combobox.signal_changed().connect(
201     sigc::mem_fun(*this, &ChoiceEntryLeverageCtrl::value_changed));
202     align.add(combobox);
203     }
204    
205     void ChoiceEntryLeverageCtrl::value_changed()
206     {
207     if (dimreg && update_gui) {
208     int rowno = combobox.get_active_row_number();
209     switch (rowno)
210     {
211     case -1:
212     break;
213     case 0:
214     (dimreg->*param).type = gig::leverage_ctrl_t::type_none;
215     break;
216     case 1:
217     (dimreg->*param).type =
218     gig::leverage_ctrl_t::type_channelaftertouch;
219     break;
220     case 2:
221     (dimreg->*param).type = gig::leverage_ctrl_t::type_velocity;
222     break;
223     default:
224     (dimreg->*param).type = gig::leverage_ctrl_t::type_controlchange;
225     int x = 3;
226     for (int cc = 0 ; cc < 96 ; cc++) {
227     if (controlChangeTexts[cc + 3]) {
228     if (rowno == x) {
229     (dimreg->*param).controller_number = cc;
230     break;
231     }
232     x++;
233     }
234     }
235     break;
236     }
237     }
238     }
239    
240     void ChoiceEntryLeverageCtrl::set_dimreg(gig::DimensionRegion* dimreg)
241     {
242     this->dimreg = 0;
243     gig::leverage_ctrl_t c = dimreg->*param;
244     int x;
245     switch (c.type)
246     {
247     case gig::leverage_ctrl_t::type_none:
248     x = 0;
249     break;
250     case gig::leverage_ctrl_t::type_channelaftertouch:
251     x = 1;
252     break;
253     case gig::leverage_ctrl_t::type_velocity:
254     x = 2;
255     break;
256     case gig::leverage_ctrl_t::type_controlchange:
257     x = -1;
258     for (int cc = 0 ; cc < 96 ; cc++) {
259     if (controlChangeTexts[cc + 3]) {
260     x++;
261     if (c.controller_number == cc) {
262     x += 3;
263     break;
264     }
265     }
266     }
267     break;
268     default:
269     x = -1;
270     break;
271     }
272     combobox.set_active(x);
273     this->dimreg = dimreg;
274     }

  ViewVC Help
Powered by ViewVC