Skip to content

Commit

Permalink
More sensible fix for the melody list crashing when the melody count …
Browse files Browse the repository at this point in the history
…reduces
  • Loading branch information
akasaka committed Sep 27, 2024
1 parent 5f14277 commit 1ec5992
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 2 additions & 3 deletions include/views/menu/melody_selection_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ class MenuMelodySelectorView: public MenuListSelectorView {
MenuListSelectorView(
title,
all_chime_names,
melodyNo % (all_chime_count + 1),
melodyNo,
[this, onActivated](bool active, Renderable* instance) {
if(!active && sequencer) sequencer->stop_sequence();

onActivated(active, instance);
},
[this, onChange](int newMelodyNo) {
sequencer->stop_sequence();
if(newMelodyNo != all_chime_count) // Don't play the random one
sequencer->play_sequence(melody_from_no(newMelodyNo), SEQUENCER_PLAY_HOOK_ONLY);
onChange(newMelodyNo % (all_chime_count + 1));
onChange(newMelodyNo);
}
) {
sequencer = preview;
Expand Down
9 changes: 7 additions & 2 deletions src/views/menu/list_selection_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

MenuListSelectorView::MenuListSelectorView(const char * title, std::vector<const char*> items_, int initialValue, std::function<void(bool, Renderable*)> onActivated_, std::function<void(int)> onChange_):
label(new StringScroll(&keyrus0808_font, title)),
value(new StringScroll(&keyrus0808_font, items_[initialValue])),
value(new StringScroll(&keyrus0808_font)),
currentValue(initialValue),
items(items_),
onChange(onChange_),
onActivated(onActivated_),
isActive(false) {
if(initialValue < items_.size()) {
value->set_string(items_[initialValue]);
} else if(items_.size() >= 1) {
value->set_string(items_[0]);
}
value->set_y_position(keyrus0808_font.height);
value->align_to_right = true;
value->start_at_visible = true;
Expand All @@ -33,7 +38,7 @@ void MenuListSelectorView::step() {
if(isActive) {
if(hid_test_key_state_repetition(KEY_DOWN) == KEYSTATE_HIT) {
currentValue++;
if(currentValue == items.size()) currentValue = 0;
if(currentValue >= items.size()) currentValue = 0;
onChange(currentValue);
value->set_string(items[currentValue]);
} else if(hid_test_key_state_repetition(KEY_UP) == KEYSTATE_HIT) {
Expand Down

0 comments on commit 1ec5992

Please sign in to comment.