/[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 3643 - (show annotations) (download) (as text)
Sat Dec 7 15:04:51 2019 UTC (4 years, 4 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 14491 byte(s)
* Gain: Allow also any positive gain dB value (instead of only +6 dB) up
  to +96 dB and dropped the old "Gain +6dB" checkbox for that reason.

* Instrument Properties Dialog: Allow -96 dB .. +96 dB and dropped
  "Gain +6dB" checkbox there as well.

* Instrument Properties Dialog: Show unit for attenuation and pitchbend
  range.

* Bumped version (1.1.1.svn7).

1 /* -*- c++ -*-
2 * Copyright (C) 2006-2019 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 #ifdef LIBGIG_HEADER_FILE
24 # include LIBGIG_HEADER_FILE(gig.h)
25 #else
26 # include <gig.h>
27 #endif
28
29 #include <cmath>
30
31 #include "compat.h"
32
33 #include <glibmm/convert.h>
34 #include <gtkmm/box.h>
35 #include <gtkmm/adjustment.h>
36 #if HAS_GTKMM_ALIGNMENT
37 # include <gtkmm/alignment.h>
38 #endif
39 #include <gtkmm/checkbutton.h>
40 #include <gtkmm/comboboxtext.h>
41 #include <gtkmm/frame.h>
42 #include <gtkmm/label.h>
43 #include <gtkmm/scale.h>
44 #include <gtkmm/spinbutton.h>
45 #if USE_GTKMM_GRID
46 # include <gtkmm/grid.h>
47 #else
48 # include <gtkmm/table.h>
49 #endif
50 #include <gtkmm/textview.h>
51
52 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 12) || GTKMM_MAJOR_VERSION < 2
53 #define OLD_TOOLTIPS
54 #include <gtkmm/tooltips.h>
55 #endif
56
57 int note_value(const Glib::ustring& note);
58 Glib::ustring note_str(int note);
59
60 void spin_button_show_notes(Gtk::SpinButton& spin_button);
61
62 class LabelWidget {
63 public:
64 Gtk::Label label;
65 Gtk::Widget& widget;
66
67 LabelWidget(const char* labelText, Gtk::Widget& widget);
68 void set_sensitive(bool sensitive = true);
69 sigc::signal<void>& signal_value_changed() {
70 return sig_changed;
71 }
72 protected:
73 virtual void on_show_tooltips_changed();
74 #ifdef OLD_TOOLTIPS
75 Gtk::Tooltips tooltips;
76 #endif
77 sigc::signal<void> sig_changed;
78 };
79
80 class ReadOnlyLabelWidget : public LabelWidget {
81 public:
82 Gtk::Label text;
83
84 ReadOnlyLabelWidget(const char* leftHandText);
85 ReadOnlyLabelWidget(const char* leftHandText, const char* rightHandText);
86 };
87
88 class NumEntry : public LabelWidget {
89 protected:
90 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
91 Gtk::Adjustment adjust;
92 #else
93 Glib::RefPtr<Gtk::Adjustment> adjust;
94 #endif
95 HScale scale;
96 Gtk::SpinButton spinbutton;
97 HBox box;
98
99 static int round_to_int(double x) {
100 return int(x < 0.0 ? x - 0.5 : x + 0.5);
101 }
102
103 public:
104 NumEntry(const char* labelText, double lower = 0, double upper = 127,
105 int decimals = 0);
106 void set_tip(const Glib::ustring& tip_text) {
107 #ifdef OLD_TOOLTIPS
108 tooltips.set_tip(spinbutton, tip_text);
109 #else
110 spinbutton.set_tooltip_text(tip_text);
111 #endif
112 }
113 void set_upper(double upper) {
114 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
115 adjust.set_upper(upper);
116 #else
117 adjust->set_upper(upper);
118 #endif
119 }
120 void on_show_tooltips_changed();
121 };
122
123 class NumEntryGain : public NumEntry {
124 private:
125 int32_t value;
126 void value_changed();
127 double coeff;
128 bool connected;
129 public:
130 NumEntryGain(const char* labelText,
131 double lower, double upper, int decimals, double coeff);
132 int32_t get_value() const { return value; }
133 void set_value(int32_t value);
134 };
135
136 template<typename T>
137 class NumEntryTemp : public NumEntry {
138 private:
139 T value;
140 void value_changed();
141 public:
142 NumEntryTemp(const char* labelText,
143 double lower = 0, double upper = 127, int decimals = 0);
144 T get_value() const { return value; }
145 void set_value(T value);
146 };
147
148 template<typename T>
149 NumEntryTemp<T>::NumEntryTemp(const char* labelText,
150 double lower, double upper, int decimals) :
151 NumEntry(labelText, lower, upper, decimals),
152 value(0)
153 {
154 spinbutton.signal_value_changed().connect(
155 sigc::mem_fun(*this, &NumEntryTemp::value_changed));
156 }
157
158 template<typename T>
159 void NumEntryTemp<T>::value_changed()
160 {
161 const double f = pow(10, spinbutton.get_digits());
162 int new_value = round_to_int(spinbutton.get_value() * f);
163 if (new_value != round_to_int(value * f)) {
164 value = T(new_value / f);
165 sig_changed();
166 }
167 }
168
169 template<typename T>
170 void NumEntryTemp<T>::set_value(T value)
171 {
172 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
173 if (value > adjust.get_upper()) value = T(adjust.get_upper());
174 #else
175 if (value > adjust->get_upper()) value = T(adjust->get_upper());
176 #endif
177 if (this->value != value) {
178 this->value = value;
179 const double f = pow(10, spinbutton.get_digits());
180 if (round_to_int(spinbutton.get_value() * f) != round_to_int(value * f)) {
181 spinbutton.set_value(value);
182 }
183 sig_changed();
184 }
185 }
186
187
188 class NoteEntry : public NumEntryTemp<uint8_t> {
189 public:
190 NoteEntry(const char* labelText);
191 private:
192 int on_input(double* new_value);
193 bool on_output();
194 };
195
196
197 class NumEntryPermille : public NumEntry {
198 private:
199 uint16_t value;
200 void value_changed();
201 public:
202 NumEntryPermille(const char* labelText,
203 double lower = 0, double upper = 127, int decimals = 0);
204 uint16_t get_value() const { return value; }
205 void set_value(uint16_t value);
206 };
207
208 class ChoiceEntryBase : public LabelWidget {
209 protected:
210 ChoiceEntryBase(const char* labelText, Gtk::Widget& widget) : LabelWidget(labelText, widget) {};
211 Gtk::ComboBoxText combobox;
212 void on_show_tooltips_changed();
213 };
214
215 template<typename T>
216 class ChoiceEntry : public ChoiceEntryBase {
217 private:
218 #if HAS_GTKMM_ALIGNMENT
219 Gtk::Alignment align;
220 #endif
221 const T* values;
222 public:
223 ChoiceEntry(const char* labelText);
224 T get_value() const;
225 void set_value(T value);
226 void set_choices(const char** texts, const T* values);
227
228 void set_tip(const Glib::ustring& tip_text) {
229 #ifdef OLD_TOOLTIPS
230 tooltips.set_tip(combobox, tip_text);
231 #else
232 combobox.set_tooltip_text(tip_text);
233 #endif
234 }
235 };
236
237 template<typename T>
238 ChoiceEntry<T>::ChoiceEntry(const char* labelText) :
239 #if HAS_GTKMM_ALIGNMENT
240 ChoiceEntryBase(labelText, align),
241 align(0, 0, 0, 0),
242 #else
243 ChoiceEntryBase(labelText, combobox),
244 #endif
245 values(0)
246 {
247 combobox.signal_changed().connect(sig_changed.make_slot());
248 #if HAS_GTKMM_ALIGNMENT
249 align.add(combobox);
250 #endif
251 }
252
253 template<typename T>
254 void ChoiceEntry<T>::set_choices(const char** texts, const T* values)
255 {
256 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 24) || GTKMM_MAJOR_VERSION < 2
257 combobox.clear_items();
258 for (int i = 0 ; texts[i] ; i++) {
259 combobox.append_text(texts[i]);
260 }
261 #else
262 combobox.remove_all();
263 for (int i = 0 ; texts[i] ; i++) {
264 combobox.append(texts[i]);
265 }
266 #endif
267 this->values = values;
268 }
269
270 template<typename T>
271 T ChoiceEntry<T>::get_value() const
272 {
273 int rowno = combobox.get_active_row_number();
274 return values[rowno];
275 }
276
277 template<typename T>
278 void ChoiceEntry<T>::set_value(T value)
279 {
280 int row = 0;
281 int nb_rows = combobox.get_model()->children().size();
282 for (; row < nb_rows ; row++) {
283 if (value == values[row]) break;
284 }
285 combobox.set_active(row == nb_rows ? -1 : row);
286 }
287
288
289 class ChoiceEntryLeverageCtrl : public LabelWidget {
290 private:
291 gig::leverage_ctrl_t value;
292 Gtk::ComboBoxText combobox;
293 #if HAS_GTKMM_ALIGNMENT
294 Gtk::Alignment align;
295 #endif
296 void value_changed();
297 protected:
298 void on_show_tooltips_changed();
299 public:
300 ChoiceEntryLeverageCtrl(const char* labelText);
301 gig::leverage_ctrl_t get_value() const { return value; }
302 void set_value(gig::leverage_ctrl_t value);
303 void set_tip(const Glib::ustring& tip_text) {
304 combobox.set_tooltip_text(tip_text);
305 }
306 };
307
308 class ChoiceEntryLfoWave : public LabelWidget {
309 private:
310 gig::lfo_wave_t value;
311 Gtk::ComboBoxText combobox;
312 #if HAS_GTKMM_ALIGNMENT
313 Gtk::Alignment align;
314 #endif
315 void value_changed();
316 protected:
317 void on_show_tooltips_changed();
318 public:
319 ChoiceEntryLfoWave(const char* labelText);
320 gig::lfo_wave_t get_value() const { return value; }
321 void set_value(gig::lfo_wave_t value);
322 void set_tip(const Glib::ustring& tip_text) {
323 combobox.set_tooltip_text(tip_text);
324 }
325 };
326
327
328 class BoolEntry : public LabelWidget {
329 private:
330 Gtk::CheckButton checkbutton;
331 public:
332 BoolEntry(const char* labelText);
333 bool get_value() const { return checkbutton.get_active(); }
334 void set_value(bool value) { checkbutton.set_active(value); }
335
336 void set_tip(const Glib::ustring& tip_text) {
337 #ifdef OLD_TOOLTIPS
338 tooltips.set_tip(checkbutton, tip_text);
339 #else
340 checkbutton.set_tooltip_text(tip_text);
341 #endif
342 }
343 };
344
345 class BoolBox : public Gtk::CheckButton {
346 public:
347 BoolBox(const char* labelText);
348 bool get_value() const { return get_active(); }
349 void set_value(bool value) { set_active(value); }
350 sigc::signal<void>& signal_value_changed() { return sig_changed; }
351 protected:
352 void on_show_tooltips_changed();
353
354 sigc::signal<void> sig_changed;
355 };
356
357
358 class StringEntry : public LabelWidget {
359 private:
360 Gtk::Entry entry;
361 public:
362 StringEntry(const char* labelText);
363 gig::String get_value() const;
364 void set_value(const gig::String& value);
365 void set_width_chars(int n_chars) { entry.set_width_chars(n_chars); }
366 };
367
368 class StringEntryMultiLine : public LabelWidget {
369 private:
370 Gtk::TextView text_view;
371 Glib::RefPtr<Gtk::TextBuffer> text_buffer;
372 Gtk::Frame frame;
373 protected:
374 void on_show_tooltips_changed();
375 public:
376 StringEntryMultiLine(const char* labelText);
377 gig::String get_value() const;
378 void set_value(const gig::String& value);
379 };
380
381
382 /**
383 * Container widget for LabelWidgets.
384 */
385 class Table :
386 #if USE_GTKMM_GRID
387 public Gtk::Grid
388 #else
389 public Gtk::Table
390 #endif
391 {
392 public:
393 Table(int x, int y);
394 void add(BoolEntry& boolentry);
395 void add(LabelWidget& labelwidget);
396 private:
397 #if USE_GTKMM_GRID
398 int cols;
399 #endif
400 int rowno;
401 };
402
403
404 /**
405 * Base class for editor components that use LabelWidgets to edit
406 * member variables of the same class. By connecting the widgets to
407 * members of the model class, the model is automatically kept
408 * updated.
409 */
410 template<class M>
411 class PropEditor {
412 public:
413 sigc::signal<void>& signal_changed() {
414 return sig_changed;
415 }
416 protected:
417 M* m;
418 int update_model; // to prevent infinite update loops
419 PropEditor() : m(0), update_model(0) { }
420 sigc::signal<void> sig_changed;
421
422 template<class C, typename T>
423 void connect(C& widget, T M::* member) {
424 // gcc 4.1.2 needs this temporary variable to resolve the
425 // address
426 void (PropEditor::*f)(const C* w, T M::* member) =
427 &PropEditor::set_member;
428 widget.signal_value_changed().connect(
429 sigc::bind(sigc::mem_fun(*this, f), &widget, member));
430
431 void (PropEditor::*g)(C* w, T M::* member) =
432 &PropEditor::get_member;
433 sig.connect(
434 sigc::bind(sigc::mem_fun(*this, g), &widget, member));
435 }
436
437 template<class C, class S, typename T>
438 void connect(C& widget, void (S::*setter)(T)) {
439 void (PropEditor::*f)(const C* w, void (S::*setter)(T)) =
440 &PropEditor<M>::call_setter;
441 widget.signal_value_changed().connect(
442 sigc::bind(sigc::mem_fun(*this, f), &widget, setter));
443 }
444
445 template<class C, class F>
446 void connectLambda(C& widget, F fn) {
447 widget.signal_value_changed().connect([&widget,fn]{
448 fn( widget.get_value() );
449 });
450 }
451
452 void connect(NoteEntry& eKeyRangeLow, NoteEntry& eKeyRangeHigh,
453 gig::range_t M::* range) {
454 eKeyRangeLow.signal_value_changed().connect(
455 sigc::bind(
456 sigc::mem_fun(*this, &PropEditor::key_range_low_changed),
457 &eKeyRangeLow, &eKeyRangeHigh, range));
458 eKeyRangeHigh.signal_value_changed().connect(
459 sigc::bind(
460 sigc::mem_fun(*this, &PropEditor::key_range_high_changed),
461 &eKeyRangeLow, &eKeyRangeHigh, range));
462 sig.connect(
463 sigc::bind(sigc::mem_fun(*this, &PropEditor::get_key_range),
464 &eKeyRangeLow, &eKeyRangeHigh, range));
465 }
466
467 void update(M* m) {
468 update_model++;
469 this->m = m;
470 sig.emit();
471 update_model--;
472 }
473
474 private:
475 sigc::signal<void> sig;
476
477 void key_range_low_changed(NoteEntry* eKeyRangeLow,
478 NoteEntry* eKeyRangeHigh,
479 gig::range_t M::* range) {
480 if (update_model == 0) {
481 uint8_t value = eKeyRangeLow->get_value();
482 (m->*range).low = value;
483 if (value > (m->*range).high) {
484 eKeyRangeHigh->set_value(value);
485 }
486 sig_changed();
487 }
488 }
489
490 void key_range_high_changed(NoteEntry* eKeyRangeLow,
491 NoteEntry* eKeyRangeHigh,
492 gig::range_t M::* range) {
493 if (update_model == 0) {
494 uint8_t value = eKeyRangeHigh->get_value();
495 (m->*range).high = value;
496 if (value < (m->*range).low) {
497 eKeyRangeLow->set_value(value);
498 }
499 sig_changed();
500 }
501 }
502
503 template<class C, typename T>
504 void set_member(const C* w, T M::* member) {
505 if (update_model == 0) {
506 m->*member = w->get_value();
507 sig_changed();
508 }
509 }
510
511 template<class C, typename T>
512 void get_member(C* w, T M::* member) {
513 w->set_value(m->*member);
514 }
515
516 void get_key_range(NoteEntry* eKeyRangeLow,
517 NoteEntry* eKeyRangeHigh,
518 gig::range_t M::* range) const {
519 eKeyRangeLow->set_value((m->*range).low);
520 eKeyRangeHigh->set_value((m->*range).high);
521 }
522
523 template<class C, class S, typename T>
524 void call_setter(const C* w, void (S::*setter)(T)) {
525 if (update_model == 0) {
526 (static_cast<S*>(this)->*setter)(w->get_value());
527 sig_changed();
528 }
529 }
530 };
531
532 #endif

  ViewVC Help
Powered by ViewVC