From c384b9b79e7b8a6cac0a04afe92e71c3ab8d747c Mon Sep 17 00:00:00 2001
From: rorist <rorist@0xcafe.ch>
Date: Fri, 25 Aug 2023 21:33:00 +0200
Subject: [PATCH] Add time signature to UI

---
 __init__.py | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/__init__.py b/__init__.py
index bfd7c4f..3369a67 100755
--- a/__init__.py
+++ b/__init__.py
@@ -38,6 +38,7 @@ class EndlessSequencer(Application):
         self.SILENCE = 99
         self.bpm = 120
         self.time_signature = [0.5, 1, 2] # 1/16, 1/8, 1/4
+        self.time_signature_txt = ['1/16', '1/4', '1/8']
         self.current_time_signature = 2 # 1/8
 
     def draw(self, ctx: Context) -> None:
@@ -98,23 +99,27 @@ class EndlessSequencer(Application):
 
             # CURRENT SAMPLE
             if self.current_sample != None and self.current_sample < len(self.sample_names):
-                ctx.move_to(0, 18)
+                ctx.move_to(0, 10)
                 ctx.rgb(*colours.RED)
                 ctx.font_size = 20
                 ctx.text(self.sample_names[self.current_sample])
 
             # BPM
             ctx.text_align = ctx.LEFT
-            ctx.move_to(-90, 50)
+            ctx.move_to(-90, 35)
             ctx.rgb(*colours.WHITE)
             ctx.font_size = 18
             ctx.text("BPM: {}".format(self.bpm))
-            ctx.move_to(-80, 70)
-            ctx.font_size = 12
-            ctx.text("left btn")
+
+            # Time signature
+            ctx.text_align = ctx.LEFT
+            ctx.move_to(-90, 50)
+            ctx.rgb(*colours.WHITE)
+            ctx.font_size = 18
+            ctx.text("TIME: {}".format(self.time_signature_txt[self.current_time_signature]))
 
             # Length
-            ctx.move_to(30, 60)
+            ctx.move_to(30, 45)
             ctx.rgb(*colours.BLUE)
             ctx.font_size = 48
             if self.current_note > 0:
@@ -122,6 +127,12 @@ class EndlessSequencer(Application):
             else:
                 ctx.text("{}".format(len(self.notes)))
 
+            # Hint
+            ctx.move_to(-80, 70)
+            ctx.rgb(*colours.GREY)
+            ctx.font_size = 12
+            ctx.text("btn to change\nbpm and time")
+
         ctx.restore()
 
     def think(self, ins: InputState, delta_ms: int) -> None:
@@ -218,7 +229,7 @@ class EndlessSequencer(Application):
 
     def next_bpm(self):
         # taken from binarybrain code
-        beatTime = 60.0 * 1000.0 / self.bpm / self.current_time_signature
+        beatTime = 60.0 * 1000.0 / self.bpm / self.time_signature[self.current_time_signature]
         curRelTime = time.ticks_diff(time.ticks_ms(), self.startTime)
         return curRelTime / beatTime > 1
 
-- 
GitLab