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