/[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 1225 by schoenebeck, Sun Jun 10 10:56:11 2007 UTC revision 2844 by persson, Sun Sep 20 08:49:40 2015 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006, 2007 Andreas Persson   * Copyright (C) 2006-2015 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>
21    
22    #include <glibmmconfig.h>
23    // threads.h must be included first to be able to build with
24    // G_DISABLE_DEPRECATED
25    #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
26        (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
27    #include <glibmm/threads.h>
28    #endif
29    
30  #include "paramedit.h"  #include "paramedit.h"
31    
32  bool update_gui;  #include "global.h"
33    #include "compat.h"
34    #include "Settings.h"
35    
36    #include <gtkmm/messagedialog.h>
37    
38    std::string gig_encoding("CP1252");
39    
40    Glib::ustring gig_to_utf8(const gig::String& gig_string) {
41        return Glib::convert_with_fallback(gig_string, "UTF-8", gig_encoding, "?");
42    }
43    
44    gig::String gig_from_utf8(const Glib::ustring& utf8_string) {
45        return Glib::convert_with_fallback(utf8_string, gig_encoding, "UTF-8", "?");
46    }
47    
48    
49  namespace {  namespace {
50      const char* const controlChangeTexts[] = {      struct CCText {
51          "none", "channelaftertouch", "velocity",          const char* const txt;
52          0,          bool isExtension; ///< True if this is a controller only supported by LinuxSampler, but not supperted by Gigasampler/GigaStudio.
53          "modwheel", // "Modulation Wheel or Lever",      };
54          "breath", // "Breath Controller",      static const CCText controlChangeTexts[] = {
55          0,          // 3 special ones (not being CCs)
56          "foot", // "Foot Controller",          { _("none") }, { _("channelaftertouch") }, { _("velocity") },
57          "portamentotime", // "Portamento Time",          {0}, // bank select MSB (hard coded in sampler, so discouraged to be used here, even though considerable)
58          0, 0, 0, 0, 0, 0,          { _("modwheel") }, // "Modulation Wheel or Lever",
59          "effect1", // "Effect Control 1",          { _("breath") }, // "Breath Controller",
60          "effect2", // "Effect Control 2",          { _("undefined"), true },
61          0, 0,          { _("foot") }, // "Foot Controller",
62          "genpurpose1", // "General Purpose Controller 1",          { _("portamentotime") }, // "Portamento Time",
63          "genpurpose2", // "General Purpose Controller 2",          { _("data entry MSB"), true },
64          "genpurpose3", // "General Purpose Controller 3",          { _("volume"), true },
65          "genpurpose4", // "General Purpose Controller 4",          { _("balance"), true },
66          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,          { _("undefined"), true },
67          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,          { _("pan"), true },
68          0, 0, 0, 0, 0, 0,          { _("expression"), true },
69          "sustainpedal", // "Damper Pedal on/off (Sustain)",          { _("effect1") }, // "Effect Control 1",
70          "portamento", // "Portamento On/Off",          { _("effect2") }, // "Effect Control 2",
71          "sostenuto", // "Sustenuto On/Off",          { _("undefined"), true },
72          "softpedal", // "Soft Pedal On/Off",          { _("undefined"), true },
73          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,          { _("genpurpose1") }, // "General Purpose Controller 1",
74          "genpurpose5", // "General Purpose Controller 5",          { _("genpurpose2") }, // "General Purpose Controller 2",
75          "genpurpose6", // "General Purpose Controller 6",          { _("genpurpose3") }, // "General Purpose Controller 3",
76          "genpurpose7", // "General Purpose Controller 7",          { _("genpurpose4") }, // "General Purpose Controller 4",
77          "genpurpose8", // "General Purpose Controller 8",          { _("undefined"), true },
78          0, 0, 0, 0, 0, 0, 0,          { _("undefined"), true },
79          "effect1depth", // "Effects 1 Depth",          { _("undefined"), true },
80          "effect2depth", // "Effects 2 Depth",          { _("undefined"), true },
81          "effect3depth", // "Effects 3 Depth",          { _("undefined"), true },
82          "effect4depth", // "Effects 4 Depth",          { _("undefined"), true },
83          "effect5depth", // "Effects 5 Depth"          { _("undefined"), true },
84            { _("undefined"), true },
85            { _("undefined"), true },
86            { _("undefined"), true },
87            { _("undefined"), true },
88            { _("undefined"), true },
89            
90            // LSB variant of the various controllers above
91            // (so discouraged to be used here for now)
92            {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
93            {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
94            {0}, {0}, {0}, {0},
95            
96            { _("sustainpedal") }, // "Damper Pedal on/off (Sustain)",
97            { _("portamento") }, // "Portamento On/Off",
98            { _("sostenuto") }, // "Sustenuto On/Off",
99            { _("softpedal") }, // "Soft Pedal On/Off",
100            { _("legato"), true },
101            { _("hold2"), true },
102            { _("soundvariation"), true },
103            { _("timbre"), true },
104            { _("releasetime"), true },
105            { _("attacktime"), true },
106            { _("brightness"), true },
107            { _("decaytime"), true },
108            { _("vibratorate"), true },
109            { _("vibratodepth"), true },
110            { _("vibratodelay"), true },
111            { _("undefined"), true },
112            { _("genpurpose5") }, // "General Purpose Controller 5",
113            { _("genpurpose6") }, // "General Purpose Controller 6",
114            { _("genpurpose7") }, // "General Purpose Controller 7",
115            { _("genpurpose8") }, // "General Purpose Controller 8",
116            { _("portamentoctrl"), true },
117            { _("undefined"), true },
118            { _("undefined"), true },
119            { _("undefined"), true },
120            {0}, // high resolution velocity prefix (so discouraged to be used here)
121            { _("undefined"), true },
122            { _("undefined"), true },
123            { _("effect1depth") }, // "Effects 1 Depth",
124            { _("effect2depth") }, // "Effects 2 Depth",
125            { _("effect3depth") }, // "Effects 3 Depth",
126            { _("effect4depth") }, // "Effects 4 Depth",
127            { _("effect5depth") }, // "Effects 5 Depth"
128            { _("dataincrement"), true },
129            { _("datadecrement"), true },
130            {0}, // NRPN LSB (so discouraged to be used here)
131            {0}, // NRPN MSB (so discouraged to be used here)
132            {0}, // RPN LSB (so discouraged to be used here)
133            {0}, // RPN MSB (so discouraged to be used here)
134            { _("undefined"), true },
135            { _("undefined"), true },
136            { _("undefined"), true },
137            { _("undefined"), true },
138            { _("undefined"), true },
139            { _("undefined"), true },
140            { _("undefined"), true },
141            { _("undefined"), true },
142            { _("undefined"), true },
143            { _("undefined"), true },
144            { _("undefined"), true },
145            { _("undefined"), true },
146            { _("undefined"), true },
147            { _("undefined"), true },
148            { _("undefined"), true },
149            { _("undefined"), true },
150            { _("undefined"), true },
151            { _("undefined"), true } // CC 119
152            // (all other ones that follow [CC 120- CC 127] are hard coded channel
153            // mode messages, so those are discouraged to be used here)
154      };      };
155  }  }
156    
157    #define controlChangeTextsSize  (sizeof(controlChangeTexts) / sizeof(CCText))
158    
159  LabelWidget::LabelWidget(const char* labelText, Gtk::Widget& widget) :  LabelWidget::LabelWidget(const char* labelText, Gtk::Widget& widget) :
160      label(Glib::ustring(labelText) + ":"),      label(Glib::ustring(labelText) + ":"),
161      widget(widget)      widget(widget)
162  {  {
163      label.set_alignment(Gtk::ALIGN_LEFT);      label.set_alignment(Gtk::ALIGN_START);
164  }  }
165    
166  void LabelWidget::set_sensitive(bool sensitive)  void LabelWidget::set_sensitive(bool sensitive)
# Line 72  void LabelWidget::set_sensitive(bool sen Line 169  void LabelWidget::set_sensitive(bool sen
169      widget.set_sensitive(sensitive);      widget.set_sensitive(sensitive);
170  }  }
171    
172    ReadOnlyLabelWidget::ReadOnlyLabelWidget(const char* leftHandText)
173        : LabelWidget(leftHandText, text)
174    {
175        text.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_START);
176    }
177    
178    ReadOnlyLabelWidget::ReadOnlyLabelWidget(const char* leftHandText, const char* rightHandText)
179       : LabelWidget(leftHandText, text)
180    {
181        text.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_START);
182        text.set_text(rightHandText);
183    }
184    
185  NumEntry::NumEntry(const char* labelText, double lower, double upper,  NumEntry::NumEntry(const char* labelText, double lower, double upper,
186                     int decimals) :                     int decimals) :
187        LabelWidget(labelText, box),
188    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
189      adjust(lower, lower, upper, 1, 10),      adjust(lower, lower, upper, 1, 10),
190    #else
191        adjust(Gtk::Adjustment::create(lower, lower, upper, 1, 10)),
192    #endif
193      scale(adjust),      scale(adjust),
194      spinbutton(adjust),      spinbutton(adjust)
     LabelWidget(labelText, box)  
195  {  {
196        scale.set_size_request(70);
197      spinbutton.set_digits(decimals);      spinbutton.set_digits(decimals);
198        spinbutton.set_value(0);
199        spinbutton.set_numeric();
200      scale.set_draw_value(false);      scale.set_draw_value(false);
201      box.pack_start(spinbutton, Gtk::PACK_SHRINK);      box.pack_start(spinbutton, Gtk::PACK_SHRINK);
202      box.add(scale);      box.add(scale);
# Line 89  NumEntryGain::NumEntryGain(const char* l Line 206  NumEntryGain::NumEntryGain(const char* l
206                             double lower, double upper,                             double lower, double upper,
207                             int decimals, double coeff) :                             int decimals, double coeff) :
208      NumEntry(labelText, lower, upper, decimals),      NumEntry(labelText, lower, upper, decimals),
209      coeff(coeff)      value(0),
210        coeff(coeff),
211        connected(true)
212  {  {
213      spinbutton.signal_value_changed().connect(      spinbutton.signal_value_changed().connect(
214          sigc::mem_fun(*this, &NumEntryGain::value_changed));          sigc::mem_fun(*this, &NumEntryGain::value_changed));
# Line 97  NumEntryGain::NumEntryGain(const char* l Line 216  NumEntryGain::NumEntryGain(const char* l
216    
217  void NumEntryGain::value_changed()  void NumEntryGain::value_changed()
218  {  {
219      if (ptr && update_gui) {      if (!connected) return;
220          *ptr = int32_t(spinbutton.get_value() * coeff);  
221        const double f = pow(10, spinbutton.get_digits());
222        int new_value = round_to_int(spinbutton.get_value() * f);
223        if (new_value != round_to_int(value / coeff * f)) {
224            value = round_to_int(new_value / f * coeff);
225            sig_changed();
226      }      }
227  }  }
228    
229  void NumEntryGain::set_ptr(int32_t* ptr)  void NumEntryGain::set_value(int32_t value)
230  {  {
231      this->ptr = 0;      if (value != this->value) {
232      bool plus6 = *ptr < 0;          this->value = value;
233      set_value(plus6 ? 0 : *ptr / coeff);  
234      set_sensitive(!plus6);          connected = false;
235      this->ptr = ptr;          bool plus6 = value < 0;
236            spinbutton.set_value(plus6 ? 0 : value / coeff);
237            set_sensitive(!plus6);
238            connected = true;
239    
240            sig_changed();
241        }
242  }  }
243    
244    
245  BoolEntryPlus6::BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value) :  BoolEntryPlus6::BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value) :
246      LabelWidget(labelText, checkbutton),      LabelWidget(labelText, checkbutton),
247        checkbutton(labelText),
248      eGain(eGain),      eGain(eGain),
249      plus6value(plus6value)      plus6value(plus6value)
250  {  {
# Line 123  BoolEntryPlus6::BoolEntryPlus6(const cha Line 254  BoolEntryPlus6::BoolEntryPlus6(const cha
254    
255  void BoolEntryPlus6::value_changed()  void BoolEntryPlus6::value_changed()
256  {  {
257      if (ptr && update_gui) {      if (checkbutton.get_active()) eGain.set_value(plus6value);
258          bool plus6 = checkbutton.get_active();      else if (eGain.get_value() < 0) eGain.set_value(0);
         if (plus6) {  
             eGain.set_value(0);  
             *ptr = plus6value;  
         } else {  
             if (*ptr < 0) {  
                 *ptr = 0;  
             }  
         }  
         eGain.set_sensitive(!plus6);  
     }  
259  }  }
260    
261  void BoolEntryPlus6::set_ptr(int32_t* ptr)  int32_t BoolEntryPlus6::get_value() const
262  {  {
263      this->ptr = 0;      return eGain.get_value();
264      checkbutton.set_active(*ptr < 0);  }
265      this->ptr = ptr;  
266    void BoolEntryPlus6::set_value(int32_t value)
267    {
268        checkbutton.set_active(value < 0);
269  }  }
270    
271  NumEntryPermille::NumEntryPermille(const char* labelText,  NumEntryPermille::NumEntryPermille(const char* labelText,
272                                     double lower, double upper, int decimals) :                                     double lower, double upper, int decimals) :
273      NumEntry(labelText, lower, upper, decimals)      NumEntry(labelText, lower, upper, decimals),
274        value(0)
275  {  {
276      spinbutton.signal_value_changed().connect(      spinbutton.signal_value_changed().connect(
277          sigc::mem_fun(*this, &NumEntryPermille::value_changed));          sigc::mem_fun(*this, &NumEntryPermille::value_changed));
# Line 154  NumEntryPermille::NumEntryPermille(const Line 279  NumEntryPermille::NumEntryPermille(const
279    
280  void NumEntryPermille::value_changed()  void NumEntryPermille::value_changed()
281  {  {
282      if (ptr && update_gui) {      uint16_t new_value = uint16_t(spinbutton.get_value() * 10 + 0.5);
283          *ptr = uint16_t(spinbutton.get_value() * 10 + 0.5);      if (new_value != value) {
284            value = uint16_t(spinbutton.get_value() * 10 + 0.5);
285            sig_changed();
286      }      }
287  }  }
288    
289  void NumEntryPermille::set_ptr(uint16_t* ptr)  void NumEntryPermille::set_value(uint16_t value)
290  {  {
291      this->ptr = 0;      if (value != this->value) {
292      set_value(*ptr / 10.0);          spinbutton.set_value(value / 10.0);
293      this->ptr = ptr;      }
294  }  }
295    
296    
297  NoteEntry::NoteEntry(const char* labelText) :  NoteEntry::NoteEntry(const char* labelText) :
298      NumEntryTemp<uint8_t>(labelText)      NumEntryTemp<uint8_t>(labelText)
299  {  {
300      spinbutton.signal_input().connect(      spin_button_show_notes(spinbutton);
         sigc::mem_fun(*this, &NoteEntry::on_input));  
     spinbutton.signal_output().connect(  
         sigc::mem_fun(*this, &NoteEntry::on_output));  
301  }  }
302    
303  const char* notes[] = {  namespace {
304      "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"      const char* notes[] = {
305  };          _("C"), _("C#"), _("D"), _("D#"), _("E"), _("F"),_("F#"),
306            _("G"), _("G#"), _("A"), _("A#"), _("B")
307        };
308    
309        int note_value(const Glib::ustring& note, double* value)
310        {
311            const char* str = note.c_str();
312    
313            int i;
314            for (i = 11 ; i >= 0 ; i--) {
315                if (strncasecmp(str, notes[i], strlen(notes[i])) == 0) break;
316            }
317            if (i >= 0) {
318                char* endptr;
319                long x = strtol(str + strlen(notes[i]), &endptr, 10);
320                if (endptr != str + strlen(notes[i])) {
321                    *value = std::max(0L, std::min(i + (x + 1) * 12, 127L));
322                    return true;
323                }
324            } else {
325                char* endptr;
326                long x = strtol(str, &endptr, 10);
327                if (endptr != str) {
328                    *value = std::max(0L, std::min(x, 127L));
329                    return true;
330                }
331            }
332            return Gtk::INPUT_ERROR;
333        }
334    }
335    
336  // Convert the Entry text to a number  int note_value(const Glib::ustring& note)
 int NoteEntry::on_input(double* new_value)  
337  {  {
338      const char* str = spinbutton.get_text().c_str();      double value = 0;
339        note_value(note, &value);
340        return value;
341    }
342    
343      int i;  Glib::ustring note_str(int note)
344      for (i = 11 ; i >= 0 ; i--) {  {
345          if (strncmp(str, notes[i], strlen(notes[i])) == 0) break;      char buf[10];
346        sprintf(buf, "%s%d", notes[note % 12], note / 12 - 1);
347        return buf;
348    }
349    
350    namespace {
351        // Convert the Entry text to a number
352        int on_input(double* new_value, Gtk::SpinButton* spinbutton) {
353            return note_value(spinbutton->get_text(), new_value);
354      }      }
355      if (i >= 0) {  
356          char* endptr;      // Convert the Adjustment position to text
357          long x = strtol(str + strlen(notes[i]), &endptr, 10);      bool on_output(Gtk::SpinButton* spinbutton) {
358          if (endptr != str + strlen(notes[i])) {          spinbutton->set_text(
359              *new_value = i + (x + 1) * 12;              note_str(spinbutton->get_adjustment()->get_value() + 0.5));
360              return true;          return true;
         }  
361      }      }
     return Gtk::INPUT_ERROR;  
362  }  }
363    
364  // Convert the Adjustment position to text  // Make a SpinButton show notes instead of numbers
365  bool NoteEntry::on_output()  void spin_button_show_notes(Gtk::SpinButton& spin_button)
366  {  {
367      int x = int(spinbutton.get_adjustment()->get_value());      spin_button.set_numeric(false);
368      char buf[10];      spin_button.set_width_chars(4);
369      sprintf(buf, "%s%d", notes[x % 12], x / 12 - 1);      spin_button.signal_input().connect(
370      spinbutton.set_text(buf);          sigc::bind(sigc::ptr_fun(&on_input), &spin_button));
371      return true;      spin_button.signal_output().connect(
372            sigc::bind(sigc::ptr_fun(&on_output), &spin_button));
373  }  }
374    
375  ChoiceEntryLeverageCtrl::ChoiceEntryLeverageCtrl(const char* labelText) :  ChoiceEntryLeverageCtrl::ChoiceEntryLeverageCtrl(const char* labelText) :
376      align(0, 0, 0, 0),      LabelWidget(labelText, align),
377      LabelWidget(labelText, align)      align(0, 0, 0, 0)
378  {  {
379      for (int i = 0 ; i < 99 ; i++) {      for (int i = 0 ; i < controlChangeTextsSize ; i++) {
380          if (controlChangeTexts[i]) {          if (controlChangeTexts[i].txt) {
381              combobox.append_text(controlChangeTexts[i]);              const int cc = i - 3;
382                Glib::ustring s = (i < 3)
383                    ? controlChangeTexts[i].txt
384                    : Glib::ustring::compose("CC%1: %2%3", cc, controlChangeTexts[i].txt, controlChangeTexts[i].isExtension ? " [EXT]" : "");
385    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 24) || GTKMM_MAJOR_VERSION < 2
386                combobox.append_text(s);
387    #else
388                combobox.append(s);
389    #endif
390          }          }
391      }      }
392      combobox.signal_changed().connect(      combobox.signal_changed().connect(
393          sigc::mem_fun(*this, &ChoiceEntryLeverageCtrl::value_changed));          sigc::mem_fun(*this, &ChoiceEntryLeverageCtrl::value_changed));
394      align.add(combobox);      align.add(combobox);
395        value.type = gig::leverage_ctrl_t::type_none;
396        value.controller_number = 0;
397  }  }
398    
399  void ChoiceEntryLeverageCtrl::value_changed()  void ChoiceEntryLeverageCtrl::value_changed()
400  {  {
401      if (ptr && update_gui) {      int rowno = combobox.get_active_row_number();
402          int rowno = combobox.get_active_row_number();      switch (rowno)
403          switch (rowno)      {
404          {      case -1:
405          case -1:          break;
406              break;      case 0:
407          case 0:          value.type = gig::leverage_ctrl_t::type_none;
408              ptr->type = gig::leverage_ctrl_t::type_none;          break;
409              break;      case 1:
410          case 1:          value.type = gig::leverage_ctrl_t::type_channelaftertouch;
411              ptr->type = gig::leverage_ctrl_t::type_channelaftertouch;          break;
412              break;      case 2:
413          case 2:          value.type = gig::leverage_ctrl_t::type_velocity;
414              ptr->type = gig::leverage_ctrl_t::type_velocity;          break;
415              break;      default:
416          default:          value.type = gig::leverage_ctrl_t::type_controlchange;
417              ptr->type = gig::leverage_ctrl_t::type_controlchange;          int x = 3;
418              int x = 3;          for (uint cc = 0 ; cc < controlChangeTextsSize - 3 ; cc++) {
419              for (int cc = 0 ; cc < 96 ; cc++) {              if (controlChangeTexts[cc + 3].txt) {
420                  if (controlChangeTexts[cc + 3]) {                  if (rowno == x) {
421                      if (rowno == x) {                      value.controller_number = cc;
422                          ptr->controller_number = cc;                      if (controlChangeTexts[cc + 3].isExtension &&
423                          break;                          Settings::singleton()->warnUserOnExtensions)
424                        {
425                            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.)");
426                            Gtk::MessageDialog msg(
427                                txt, true, Gtk::MESSAGE_WARNING
428                            );
429                            msg.run();
430                      }                      }
431                      x++;                      break;
432                  }                  }
433                    x++;
434              }              }
             break;  
435          }          }
436            break;
437      }      }
438        if (rowno >= 0) sig_changed();
439  }  }
440    
441  void ChoiceEntryLeverageCtrl::set_ptr(gig::leverage_ctrl_t* ptr)  void ChoiceEntryLeverageCtrl::set_value(gig::leverage_ctrl_t value)
442  {  {
443      this->ptr = 0;      int comboIndex;
444      int x;      switch (value.type)
     switch (ptr->type)  
445      {      {
446      case gig::leverage_ctrl_t::type_none:      case gig::leverage_ctrl_t::type_none:
447          x = 0;          comboIndex = 0;
448          break;          break;
449      case gig::leverage_ctrl_t::type_channelaftertouch:      case gig::leverage_ctrl_t::type_channelaftertouch:
450          x = 1;          comboIndex = 1;
451          break;          break;
452      case gig::leverage_ctrl_t::type_velocity:      case gig::leverage_ctrl_t::type_velocity:
453          x = 2;          comboIndex = 2;
454          break;          break;
455      case gig::leverage_ctrl_t::type_controlchange:      case gig::leverage_ctrl_t::type_controlchange: {
456          x = -1;          comboIndex = -1;
457          for (int cc = 0 ; cc < 96 ; cc++) {          int x = 3;
458              if (controlChangeTexts[cc + 3]) {          for (uint cc = 0 ; cc < controlChangeTextsSize - 3 ; cc++) {
459                  x++;              if (controlChangeTexts[cc + 3].txt) {
460                  if (ptr->controller_number == cc) {                  if (value.controller_number == cc) {
461                      x += 3;                      comboIndex = x;
462                      break;                      break;
463                  }                  }
464                    x++;
465              }              }
466          }          }
467          break;          break;
468        }
469      default:      default:
470          x = -1;          comboIndex = -1;
471          break;          break;
472      }      }
473      combobox.set_active(x);      combobox.set_active(comboIndex);
     this->ptr = ptr;  
474  }  }
475    
476    
477  BoolEntry::BoolEntry(const char* labelText) :  BoolEntry::BoolEntry(const char* labelText) :
478      LabelWidget(labelText, checkbutton),      LabelWidget(labelText, checkbutton),
479      checkbutton(labelText),      checkbutton(labelText)
     ptr(0)  
480  {  {
481      checkbutton.signal_toggled().connect(      checkbutton.signal_toggled().connect(sig_changed.make_slot());
         sigc::mem_fun(*this, &BoolEntry::value_changed));  
482  }  }
483    
484  void BoolEntry::value_changed()  
485    StringEntry::StringEntry(const char* labelText) :
486        LabelWidget(labelText, entry)
487  {  {
488      if (ptr && update_gui) {      entry.signal_changed().connect(sig_changed.make_slot());
         *ptr = checkbutton.get_active();  
     }  
489  }  }
490    
491  void BoolEntry::set_ptr(bool* ptr)  gig::String StringEntry::get_value() const
492  {  {
493      this->ptr = 0;      return gig_from_utf8(entry.get_text());
     checkbutton.set_active(*ptr);  
     this->ptr = ptr;  
494  }  }
495    
496    void StringEntry::set_value(const gig::String& value) {
497        entry.set_text(gig_to_utf8(value));
498    }
499    
500  StringEntry::StringEntry(const char* labelText) :  
501      LabelWidget(labelText, entry)  StringEntryMultiLine::StringEntryMultiLine(const char* labelText) :
502        LabelWidget(labelText, frame)
503  {  {
504      entry.signal_changed().connect(      text_buffer = text_view.get_buffer();
505          sigc::mem_fun(*this, &StringEntry::value_changed));      frame.set_shadow_type(Gtk::SHADOW_IN);
506        frame.add(text_view);
507        text_buffer->signal_changed().connect(sig_changed.make_slot());
508  }  }
509    
510  void StringEntry::value_changed()  gig::String StringEntryMultiLine::get_value() const
511  {  {
512      if (ptr && update_gui) {      Glib::ustring value = text_buffer->get_text();
513          *ptr = entry.get_text();      for (int i = 0 ; (i = value.find("\x0a", i)) >= 0 ; i += 2)
514      }          value.replace(i, 1, "\x0d\x0a");
515        return gig_from_utf8(value);
516    }
517    
518    void StringEntryMultiLine::set_value(const gig::String& value)
519    {
520        Glib::ustring text = gig_to_utf8(value);
521        for (int i = 0 ; (i = text.find("\x0d\x0a", i, 2)) >= 0 ; i++)
522            text.replace(i, 2, "\x0a");
523        text_buffer->set_text(text);
524    }
525    
526    
527    Table::Table(int x, int y) : Gtk::Table(x, y), rowno(0) {  }
528    
529    void Table::add(BoolEntry& boolentry)
530    {
531        attach(boolentry.widget, 0, 2, rowno, rowno + 1,
532               Gtk::FILL, Gtk::SHRINK);
533        rowno++;
534    }
535    
536    void Table::add(BoolEntryPlus6& boolentry)
537    {
538        attach(boolentry.widget, 0, 2, rowno, rowno + 1,
539               Gtk::FILL, Gtk::SHRINK);
540        rowno++;
541  }  }
542    
543  void StringEntry::set_ptr(gig::String* ptr)  void Table::add(LabelWidget& prop)
544  {  {
545      this->ptr = 0;      attach(prop.label, 1, 2, rowno, rowno + 1,
546      entry.set_text(*ptr);             Gtk::FILL, Gtk::SHRINK);
547      this->ptr = ptr;      attach(prop.widget, 2, 3, rowno, rowno + 1,
548               Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK);
549        rowno++;
550  }  }

Legend:
Removed from v.1225  
changed lines
  Added in v.2844

  ViewVC Help
Powered by ViewVC