prevent bank/channel switching past the end of the available routes; do nothing when a view mode finds no matching routes

This commit is contained in:
Paul Davis
2016-01-28 16:27:33 -05:00
parent ea895efb97
commit 54c3c9e494
3 changed files with 36 additions and 27 deletions

View File

@@ -374,31 +374,38 @@ MackieControlProtocol::n_strips (bool with_locked_strips) const
return strip_count;
}
void
int
MackieControlProtocol::switch_banks (uint32_t initial, bool force)
{
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("switch banking to start at %1 force ? %2 current = %3\n", initial, force, _current_initial_bank));
if (initial == _current_initial_bank && !force) {
return;
/* everything is as it should be */
return 0;
}
Sorted sorted = get_sorted_routes();
uint32_t strip_cnt = n_strips (false); // do not include locked strips
// in this count
if (initial >= sorted.size()) {
/* too high, we can't get there */
return -1;
}
if (sorted.size() <= strip_cnt && _current_initial_bank == 0 && !force) {
/* no banking - not enough routes to fill all strips and we're
* not at the first one.
*/
return;
return -1;
}
_current_initial_bank = initial;
_current_selected_track = -1;
// Map current bank of routes onto each surface(+strip)
if (_current_initial_bank <= sorted.size()) {
if (_current_initial_bank < sorted.size()) {
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("switch to %1, %2, available routes %3 on %4 surfaces\n",
_current_initial_bank, strip_cnt, sorted.size(),
@@ -422,6 +429,9 @@ MackieControlProtocol::switch_banks (uint32_t initial, bool force)
(*si)->map_routes (routes);
}
} else {
return -1;
}
/* make sure selection is correct */
@@ -430,6 +440,8 @@ MackieControlProtocol::switch_banks (uint32_t initial, bool force)
/* current bank has not been saved */
session->set_dirty();
return 0;
}
int
@@ -653,7 +665,7 @@ MackieControlProtocol::update_surfaces()
// do the initial bank switch to connect signals
// _current_initial_bank is initialised by set_state
switch_banks (_current_initial_bank, true);
(void) switch_banks (_current_initial_bank, true);
DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::update_surfaces() finished\n");
}
@@ -1069,7 +1081,7 @@ MackieControlProtocol::set_state (const XMLNode & node, int version)
state_version = version;
}
switch_banks (bank, true);
(void) switch_banks (bank, true);
DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::set_state done\n");
@@ -1276,9 +1288,9 @@ MackieControlProtocol::notify_remote_id_changed()
if (sorted.size() - _current_initial_bank < sz) {
// but don't shift backwards past the zeroth channel
if (sorted.size() < sz) { // avoid unsigned math mistake below
switch_banks(0, true);
(void) switch_banks(0, true);
} else {
switch_banks (max((Sorted::size_type) 0, sorted.size() - sz), true);
(void) switch_banks (max((Sorted::size_type) 0, sorted.size() - sz), true);
}
} else {
// Otherwise just refresh the current bank
@@ -1777,14 +1789,18 @@ MackieControlProtocol::set_subview_mode (SubViewMode sm, boost::shared_ptr<Route
void
MackieControlProtocol::set_view_mode (ViewMode m)
{
_last_bank[_view_mode] = _current_initial_bank;
ViewMode old_view_mode = _view_mode;
_view_mode = m;
if (switch_banks(_last_bank[m], true)) {
_view_mode = old_view_mode;
return;
}
_last_bank[_view_mode] = _current_initial_bank;
/* leave subview mode, whatever it was */
set_subview_mode (None, boost::shared_ptr<Route>());
switch_banks(_last_bank[_view_mode], true);
display_view_mode ();
}
@@ -2182,7 +2198,7 @@ MackieControlProtocol::ipmidi_restart ()
if (create_surfaces ()) {
return -1;
}
switch_banks (_current_initial_bank, true);
(void) switch_banks (_current_initial_bank, true);
needs_ipmidi_restart = false;
return 0;
}

View File

@@ -282,7 +282,7 @@ class MackieControlProtocol
Sorted get_sorted_routes();
// bank switching
void switch_banks (uint32_t first_remote_id, bool force = false);
int switch_banks (uint32_t first_remote_id, bool force = false);
void prev_track ();
void next_track ();

View File

@@ -108,9 +108,9 @@ MackieControlProtocol::left_press (Button &)
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank left with current initial = %1 nstrips = %2 tracks/busses = %3\n",
_current_initial_bank, strip_cnt, sorted.size()));
if (_current_initial_bank > 0) {
switch_banks ((_current_initial_bank - 1) / strip_cnt * strip_cnt);
(void) switch_banks ((_current_initial_bank - 1) / strip_cnt * strip_cnt);
} else {
switch_banks (0);
(void) switch_banks (0);
}
@@ -120,7 +120,7 @@ MackieControlProtocol::left_press (Button &)
LedState
MackieControlProtocol::left_release (Button &)
{
return off;
return none;
}
LedState
@@ -141,23 +141,16 @@ MackieControlProtocol::right_press (Button &)
if (_current_initial_bank < max_bank) {
uint32_t new_initial = (_current_initial_bank / strip_cnt * strip_cnt) + strip_cnt;
switch_banks (new_initial);
} else {
switch_banks (max_bank);
(void) switch_banks (new_initial);
}
return on;
return none;
}
LedState
MackieControlProtocol::right_release (Button &)
{
if (zoom_mode()) {
}
return off;
return none;
}
LedState
@@ -581,7 +574,7 @@ MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
bank_num = 8 + basic_bank_num;
}
switch_banks (n_strips() * bank_num);
(void) switch_banks (n_strips() * bank_num);
return on;
}