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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1359 - (hide annotations) (download) (as text)
Sun Sep 30 18:30:52 2007 UTC (16 years, 6 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 8464 byte(s)
* fixed couple other parameters which were silently ignored by the sampler
  on a live-editing session with LS (parameter "Gain" and various velocity
  response parameters for attenuation, filter cutoff frequency and EG
  release time)

1 schoenebeck 1225 /* -*- c++ -*-
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     #ifndef GIGEDIT_PARAMEDIT_H
21     #define GIGEDIT_PARAMEDIT_H
22    
23     #include <gig.h>
24    
25 schoenebeck 1300 #include <math.h>
26    
27 schoenebeck 1225 #include <gtkmm/adjustment.h>
28     #include <gtkmm/alignment.h>
29     #include <gtkmm/box.h>
30     #include <gtkmm/comboboxtext.h>
31     #include <gtkmm/label.h>
32     #include <gtkmm/scale.h>
33     #include <gtkmm/spinbutton.h>
34     #include <gtkmm/tooltips.h>
35    
36     class LabelWidget {
37     public:
38     Gtk::Label label;
39     Gtk::Widget& widget;
40    
41     LabelWidget(const char* labelText, Gtk::Widget& widget);
42     void set_sensitive(bool sensitive = true);
43 schoenebeck 1339 sigc::signal<void>& signal_changed_by_user() {
44 persson 1261 return sig_changed;
45     }
46 schoenebeck 1225 protected:
47     Gtk::Tooltips tooltips;
48 persson 1261 sigc::signal<void> sig_changed;
49 schoenebeck 1225 };
50    
51     class NumEntry : public LabelWidget {
52     protected:
53     Gtk::Adjustment adjust;
54     Gtk::HScale scale;
55     Gtk::SpinButton spinbutton;
56     Gtk::HBox box;
57 persson 1261
58     int round_to_int(double x) {
59     return int(x < 0.0 ? x - 0.5 : x + 0.5);
60     }
61 schoenebeck 1225 public:
62     NumEntry(const char* labelText, double lower = 0, double upper = 127,
63     int decimals = 0);
64     void set_value(double value) {
65     spinbutton.set_value(value);
66     }
67     double get_value() const {
68     return spinbutton.get_value();
69     }
70     void set_tip(const Glib::ustring& tip_text) {
71     tooltips.set_tip(spinbutton, tip_text);
72     }
73     void set_upper(double upper) {
74     adjust.set_upper(upper);
75     }
76     };
77    
78     class NumEntryGain : public NumEntry {
79     private:
80     void value_changed();
81     int32_t* ptr;
82     double coeff;
83 schoenebeck 1359 protected:
84     sigc::signal<void> sig_to_be_changed;
85     sigc::signal<void, int32_t> sig_val_changed;
86 schoenebeck 1225 public:
87     NumEntryGain(const char* labelText,
88     double lower, double upper, int decimals, double coeff);
89     void set_ptr(int32_t* ptr);
90 schoenebeck 1359 sigc::signal<void>& signal_to_be_changed() {
91     return sig_to_be_changed;
92     }
93     sigc::signal<void, int32_t>& signal_value_changed() {
94     return sig_val_changed;
95     }
96 schoenebeck 1225 };
97    
98     template<typename T>
99     class NumEntryTemp : public NumEntry {
100     private:
101     T* ptr;
102     void value_changed();
103 schoenebeck 1359 protected:
104     sigc::signal<void> sig_to_be_changed;
105     sigc::signal<void, T> sig_val_changed;
106 schoenebeck 1225 public:
107     NumEntryTemp(const char* labelText,
108     double lower = 0, double upper = 127, int decimals = 0);
109     void set_ptr(T* ptr);
110 schoenebeck 1359 sigc::signal<void>& signal_to_be_changed() {
111     return sig_to_be_changed;
112     }
113     sigc::signal<void, T>& signal_value_changed() {
114     return sig_val_changed;
115     }
116 schoenebeck 1225 };
117    
118     template<typename T>
119     NumEntryTemp<T>::NumEntryTemp(const char* labelText,
120     double lower, double upper, int decimals) :
121     NumEntry(labelText, lower, upper, decimals)
122     {
123     spinbutton.signal_value_changed().connect(
124     sigc::mem_fun(*this, &NumEntryTemp::value_changed));
125     }
126    
127     template<typename T>
128     void NumEntryTemp<T>::value_changed()
129     {
130 schoenebeck 1359 const double f = pow(10, spinbutton.get_digits());
131     int new_value = round_to_int(spinbutton.get_value() * f);
132     const T val = T(new_value / f);
133 persson 1261 if (ptr) {
134     if (new_value != round_to_int(*ptr * f)) {
135 schoenebeck 1359 sig_to_be_changed.emit();
136     *ptr = val;
137     sig_val_changed.emit(val);
138     sig_changed.emit();
139 persson 1261 }
140 schoenebeck 1359 } else {
141     sig_to_be_changed.emit();
142     sig_val_changed.emit(val);
143     sig_changed.emit();
144 schoenebeck 1225 }
145     }
146    
147     template<typename T>
148     void NumEntryTemp<T>::set_ptr(T* ptr)
149     {
150     this->ptr = 0;
151     if (ptr) set_value(*ptr);
152     this->ptr = ptr;
153     }
154    
155    
156     class NoteEntry : public NumEntryTemp<uint8_t> {
157     public:
158     NoteEntry(const char* labelText);
159     private:
160     int on_input(double* new_value);
161     bool on_output();
162     };
163    
164    
165     class NumEntryPermille : public NumEntry {
166     private:
167     uint16_t* ptr;
168     void value_changed();
169     public:
170     NumEntryPermille(const char* labelText,
171     double lower = 0, double upper = 127, int decimals = 0);
172     void set_ptr(uint16_t* ptr);
173     };
174    
175    
176     template<typename T>
177     class ChoiceEntry : public LabelWidget {
178     private:
179     Gtk::ComboBoxText combobox;
180     Gtk::Alignment align;
181     T* ptr;
182     void value_changed();
183     const T* values;
184 schoenebeck 1359 protected:
185     sigc::signal<void> sig_to_be_changed;
186     sigc::signal<void, T> sig_val_changed;
187 schoenebeck 1225 public:
188     ChoiceEntry(const char* labelText);
189     void set_choices(const char** texts, const T* values);
190     void set_ptr(T* ptr);
191     int get_active_row_number() { return combobox.get_active_row_number(); }
192 schoenebeck 1359 sigc::signal<void>& signal_to_be_changed() {
193     return sig_to_be_changed;
194     }
195     sigc::signal<void, T>& signal_value_changed() {
196     return sig_val_changed;
197     }
198 schoenebeck 1225 Glib::SignalProxy0<void> signal_changed() {
199     return combobox.signal_changed();
200     }
201     void set_tip(const Glib::ustring& tip_text) {
202     tooltips.set_tip(combobox, tip_text); //FIXME: don't Gtk::ComboBoxes support tooltips ???
203     }
204     };
205    
206     template<typename T>
207     ChoiceEntry<T>::ChoiceEntry(const char* labelText) :
208     align(0, 0, 0, 0),
209     LabelWidget(labelText, align)
210     {
211     combobox.signal_changed().connect(
212     sigc::mem_fun(*this, &ChoiceEntry::value_changed));
213     align.add(combobox);
214     }
215    
216     template<typename T>
217     void ChoiceEntry<T>::set_choices(const char** texts, const T* values)
218     {
219     for (int i = 0 ; texts[i] ; i++) {
220     combobox.append_text(texts[i]);
221     }
222     this->values = values;
223     }
224    
225     template<typename T>
226     void ChoiceEntry<T>::value_changed()
227     {
228 schoenebeck 1359 int rowno = combobox.get_active_row_number();
229     if (rowno == -1) return;
230     const T val = values[rowno];
231     sig_to_be_changed.emit();
232     if (ptr) *ptr = val;
233     sig_val_changed.emit(val);
234     sig_changed.emit();
235 schoenebeck 1225 }
236    
237     template<typename T>
238     void ChoiceEntry<T>::set_ptr(T* ptr)
239     {
240     this->ptr = 0;
241     if (ptr) {
242     T value = *ptr;
243     int row = 0;
244     int nb_rows = combobox.get_model()->children().size();
245     for (; row < nb_rows ; row++) {
246     if (value == values[row]) break;
247     }
248     combobox.set_active(row == nb_rows ? -1 : row);
249     } else combobox.set_active(-1);
250     this->ptr = ptr;
251     }
252    
253    
254     class ChoiceEntryLeverageCtrl : public LabelWidget {
255     private:
256     Gtk::ComboBoxText combobox;
257     Gtk::Alignment align;
258     gig::leverage_ctrl_t* ptr;
259     void value_changed();
260     public:
261     ChoiceEntryLeverageCtrl(const char* labelText);
262     void set_ptr(gig::leverage_ctrl_t* ptr);
263     int get_active_row_number() { return combobox.get_active_row_number(); }
264     Glib::SignalProxy0<void> signal_changed() {
265     return combobox.signal_changed();
266     }
267     };
268    
269    
270     class BoolEntry : public LabelWidget {
271     private:
272     Gtk::CheckButton checkbutton;
273     bool* ptr;
274     void value_changed();
275     public:
276     BoolEntry(const char* labelText);
277     bool get_active() { return checkbutton.get_active(); }
278     bool set_active(bool b) { checkbutton.set_active(b); }
279     Glib::SignalProxy0<void> signal_toggled() {
280     return checkbutton.signal_toggled();
281     }
282     void set_ptr(bool* ptr);
283     void set_tip(const Glib::ustring& tip_text) {
284     tooltips.set_tip(checkbutton, tip_text);
285     }
286     };
287    
288    
289     class BoolEntryPlus6 : public LabelWidget {
290     private:
291     Gtk::CheckButton checkbutton;
292     int32_t* ptr;
293     void value_changed();
294     NumEntryGain& eGain;
295     int32_t plus6value;
296     public:
297     BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value);
298     void set_ptr(int32_t* ptr);
299     bool get_active() { return checkbutton.get_active(); }
300     Glib::SignalProxy0<void> signal_toggled() {
301     return checkbutton.signal_toggled();
302     }
303     };
304    
305     class StringEntry : public LabelWidget {
306     private:
307     Gtk::Entry entry;
308     gig::String* ptr;
309     void value_changed();
310     public:
311     StringEntry(const char* labelText);
312     void set_ptr(gig::String* ptr);
313     };
314    
315    
316     #endif

  ViewVC Help
Powered by ViewVC