1 |
/* |
/* |
2 |
* Copyright (C) 2006-2013 Andreas Persson |
* Copyright (C) 2006-2014 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 |
100 |
scale.set_size_request(70); |
scale.set_size_request(70); |
101 |
spinbutton.set_digits(decimals); |
spinbutton.set_digits(decimals); |
102 |
spinbutton.set_value(0); |
spinbutton.set_value(0); |
103 |
|
spinbutton.set_numeric(); |
104 |
scale.set_draw_value(false); |
scale.set_draw_value(false); |
105 |
box.pack_start(spinbutton, Gtk::PACK_SHRINK); |
box.pack_start(spinbutton, Gtk::PACK_SHRINK); |
106 |
box.add(scale); |
box.add(scale); |
201 |
NoteEntry::NoteEntry(const char* labelText) : |
NoteEntry::NoteEntry(const char* labelText) : |
202 |
NumEntryTemp<uint8_t>(labelText) |
NumEntryTemp<uint8_t>(labelText) |
203 |
{ |
{ |
204 |
spinbutton.set_width_chars(4); |
spin_button_show_notes(spinbutton); |
205 |
spinbutton.signal_input().connect( |
} |
206 |
sigc::mem_fun(*this, &NoteEntry::on_input)); |
|
207 |
spinbutton.signal_output().connect( |
namespace { |
208 |
sigc::mem_fun(*this, &NoteEntry::on_output)); |
const char* notes[] = { |
209 |
} |
_("C"), _("C#"), _("D"), _("D#"), _("E"), _("F"),_("F#"), |
210 |
|
_("G"), _("G#"), _("A"), _("A#"), _("B") |
211 |
const char* notes[] = { |
}; |
212 |
_("C"), _("C#"), _("D"), _("D#"), _("E"), _("F"),_("F#"), |
|
213 |
_("G"), _("G#"), _("A"), _("A#"), _("B") |
int note_value(const Glib::ustring& note, double* value) |
214 |
}; |
{ |
215 |
|
const char* str = note.c_str(); |
216 |
|
|
217 |
// Convert the Entry text to a number |
int i; |
218 |
int NoteEntry::on_input(double* new_value) |
for (i = 11 ; i >= 0 ; i--) { |
219 |
{ |
if (strncasecmp(str, notes[i], strlen(notes[i])) == 0) break; |
|
const char* str = spinbutton.get_text().c_str(); |
|
|
|
|
|
int i; |
|
|
for (i = 11 ; i >= 0 ; i--) { |
|
|
if (strncmp(str, notes[i], strlen(notes[i])) == 0) break; |
|
|
} |
|
|
if (i >= 0) { |
|
|
char* endptr; |
|
|
long x = strtol(str + strlen(notes[i]), &endptr, 10); |
|
|
if (endptr != str + strlen(notes[i])) { |
|
|
*new_value = i + (x + 1) * 12; |
|
|
return true; |
|
220 |
} |
} |
221 |
|
if (i >= 0) { |
222 |
|
char* endptr; |
223 |
|
long x = strtol(str + strlen(notes[i]), &endptr, 10); |
224 |
|
if (endptr != str + strlen(notes[i])) { |
225 |
|
*value = std::max(0L, std::min(i + (x + 1) * 12, 127L)); |
226 |
|
return true; |
227 |
|
} |
228 |
|
} else { |
229 |
|
char* endptr; |
230 |
|
long x = strtol(str, &endptr, 10); |
231 |
|
if (endptr != str) { |
232 |
|
*value = std::max(0L, std::min(x, 127L)); |
233 |
|
return true; |
234 |
|
} |
235 |
|
} |
236 |
|
return Gtk::INPUT_ERROR; |
237 |
} |
} |
|
return Gtk::INPUT_ERROR; |
|
238 |
} |
} |
239 |
|
|
240 |
// Convert the Adjustment position to text |
int note_value(const Glib::ustring& note) |
241 |
bool NoteEntry::on_output() |
{ |
242 |
|
double value = 0; |
243 |
|
note_value(note, &value); |
244 |
|
return value; |
245 |
|
} |
246 |
|
|
247 |
|
Glib::ustring note_str(int note) |
248 |
{ |
{ |
|
int x = int(spinbutton.get_adjustment()->get_value() + 0.5); |
|
249 |
char buf[10]; |
char buf[10]; |
250 |
sprintf(buf, "%s%d", notes[x % 12], x / 12 - 1); |
sprintf(buf, "%s%d", notes[note % 12], note / 12 - 1); |
251 |
spinbutton.set_text(buf); |
return buf; |
252 |
return true; |
} |
253 |
|
|
254 |
|
namespace { |
255 |
|
// Convert the Entry text to a number |
256 |
|
int on_input(double* new_value, Gtk::SpinButton* spinbutton) { |
257 |
|
return note_value(spinbutton->get_text(), new_value); |
258 |
|
} |
259 |
|
|
260 |
|
// Convert the Adjustment position to text |
261 |
|
bool on_output(Gtk::SpinButton* spinbutton) { |
262 |
|
spinbutton->set_text( |
263 |
|
note_str(spinbutton->get_adjustment()->get_value() + 0.5)); |
264 |
|
return true; |
265 |
|
} |
266 |
|
} |
267 |
|
|
268 |
|
// Make a SpinButton show notes instead of numbers |
269 |
|
void spin_button_show_notes(Gtk::SpinButton& spin_button) |
270 |
|
{ |
271 |
|
spin_button.set_numeric(false); |
272 |
|
spin_button.set_width_chars(4); |
273 |
|
spin_button.signal_input().connect( |
274 |
|
sigc::bind(sigc::ptr_fun(&on_input), &spin_button)); |
275 |
|
spin_button.signal_output().connect( |
276 |
|
sigc::bind(sigc::ptr_fun(&on_output), &spin_button)); |
277 |
} |
} |
278 |
|
|
279 |
ChoiceEntryLeverageCtrl::ChoiceEntryLeverageCtrl(const char* labelText) : |
ChoiceEntryLeverageCtrl::ChoiceEntryLeverageCtrl(const char* labelText) : |
282 |
{ |
{ |
283 |
for (int i = 0 ; i < 99 ; i++) { |
for (int i = 0 ; i < 99 ; i++) { |
284 |
if (controlChangeTexts[i]) { |
if (controlChangeTexts[i]) { |
285 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 24) || GTKMM_MAJOR_VERSION < 2 |
286 |
combobox.append_text(controlChangeTexts[i]); |
combobox.append_text(controlChangeTexts[i]); |
287 |
#else |
#else |
288 |
combobox.append(controlChangeTexts[i]); |
combobox.append(controlChangeTexts[i]); |