Init and tempo().get()

KVRer
5 posts since 19 Aug, 2014

Post Thu Apr 15, 2021 1:23 pm

Hi,

I have just started having a go with creating my first script. My basic plan is to create a turntable style pitch(tempo) control. So the idea is the tempo will be grabbed at load time then used to map +/-8% range to a controller which will adjust the tempo. (Not sure I have explained that particularly well there!).

I seem to have stumbled at the first hurdle. For some reason when I perform a tempo().get() as part of the init() it always returns 0. However once the script is loaded and I do something like println(transport.tempo().get()) in the console it works!

Here's my code:

Code: Select all

loadAPI(2);

host.defineController("adamcathersides", "test", "1.0", "1503f960-9c54-11eb-8ab0-0800200c9a66");
host.defineMidiPorts(0, 0);

function init()
{
	transport = host.createTransport();
	transport.tempo.markInterested();
	getTempo()
}

function exit()
{
	println('Exited');
}

function flush()
{
}

function getTempo()
{
	currentTempo = transport.tempo().get(); //* 646 + 20;
	println(currentTempo);
	upperRange = currentTempo + currentTempo / 100 * 8
	lowerRange = currentTempo - currentTempo / 100 * 8
	stepInc = upperRange - lowerRange / 128
	println(stepInc)
}
I had a quick search on this forum and coudn't see any thing obvious and I am obviously misunderstanding how init() should be used. My head is starting to hurt from banging it against a wall! Any thoughts?

User avatar
KVRAF
2741 posts since 13 May, 2004

Post Fri Apr 16, 2021 12:20 am

adamcathersides wrote:
Thu Apr 15, 2021 1:23 pm
I had a quick search on this forum and coudn't see any thing obvious and I am obviously misunderstanding how init() should be used. My head is starting to hurt from banging it against a wall! Any thoughts?
The whole Bitwig API works asynchroneously, which means values are updated "when there is time". In your case it did not yet happen. If you need to trigger something in the init() you can use host.scheduleTask.

KVRer

Topic Starter

5 posts since 19 Aug, 2014

Post Fri Apr 16, 2021 9:55 am

Ohh I see, thanks so much that really helps! :tu:

Return to “Controller Scripting”