Here is a simple metronome script in Bash using ASCII bell.
#!/bin/bash
read -s tempo
interval=$(bc -l <<< "scale=4; 60/$tempo")
echo -n "tempo is $tempo interval is $interval seconds"
while true
do
echo -en "\a"
sleep $interval
done
The bug I'm encountering:
When tempo is set at more than 60, metronome script will start always at 120BPM initially, and only update to the correct tempo fast or slower after I interrupt it by hitting a random key.
I also tried it in Java and encountered the same issue.
import java.util.Scanner;
import java.lang.Runtime;
import java.io.*;
public class Metronome {
public static void main(String[] args) throws InterruptedException {
Scanner in = new Scanner(System.in);
double tempo = in.nextDouble();
double interval = (60 / tempo) *1000;
while (true) {
System.out.println("\u0007");
Thread.sleep((long) interval);
}
}
}
Is there a system default interval time that is set between bell chimes? How come it changed speed after I interrupt the thread/job?