Live API: Timer questions

Dec 27, 2009 at 3:15am

Live API: Timer questions

Hi. I’m trying to build an accurate timer that correctly reflects tempo changes, but I’m having trouble. I found two possible solutions in the LOM (live_set current_song_time and live_set current_smpte_song_time) which I thought might help, but I’m getting strange behavior. If you want to help me, please paste this into an empty max device, draw a tempo ramp in Live, and watch what happens. For me, it gets off the correct time as soon as the tempo changes. Does this happen for you? Do you have any suggestions or leads for me?
Thanks a million!

– Pasted Max Patch, click to expand. –
#47427
Dec 27, 2009 at 10:52am

Hi I’ve done some experimenting for an accurate time-signal that follows the live song. This patch is the best I’ve come up with until now.

It’s a MFL patcher and a JS script called transport.js.

Willem Lageman

– Pasted Max Patch, click to expand. –

// JS FILE transport.js
post(“re_compile”);

inlets = 1;
outlets = 6;
autowatch = 1;

var signature_numerator;
var prev_bar = -1;
var prev_beat = -1;

var is_playing = 0;
var loop = 0;

var loop_start = 0;

var loop_end = 0;

function bang()
{
post(“bang”);
}

function is_running(on)
{
post(“is_playing: ” + on);
post();
this.is_playing = on;
if (on != 0)
{
this.prev_bar = -1;
this.prev_beat = -1;
}
}

function is_looping(on)
{
post(“is_looping: ” + on);
post();
this.loop = on;

if (on == 0)
timepoint_loopstart(0, 0)
}

function on_loop_start_change(beat)
{
this.loop_start = beat;

bar = Math.floor(beat / this.signature_numerator) + 1;
beat = Math.floor(beat % this.signature_numerator) + 1;
post(“loop_start”, bar, beat, 0);
post();
//timepoint_loopstart(bar, beat);
}

function on_loop_length_change(beat)
{
this.loop_length = beat;

bar = Math.floor(beat / this.signature_numerator) + 1;
beat = Math.floor(beat % this.signature_numerator) + 1;
post(“loop_length”, bar, beat, 0);
post();
//timepoint_loopstart(bar, beat);
}

function on_metro(bar, beat, unit, resolution, tempo, signature_numerator, signature_denomenator, state, raw_ticks)
{
if (this.signature_numerator != signature_numerator)
{
this.signature_numerator = signature_numerator;
post(“signature_numerator: “, signature_numerator);
}

if (beat != this.prev_beat)
if (unit < 20)
on_beat(bar, beat, unit);
//else
// do_beat(bar, beat, unit);
}

function on_beat(bar, beat, unit)
{
song_pos = (bar – 1) * this.signature_numerator + beat – 1;
loop_end = this.loop_start + this.loop_length;

if (this.loop > 0)
{
if (song_pos >= loop_start)
{
bar1 = Math.floor(this.loop_start / this.signature_numerator) + 1;
beat1 = Math.floor(this.loop_start % this.signature_numerator) + 1;
timepoint_loopstart(bar1, beat1);
}
else
{
timepoint_loopstart(0, 0);
}
if (song_pos == loop_end)
{
bar = Math.floor(this.loop_start / this.signature_numerator) + 1;
beat = Math.floor(this.loop_start % this.signature_numerator) + 1;
song_pos = this.loop_start;
this.prev_bar = -1;
this.prev_beat = -1;
}
}
else
{
timepoint_loopstart(0, 0)
}

post(“Pos: ” + bar + “.” + beat + “.” + unit);
if (this.prev_beat != beat)
post(“Pos: ” + song_pos + ” Loopstart: ” + this.loop_start + ” Loopend: ” + (this.loop_start + this.loop_length));
post();

outlet(3, bar, beat);
outlet(2, beat);
this.prev_beat = beat;
if (this.prev_bar != bar)
{
outlet(1, bar);
this.prev_bar = bar;
}
outlet(0, bang);
do_beat(bar, beat, unit);
}

function do_beat(bar, beat, unit)
{
var next_bar = bar;
var next_beat = beat + 1;
if (next_beat > this.signature_numerator)
{
next_bar ++;
next_beat = 1;
}
//this.prev_bar = next_bar;
outlet(4, next_bar, next_beat, 0);
}

function timepoint_loopstart(bar, beat)
{
//post(“Timepoint_loopstart: “, bar, beat);
//post();
outlet(5, bar, beat, 0);
}
// END JS FILE

#170664
Dec 27, 2009 at 11:56am

hello Willem Lageman, this seems brilliant to me, so really – thanks for sharing, very generous.

in the copying / pasting / etc from forum to patch + .js file, of course the patch loses the 6 connections from the outlets of the .js. i think i can work it out ok, but could you confirm exactly where they are all supposed to be connected to?

i’d love to investigate your patch/js more in the knowledge i’d be doing the patching/coding justice!…

#170665
Dec 27, 2009 at 12:02pm

Hi The six outlets go from left to right to:
- button
- number
- number
- message
- timepoint
- timepoint

Willem.

#170666
Dec 27, 2009 at 1:03pm

thanks very much

#170667

You must be logged in to reply to this topic.