]> bicyclesonthemoon.info Git - klavirko/ui/commitdiff
voice settings removing; confirmation for destructive actions; updated event handling...
authorb <rowerynaksiezycu@gmail.com>
Mon, 30 Dec 2024 23:07:32 +0000 (00:07 +0100)
committerb <rowerynaksiezycu@gmail.com>
Mon, 30 Dec 2024 23:07:32 +0000 (00:07 +0100)
fs.c
fs.h
gui.c
gui.h

diff --git a/fs.c b/fs.c
index 460e42813ca7cd61916048b792dc6b61759257ef..e15fdea4eca3fa464b2d8257dc7ec70acedbaaab 100644 (file)
--- 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<<id);
+       overwrite = fs_page_flags & (1<<id);
        
        for (i=0; ;++i)
        {
@@ -976,7 +976,7 @@ void  fs_store_voice (
        fs_optimise_index();
 }
 
-uint8_t  fs_load_voice (
+uint8_t fs_load_voice (
        const uint8_t    id,
        uint32_t * const A,
        uint32_t * const D,
@@ -1009,6 +1009,35 @@ uint8_t  fs_load_voice (
        return 0xff;
 }
 
+void fs_delete_voice (const uint8_t id)
+{
+       if ((fs_index0 < 0) || (fs_index1 < 0))
+               return;
+       
+       if (!(fs_page_flags & (1<<id)))
+               return;
+       
+       fs_delete_record(
+               fs_page_indexes[id],
+               fs_page_indexblocks[id],
+               fs_page_indexrecords[id]
+       );
+       fs_delete_file(
+               fs_page_sectors[id],
+               fs_page_fileids[id]
+       );
+       
+       fs_page_flags &= ~(1<<id);
+       fs_page_names[id][0] = '\0';
+       
+       fs_optimise_sector(fs_page_sectors[id]);
+}
+
+inline uint8_t fs_is_voice_stored (const uint8_t id)
+{
+       return fs_page_flags & (1<<id);
+}
+
 void fs_optimise_sector (const uint8_t opt_sector)
 {
        uint8_t  found = 0;
diff --git a/fs.h b/fs.h
index 885d6ee5a1f5cad1333b46824546b8c6db3d3f2d..1b6bc76e31d5a4c9c87ec60cc3d94783adafd7eb 100644 (file)
--- a/fs.h
+++ b/fs.h
@@ -359,7 +359,7 @@ inline void fs_watchdog (void) LOWTEXT;
 
 // SPI flash handling
 inline uint8_t fs_spi_1b (const uint8_t data); // send & receive single byte
-void fs_spi( // execute single command 
+       void fs_spi( // execute single command 
        const uint8_t   opcode,
        const uint16_t  address_bytes,
        const uint16_t  dummy_bytes,
@@ -407,7 +407,7 @@ inline void     fs_spi_write_status (const uint16_t status);
 inline void     fs_spi_reset (void);
 inline uint32_t fs_spi_read_id (void);
 
-inline void fs_wait_ready (const uint16_t timeout);
+inline void     fs_wait_ready (const uint16_t timeout);
 
 // support for filesystem operations
 inline uint32_t fs_expand_address (
@@ -425,7 +425,7 @@ inline uint8_t  fs_is_file_free (
        const uint8_t sector,
        const uint8_t id
 );
-uint16_t        fs_get_file_type (
+       uint16_t fs_get_file_type (
        const uint8_t sector,
        const uint8_t id
 );
@@ -439,24 +439,24 @@ inline void fs_index_next_sector (void);
 inline void fs_index_next_file (void);
 
 // filesystem operations, low level
-uint8_t     fs_create_file (
+       uint8_t fs_create_file (
        const uint8_t sector,
        const uint8_t id,
        const uint8_t type
 );
-uint8_t     fs_delete_file (
+       uint8_t fs_delete_file (
        const uint8_t sector,
        const uint8_t id
 );
-uint8_t     fs_duplicate_file (
+       uint8_t fs_duplicate_file (
        const uint8_t src_sector,
        const uint8_t src_id,
        const uint8_t dst_sector,
        const uint8_t dst_id
 );
-inline void fs_erase_sector (const uint8_t sector);
-void        fs_format (void);
-uint8_t     fs_read_record (
+inline void    fs_erase_sector (const uint8_t sector);
+       void    fs_format (void);
+       uint8_t fs_read_record (
        const uint8_t   index,
        const uint8_t   block,
        const uint8_t   record,
@@ -465,7 +465,7 @@ uint8_t     fs_read_record (
        uint8_t * const sector,
        uint8_t * const fileid
 );
-void        fs_write_record (
+       void    fs_write_record (
        const uint8_t index,
        const uint8_t block,
        const uint8_t record,
@@ -474,20 +474,20 @@ void        fs_write_record (
        const uint8_t sector,
        const uint8_t fileid
 );
-void        fs_delete_record (
+       void    fs_delete_record (
        uint8_t index,
        uint8_t block,
        uint8_t record
 );
 
 // filesystem operations, high level
-void    fs_get_file_name(
+       void    fs_get_file_name(
        const uint8_t   sector,
        const uint8_t   id,
        uint8_t * const name
 );
-void    fs_load_page (const uint8_t new_page);
-void    fs_store_voice (
+       void    fs_load_page (const uint8_t new_page);
+       void    fs_store_voice (
        const uint8_t  id,
        const uint8_t * const name,
        const uint32_t A,
@@ -496,7 +496,7 @@ void    fs_store_voice (
        const uint32_t R,
        const uint8_t * const wave
 );
-uint8_t fs_load_voice (
+       uint8_t fs_load_voice (
        const uint8_t    id,
        uint32_t * const A,
        uint32_t * const D,
@@ -504,14 +504,16 @@ uint8_t fs_load_voice (
        uint32_t * const R,
        uint8_t  * const wave
 );
-void    fs_optimise_sector (const uint8_t opt_sector);
-void    fs_optimise_index (void);
+       void    fs_delete_voice (const uint8_t id);
+inline uint8_t fs_is_voice_stored (const uint8_t id);
+       void    fs_optimise_sector (const uint8_t opt_sector);
+       void    fs_optimise_index (void);
 
 // general
 inline void setup_fs (void);
 inline void init_fs (void);
-void        debug_file (
+       void debug_file (
        const uint8_t sector,
        const uint8_t id
 );
-void        debug_sector (const uint8_t sector);
+       void debug_sector (const uint8_t sector);
diff --git a/gui.c b/gui.c
index 162ab28eb8c6910e36847bf8089a35de7972eac3..a863a5ce246a2886cff9bd231a165a6dd3ad5725 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -23,7 +23,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 volatile uint8_t  button = 0;
 volatile uint8_t  button_old = 0;
 volatile uint8_t  button_new = 0;
+volatile uint8_t  button_valid = 0;
 volatile uint8_t  button_hold = 0;
+volatile uint8_t  button_long = 0;
 volatile uint16_t button_count = 0;
 volatile uint16_t button_hold_count = 0;
 volatile uint16_t button_y_count = 0;
@@ -86,6 +88,8 @@ inline void add_gui_event(const uint16_t event)
 
 inline void reject_gui_events (void)
 {
+       button_valid = 0; // reject any already pressed buttons
+       button_hold_count = 0; // to not get a long hold in new state
        gui_event_r = gui_event_w;
 }
 
@@ -289,13 +293,24 @@ inline void int_button_abcdef(void) // interrupt from button ADC
                        {
                                button_hold_count = button_count;
                                press = button_new & (~button);
+                               button_valid |= press;
                                release = button & (~button_new);
                                button = button_new;
+                               release &= button_valid;
+                               button_hold &= button_valid;
+                               button_long &= button_valid;
+                               button_valid &= button;
                                if (press)
                                        add_gui_event(EVENT_PRESS | press);
                                if (release)
                                {
-                                       if (button_hold & release)
+                                       if (button_long & release)
+                                       {
+                                               add_gui_event(EVENT_RELEASE | EVENT_WAS_HOLD | EVENT_LONG | release);
+                                               button_long &= (~release);
+                                               button_hold &= (~release);
+                                       }
+                                       else if (button_hold & release)
                                        {
                                                add_gui_event(EVENT_RELEASE | EVENT_WAS_HOLD | release);
                                                button_hold &= (~release);
@@ -310,15 +325,23 @@ inline void int_button_abcdef(void) // interrupt from button ADC
                button_count = 0;
        
        // do button debouncing for long hold
-       if (button_hold_count < BUTTON_HOLD)
+       if (button_hold_count < (BUTTON_HOLD + BUTTON_LONG))
        {
                ++button_hold_count;
          if (button_hold_count == BUTTON_HOLD)
                {
-                       if(button)
+                       if (button & button_valid)
+                       {
+                               button_hold = button & button_valid;
+                               add_gui_event(EVENT_HOLD | button_hold);
+                       }
+               }
+               else if (button_hold_count == (BUTTON_HOLD + BUTTON_LONG))
+               {
+                       if (button & button_valid)
                        {
-                               button_hold = button;
-                               add_gui_event(EVENT_HOLD | button);
+                               button_long = button & button_valid;
+                               add_gui_event(EVENT_HOLD | EVENT_LONG | button_long);
                        }
                }
        }
@@ -421,8 +444,13 @@ inline void gui_gotostate_wave (void)
 
 inline void gui_event_wave (const uint16_t event)
 {
-       if((event & EVENT_BITS) == EVENT_RELEASE)
+       switch (event & EVENT_BITS)
        {
+       case EVENT_HOLD: // no need to check long hold
+               if (event & BUTTON_Y)
+                       gui_gotostate_name(1);
+               break;
+       case EVENT_RELEASE:
                if (event & BUTTON_X)
                {
                        gui_gotostate_options();
@@ -452,11 +480,7 @@ inline void gui_event_wave (const uint16_t event)
                                gui_lock_adsr();
                        }
                }
-       }
-       else if((event & EVENT_BITS) == EVENT_HOLD)
-       {
-               if (event & BUTTON_Y)
-                       gui_gotostate_name(1);
+               break;
        }
 }
 
@@ -485,81 +509,99 @@ inline void gui_gotostate_select (void)
 
 inline void gui_event_select (const uint16_t event)
 {
-       // uint8_t wave, adsr;
        uint8_t id;
+       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_HOLD:
+               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;
-                       
-                       // adsr = adsr_locked;
-                       // wave = wave_locked;
-                       
-                       gui_lock_adsr();
-                       gui_lock_wave();
-                       
-                       if (fs_load_voice(
-                               id,
-                               &adsr_A,
-                               &adsr_D,
-                               &adsr_S,
-                               &adsr_R,
-                               sample)
-                       ){
-                               ctrl_update_wave();
-                               ctrl_update_adsr();
-                               gui_update_adsr();
-                               gui_update_wave();
+                       if (fs_is_voice_stored(id))
+                       {
+                               if (event & EVENT_LONG)
+                               {
+                                       fs_delete_voice(id);
+                                       lcd_update_button(id, "");
+                                       reject_gui_events();
+                               }
+                               else
+                                       lcd_update_button(id, GUI_BUTTONTEXT_CONFIRM_REMOVE);
+                       }
+               }
+               else if (event & BUTTON_Y) // no need to check long hold
+                       gui_gotostate_name(1);
+               break;
+       case EVENT_RELEASE:
+               if (event & (BUTTON_ABCDEF))
+               {
+                       if (fs_is_voice_stored(id))
+                       {
+                               if (event & EVENT_WAS_HOLD)
+                                       lcd_update_button(id, fs_page_names[id]);
+                               else
+                               {
+                                       gui_lock_adsr();
+                                       gui_lock_wave();
+                                       
+                                       if (fs_load_voice(
+                                               id,
+                                               &adsr_A,
+                                               &adsr_D,
+                                               &adsr_S,
+                                               &adsr_R,
+                                               sample)
+                                       ){
+                                               ctrl_update_wave();
+                                               ctrl_update_adsr();
+                                               gui_update_adsr();
+                                               gui_update_wave();
+                                       }
+                                       else
+                                       {
+                                               gui_unlock_adsr();
+                                               gui_unlock_wave();
+                                       }
+                               }
                        }
                        else
                        {
-                               // if(!adsr)
-                                       gui_unlock_adsr();
-                               // if(!wave)
-                                       gui_unlock_wave();
+                               gui_unlock_adsr();
+                               gui_unlock_wave();
                        }
                }
                else if (event & BUTTON_X)
                        gui_gotostate_options();
                else if (event & BUTTON_Y)
                        gui_gotostate_wave();
-       }
-       else if((event & EVENT_BITS) == EVENT_HOLD)
-       {
-               if (event & BUTTON_Y)
-                       gui_gotostate_name(1);
-       }
-       else if((event & EVENT_BITS) == EVENT_JOG)
-       {
+               break;
+       case EVENT_JOG:
                if ((event & JOG_BITS) == JOG_PLUS)
-               {
-                       if (gui_page < (N_PAGES - 1))
-                               ++gui_page;
-                       else
-                               gui_page = 0;
-               }
+                       new_page = gui_page + gui_jog_boost((event & JOG_TIME_BITS) << 3);
                else
-               {
-                       if (gui_page > 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 6dd6fcd07d6336d51a95ee225d900e35a9af0375..62c4abc29f2ef507801aac2f0dc7c826c2380ea6 100644 (file)
--- 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          "  <xx"
-#define GUI_BUTTONTEXT_SPACE        ""
-#define GUI_BUTTONTEXT_ABC          "  ABC"
-#define GUI_BUTTONTEXT_abc          "  abc"
-#define GUI_BUTTONTEXT_123          " 123!?"
-#define GUI_BUTTONTEXT_OK           "  OK."
-#define GUI_BUTTONTEXT_MIDI_PEDAL   "MIDI   pedal         allowed"
-#define GUI_BUTTONTEXT_MIDI_NOPEDAL "MIDI   pedal         illegal"
-#define GUI_BUTTONTEXT_RESET        " TOTAL  RESET"
-#define GUI_BUTTONTEXT_IGNORE       "ignore  and   resume"
-#define GUI_BUTTONTEXT_RECOVER      "recover(TODO)"
-#define GUI_BUTTONTEXT_FORMAT       "format"
+#define GUI_BUTTONTEXT_DEL             "  <xx"
+#define GUI_BUTTONTEXT_SPACE           ""
+#define GUI_BUTTONTEXT_ABC             "  ABC"
+#define GUI_BUTTONTEXT_abc             "  abc"
+#define GUI_BUTTONTEXT_123             " 123!?"
+#define GUI_BUTTONTEXT_OK              "  OK."
+#define GUI_BUTTONTEXT_MIDI_PEDAL      "MIDI   pedal         allowed"
+#define GUI_BUTTONTEXT_MIDI_NOPEDAL    "MIDI   pedal         illegal"
+#define GUI_BUTTONTEXT_RESET           " TOTAL  RESET"
+#define GUI_BUTTONTEXT_IGNORE          "ignore  and   resume"
+#define GUI_BUTTONTEXT_RECOVER         "recover(TODO)"
+#define GUI_BUTTONTEXT_FORMAT          "format"
+#define GUI_BUTTONTEXT_CONFIRM_RESET   "\x01\x01\x01\x01\x01\x01\x01HOLD TO RESET \x01\x01\x01\x01\x01\x01\x01"
+#define GUI_BUTTONTEXT_CONFIRM_REMOVE  "\x01\x01\x01\x01\x01\x01\x01HOLD TOREMOVE \x01\x01\x01\x01\x01\x01\x01"
+#define GUI_BUTTONTEXT_CONFIRM_REPLACE "\x01\x01\x01\x01\x01\x01\x01HOLD TOREPLACE\x01\x01\x01\x01\x01\x01\x01"
 
 #define GUI_BUTTONTEXT_TUNING        "tuning        "
 #define GUI_BUTTONTEXT_TUNING_N      15