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