1 |
/* -*- c++ -*- |
/* -*- c++ -*- |
2 |
* Copyright (C) 2006-2011 Andreas Persson |
* Copyright (C) 2006-2019 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
20 |
#ifndef GIGEDIT_PARAMEDIT_H |
#ifndef GIGEDIT_PARAMEDIT_H |
21 |
#define GIGEDIT_PARAMEDIT_H |
#define GIGEDIT_PARAMEDIT_H |
22 |
|
|
23 |
#include <gig.h> |
#ifdef LIBGIG_HEADER_FILE |
24 |
|
# include LIBGIG_HEADER_FILE(gig.h) |
25 |
|
#else |
26 |
|
# include <gig.h> |
27 |
|
#endif |
28 |
|
|
29 |
#include <cmath> |
#include <cmath> |
30 |
|
|
31 |
#include <gtkmm/adjustment.h> |
#include "compat.h" |
32 |
#include <gtkmm/alignment.h> |
|
33 |
|
#include <glibmm/convert.h> |
34 |
#include <gtkmm/box.h> |
#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> |
#include <gtkmm/checkbutton.h> |
40 |
#include <gtkmm/comboboxtext.h> |
#include <gtkmm/comboboxtext.h> |
41 |
#include <gtkmm/frame.h> |
#include <gtkmm/frame.h> |
42 |
#include <gtkmm/label.h> |
#include <gtkmm/label.h> |
43 |
#include <gtkmm/scale.h> |
#include <gtkmm/scale.h> |
44 |
#include <gtkmm/spinbutton.h> |
#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> |
#include <gtkmm/textview.h> |
51 |
|
|
52 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 12) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 12) || GTKMM_MAJOR_VERSION < 2 |
54 |
#include <gtkmm/tooltips.h> |
#include <gtkmm/tooltips.h> |
55 |
#endif |
#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 { |
class LabelWidget { |
63 |
public: |
public: |
64 |
Gtk::Label label; |
Gtk::Label label; |
70 |
return sig_changed; |
return sig_changed; |
71 |
} |
} |
72 |
protected: |
protected: |
73 |
|
virtual void on_show_tooltips_changed(); |
74 |
#ifdef OLD_TOOLTIPS |
#ifdef OLD_TOOLTIPS |
75 |
Gtk::Tooltips tooltips; |
Gtk::Tooltips tooltips; |
76 |
#endif |
#endif |
77 |
sigc::signal<void> sig_changed; |
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 { |
class NumEntry : public LabelWidget { |
89 |
protected: |
protected: |
90 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
92 |
#else |
#else |
93 |
Glib::RefPtr<Gtk::Adjustment> adjust; |
Glib::RefPtr<Gtk::Adjustment> adjust; |
94 |
#endif |
#endif |
95 |
Gtk::HScale scale; |
HScale scale; |
96 |
Gtk::SpinButton spinbutton; |
Gtk::SpinButton spinbutton; |
97 |
Gtk::HBox box; |
HBox box; |
98 |
|
|
99 |
int round_to_int(double x) { |
static int round_to_int(double x) { |
100 |
return int(x < 0.0 ? x - 0.5 : x + 0.5); |
return int(x < 0.0 ? x - 0.5 : x + 0.5); |
101 |
} |
} |
102 |
|
|
103 |
public: |
public: |
104 |
NumEntry(const char* labelText, double lower = 0, double upper = 127, |
NumEntry(const char* labelText, double lower = 0, double upper = 127, |
105 |
int decimals = 0); |
int decimals = 0); |
117 |
adjust->set_upper(upper); |
adjust->set_upper(upper); |
118 |
#endif |
#endif |
119 |
} |
} |
120 |
|
void on_show_tooltips_changed(); |
121 |
}; |
}; |
122 |
|
|
123 |
class NumEntryGain : public NumEntry { |
class NumEntryGain : public NumEntry { |
205 |
void set_value(uint16_t value); |
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> |
template<typename T> |
216 |
class ChoiceEntry : public LabelWidget { |
class ChoiceEntry : public ChoiceEntryBase { |
217 |
private: |
private: |
218 |
Gtk::ComboBoxText combobox; |
#if HAS_GTKMM_ALIGNMENT |
219 |
Gtk::Alignment align; |
Gtk::Alignment align; |
220 |
|
#endif |
221 |
const T* values; |
const T* values; |
222 |
public: |
public: |
223 |
ChoiceEntry(const char* labelText); |
ChoiceEntry(const char* labelText); |
236 |
|
|
237 |
template<typename T> |
template<typename T> |
238 |
ChoiceEntry<T>::ChoiceEntry(const char* labelText) : |
ChoiceEntry<T>::ChoiceEntry(const char* labelText) : |
239 |
LabelWidget(labelText, align), |
#if HAS_GTKMM_ALIGNMENT |
240 |
align(0, 0, 0, 0) |
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()); |
combobox.signal_changed().connect(sig_changed.make_slot()); |
248 |
|
#if HAS_GTKMM_ALIGNMENT |
249 |
align.add(combobox); |
align.add(combobox); |
250 |
|
#endif |
251 |
} |
} |
252 |
|
|
253 |
template<typename T> |
template<typename T> |
254 |
void ChoiceEntry<T>::set_choices(const char** texts, const T* values) |
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++) { |
for (int i = 0 ; texts[i] ; i++) { |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
|
259 |
combobox.append_text(texts[i]); |
combobox.append_text(texts[i]); |
260 |
|
} |
261 |
#else |
#else |
262 |
|
combobox.remove_all(); |
263 |
|
for (int i = 0 ; texts[i] ; i++) { |
264 |
combobox.append(texts[i]); |
combobox.append(texts[i]); |
|
#endif |
|
265 |
} |
} |
266 |
|
#endif |
267 |
this->values = values; |
this->values = values; |
268 |
} |
} |
269 |
|
|
290 |
private: |
private: |
291 |
gig::leverage_ctrl_t value; |
gig::leverage_ctrl_t value; |
292 |
Gtk::ComboBoxText combobox; |
Gtk::ComboBoxText combobox; |
293 |
|
#if HAS_GTKMM_ALIGNMENT |
294 |
Gtk::Alignment align; |
Gtk::Alignment align; |
295 |
|
#endif |
296 |
void value_changed(); |
void value_changed(); |
297 |
|
protected: |
298 |
|
void on_show_tooltips_changed(); |
299 |
public: |
public: |
300 |
ChoiceEntryLeverageCtrl(const char* labelText); |
ChoiceEntryLeverageCtrl(const char* labelText); |
301 |
gig::leverage_ctrl_t get_value() const { return value; } |
gig::leverage_ctrl_t get_value() const { return value; } |
302 |
void set_value(gig::leverage_ctrl_t value); |
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 |
|
|
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 BoolEntryPlus6 : public LabelWidget { |
class BoolEntryPlus6 : public LabelWidget { |
359 |
private: |
private: |
361 |
void value_changed(); |
void value_changed(); |
362 |
NumEntryGain& eGain; |
NumEntryGain& eGain; |
363 |
int32_t plus6value; |
int32_t plus6value; |
364 |
|
protected: |
365 |
|
void on_show_tooltips_changed(); |
366 |
public: |
public: |
367 |
BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value); |
BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value); |
368 |
int32_t get_value() const; |
int32_t get_value() const; |
369 |
void set_value(int32_t value); |
void set_value(int32_t value); |
370 |
}; |
}; |
371 |
|
|
372 |
|
|
373 |
class StringEntry : public LabelWidget { |
class StringEntry : public LabelWidget { |
374 |
private: |
private: |
375 |
Gtk::Entry entry; |
Gtk::Entry entry; |
376 |
public: |
public: |
377 |
StringEntry(const char* labelText); |
StringEntry(const char* labelText); |
378 |
gig::String get_value() const { return entry.get_text(); } |
gig::String get_value() const; |
379 |
void set_value(gig::String value) { entry.set_text(value); } |
void set_value(const gig::String& value); |
380 |
void set_width_chars(int n_chars) { entry.set_width_chars(n_chars); } |
void set_width_chars(int n_chars) { entry.set_width_chars(n_chars); } |
381 |
}; |
}; |
382 |
|
|
385 |
Gtk::TextView text_view; |
Gtk::TextView text_view; |
386 |
Glib::RefPtr<Gtk::TextBuffer> text_buffer; |
Glib::RefPtr<Gtk::TextBuffer> text_buffer; |
387 |
Gtk::Frame frame; |
Gtk::Frame frame; |
388 |
|
protected: |
389 |
|
void on_show_tooltips_changed(); |
390 |
public: |
public: |
391 |
StringEntryMultiLine(const char* labelText); |
StringEntryMultiLine(const char* labelText); |
392 |
gig::String get_value() const; |
gig::String get_value() const; |
393 |
void set_value(gig::String value); |
void set_value(const gig::String& value); |
394 |
}; |
}; |
395 |
|
|
396 |
|
|
397 |
|
/** |
398 |
|
* Container widget for LabelWidgets. |
399 |
|
*/ |
400 |
|
class Table : |
401 |
|
#if USE_GTKMM_GRID |
402 |
|
public Gtk::Grid |
403 |
|
#else |
404 |
|
public Gtk::Table |
405 |
|
#endif |
406 |
|
{ |
407 |
|
public: |
408 |
|
Table(int x, int y); |
409 |
|
void add(BoolEntry& boolentry); |
410 |
|
void add(BoolEntryPlus6& boolentry); |
411 |
|
void add(LabelWidget& labelwidget); |
412 |
|
private: |
413 |
|
#if USE_GTKMM_GRID |
414 |
|
int cols; |
415 |
|
#endif |
416 |
|
int rowno; |
417 |
|
}; |
418 |
|
|
419 |
|
|
420 |
|
/** |
421 |
|
* Base class for editor components that use LabelWidgets to edit |
422 |
|
* member variables of the same class. By connecting the widgets to |
423 |
|
* members of the model class, the model is automatically kept |
424 |
|
* updated. |
425 |
|
*/ |
426 |
|
template<class M> |
427 |
|
class PropEditor { |
428 |
|
public: |
429 |
|
sigc::signal<void>& signal_changed() { |
430 |
|
return sig_changed; |
431 |
|
} |
432 |
|
protected: |
433 |
|
M* m; |
434 |
|
int update_model; // to prevent infinite update loops |
435 |
|
PropEditor() : m(0), update_model(0) { } |
436 |
|
sigc::signal<void> sig_changed; |
437 |
|
|
438 |
|
template<class C, typename T> |
439 |
|
void connect(C& widget, T M::* member) { |
440 |
|
// gcc 4.1.2 needs this temporary variable to resolve the |
441 |
|
// address |
442 |
|
void (PropEditor::*f)(const C* w, T M::* member) = |
443 |
|
&PropEditor::set_member; |
444 |
|
widget.signal_value_changed().connect( |
445 |
|
sigc::bind(sigc::mem_fun(*this, f), &widget, member)); |
446 |
|
|
447 |
|
void (PropEditor::*g)(C* w, T M::* member) = |
448 |
|
&PropEditor::get_member; |
449 |
|
sig.connect( |
450 |
|
sigc::bind(sigc::mem_fun(*this, g), &widget, member)); |
451 |
|
} |
452 |
|
|
453 |
|
template<class C, class S, typename T> |
454 |
|
void connect(C& widget, void (S::*setter)(T)) { |
455 |
|
void (PropEditor::*f)(const C* w, void (S::*setter)(T)) = |
456 |
|
&PropEditor<M>::call_setter; |
457 |
|
widget.signal_value_changed().connect( |
458 |
|
sigc::bind(sigc::mem_fun(*this, f), &widget, setter)); |
459 |
|
} |
460 |
|
|
461 |
|
void connect(NoteEntry& eKeyRangeLow, NoteEntry& eKeyRangeHigh, |
462 |
|
gig::range_t M::* range) { |
463 |
|
eKeyRangeLow.signal_value_changed().connect( |
464 |
|
sigc::bind( |
465 |
|
sigc::mem_fun(*this, &PropEditor::key_range_low_changed), |
466 |
|
&eKeyRangeLow, &eKeyRangeHigh, range)); |
467 |
|
eKeyRangeHigh.signal_value_changed().connect( |
468 |
|
sigc::bind( |
469 |
|
sigc::mem_fun(*this, &PropEditor::key_range_high_changed), |
470 |
|
&eKeyRangeLow, &eKeyRangeHigh, range)); |
471 |
|
sig.connect( |
472 |
|
sigc::bind(sigc::mem_fun(*this, &PropEditor::get_key_range), |
473 |
|
&eKeyRangeLow, &eKeyRangeHigh, range)); |
474 |
|
} |
475 |
|
|
476 |
|
void update(M* m) { |
477 |
|
update_model++; |
478 |
|
this->m = m; |
479 |
|
sig.emit(); |
480 |
|
update_model--; |
481 |
|
} |
482 |
|
|
483 |
|
private: |
484 |
|
sigc::signal<void> sig; |
485 |
|
|
486 |
|
void key_range_low_changed(NoteEntry* eKeyRangeLow, |
487 |
|
NoteEntry* eKeyRangeHigh, |
488 |
|
gig::range_t M::* range) { |
489 |
|
if (update_model == 0) { |
490 |
|
uint8_t value = eKeyRangeLow->get_value(); |
491 |
|
(m->*range).low = value; |
492 |
|
if (value > (m->*range).high) { |
493 |
|
eKeyRangeHigh->set_value(value); |
494 |
|
} |
495 |
|
sig_changed(); |
496 |
|
} |
497 |
|
} |
498 |
|
|
499 |
|
void key_range_high_changed(NoteEntry* eKeyRangeLow, |
500 |
|
NoteEntry* eKeyRangeHigh, |
501 |
|
gig::range_t M::* range) { |
502 |
|
if (update_model == 0) { |
503 |
|
uint8_t value = eKeyRangeHigh->get_value(); |
504 |
|
(m->*range).high = value; |
505 |
|
if (value < (m->*range).low) { |
506 |
|
eKeyRangeLow->set_value(value); |
507 |
|
} |
508 |
|
sig_changed(); |
509 |
|
} |
510 |
|
} |
511 |
|
|
512 |
|
template<class C, typename T> |
513 |
|
void set_member(const C* w, T M::* member) { |
514 |
|
if (update_model == 0) { |
515 |
|
m->*member = w->get_value(); |
516 |
|
sig_changed(); |
517 |
|
} |
518 |
|
} |
519 |
|
|
520 |
|
template<class C, typename T> |
521 |
|
void get_member(C* w, T M::* member) { |
522 |
|
w->set_value(m->*member); |
523 |
|
} |
524 |
|
|
525 |
|
void get_key_range(NoteEntry* eKeyRangeLow, |
526 |
|
NoteEntry* eKeyRangeHigh, |
527 |
|
gig::range_t M::* range) const { |
528 |
|
eKeyRangeLow->set_value((m->*range).low); |
529 |
|
eKeyRangeHigh->set_value((m->*range).high); |
530 |
|
} |
531 |
|
|
532 |
|
template<class C, class S, typename T> |
533 |
|
void call_setter(const C* w, void (S::*setter)(T)) { |
534 |
|
if (update_model == 0) { |
535 |
|
(static_cast<S*>(this)->*setter)(w->get_value()); |
536 |
|
sig_changed(); |
537 |
|
} |
538 |
|
} |
539 |
|
}; |
540 |
|
|
541 |
#endif |
#endif |