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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1138 - (show annotations) (download) (as text)
Sat Mar 31 09:33:40 2007 UTC (17 years ago) by persson
File MIME type: text/x-c++hdr
File size: 6305 byte(s)
* reworked instrument properties dialog - properties can now be edited
* code cleanup: removed the pointer to member usage in paramedit as it
  just made things more complicated

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 <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 class NumEntryGain : public NumEntry {
65 private:
66 void value_changed();
67 int32_t* ptr;
68 double coeff;
69 public:
70 NumEntryGain(char* labelText,
71 double lower, double upper, int decimals, double coeff);
72 void set_ptr(int32_t* ptr);
73 };
74
75 template<typename T>
76 class NumEntryTemp : public NumEntry {
77 private:
78 T* ptr;
79 void value_changed();
80 public:
81 NumEntryTemp(char* labelText,
82 double lower = 0, double upper = 127, int decimals = 0);
83 void set_ptr(T* ptr);
84 };
85
86 template<typename T>
87 NumEntryTemp<T>::NumEntryTemp(char* labelText,
88 double lower, double upper, int decimals) :
89 NumEntry(labelText, lower, upper, decimals)
90 {
91 spinbutton.signal_value_changed().connect(
92 sigc::mem_fun(*this, &NumEntryTemp::value_changed));
93 }
94
95 template<typename T>
96 void NumEntryTemp<T>::value_changed()
97 {
98 if (ptr && update_gui) {
99 *ptr = T(spinbutton.get_value());
100 }
101 }
102
103 template<typename T>
104 void NumEntryTemp<T>::set_ptr(T* ptr)
105 {
106 this->ptr = 0;
107 set_value(*ptr);
108 this->ptr = ptr;
109 }
110
111
112 class NoteEntry : public NumEntryTemp<uint8_t> {
113 public:
114 NoteEntry(char* labelText);
115 private:
116 int on_input(double* new_value);
117 bool on_output();
118 };
119
120
121 class NumEntryPermille : public NumEntry {
122 private:
123 uint16_t* ptr;
124 void value_changed();
125 public:
126 NumEntryPermille(char* labelText,
127 double lower = 0, double upper = 127, int decimals = 0);
128 void set_ptr(uint16_t* ptr);
129 };
130
131
132 template<typename T>
133 class ChoiceEntry : public LabelWidget {
134 private:
135 Gtk::ComboBoxText combobox;
136 Gtk::Alignment align;
137 T* ptr;
138 void value_changed();
139 const T* values;
140 public:
141 ChoiceEntry(char* labelText);
142 void set_choices(char** texts, const T* values);
143 void set_ptr(T* ptr);
144 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 ChoiceEntry<T>::ChoiceEntry(char* labelText) :
152 align(0, 0, 0, 0),
153 LabelWidget(labelText, align)
154 {
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 if (ptr && update_gui) {
173 int rowno = combobox.get_active_row_number();
174 if (rowno != -1) *ptr = values[rowno];
175 }
176 }
177
178 template<typename T>
179 void ChoiceEntry<T>::set_ptr(T* ptr)
180 {
181 this->ptr = 0;
182 T value = *ptr;
183 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 this->ptr = ptr;
190 }
191
192
193 class ChoiceEntryLeverageCtrl : public LabelWidget {
194 private:
195 Gtk::ComboBoxText combobox;
196 Gtk::Alignment align;
197 gig::leverage_ctrl_t* ptr;
198 void value_changed();
199 public:
200 ChoiceEntryLeverageCtrl(char* labelText);
201 void set_ptr(gig::leverage_ctrl_t* ptr);
202 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 bool* ptr;
213 void value_changed();
214 public:
215 BoolEntry(char* labelText);
216 bool get_active() { return checkbutton.get_active(); }
217 Glib::SignalProxy0<void> signal_toggled() {
218 return checkbutton.signal_toggled();
219 }
220 void set_ptr(bool* ptr);
221 };
222
223
224 class BoolEntryPlus6 : public LabelWidget {
225 private:
226 Gtk::CheckButton checkbutton;
227 int32_t* ptr;
228 void value_changed();
229 NumEntryGain& eGain;
230 int32_t plus6value;
231 public:
232 BoolEntryPlus6(char* labelText, NumEntryGain& eGain, int32_t plus6value);
233 void set_ptr(int32_t* ptr);
234 bool get_active() { return checkbutton.get_active(); }
235 Glib::SignalProxy0<void> signal_toggled() {
236 return checkbutton.signal_toggled();
237 }
238 };
239
240 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 #endif

  ViewVC Help
Powered by ViewVC