From: b Date: Mon, 30 Dec 2024 23:07:32 +0000 (+0100) Subject: voice settings removing; confirmation for destructive actions; updated event handling... X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=51c3eeba0813ccf3c8f12707fe18596cd7cb8818;p=klavirko%2Fui voice settings removing; confirmation for destructive actions; updated event handling; long hold --- diff --git a/fs.c b/fs.c index 460e428..e15fdea 100644 --- a/fs.c +++ b/fs.c @@ -877,7 +877,7 @@ void fs_load_page (const uint8_t new_page) fs_page = new_page; } -void fs_store_voice ( +void fs_store_voice ( const uint8_t id, const uint8_t * const name, const uint32_t A, @@ -896,7 +896,7 @@ void fs_store_voice ( if ((fs_index0 < 0) || (fs_index1 < 0)) return; - overwrite = fs_page_flags & (1< 0) - --gui_page; - else - gui_page = N_PAGES - 1; - } + new_page = gui_page - gui_jog_boost((event & JOG_TIME_BITS) << 3); + if (new_page < 0) + gui_page = new_page + N_PAGES; + else if (new_page >= N_PAGES) + gui_page = new_page - N_PAGES; + else + gui_page = new_page; draw_select(); reject_gui_events(); + break; } } @@ -604,8 +646,9 @@ inline void gui_event_name (const uint16_t event) { uint8_t oldcursor; - if((event & EVENT_BITS) == EVENT_RELEASE) + switch (event & EVENT_BITS) { + case EVENT_RELEASE: if (event & BUTTON_X) { if (gui_return_state == GUI_SELECT) @@ -680,9 +723,8 @@ inline void gui_event_name (const uint16_t event) gui_gotostate_select_save(); } } - } - else if((event & EVENT_BITS) == EVENT_JOG) - { + break; + case EVENT_JOG: oldcursor = gui_name_cursor; if ((event & JOG_BITS) == JOG_PLUS) { @@ -700,6 +742,7 @@ inline void gui_event_name (const uint16_t event) } lcd_draw_name_cursor(gui_name_cursor); lcd_erase_name_cursor(oldcursor); + break; } } @@ -727,63 +770,95 @@ inline void gui_gotostate_select_save (void) inline void gui_event_select_save (const uint16_t event) { - uint8_t id; + uint8_t id = 0; + int16_t new_page; - if((event & EVENT_BITS) == EVENT_RELEASE) + if (event & BUTTON_A) + id = 0; + else if (event & BUTTON_B) + id = 1; + else if (event & BUTTON_C) + id = 2; + else if (event & BUTTON_D) + id = 3; + else if (event & BUTTON_E) + id = 4; + else if (event & BUTTON_F) + id = 5; + + switch (event & EVENT_BITS) { - if (event & (BUTTON_A | BUTTON_B | BUTTON_C | BUTTON_D | BUTTON_E | BUTTON_F)) + case EVENT_PRESS: + if (event & (BUTTON_ABCDEF)) { - if (event & BUTTON_A) - id = 0; - else if (event & BUTTON_B) - id = 1; - else if (event & BUTTON_C) - id = 2; - else if (event & BUTTON_D) - id = 3; - else if (event & BUTTON_E) - id = 4; - else - id = 5; - - fs_store_voice( - id, - gui_name, - adsr_A, - adsr_D, - adsr_S, - adsr_R, - sample - ); - - if (gui_return_state == GUI_SELECT) - gui_gotostate_select(); - else - gui_gotostate_wave(); + if (fs_is_voice_stored(id)) + lcd_update_button(id, GUI_BUTTONTEXT_CONFIRM_REPLACE); } - else if (event & BUTTON_X) + break; + case EVENT_HOLD: + if ((event & (BUTTON_ABCDEF)) && (event & EVENT_LONG)) { - gui_gotostate_name(0); + if (fs_is_voice_stored(id)) + { + fs_store_voice( + id, + gui_name, + adsr_A, + adsr_D, + adsr_S, + adsr_R, + sample + ); + + if (gui_return_state == GUI_SELECT) + gui_gotostate_select(); + else + gui_gotostate_wave(); + } } - } - else if((event & EVENT_BITS) == EVENT_JOG) - { - if ((event & JOG_BITS) == JOG_PLUS) + break; + case EVENT_RELEASE: + if (event & (BUTTON_ABCDEF)) { - if (gui_page < (N_PAGES - 1)) - ++gui_page; + if (fs_is_voice_stored(id)) + lcd_update_button(id, fs_page_names[id]); else - gui_page = 0; + { + fs_store_voice( + id, + gui_name, + adsr_A, + adsr_D, + adsr_S, + adsr_R, + sample + ); + + if (gui_return_state == GUI_SELECT) + gui_gotostate_select(); + else + gui_gotostate_wave(); + } } - else + else if (event & BUTTON_X) { - if (gui_page > 0) - --gui_page; - else - gui_page = N_PAGES - 1; + gui_gotostate_name(0); } + break; + case EVENT_JOG: + if ((event & JOG_BITS) == JOG_PLUS) + new_page = gui_page + gui_jog_boost((event & JOG_TIME_BITS) << 3); + else + new_page = gui_page - gui_jog_boost((event & JOG_TIME_BITS) << 3); + if (new_page < 0) + gui_page = new_page + N_PAGES; + else if (new_page >= N_PAGES) + gui_page = new_page - N_PAGES; + else + gui_page = new_page; draw_select_save(); reject_gui_events(); + break; } } @@ -811,19 +886,26 @@ inline void gui_gotostate_options (void) inline void gui_event_options (const uint16_t event) { - if((event & EVENT_BITS) == EVENT_HOLD) + switch (event & EVENT_BITS) { + case EVENT_PRESS: + if (event & BUTTON_F) + lcd_update_button(5, GUI_BUTTONTEXT_CONFIRM_RESET); + break; + case EVENT_HOLD: if (event & BUTTON_A) { set_tuning(DEFAULT_TUNING); make_text_tuning(); lcd_update_button(0, text_tuning); + reject_gui_events(); } else if (event & BUTTON_B) { set_transp(0); make_text_transpose(); lcd_update_button(1, text_transpose); + reject_gui_events(); } else if (event & BUTTON_C) { @@ -831,6 +913,7 @@ inline void gui_event_options (const uint16_t event) ctrl_update_midi(); make_text_midi_in(); lcd_update_button(2, text_midi_in); + reject_gui_events(); } else if (event & BUTTON_D) { @@ -838,37 +921,28 @@ inline void gui_event_options (const uint16_t event) ctrl_update_midi(); make_text_midi_out(); lcd_update_button(3, text_midi_out); + reject_gui_events(); } // no long press on button E else if (event & BUTTON_F) - gui_gotostate_total_reset(); - } - else if((event & EVENT_BITS) == EVENT_RELEASE) - { + { + if (event & EVENT_LONG) + gui_gotostate_total_reset(); + } + break; + case EVENT_RELEASE: if (event & BUTTON_X) gui_gotostate_wave(); else if (event & BUTTON_Y) gui_gotostate_select(); else if (event & BUTTON_A) - { - if (!(event & EVENT_WAS_HOLD)) - gui_gotostate_tuning(); - } + gui_gotostate_tuning(); else if (event & BUTTON_B) - { - if (!(event & EVENT_WAS_HOLD)) - gui_gotostate_transpose(); - } + gui_gotostate_transpose(); else if (event & BUTTON_C) - { - if (!(event & EVENT_WAS_HOLD)) - gui_gotostate_midi_id(); - } + gui_gotostate_midi_id(); else if (event & BUTTON_D) - { - if (!(event & EVENT_WAS_HOLD)) - gui_gotostate_midi_id_out(); - } + gui_gotostate_midi_id_out(); else if (event & BUTTON_E) { if (midi_pedal_en) @@ -883,7 +957,9 @@ inline void gui_event_options (const uint16_t event) } ctrl_update_midi(); } - // no short press on button F - long press is needed + else if (event & BUTTON_F) + lcd_update_button(5, GUI_BUTTONTEXT_RESET); + break; } } @@ -903,25 +979,22 @@ inline void gui_gotostate_tuning (void) inline void gui_event_tuning (const uint16_t event) { - if((event & EVENT_BITS) == EVENT_HOLD) + switch (event & EVENT_BITS) { + case EVENT_HOLD: if (event & BUTTON_A) { set_tuning(DEFAULT_TUNING); make_text_tuning(); lcd_update_button(0, text_tuning); + reject_gui_events(); } - } - else if((event & EVENT_BITS) == EVENT_RELEASE) - { - if ( - (event & (BUTTON_X | BUTTON_Y)) || - ((event & BUTTON_A) && !(event & EVENT_WAS_HOLD)) - ) + break; + case EVENT_RELEASE: + if (event & (BUTTON_A | BUTTON_X | BUTTON_Y)) gui_gotostate_options(); - } - else if((event & EVENT_BITS) == EVENT_JOG) - { + break; + case EVENT_JOG: if ((event & JOG_BITS) == JOG_PLUS) { set_tuning(tuning + gui_jog_boost(event & JOG_TIME_BITS)); @@ -933,6 +1006,7 @@ inline void gui_event_tuning (const uint16_t event) make_text_tuning(); lcd_update_button(0, text_tuning); + break; } } @@ -952,25 +1026,22 @@ inline void gui_gotostate_transpose (void) inline void gui_event_transpose (const uint16_t event) { - if((event & EVENT_BITS) == EVENT_HOLD) + switch (event & EVENT_BITS) { + case EVENT_HOLD: if (event & BUTTON_B) { set_transp(0); make_text_transpose(); - lcd_update_button(1, text_transpose); + lcd_update_button(1, text_transpose); + reject_gui_events(); } - } - else if((event & EVENT_BITS) == EVENT_RELEASE) - { - if ( - (event & (BUTTON_X | BUTTON_Y)) || - ((event & BUTTON_B) && !(event & EVENT_WAS_HOLD)) - ) + break; + case EVENT_RELEASE: + if (event & (BUTTON_B | BUTTON_X | BUTTON_Y)) gui_gotostate_options(); - } - else if((event & EVENT_BITS) == EVENT_JOG) - { + break; + case EVENT_JOG: if ((event & JOG_BITS) == JOG_PLUS) { if (transp<12) @@ -984,6 +1055,7 @@ inline void gui_event_transpose (const uint16_t event) make_text_transpose(); lcd_update_button(1, text_transpose); + break; } } @@ -1003,26 +1075,23 @@ inline void gui_gotostate_midi_id (void) inline void gui_event_midi_id (const uint16_t event) { - if((event & EVENT_BITS) == EVENT_HOLD) + switch (event & EVENT_BITS) { + case EVENT_HOLD: if (event & BUTTON_C) { midi_id = N_MIDI_ID; ctrl_update_midi(); make_text_midi_in(); lcd_update_button(2, text_midi_in); + reject_gui_events(); } - } - else if((event & EVENT_BITS) == EVENT_RELEASE) - { - if ( - (event & (BUTTON_X | BUTTON_Y)) || - ((event & BUTTON_C) && !(event & EVENT_WAS_HOLD)) - ) + break; + case EVENT_RELEASE: + if (event & (BUTTON_C | BUTTON_X | BUTTON_Y)) gui_gotostate_options(); - } - else if((event & EVENT_BITS) == EVENT_JOG) - { + break; + case EVENT_JOG: if ((event & JOG_BITS) == JOG_PLUS) { if (midi_id < N_MIDI_ID) @@ -1041,6 +1110,7 @@ inline void gui_event_midi_id (const uint16_t event) ctrl_update_midi(); make_text_midi_in(); lcd_update_button(2, text_midi_in); + break; } } @@ -1060,26 +1130,23 @@ inline void gui_gotostate_midi_id_out (void) inline void gui_event_midi_id_out (const uint16_t event) { - if((event & EVENT_BITS) == EVENT_HOLD) + switch (event & EVENT_BITS) { + case EVENT_HOLD: if (event & BUTTON_D) { midi_id_out = 0; ctrl_update_midi(); make_text_midi_out(); lcd_update_button(3, text_midi_out); + reject_gui_events(); } - } - else if((event & EVENT_BITS) == EVENT_RELEASE) - { - if ( - (event & (BUTTON_X | BUTTON_Y)) || - ((event & BUTTON_D) && !(event & EVENT_WAS_HOLD)) - ) + break; + case EVENT_RELEASE: + if (event & (BUTTON_D | BUTTON_X | BUTTON_Y)) gui_gotostate_options(); - } - else if((event & EVENT_BITS) == EVENT_JOG) - { + break; + case EVENT_JOG: if ((event & JOG_BITS) == JOG_PLUS) { if (midi_id_out < N_MIDI_ID-1) @@ -1098,6 +1165,7 @@ inline void gui_event_midi_id_out (const uint16_t event) ctrl_update_midi(); make_text_midi_out(); lcd_update_button(3, text_midi_out); + break; } } @@ -1166,7 +1234,7 @@ inline void gui_gotostate_err_fs (void) inline void gui_event_err_fs (const uint16_t event) { - if((event & EVENT_BITS) == EVENT_RELEASE) + if ((event & EVENT_BITS) == EVENT_RELEASE) { if (event & BUTTON_D) { @@ -1246,6 +1314,8 @@ void handle_gui(void) // debug_string(" HOLD", 1); // if (event & EVENT_WAS_HOLD) // debug_string(" (WAS HOLD)", 1); + // if (event & EVENT_LONG) + // debug_string(" (LONG)", 1); // } // debug_string("\r\n", 1); diff --git a/gui.h b/gui.h index 6dd6fcd..62c4abc 100644 --- a/gui.h +++ b/gui.h @@ -1,7 +1,6 @@ /* GUI */ -/* Encoding of this file is ISO 8859-2 */ /* -Copyright 2021, 2022, 2024 Balthasar Szczepañski +Copyright 2021, 2022, 2024 Balthasar Szczepański Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -17,6 +16,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #define BUTTON_DEBOUNCE 4 #define BUTTON_HOLD 680 +#define BUTTON_LONG 2000 #define BUTTON_A 0b00000001 #define BUTTON_B 0b00000010 @@ -74,7 +74,10 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #define EVENT_RELEASE 0x4000 #define EVENT_HOLD 0xC000 #define EVENT_JOG 0x2000 + +#define EVENT_FLAGS 0x1800 #define EVENT_WAS_HOLD 0x1000 +#define EVENT_LONG 0x0800 #define GUI_INIT 0x00 #define GUI_WAVE 0x01 @@ -99,8 +102,8 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #define GUI_ERRF_ALL (GUI_ERRF_AIX | GUI_ERRF_CTRL | GUI_ERRF_FS) -#define LIST_ABC "A¡BCÆDEÊFGHIJKL£MNÑOÓPQRS¦TUVWXYZ¬¯" -#define LIST_abc "a±bcædeêfghijkl³mnñoópqrs¶tuvwxyz¼¿" +#define LIST_ABC "A""\xa1""BC""\xc6""DE""\xca""FGHIJKL""\xa3""MN""\xd1""O""\xd3""PQRS""\xa6""TUVWXYZ""\xac\xaf" /* AĄBCĆDEĘFGHIJKLŁMNŃOÓPQRSŚTUVWXYZŹŻ */ +#define LIST_abc "a""\xB1""bc""\xE6""de""\xEA""fghijkl""\xB3""mn""\xF1""o""\xF3""pqrs""\xB6""tuvwxyz""\xBC\xBF" /* aąbcćdeęfghijklłmnńoópqrsśtuvwxyzźż */ #define LIST_123 "0123456789.,!?:;+-*/=\\^<>()[]{}#$%&'\"`~_|@" #define N_ABC 35 @@ -118,18 +121,21 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #define GUI_TITLE_ERR_FS "File system unformatted or damaged!" #define GUI_TITLE_RESET "TERAS BENDZIE INNY $WIAT" -#define GUI_BUTTONTEXT_DEL "