[jack] sync application to master

Programming applications for making music on Linux.

Moderators: khz, MattKingUSA

Post Reply
User avatar
Established Member
Posts: 33
Joined: Thu Jan 19, 2017 10:39 pm
Location: Germany

[jack] sync application to master

Post by flappix »

I'm wondering about the correct way of keeping my application in sync with a timebase master application.
Let's say I have Hydrogen running in master mode and I want to print a message on every 1/4 note Hydrogen is playing.

This is what I would do intuitive (using python):

Code: Select all

#!/usr/bin/env python3

import time
import jack

client = jack.Client('klicker')

def print_msg (last_tick):
	state, pos = client.transport_query()
	if state == jack.ROLLING:
		if pos['tick'] < last_tick:
			print ("klick")
	return pos['tick']

with client:
	last_tick = 0
	while True:
		last_tick = print_msg (last_tick)
So I'm running a loop with very little sleep time and check in every iteration if the current beat is already over.

This seems a little bit dirty and imprecise to me. So what would the right way of solving this problem?

Would be very happy if someone could help :)
Post Reply