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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1300 - (show annotations) (download) (as text)
Fri Aug 24 19:11:41 2007 UTC (16 years, 7 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7370 byte(s)
* start with a new gig file by default
* fixed minor compilation error

1 /* -*- 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 #include <math.h>
26
27 #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 sigc::signal<void> signal_changed_by_user() {
44 return sig_changed;
45 }
46 protected:
47 Gtk::Tooltips tooltips;
48 sigc::signal<void> sig_changed;
49 };
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
58 int round_to_int(double x) {
59 return int(x < 0.0 ? x - 0.5 : x + 0.5);
60 }
61 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 public:
84 NumEntryGain(const char* labelText,
85 double lower, double upper, int decimals, double coeff);
86 void set_ptr(int32_t* ptr);
87 };
88
89 template<typename T>
90 class NumEntryTemp : public NumEntry {
91 private:
92 T* ptr;
93 void value_changed();
94 public:
95 NumEntryTemp(const char* labelText,
96 double lower = 0, double upper = 127, int decimals = 0);
97 void set_ptr(T* ptr);
98 };
99
100 template<typename T>
101 NumEntryTemp<T>::NumEntryTemp(const char* labelText,
102 double lower, double upper, int decimals) :
103 NumEntry(labelText, lower, upper, decimals)
104 {
105 spinbutton.signal_value_changed().connect(
106 sigc::mem_fun(*this, &NumEntryTemp::value_changed));
107 }
108
109 template<typename T>
110 void NumEntryTemp<T>::value_changed()
111 {
112 if (ptr) {
113 const double f = pow(10, spinbutton.get_digits());
114 int new_value = round_to_int(spinbutton.get_value() * f);
115 if (new_value != round_to_int(*ptr * f)) {
116 *ptr = T(new_value / f);
117 sig_changed();
118 }
119 }
120 }
121
122 template<typename T>
123 void NumEntryTemp<T>::set_ptr(T* ptr)
124 {
125 this->ptr = 0;
126 if (ptr) set_value(*ptr);
127 this->ptr = ptr;
128 }
129
130
131 class NoteEntry : public NumEntryTemp<uint8_t> {
132 public:
133 NoteEntry(const char* labelText);
134 private:
135 int on_input(double* new_value);
136 bool on_output();
137 };
138
139
140 class NumEntryPermille : public NumEntry {
141 private:
142 uint16_t* ptr;
143 void value_changed();
144 public:
145 NumEntryPermille(const char* labelText,
146 double lower = 0, double upper = 127, int decimals = 0);
147 void set_ptr(uint16_t* ptr);
148 };
149
150
151 template<typename T>
152 class ChoiceEntry : public LabelWidget {
153 private:
154 Gtk::ComboBoxText combobox;
155 Gtk::Alignment align;
156 T* ptr;
157 void value_changed();
158 const T* values;
159 public:
160 ChoiceEntry(const char* labelText);
161 void set_choices(const char** texts, const T* values);
162 void set_ptr(T* ptr);
163 int get_active_row_number() { return combobox.get_active_row_number(); }
164 Glib::SignalProxy0<void> signal_changed() {
165 return combobox.signal_changed();
166 }
167 void set_tip(const Glib::ustring& tip_text) {
168 tooltips.set_tip(combobox, tip_text); //FIXME: don't Gtk::ComboBoxes support tooltips ???
169 }
170 };
171
172 template<typename T>
173 ChoiceEntry<T>::ChoiceEntry(const char* labelText) :
174 align(0, 0, 0, 0),
175 LabelWidget(labelText, align)
176 {
177 combobox.signal_changed().connect(
178 sigc::mem_fun(*this, &ChoiceEntry::value_changed));
179 align.add(combobox);
180 }
181
182 template<typename T>
183 void ChoiceEntry<T>::set_choices(const char** texts, const T* values)
184 {
185 for (int i = 0 ; texts[i] ; i++) {
186 combobox.append_text(texts[i]);
187 }
188 this->values = values;
189 }
190
191 template<typename T>
192 void ChoiceEntry<T>::value_changed()
193 {
194 if (ptr) {
195 int rowno = combobox.get_active_row_number();
196 if (rowno != -1) {
197 *ptr = values[rowno];
198 sig_changed();
199 }
200 }
201 }
202
203 template<typename T>
204 void ChoiceEntry<T>::set_ptr(T* ptr)
205 {
206 this->ptr = 0;
207 if (ptr) {
208 T value = *ptr;
209 int row = 0;
210 int nb_rows = combobox.get_model()->children().size();
211 for (; row < nb_rows ; row++) {
212 if (value == values[row]) break;
213 }
214 combobox.set_active(row == nb_rows ? -1 : row);
215 } else combobox.set_active(-1);
216 this->ptr = ptr;
217 }
218
219
220 class ChoiceEntryLeverageCtrl : public LabelWidget {
221 private:
222 Gtk::ComboBoxText combobox;
223 Gtk::Alignment align;
224 gig::leverage_ctrl_t* ptr;
225 void value_changed();
226 public:
227 ChoiceEntryLeverageCtrl(const char* labelText);
228 void set_ptr(gig::leverage_ctrl_t* ptr);
229 int get_active_row_number() { return combobox.get_active_row_number(); }
230 Glib::SignalProxy0<void> signal_changed() {
231 return combobox.signal_changed();
232 }
233 };
234
235
236 class BoolEntry : public LabelWidget {
237 private:
238 Gtk::CheckButton checkbutton;
239 bool* ptr;
240 void value_changed();
241 public:
242 BoolEntry(const char* labelText);
243 bool get_active() { return checkbutton.get_active(); }
244 bool set_active(bool b) { checkbutton.set_active(b); }
245 Glib::SignalProxy0<void> signal_toggled() {
246 return checkbutton.signal_toggled();
247 }
248 void set_ptr(bool* ptr);
249 void set_tip(const Glib::ustring& tip_text) {
250 tooltips.set_tip(checkbutton, tip_text);
251 }
252 };
253
254
255 class BoolEntryPlus6 : public LabelWidget {
256 private:
257 Gtk::CheckButton checkbutton;
258 int32_t* ptr;
259 void value_changed();
260 NumEntryGain& eGain;
261 int32_t plus6value;
262 public:
263 BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value);
264 void set_ptr(int32_t* ptr);
265 bool get_active() { return checkbutton.get_active(); }
266 Glib::SignalProxy0<void> signal_toggled() {
267 return checkbutton.signal_toggled();
268 }
269 };
270
271 class StringEntry : public LabelWidget {
272 private:
273 Gtk::Entry entry;
274 gig::String* ptr;
275 void value_changed();
276 public:
277 StringEntry(const char* labelText);
278 void set_ptr(gig::String* ptr);
279 };
280
281
282 #endif

  ViewVC Help
Powered by ViewVC