shithub: orca

Download patch

ref: 90c8596b1cd8ebae65001c948ab75fb70b9e4fe6
parent: a89b2ace5180ff58e71886c77539cbb39f296a37
author: cancel <cancel@cancel.fm>
date: Thu Jan 2 13:52:23 EST 2020

Add "Set BPM" menu item

--- a/tui_main.c
+++ b/tui_main.c
@@ -1751,6 +1751,7 @@
 enum {
   Main_menu_id = 1,
   Save_as_form_id,
+  Set_tempo_form_id,
 };
 
 enum {
@@ -1758,11 +1759,16 @@
 };
 
 enum {
+  Tempo_text_line_id = 1,
+};
+
+enum {
   Main_menu_quit = 1,
   Main_menu_controls,
   Main_menu_opers_guide,
   Main_menu_save,
   Main_menu_save_as,
+  Main_menu_set_tempo,
   Main_menu_about,
 };
 
@@ -1772,6 +1778,8 @@
   qmenu_add_choice(qm, "Save", Main_menu_save);
   qmenu_add_choice(qm, "Save As...", Main_menu_save_as);
   qmenu_add_spacer(qm);
+  qmenu_add_choice(qm, "Set BPM...", Main_menu_set_tempo);
+  qmenu_add_spacer(qm);
   qmenu_add_choice(qm, "Controls...", Main_menu_controls);
   qmenu_add_choice(qm, "Operators...", Main_menu_opers_guide);
   qmenu_add_choice(qm, "About...", Main_menu_about);
@@ -1977,6 +1985,16 @@
   qform_push_to_nav(qf);
 }
 
+void push_set_tempo_form(Usz initial) {
+  Qform* qf = qform_create(Set_tempo_form_id);
+  char buff[64];
+  int snres = snprintf(buff, sizeof buff, "%zu", initial);
+  char const* inistr = snres > 0 && (Usz)snres < sizeof buff ? buff : "";
+  qform_set_title(qf, "Set BPM");
+  qform_add_text_line(qf, Tempo_text_line_id, inistr);
+  qform_push_to_nav(qf);
+}
+
 //
 // main
 //
@@ -2477,6 +2495,9 @@
               case Main_menu_save_as:
                 push_save_as_form(file_name.str);
                 break;
+              case Main_menu_set_tempo:
+                push_set_tempo_form(ged_state.bpm);
+                break;
               }
             }
           } break;
@@ -2504,6 +2525,19 @@
                 try_save_with_msg(&ged_state);
               }
               heapstr_deinit(&temp_name);
+            } break;
+            case Set_tempo_form_id: {
+              Heapstr tmpstr;
+              heapstr_init(&tmpstr);
+              if (qform_get_text_line(qf, Tempo_text_line_id, &tmpstr) &&
+                  heapstr_len(&tmpstr) > 0) {
+                int newbpm = atoi(tmpstr.str);
+                if (newbpm > 0) {
+                  ged_state.bpm = (Usz)newbpm;
+                  qnav_stack_pop();
+                }
+              }
+              heapstr_deinit(&tmpstr);
             } break;
             }
           } break;