I am making sort of MIDI sequencer.
Currently it can play music. Now I want to add recording but I need to figure out how to do precise timing without using sleep because I need to process events and want to have instant feedback.
Current code:
Code: Select all
while (1) {
play_some_notes()
sleep(500) // I have currently fixed tempo of 120 BPM
step = step + 1
}
Where to place get_event()? Do events queue?
For example, I was thinking about something like this:
Code: Select all
while (1) {
process_events()
// right time it's only two times in second
// because of 120 BPM tempo
if its_right_time() {
play_some_notes()
}
step = step + 1
}