]> bicyclesonthemoon.info Git - klavirko/ui/commitdiff
tuning jog boost, defaults on longpress, transpose +-12 semitones
authorb <rowerynaksiezycu@gmail.com>
Sat, 28 Dec 2024 16:45:57 +0000 (17:45 +0100)
committerb <rowerynaksiezycu@gmail.com>
Sat, 28 Dec 2024 16:45:57 +0000 (17:45 +0100)
ctrl.c
gui.c
gui.h
interrupt_handlers.c
wave.c

diff --git a/ctrl.c b/ctrl.c
index 41fc9089048aa41cb73d155e674d321560149535..985191294080e86fc5aaf99940ad50040759a8fd 100644 (file)
--- a/ctrl.c
+++ b/ctrl.c
@@ -1,6 +1,6 @@
 /* COMMUNICATING WITH MAIN CONTROLLER */
 /*
-Copyright 2021 Balthasar Szczepański
+Copyright 2021, 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:
 
@@ -42,8 +42,8 @@ volatile uint16_t ctrl_timeout = 0;
          int16_t  ctrl_index = 0;
          int16_t  ctrl_limit = 0;
 
-         uint8_t  midi_id = 0;
-         uint8_t  midi_id_out = 16;
+         uint8_t  midi_id = N_MIDI_ID;
+         uint8_t  midi_id_out = 0;
          uint8_t  midi_pedal_en = 1;
 
 
diff --git a/gui.c b/gui.c
index 513c62c6c38eab644ddf23ae855138d8ac40af61..ea244d118c12765daff5509d8b0522df83df20ce 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -23,13 +23,16 @@ 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_hold = 0;
 volatile uint16_t button_count = 0;
 volatile uint16_t button_hold_count = 0;
 volatile uint16_t button_y_count = 0;
 
-volatile uint8_t  jog = 0;
-volatile uint8_t  jog_old = 0;
-volatile uint8_t  jog_new = 0;
+volatile uint16_t jog = 0;
+volatile uint16_t jog_old = 0;
+volatile uint16_t jog_new = 0;
+
+volatile uint16_t jog_timer = 0;
 
 volatile uint16_t gui_event[N_GUI_EVENT];
 volatile uint8_t  gui_event_r = 0;
@@ -153,21 +156,75 @@ inline void gui_switch_adsr (void)
 
 /* handling inputs */
 
+inline void int_jog_timer (void) // count time since last jog action
+{
+       if (jog_timer < JOG_TIME_BITS)
+               ++jog_timer;
+}
+
 inline void int_jog (void) // interrupt from rotary dial
 {
        jog_old = jog_new;
        jog_new = GET_JOG();
        
-       if(!(jog_new & 0x1)) //full position
+       if(!(jog_new & JOG_L)) //full position
        {
                if(jog_new != jog) //new position, not return
                {
                        jog = jog_new;
-                       add_gui_event(EVENT_JOG | ((jog_new - jog_old) & 0x3));
+                       add_gui_event(
+                               EVENT_JOG |
+                               ((jog_new - jog_old) & JOG_BITS) |
+                               jog_timer & JOG_TIME_BITS
+                       );
+                       jog_timer = 0;
                }
        }
 }
 
+inline uint16_t gui_jog_boost(const uint16_t time)
+{
+       if (time <= JOG_X_20)
+               return 20;
+       if (time <= JOG_X_19)
+               return 19;
+       if (time <= JOG_X_18)
+               return 18;
+       if (time <= JOG_X_17)
+               return 17;
+       if (time <= JOG_X_16)
+               return 16;
+       if (time <= JOG_X_15)
+               return 15;
+       if (time <= JOG_X_14)
+               return 14;
+       if (time <= JOG_X_13)
+               return 13;
+       if (time <= JOG_X_12)
+               return 12;
+       if (time <= JOG_X_11)
+               return 11;
+       if (time <= JOG_X_10)
+               return 10;
+       if (time <= JOG_X_9)
+               return 9;
+       if (time <= JOG_X_8)
+               return 8;
+       if (time <= JOG_X_7)
+               return 7;
+       if (time <= JOG_X_6)
+               return 6;
+       if (time <= JOG_X_5)
+               return 5;
+       if (time <= JOG_X_4)
+               return 4;
+       if (time <= JOG_X_3)
+               return 3;
+       if (time <= JOG_X_2)
+               return 2;
+       return 1;
+}
+
 inline void int_button_abcdef(void) // interrupt from button ADC
 {
        uint8_t adc;
@@ -237,7 +294,15 @@ inline void int_button_abcdef(void) // interrupt from button ADC
                                if (press)
                                        add_gui_event(EVENT_PRESS | press);
                                if (release)
-                                       add_gui_event(EVENT_RELEASE | release);
+                               {
+                                       if (button_hold & release)
+                                       {
+                                               add_gui_event(EVENT_RELEASE | EVENT_WAS_HOLD | release);
+                                               button_hold &= (~release);
+                                       }
+                                       else
+                                               add_gui_event(EVENT_RELEASE | release);
+                               }
                        }
                }
        }
@@ -251,7 +316,10 @@ inline void int_button_abcdef(void) // interrupt from button ADC
          if (button_hold_count == BUTTON_HOLD)
                {
                        if(button)
+                       {
+                               button_hold = button;
                                add_gui_event(EVENT_HOLD | button);
+                       }
                }
        }
 }
@@ -476,7 +544,7 @@ inline void gui_event_select (const uint16_t event)
        }
        else if((event & EVENT_BITS) == EVENT_JOG)
        {
-               if ((event & ~EVENT_BITS) == JOG_PLUS)
+               if ((event & JOG_BITS) == JOG_PLUS)
                {
                        if (gui_page < (N_PAGES - 1))
                                ++gui_page;
@@ -616,7 +684,7 @@ inline void gui_event_name (const uint16_t event)
        else if((event & EVENT_BITS) == EVENT_JOG)
        {
                oldcursor = gui_name_cursor;
-               if ((event & ~EVENT_BITS) == JOG_PLUS)
+               if ((event & JOG_BITS) == JOG_PLUS)
                {
                        if (gui_name_cursor < gui_name_maxcursor)
                                ++gui_name_cursor;
@@ -700,7 +768,7 @@ inline void gui_event_select_save (const uint16_t event)
        }
        else if((event & EVENT_BITS) == EVENT_JOG)
        {
-               if ((event & ~EVENT_BITS) == JOG_PLUS)
+               if ((event & JOG_BITS) == JOG_PLUS)
                {
                        if (gui_page < (N_PAGES - 1))
                                ++gui_page;
@@ -743,20 +811,64 @@ inline void gui_gotostate_options (void)
 
 inline void gui_event_options (const uint16_t event)
 {
-       if((event & EVENT_BITS) == EVENT_RELEASE)
+       if((event & EVENT_BITS) == EVENT_HOLD)
+       {
+               if (event & BUTTON_A)
+               {
+                       set_tuning(DEFAULT_TUNING);
+                       make_text_tuning();
+                       lcd_update_button(0, text_tuning);
+               }
+               else if (event & BUTTON_B)
+               {
+                       set_transp(0);
+                       make_text_transpose();
+                       lcd_update_button(1, text_transpose);
+               }
+               else if (event & BUTTON_C)
+               {
+                       midi_id = N_MIDI_ID;
+                       ctrl_update_midi();
+                       make_text_midi_in();
+                       lcd_update_button(2, text_midi_in);
+               }
+               else if (event & BUTTON_D)
+               {
+                       midi_id_out = 0;
+                       ctrl_update_midi();
+                       make_text_midi_out();
+                       lcd_update_button(3, text_midi_out);
+               }
+               // no long press on button E
+               else if (event & BUTTON_F)
+                       gui_gotostate_total_reset();
+       }
+       else if((event & EVENT_BITS) == EVENT_RELEASE)
        {
                if (event & BUTTON_X)
                        gui_gotostate_wave();
                else if (event & BUTTON_Y)
                        gui_gotostate_select();
                else if (event & BUTTON_A)
-                       gui_gotostate_tuning();
+               {
+                       if (!(event & EVENT_WAS_HOLD))
+                               gui_gotostate_tuning();
+               }
                else if (event & BUTTON_B)
-                       gui_gotostate_transpose();
+               {
+                       if (!(event & EVENT_WAS_HOLD))
+                               gui_gotostate_transpose();
+               }
                else if (event & BUTTON_C)
-                       gui_gotostate_midi_id();
+               {
+                       if (!(event & EVENT_WAS_HOLD))
+                               gui_gotostate_midi_id();
+               }
                else if (event & BUTTON_D)
-                       gui_gotostate_midi_id_out();
+               {
+                       if (!(event & EVENT_WAS_HOLD))
+                               gui_gotostate_midi_id_out();
+               }
                else if (event & BUTTON_E)
                {
                        if (midi_pedal_en)
@@ -771,8 +883,7 @@ inline void gui_event_options (const uint16_t event)
                        }
                        ctrl_update_midi();
                }
-               else if (event & BUTTON_F)
-                       gui_gotostate_total_reset();
+               // no short press on button F - long press is needed
        }
 }
 
@@ -792,20 +903,32 @@ inline void gui_gotostate_tuning (void)
 
 inline void gui_event_tuning (const uint16_t event)
 {
-       if((event & EVENT_BITS) == EVENT_RELEASE)
+       if((event & EVENT_BITS) == EVENT_HOLD)
+       {
+               if (event & BUTTON_A)
+               {
+                       set_tuning(DEFAULT_TUNING);
+                       make_text_tuning();
+                       lcd_update_button(0, text_tuning);
+               }
+       }
+       else if((event & EVENT_BITS) == EVENT_RELEASE)
        {
-               if (event & (BUTTON_X | BUTTON_Y | BUTTON_A))
+               if (
+                       (event & (BUTTON_X | BUTTON_Y)) ||
+                       ((event & BUTTON_A) && !(event & EVENT_WAS_HOLD))
+               )
                        gui_gotostate_options();
        }
        else if((event & EVENT_BITS) == EVENT_JOG)
        {
-               if ((event & ~EVENT_BITS) == JOG_PLUS)
+               if ((event & JOG_BITS) == JOG_PLUS)
                {
-                       set_tuning(tuning + 1);
+                       set_tuning(tuning + gui_jog_boost(event & JOG_TIME_BITS));
                }
                else
                {
-                       set_tuning(tuning - 1);
+                       set_tuning(tuning - gui_jog_boost(event & JOG_TIME_BITS));
                }
                
                make_text_tuning();
@@ -813,7 +936,7 @@ inline void gui_event_tuning (const uint16_t event)
        }
 }
 
-// TRANSPOSE: shift by -6 to 6 semitones
+// TRANSPOSE: shift by -12 to 12 semitones
 
 inline void gui_gotostate_transpose (void)
 {
@@ -829,21 +952,33 @@ inline void gui_gotostate_transpose (void)
 
 inline void gui_event_transpose (const uint16_t event)
 {
-       if((event & EVENT_BITS) == EVENT_RELEASE)
+       if((event & EVENT_BITS) == EVENT_HOLD)
        {
-               if (event & (BUTTON_X | BUTTON_Y | BUTTON_B))
+               if (event & BUTTON_B)
+               {
+                       set_transp(0);
+                       make_text_transpose();
+               lcd_update_button(1, text_transpose);
+               }
+       }
+       else if((event & EVENT_BITS) == EVENT_RELEASE)
+       {
+               if (
+                       (event & (BUTTON_X | BUTTON_Y)) ||
+                       ((event & BUTTON_B) && !(event & EVENT_WAS_HOLD))
+               )
                        gui_gotostate_options();
        }
        else if((event & EVENT_BITS) == EVENT_JOG)
        {
-               if ((event & ~EVENT_BITS) == JOG_PLUS)
+               if ((event & JOG_BITS) == JOG_PLUS)
                {
-                       if (transp<6)
+                       if (transp<12)
                                set_transp(transp + 1);
                }
                else
                {
-                       if (transp>-6)
+                       if (transp>-12)
                                set_transp(transp - 1);
                }
                
@@ -868,14 +1003,27 @@ inline void gui_gotostate_midi_id (void)
 
 inline void gui_event_midi_id (const uint16_t event)
 {
-       if((event & EVENT_BITS) == EVENT_RELEASE)
+       if((event & EVENT_BITS) == 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);
+               }
+       }
+       else if((event & EVENT_BITS) == EVENT_RELEASE)
        {
-               if (event & (BUTTON_X | BUTTON_Y | BUTTON_C))
+               if (
+                       (event & (BUTTON_X | BUTTON_Y)) ||
+                       ((event & BUTTON_C) && !(event & EVENT_WAS_HOLD))
+               )
                        gui_gotostate_options();
        }
        else if((event & EVENT_BITS) == EVENT_JOG)
        {
-               if ((event & ~EVENT_BITS) == JOG_PLUS)
+               if ((event & JOG_BITS) == JOG_PLUS)
                {
                        if (midi_id < N_MIDI_ID)
                                ++midi_id;
@@ -912,14 +1060,27 @@ inline void gui_gotostate_midi_id_out (void)
 
 inline void gui_event_midi_id_out (const uint16_t event)
 {
-       if((event & EVENT_BITS) == EVENT_RELEASE)
+       if((event & EVENT_BITS) == EVENT_HOLD)
+       {
+               if (event & BUTTON_D)
+               {
+                       midi_id_out = 0;
+                       ctrl_update_midi();
+                       make_text_midi_out();
+                       lcd_update_button(3, text_midi_out);
+               }
+       }
+       else if((event & EVENT_BITS) == EVENT_RELEASE)
        {
-               if (event & (BUTTON_X | BUTTON_Y | BUTTON_D))
+               if (
+                       (event & (BUTTON_X | BUTTON_Y)) ||
+                       ((event & BUTTON_D) && !(event & EVENT_WAS_HOLD))
+               )
                        gui_gotostate_options();
        }
        else if((event & EVENT_BITS) == EVENT_JOG)
        {
-               if ((event & ~EVENT_BITS) == JOG_PLUS)
+               if ((event & JOG_BITS) == JOG_PLUS)
                {
                        if (midi_id_out < N_MIDI_ID-1)
                                ++midi_id_out;
@@ -1050,6 +1211,44 @@ void handle_gui(void)
                else
                        ++gui_event_r;
                
+               if ((event & EVENT_BITS) == EVENT_JOG)
+               {
+                       debug_string("JOG", 1);
+                       if ((event & JOG_BITS) == JOG_PLUS)
+                               debug_string("+", 1);
+                       if ((event & JOG_BITS) == JOG_MINUS)
+                               debug_string("-", 1);
+                       debug_dec(event & JOG_TIME_BITS, 1, 0);
+               }
+               else
+               {
+                       if (event & BUTTON_A)
+                               debug_string("A", 1);
+                       if (event & BUTTON_B)
+                               debug_string("B", 1);
+                       if (event & BUTTON_C)
+                               debug_string("C", 1);
+                       if (event & BUTTON_D)
+                               debug_string("D", 1);
+                       if (event & BUTTON_E)
+                               debug_string("E", 1);
+                       if (event & BUTTON_F)
+                               debug_string("F", 1);
+                       if (event & BUTTON_X)
+                               debug_string("X", 1);
+                       if (event & BUTTON_Y)
+                               debug_string("Y", 1);
+                       if ((event & EVENT_BITS) == EVENT_PRESS)
+                               debug_string(" PRESS", 1);
+                       if ((event & EVENT_BITS) == EVENT_RELEASE)
+                               debug_string(" RELEASE", 1);
+                       if ((event & EVENT_BITS) == EVENT_HOLD)
+                               debug_string(" HOLD", 1);
+                       if (event & EVENT_WAS_HOLD)
+                               debug_string(" (WAS HOLD)", 1);
+               }
+               debug_string("\r\n", 1);
+                       
                // execute appropriate event handler for current state
                switch (gui_state)
                {
diff --git a/gui.h b/gui.h
index 424bf52158d5009e2386ecbe708e560f5713f617..6dd6fcd07d6336d51a95ee225d900e35a9af0375 100644 (file)
--- a/gui.h
+++ b/gui.h
@@ -1,7 +1,7 @@
 /* GUI */
 /* Encoding of this file is ISO 8859-2 */
 /*
-Copyright 2021, 2022 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:
 
@@ -15,8 +15,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 #include <stdint.h>
 #include "klavirko-ui.h"
 
-#define GET_JOG() ((JOG_A ? 0x1 : 0x0) ^ (JOG_B ? 0x3 : 0x0))
-
 #define BUTTON_DEBOUNCE  4
 #define BUTTON_HOLD    680
 
@@ -41,16 +39,42 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 #define BUTTON_THR_5 147
 #define BUTTON_THR_6 208
 
-#define JOG_PLUS  1
-#define JOG_MINUS 3
+#define JOG_BITS  0x0C00
+#define JOG_L     0x0400
+#define JOG_H     0x0C00
+#define JOG_PLUS  0x0400
+#define JOG_MINUS 0x0C00
+
+#define JOG_X_20 06 
+#define JOG_X_19 14 
+#define JOG_X_18 22 
+#define JOG_X_17 30 
+#define JOG_X_16 38 
+#define JOG_X_15 46 
+#define JOG_X_14 54 
+#define JOG_X_13 62 
+#define JOG_X_12 70 
+#define JOG_X_11 78 
+#define JOG_X_10 86
+#define JOG_X_9  94
+#define JOG_X_8 102
+#define JOG_X_7 110
+#define JOG_X_6 118
+#define JOG_X_5 126
+#define JOG_X_4 134
+#define JOG_X_3 142
+#define JOG_X_2 150
+
+#define JOG_TIME_BITS 0x03FF
 
 #define N_GUI_EVENT 16
 
-#define EVENT_BITS    0xE000
-#define EVENT_PRESS   0x8000
-#define EVENT_RELEASE 0x4000
-#define EVENT_HOLD    0xC000
-#define EVENT_JOG     0x2000
+#define EVENT_BITS     0xE000
+#define EVENT_PRESS    0x8000
+#define EVENT_RELEASE  0x4000
+#define EVENT_HOLD     0xC000
+#define EVENT_JOG      0x2000
+#define EVENT_WAS_HOLD 0x1000
 
 #define GUI_INIT        0x00
 #define GUI_WAVE        0x01
@@ -131,6 +155,10 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 #define GUI_TITLE_SAVE_N      21
 #define GUI_TITLE_SAVE_INSERT 16
 
+
+#define GET_JOG() ((JOG_A ? JOG_L : 0) ^ (JOG_B ? JOG_H : 0))
+
+
 // event handling
 
 inline void add_gui_event(const uint16_t event);
@@ -151,9 +179,11 @@ inline void gui_switch_adsr (void);
 
 // handling inputs
 
-inline void int_jog (void) LOWTEXT_INT;
-inline void int_button_abcdef (void) LOWTEXT;
-inline void int_button_y (void) LOWTEXT_INT;
+inline void     int_jog (void) LOWTEXT_INT;
+inline void     int_jog_timer (void);
+inline uint16_t gui_jog_boost(const uint16_t time);
+inline void     int_button_abcdef (void) LOWTEXT;
+inline void     int_button_y (void) LOWTEXT_INT;
 
 // general setup
 
index 75b70495df60218ee3b45473245dc185bc4e07a0..41fab7991beeeac3a967ac907d7e67b7ec417e5b 100644 (file)
@@ -1,5 +1,5 @@
 /*
-Copyright 2021 Balthasar Szczepański
+Copyright 2021, 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:
 
@@ -27,6 +27,7 @@ void INT_AD (void)
        // use it as a global time source
        int_button_abcdef();
        int_main_timer();
+       int_jog_timer();
        aix_watchdog();
        ctrl_watchdog();
        fs_watchdog();
diff --git a/wave.c b/wave.c
index 5c35c2d71a4e4e4aef3b0a05a0dde067436ea6d5..9642361ddf25489f992dcaabaed96576d197db09 100644 (file)
--- a/wave.c
+++ b/wave.c
@@ -1,6 +1,6 @@
 /* waveform & envelope */
 /*
-Copyright 2021 Balthasar Szczepański
+Copyright 2021, 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:
 
@@ -68,9 +68,17 @@ inline void set_max_tuning (const uint16_t max)
 
 inline void set_tuning (const uint16_t new)
 {
-       if (new <= max_tuning)
+       uint16_t set;
+       
+       if (((int16_t) new) <= 0)
+               set = 1;
+       else if (new > max_tuning)
+               set = max_tuning;
+       else
+               set = new;
+       if (set != tuning)
        {
-               tuning = new;
+               tuning = set;
                ctrl_update_tuning();
        }
 }