Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
abbysmal committed Jan 25, 2024
1 parent d41e91b commit 41a20d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 23 additions & 2 deletions bin/read_clock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ let process_event queue device (ev : Portmidi.Portmidi_event.t) =
| None -> ());
match Queue.take_opt queue with
| None -> Atomic.set milestone (None, 96)
| Some (note, cycles) ->
| Some (note, notes_per_beat) ->
let cycles = 24/notes_per_beat in
print_endline "milestone started: turn on note";
Midi.(
write_output device
Expand All @@ -45,7 +46,27 @@ let external_main input_device_id output_device note_queue =
in
aux ()

let internal_main bpm device note_queue =
let rec aux () =
if Atomic.get Watchdog.terminate then
()
else begin
match Queue.take_opt note_queue with
| None -> Unix.sleepf (60. /. float_of_int bpm ); aux ()
| Some (note, n) ->
Midi.(
write_output device
[ message_on ~note ~timestamp:0l ~volume:'\090' ~channel:6 () ]);
Unix.sleepf (60. /. float_of_int bpm /. float_of_int n);
Midi.(
write_output device
[ message_off ~note ~timestamp:0l ~volume:'\090' ~channel:6 () ]);
aux ()
end
in
aux ()

let clock_domain_main clock_source output_device note_queue () =
match clock_source with
| External input_device_id -> external_main input_device_id output_device note_queue
| Internal _bpm -> assert false
| Internal bpm -> internal_main bpm output_device note_queue
2 changes: 1 addition & 1 deletion bin/stat_engine.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ let rec sequencer_main_func num_beats tones device bpm queue _ =
[ message_on ~note ~timestamp:0l ~volume ~channel:0 () ]); *)
(*FIXME: don't sleep, but use a timestamp*)
(* Unix.sleepf (60. /. Float.of_int bpm /. Float.of_int n)) *)
Queue.push (note, 24/n) queue)
Queue.push (note, n) queue)
interesting_stuff;
Mutex.lock event_table_lock;
Hashtbl.clear event_table;
Expand Down

0 comments on commit 41a20d4

Please sign in to comment.