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

Diff of /gigedit/trunk/src/gigedit/paramedit.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2507 by persson, Sun Jan 12 19:37:55 2014 UTC revision 3409 by schoenebeck, Tue Jan 23 16:30:56 2018 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2014 Andreas Persson   * Copyright (C) 2006-2017 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
# Line 17  Line 17 
17   * 02110-1301 USA.   * 02110-1301 USA.
18   */   */
19    
20  #include <cstring>  #include "global.h"
   
21  #include "paramedit.h"  #include "paramedit.h"
22    
 #include "global.h"  
23  #include "compat.h"  #include "compat.h"
24    #include "Settings.h"
25    
26  std::string gig_encoding("CP1252");  #include <glibmm/glibmm.h>
27    #include <gtkmm/messagedialog.h>
 Glib::ustring gig_to_utf8(const gig::String& gig_string) {  
     return Glib::convert_with_fallback(gig_string, "UTF-8", gig_encoding, "?");  
 }  
   
 gig::String gig_from_utf8(const Glib::ustring& utf8_string) {  
     return Glib::convert_with_fallback(utf8_string, gig_encoding, "UTF-8", "?");  
 }  
   
28    
29  namespace {  namespace {
30      const char* const controlChangeTexts[] = {      struct CCText {
31          _("none"), _("channelaftertouch"), _("velocity"),          const char* const txt;
32          0,          bool isExtension; ///< True if this is a controller only supported by LinuxSampler, but not supperted by Gigasampler/GigaStudio.
33          _("modwheel"), // "Modulation Wheel or Lever",      };
34          _("breath"), // "Breath Controller",      static const CCText controlChangeTexts[] = {
35          0,          // 3 special ones (not being CCs)
36          _("foot"), // "Foot Controller",          { _("none") }, { _("channelaftertouch") }, { _("velocity") },
37          _("portamentotime"), // "Portamento Time",          {0}, // bank select MSB (hard coded in sampler, so discouraged to be used here, even though considerable)
38          0, 0, 0, 0, 0, 0,          { _("modwheel") }, // "Modulation Wheel or Lever",
39          _("effect1"), // "Effect Control 1",          { _("breath") }, // "Breath Controller",
40          _("effect2"), // "Effect Control 2",          { _("undefined"), true },
41          0, 0,          { _("foot") }, // "Foot Controller",
42          _("genpurpose1"), // "General Purpose Controller 1",          { _("portamentotime") }, // "Portamento Time",
43          _("genpurpose2"), // "General Purpose Controller 2",          { _("data entry MSB"), true },
44          _("genpurpose3"), // "General Purpose Controller 3",          { _("volume"), true },
45          _("genpurpose4"), // "General Purpose Controller 4",          { _("balance"), true },
46          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,          { _("undefined"), true },
47          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,          { _("pan"), true },
48          0, 0, 0, 0, 0, 0,          { _("expression"), true },
49          _("sustainpedal"), // "Damper Pedal on/off (Sustain)",          { _("effect1") }, // "Effect Control 1",
50          _("portamento"), // "Portamento On/Off",          { _("effect2") }, // "Effect Control 2",
51          _("sostenuto"), // "Sustenuto On/Off",          { _("undefined"), true },
52          _("softpedal"), // "Soft Pedal On/Off",          { _("undefined"), true },
53          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,          { _("genpurpose1") }, // "General Purpose Controller 1",
54          _("genpurpose5"), // "General Purpose Controller 5",          { _("genpurpose2") }, // "General Purpose Controller 2",
55          _("genpurpose6"), // "General Purpose Controller 6",          { _("genpurpose3") }, // "General Purpose Controller 3",
56          _("genpurpose7"), // "General Purpose Controller 7",          { _("genpurpose4") }, // "General Purpose Controller 4",
57          _("genpurpose8"), // "General Purpose Controller 8",          { _("undefined"), true },
58          0, 0, 0, 0, 0, 0, 0,          { _("undefined"), true },
59          _("effect1depth"), // "Effects 1 Depth",          { _("undefined"), true },
60          _("effect2depth"), // "Effects 2 Depth",          { _("undefined"), true },
61          _("effect3depth"), // "Effects 3 Depth",          { _("undefined"), true },
62          _("effect4depth"), // "Effects 4 Depth",          { _("undefined"), true },
63          _("effect5depth"), // "Effects 5 Depth"          { _("undefined"), true },
64            { _("undefined"), true },
65            { _("undefined"), true },
66            { _("undefined"), true },
67            { _("undefined"), true },
68            { _("undefined"), true },
69            
70            // LSB variant of the various controllers above
71            // (so discouraged to be used here for now)
72            {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
73            {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
74            {0}, {0}, {0}, {0},
75            
76            { _("sustainpedal") }, // "Damper Pedal on/off (Sustain)",
77            { _("portamento") }, // "Portamento On/Off",
78            { _("sostenuto") }, // "Sustenuto On/Off",
79            { _("softpedal") }, // "Soft Pedal On/Off",
80            { _("legato"), true },
81            { _("hold2"), true },
82            { _("soundvariation"), true },
83            { _("timbre"), true },
84            { _("releasetime"), true },
85            { _("attacktime"), true },
86            { _("brightness"), true },
87            { _("decaytime"), true },
88            { _("vibratorate"), true },
89            { _("vibratodepth"), true },
90            { _("vibratodelay"), true },
91            { _("undefined"), true },
92            { _("genpurpose5") }, // "General Purpose Controller 5",
93            { _("genpurpose6") }, // "General Purpose Controller 6",
94            { _("genpurpose7") }, // "General Purpose Controller 7",
95            { _("genpurpose8") }, // "General Purpose Controller 8",
96            { _("portamentoctrl"), true },
97            { _("undefined"), true },
98            { _("undefined"), true },
99            { _("undefined"), true },
100            {0}, // high resolution velocity prefix (so discouraged to be used here)
101            { _("undefined"), true },
102            { _("undefined"), true },
103            { _("effect1depth") }, // "Effects 1 Depth",
104            { _("effect2depth") }, // "Effects 2 Depth",
105            { _("effect3depth") }, // "Effects 3 Depth",
106            { _("effect4depth") }, // "Effects 4 Depth",
107            { _("effect5depth") }, // "Effects 5 Depth"
108            { _("dataincrement"), true },
109            { _("datadecrement"), true },
110            {0}, // NRPN LSB (so discouraged to be used here)
111            {0}, // NRPN MSB (so discouraged to be used here)
112            {0}, // RPN LSB (so discouraged to be used here)
113            {0}, // RPN MSB (so discouraged to be used here)
114            { _("undefined"), true },
115            { _("undefined"), true },
116            { _("undefined"), true },
117            { _("undefined"), true },
118            { _("undefined"), true },
119            { _("undefined"), true },
120            { _("undefined"), true },
121            { _("undefined"), true },
122            { _("undefined"), true },
123            { _("undefined"), true },
124            { _("undefined"), true },
125            { _("undefined"), true },
126            { _("undefined"), true },
127            { _("undefined"), true },
128            { _("undefined"), true },
129            { _("undefined"), true },
130            { _("undefined"), true },
131            { _("undefined"), true } // CC 119
132            // (all other ones that follow [CC 120- CC 127] are hard coded channel
133            // mode messages, so those are discouraged to be used here)
134      };      };
135  }  }
136    
137    #define controlChangeTextsSize  (sizeof(controlChangeTexts) / sizeof(CCText))
138    
139  LabelWidget::LabelWidget(const char* labelText, Gtk::Widget& widget) :  LabelWidget::LabelWidget(const char* labelText, Gtk::Widget& widget) :
140      label(Glib::ustring(labelText) + ":"),      label(Glib::ustring(labelText) + ":"),
141      widget(widget)      widget(widget)
142  {  {
143    #if HAS_GTKMM_ALIGNMENT
144      label.set_alignment(Gtk::ALIGN_START);      label.set_alignment(Gtk::ALIGN_START);
145    #else
146        label.set_halign(Gtk::Align::START);
147    #endif
148        Settings::singleton()->showTooltips.get_proxy().signal_changed().connect(
149            sigc::mem_fun(this, &LabelWidget::on_show_tooltips_changed)
150        );
151    
152        // workaround for a crash with certain gtkmm versions: postpone calling
153        // on_show_tooltips_changed() because widget.gobj() might be uninitialized
154        // at this point yet
155        Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
156            sigc::mem_fun(*this, &LabelWidget::on_show_tooltips_changed),
157            300
158        );
159    }
160    
161    void LabelWidget::on_show_tooltips_changed() {
162        const bool b = Settings::singleton()->showTooltips;
163        label.set_has_tooltip(b);
164        widget.set_has_tooltip(b);
165  }  }
166    
167  void LabelWidget::set_sensitive(bool sensitive)  void LabelWidget::set_sensitive(bool sensitive)
# Line 86  void LabelWidget::set_sensitive(bool sen Line 170  void LabelWidget::set_sensitive(bool sen
170      widget.set_sensitive(sensitive);      widget.set_sensitive(sensitive);
171  }  }
172    
173    ReadOnlyLabelWidget::ReadOnlyLabelWidget(const char* leftHandText)
174        : LabelWidget(leftHandText, text)
175    {
176    #if HAS_GTKMM_ALIGNMENT
177        text.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_START);
178    #else
179        label.set_halign(Gtk::Align::START);
180        label.set_valign(Gtk::Align::START);
181    #endif
182    }
183    
184    ReadOnlyLabelWidget::ReadOnlyLabelWidget(const char* leftHandText, const char* rightHandText)
185       : LabelWidget(leftHandText, text)
186    {
187    #if HAS_GTKMM_ALIGNMENT
188        text.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_START);
189    #else
190        text.set_halign(Gtk::Align::START);
191        text.set_valign(Gtk::Align::START);
192    #endif
193        text.set_text(rightHandText);
194    }
195    
196  NumEntry::NumEntry(const char* labelText, double lower, double upper,  NumEntry::NumEntry(const char* labelText, double lower, double upper,
197                     int decimals) :                     int decimals) :
198      LabelWidget(labelText, box),      LabelWidget(labelText, box),
# Line 106  NumEntry::NumEntry(const char* labelText Line 213  NumEntry::NumEntry(const char* labelText
213      box.add(scale);      box.add(scale);
214  }  }
215    
216    void NumEntry::on_show_tooltips_changed() {
217        LabelWidget::on_show_tooltips_changed();
218    
219        const bool b = Settings::singleton()->showTooltips;
220        spinbutton.set_has_tooltip(b);
221        scale.set_has_tooltip(b);
222    }
223    
224  NumEntryGain::NumEntryGain(const char* labelText,  NumEntryGain::NumEntryGain(const char* labelText,
225                             double lower, double upper,                             double lower, double upper,
226                             int decimals, double coeff) :                             int decimals, double coeff) :
# Line 156  BoolEntryPlus6::BoolEntryPlus6(const cha Line 271  BoolEntryPlus6::BoolEntryPlus6(const cha
271          sigc::mem_fun(*this, &BoolEntryPlus6::value_changed));          sigc::mem_fun(*this, &BoolEntryPlus6::value_changed));
272  }  }
273    
274    void BoolEntryPlus6::on_show_tooltips_changed() {
275        LabelWidget::on_show_tooltips_changed();
276    
277        eGain.on_show_tooltips_changed();
278    }
279    
280  void BoolEntryPlus6::value_changed()  void BoolEntryPlus6::value_changed()
281  {  {
282      if (checkbutton.get_active()) eGain.set_value(plus6value);      if (checkbutton.get_active()) eGain.set_value(plus6value);
# Line 233  namespace { Line 354  namespace {
354                  return true;                  return true;
355              }              }
356          }          }
357    
358    #if HAS_GTKMM_CPP11_ENUMS
359            return Gtk::SpinButton::INPUT_ERROR;
360    #else
361          return Gtk::INPUT_ERROR;          return Gtk::INPUT_ERROR;
362    #endif
363      }      }
364  }  }
365    
# Line 253  Glib::ustring note_str(int note) Line 379  Glib::ustring note_str(int note)
379    
380  namespace {  namespace {
381      // Convert the Entry text to a number      // Convert the Entry text to a number
382    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
383        int on_input(double& new_value, Gtk::SpinButton* spinbutton) {
384            return note_value(spinbutton->get_text(), &new_value);
385        }
386    #else
387      int on_input(double* new_value, Gtk::SpinButton* spinbutton) {      int on_input(double* new_value, Gtk::SpinButton* spinbutton) {
388          return note_value(spinbutton->get_text(), new_value);          return note_value(spinbutton->get_text(), new_value);
389      }      }
390    #endif
391    
392      // Convert the Adjustment position to text      // Convert the Adjustment position to text
393      bool on_output(Gtk::SpinButton* spinbutton) {      bool on_output(Gtk::SpinButton* spinbutton) {
# Line 276  void spin_button_show_notes(Gtk::SpinBut Line 408  void spin_button_show_notes(Gtk::SpinBut
408          sigc::bind(sigc::ptr_fun(&on_output), &spin_button));          sigc::bind(sigc::ptr_fun(&on_output), &spin_button));
409  }  }
410    
411    void ChoiceEntryBase::on_show_tooltips_changed() {
412        LabelWidget::on_show_tooltips_changed();
413    
414        const bool b = Settings::singleton()->showTooltips;
415        combobox.set_has_tooltip(b);
416    }
417    
418  ChoiceEntryLeverageCtrl::ChoiceEntryLeverageCtrl(const char* labelText) :  ChoiceEntryLeverageCtrl::ChoiceEntryLeverageCtrl(const char* labelText) :
419    #if HAS_GTKMM_ALIGNMENT
420      LabelWidget(labelText, align),      LabelWidget(labelText, align),
421      align(0, 0, 0, 0)      align(0, 0, 0, 0)
422    #else
423        LabelWidget(labelText, combobox)
424    #endif
425  {  {
426      for (int i = 0 ; i < 99 ; i++) {      for (int i = 0 ; i < controlChangeTextsSize ; i++) {
427          if (controlChangeTexts[i]) {          if (controlChangeTexts[i].txt) {
428                const int cc = i - 3;
429                Glib::ustring s = (i < 3)
430                    ? controlChangeTexts[i].txt
431                    : Glib::ustring::compose("CC%1: %2%3", cc, controlChangeTexts[i].txt, controlChangeTexts[i].isExtension ? " [EXT]" : "");
432  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 24) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 24) || GTKMM_MAJOR_VERSION < 2
433              combobox.append_text(controlChangeTexts[i]);              combobox.append_text(s);
434  #else  #else
435              combobox.append(controlChangeTexts[i]);              combobox.append(s);
436  #endif  #endif
437          }          }
438      }      }
439      combobox.signal_changed().connect(      combobox.signal_changed().connect(
440          sigc::mem_fun(*this, &ChoiceEntryLeverageCtrl::value_changed));          sigc::mem_fun(*this, &ChoiceEntryLeverageCtrl::value_changed));
441    #if HAS_GTKMM_ALIGNMENT
442      align.add(combobox);      align.add(combobox);
443    #else
444        combobox.set_halign(Gtk::Align::FILL);
445        combobox.set_valign(Gtk::Align::FILL);
446    #endif
447      value.type = gig::leverage_ctrl_t::type_none;      value.type = gig::leverage_ctrl_t::type_none;
448      value.controller_number = 0;      value.controller_number = 0;
449  }  }
450    
451    void ChoiceEntryLeverageCtrl::on_show_tooltips_changed() {
452        LabelWidget::on_show_tooltips_changed();
453    
454        const bool b = Settings::singleton()->showTooltips;
455        combobox.set_has_tooltip(b);
456    }
457    
458  void ChoiceEntryLeverageCtrl::value_changed()  void ChoiceEntryLeverageCtrl::value_changed()
459  {  {
460      int rowno = combobox.get_active_row_number();      int rowno = combobox.get_active_row_number();
# Line 315  void ChoiceEntryLeverageCtrl::value_chan Line 474  void ChoiceEntryLeverageCtrl::value_chan
474      default:      default:
475          value.type = gig::leverage_ctrl_t::type_controlchange;          value.type = gig::leverage_ctrl_t::type_controlchange;
476          int x = 3;          int x = 3;
477          for (uint cc = 0 ; cc < 96 ; cc++) {          for (uint cc = 0 ; cc < controlChangeTextsSize - 3 ; cc++) {
478              if (controlChangeTexts[cc + 3]) {              if (controlChangeTexts[cc + 3].txt) {
479                  if (rowno == x) {                  if (rowno == x) {
480                      value.controller_number = cc;                      value.controller_number = cc;
481                        if (controlChangeTexts[cc + 3].isExtension &&
482                            Settings::singleton()->warnUserOnExtensions)
483                        {
484                            Glib::ustring txt = _("<b>Format Extension</b>\n\nAll controllers marked with \"<b>[EXT]</b>\" are an extension to the original gig sound format. They will only work with LinuxSampler, but they will <b>not work</b> with Gigasampler/GigaStudio!\n\n(You may disable this warning in the <i>Settings</i> menu.)");
485                            Gtk::MessageDialog msg(
486                                txt, true, Gtk::MESSAGE_WARNING
487                            );
488                            msg.run();
489                        }
490                      break;                      break;
491                  }                  }
492                  x++;                  x++;
# Line 331  void ChoiceEntryLeverageCtrl::value_chan Line 499  void ChoiceEntryLeverageCtrl::value_chan
499    
500  void ChoiceEntryLeverageCtrl::set_value(gig::leverage_ctrl_t value)  void ChoiceEntryLeverageCtrl::set_value(gig::leverage_ctrl_t value)
501  {  {
502      int x;      int comboIndex;
503      switch (value.type)      switch (value.type)
504      {      {
505      case gig::leverage_ctrl_t::type_none:      case gig::leverage_ctrl_t::type_none:
506          x = 0;          comboIndex = 0;
507          break;          break;
508      case gig::leverage_ctrl_t::type_channelaftertouch:      case gig::leverage_ctrl_t::type_channelaftertouch:
509          x = 1;          comboIndex = 1;
510          break;          break;
511      case gig::leverage_ctrl_t::type_velocity:      case gig::leverage_ctrl_t::type_velocity:
512          x = 2;          comboIndex = 2;
513          break;          break;
514      case gig::leverage_ctrl_t::type_controlchange:      case gig::leverage_ctrl_t::type_controlchange: {
515          x = -1;          comboIndex = -1;
516          for (uint cc = 0 ; cc < 96 ; cc++) {          int x = 3;
517              if (controlChangeTexts[cc + 3]) {          for (uint cc = 0 ; cc < controlChangeTextsSize - 3 ; cc++) {
518                  x++;              if (controlChangeTexts[cc + 3].txt) {
519                  if (value.controller_number == cc) {                  if (value.controller_number == cc) {
520                      x += 3;                      comboIndex = x;
521                      break;                      break;
522                  }                  }
523                    x++;
524              }              }
525          }          }
526          break;          break;
527        }
528      default:      default:
529          x = -1;          comboIndex = -1;
530          break;          break;
531      }      }
532      combobox.set_active(x);      combobox.set_active(comboIndex);
533    }
534    
535    
536    BoolBox::BoolBox(const char* labelText) : Gtk::CheckButton(labelText) {
537        signal_toggled().connect(sig_changed.make_slot());
538        Settings::singleton()->showTooltips.get_proxy().signal_changed().connect(
539            sigc::mem_fun(this, &BoolBox::on_show_tooltips_changed)
540        );
541        on_show_tooltips_changed();
542    }
543    
544    void BoolBox::on_show_tooltips_changed() {
545        const bool b = Settings::singleton()->showTooltips;
546        set_has_tooltip(b);
547  }  }
548    
549    
# Line 412  void StringEntryMultiLine::set_value(con Line 596  void StringEntryMultiLine::set_value(con
596      text_buffer->set_text(text);      text_buffer->set_text(text);
597  }  }
598    
599    void StringEntryMultiLine::on_show_tooltips_changed() {
600        LabelWidget::on_show_tooltips_changed();
601    
602        const bool b = Settings::singleton()->showTooltips;
603        text_view.set_has_tooltip(b);
604    }
605    
606    
607  Table::Table(int x, int y) : Gtk::Table(x, y), rowno(0) {  }  Table::Table(int x, int y) :
608    #if USE_GTKMM_GRID
609        Gtk::Grid(),
610        cols(x),
611    #else
612        Gtk::Table(x, y),
613    #endif
614        rowno(0)
615    {
616    }
617    
618  void Table::add(BoolEntry& boolentry)  void Table::add(BoolEntry& boolentry)
619  {  {
620    #if USE_GTKMM_GRID
621        attach(boolentry.widget, 0, rowno, 2);
622    #else
623      attach(boolentry.widget, 0, 2, rowno, rowno + 1,      attach(boolentry.widget, 0, 2, rowno, rowno + 1,
624             Gtk::FILL, Gtk::SHRINK);             Gtk::FILL, Gtk::SHRINK);
625    #endif
626      rowno++;      rowno++;
627  }  }
628    
629  void Table::add(BoolEntryPlus6& boolentry)  void Table::add(BoolEntryPlus6& boolentry)
630  {  {
631    #if USE_GTKMM_GRID
632        attach(boolentry.widget, 0, rowno, 2);
633    #else
634      attach(boolentry.widget, 0, 2, rowno, rowno + 1,      attach(boolentry.widget, 0, 2, rowno, rowno + 1,
635             Gtk::FILL, Gtk::SHRINK);             Gtk::FILL, Gtk::SHRINK);
636    #endif
637      rowno++;      rowno++;
638  }  }
639    
640  void Table::add(LabelWidget& prop)  void Table::add(LabelWidget& prop)
641  {  {
642    #if USE_GTKMM_GRID
643        attach(prop.label, 1, rowno);
644        attach(prop.widget, 2, rowno);
645    #else
646      attach(prop.label, 1, 2, rowno, rowno + 1,      attach(prop.label, 1, 2, rowno, rowno + 1,
647             Gtk::FILL, Gtk::SHRINK);             Gtk::FILL, Gtk::SHRINK);
648      attach(prop.widget, 2, 3, rowno, rowno + 1,      attach(prop.widget, 2, 3, rowno, rowno + 1,
649             Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK);             Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK);
650    #endif
651      rowno++;      rowno++;
652  }  }

Legend:
Removed from v.2507  
changed lines
  Added in v.3409

  ViewVC Help
Powered by ViewVC