Metronome: Difference between revisions

Scala solution added
(Scala solution added)
Line 1,320:
</lang>
 
=={{header|Scala}}==
<lang Scala>def metronome(bpm: Int, bpb: Int, maxBeats: Int = Int.MaxValue) {
val delay = 60000L / bpm
var beats = 0
do {
Thread.sleep(delay)
if (beats % bpb == 0) print("\nTICK ")
else print("tick ")
beats+=1
}
while (beats < maxBeats)
println()
}
 
metronome(120, 4, 20) // limit to 20</lang>
{{Out}} See it running in your browser by [https://scastie.scala-lang.org/7iejBcWqQISAIGtBCG6BNQ Scastie (JVM)].
=={{header|Tcl}}==
This code only rings the bell on the high beat, which occurs at the start of the bar.
Anonymous user