Metronome: Difference between revisions
Content added Content deleted
Line 321: | Line 321: | ||
let cpu_error = -750.0 |
let cpu_error = -750.0 |
||
let print = function |
let print = function |
||
| 1 -> high_pitch.Play(); "\nTICK " |
| 1 -> high_pitch.Play(); printf "\nTICK " |
||
| _ -> low_pitch.Play(); "tick " |
| _ -> low_pitch.Play(); printf "tick " |
||
let wait (time:int) = |
let wait (time:int) = |
||
Thread.Sleep(time) |
Thread.Sleep(time) |
||
// Composition of functions |
// Composition of functions |
||
let tick = |
let tick = float>>factor (60000.0+cpu_error)>>int>>wait |
||
let rec play beats_per_measure current_beat beats_per_minute = |
let rec play beats_per_measure current_beat beats_per_minute = |
||
match current_beat, beats_per_measure with |
match current_beat, beats_per_measure with |
||
| a, b -> |
| a, b -> |
||
current_beat |> |
current_beat |> print |
||
beats_per_minute |> tick |
beats_per_minute |> tick |
||
if a <> b then |
if a <> b then |
||
Line 339: | Line 339: | ||
Seq.initInfinite (fun i -> i + 1) |
Seq.initInfinite (fun i -> i + 1) |
||
|> Seq.iter (fun _ -> tempo |> play beats 1 |> ignore) |
|> Seq.iter (fun _ -> tempo |> play beats 1 |> ignore) |
||
0</lang> |
0 </lang> |
||
Sample run: |
Sample run: |
||
<pre>$ metronome 120 6 |
<pre>$ metronome 120 6 |