timing without sleep

Pixilang programming language
Post Reply
Severak
Posts: 11
Joined: Fri Nov 18, 2016 5:27 pm

timing without sleep

Post by Severak » Mon Sep 10, 2018 1:44 pm

Hi,
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
}
(full code here if you are interested - https://github.com/severak/notovid)

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
}
But I am not getting how to write its_right_time() function...

Post Reply