about summary refs log tree commit diff
path: root/users/Profpatsch/lyric/src/tap-bpm.ts
diff options
context:
space:
mode:
Diffstat (limited to 'users/Profpatsch/lyric/src/tap-bpm.ts')
-rw-r--r--users/Profpatsch/lyric/src/tap-bpm.ts29
1 files changed, 11 insertions, 18 deletions
diff --git a/users/Profpatsch/lyric/src/tap-bpm.ts b/users/Profpatsch/lyric/src/tap-bpm.ts
index 2062fb8bbca7..b3c727df5608 100644
--- a/users/Profpatsch/lyric/src/tap-bpm.ts
+++ b/users/Profpatsch/lyric/src/tap-bpm.ts
@@ -1,7 +1,7 @@
 // create a node command line listener that allows the user to press any key , and averages the distances between the key presses to determine the BPM (with a window of 4 key presses). If the user presses q, the program should exit and print the final BPM.
 
 // Import the necessary modules
-import * as readline from "readline";
+import * as readline from 'readline';
 
 export function tapBpm() {
   // Set up readline interface to listen for keypresses
@@ -19,35 +19,28 @@ export function tapBpm() {
       return 0;
     }
     const averageTimeDiff =
-      timeDifferences.reduce((acc, curr) => acc + curr, 0) /
-      timeDifferences.length;
+      timeDifferences.reduce((acc, curr) => acc + curr, 0) / timeDifferences.length;
     return (60 * 1000) / averageTimeDiff;
   }
 
   // Handle the SIGINT (Ctrl+C) event manually
-  process.on("SIGINT", () => {
-    console.log(
-      "\nExiting via SIGINT (Ctrl+C)... Final BPM:",
-      calculateBPM().toFixed(2)
-    );
+  process.on('SIGINT', () => {
+    console.log('\nExiting via SIGINT (Ctrl+C)... Final BPM:', calculateBPM().toFixed(2));
     process.exit();
   });
 
   // Listen for keypress events
-  process.stdin.on("keypress", (str, key) => {
+  process.stdin.on('keypress', (str, key: { name: string; sequence: string }) => {
     // Exit if 'q' is pressed
-    if (key.name === "q") {
-      console.log("Exiting... Final BPM:", calculateBPM().toFixed(2));
+    if (key.name === 'q') {
+      console.log('Exiting... Final BPM:', calculateBPM().toFixed(2));
       process.exit();
     }
 
     // Handle Ctrl+C (SIGINT)
-    if (key.sequence === "\u0003") {
+    if (key.sequence === '\u0003') {
       // '\u0003' is the raw code for Ctrl+C
-      console.log(
-        "\nExiting via Ctrl+C... Final BPM:",
-        calculateBPM().toFixed(2)
-      );
+      console.log('\nExiting via Ctrl+C... Final BPM:', calculateBPM().toFixed(2));
       process.exit();
     }
 
@@ -66,9 +59,9 @@ export function tapBpm() {
 
       // Calculate and display the BPM
       const bpm = calculateBPM();
-      console.log("Current BPM:", bpm.toFixed(2));
+      console.log('Current BPM:', bpm.toFixed(2));
     } else {
-      console.log("Waiting for more key presses to calculate BPM...");
+      console.log('Waiting for more key presses to calculate BPM...');
     }
 
     // Update the lastPressTime to the current time