26 static const int no_note = 1000;
27 static const int bad_note = 1002;
30 return std::abs(n - no_note) < 1;
34 : settings(settings_),
51 bool TunerSwitcher::display_bank_key(
int idx) {
52 last_bank_idx = settings.
banks.
size() - idx - 1;
62 bool TunerSwitcher::display_preset_key(
int idx) {
63 last_preset_idx = idx;
70 if (idx >= f->
size()) {
78 void TunerSwitcher::try_load_preset() {
79 switch (last_bank_idx) {
84 case tuner_on: new_tuner_active =
true;
break;
85 case tuner_off: new_tuner_active =
false;
break;
90 if (last_preset_idx < f->size()) {
91 Glib::ustring preset = f->
get_name(last_preset_idx);
102 if (state == newstate) {
109 bool TunerSwitcher::on_note_timeout() {
110 if (-24 <= current_note && current_note < -10) {
112 display_bank_key(current_note - (-24));
113 }
else if (current_note >= -10 && current_note <= 7) {
114 if (display_preset_key(current_note - (-10))) {
119 }
else if (current_note == -25) {
121 display(
"", _(
"MUTE"));
122 last_bank_idx = mute_on;
124 display(
"", _(
"UNMUTE"));
125 last_bank_idx = mute_off;
128 }
else if (current_note == -26) {
130 display(
"", _(
"BYPASS"));
131 last_bank_idx = bypass_on;
133 display(
"", _(
"BYPASS OFF"));
134 last_bank_idx = bypass_off;
137 }
else if (current_note < 26) {
138 if (!old_tuner_active) {
139 display(
"", _(
"TUNER ON"));
140 last_bank_idx = tuner_on;
142 display(
"", _(
"TUNER OFF"));
143 last_bank_idx = tuner_off;
150 bool TunerSwitcher::on_state_timeout() {
153 current_note = no_note;
158 last_bank_idx = last_preset_idx = 0;
168 void TunerSwitcher::on_tuner_freq_changed() {
173 if (!timeout_conn.connected()) {
174 current_note = no_note;
175 timeout_conn = Glib::signal_timeout().connect(
176 sigc::mem_fun(
this, &TunerSwitcher::on_state_timeout),
180 timeout_conn.disconnect();
184 if (std::abs(current_note - note) < precision) {
190 timeout_conn.disconnect();
192 if (!timeout_conn.connected()) {
193 current_note = no_note;
194 timeout_conn = Glib::signal_timeout().connect(
195 sigc::mem_fun(
this, &TunerSwitcher::on_state_timeout),
201 timeout_conn.disconnect();
202 float n = round(note);
203 if (std::abs(note - n) < precision) {
206 timeout_conn = Glib::signal_timeout().connect(
207 sigc::mem_fun(
this, &TunerSwitcher::on_note_timeout),
211 current_note = bad_note;
223 new_engine_state = old_engine_state = engine.
get_state();
225 new_tuner_active = old_tuner_active = tuner_active;
227 sigc::mem_fun(
this, &TunerSwitcher::on_tuner_freq_changed));
229 on_tuner_freq_changed();
237 switcher_conn.disconnect();
238 timeout_conn.disconnect();
245 selection_done(new_tuner_active);
256 selection_done(
false);
TunerSwitcher(gx_preset::GxSettings &settings, gx_engine::GxEngine &engine)
PresetFile * get_current_bank_file()
void activate(bool tuner_active)
PresetFile * get_file(const Glib::ustring &bank) const
Glib::ustring get_name(int n)
int get_index(const Glib::ustring &name)
void used_for_switching(bool on)
void load_preset(PresetFile *pf, const Glib::ustring &name)
std::string to_string(const T &t)
void set_state(GxEngineState state)
int get_index(const Glib::ustring &bank) const
const Glib::ustring & get_current_name()
GxEngineState get_state()
Glib::Dispatcher & signal_freq_changed()
const Glib::ustring & get_name(int n)
void toggle(bool tuner_active)
const Glib::ustring & get_current_bank()