beatsPerBar change

dear all!
I am writing a precise scheduler connected with the tempo changes and meter changes at certain bars and beats. I want the time signature at bar 94 to change to 2/4 and at bar 97 to change to 3/4.
I don’t understand what is happening while the .beatsPerBar is changed , that causes the beats and bars numbers to be messed up in the post window. In the first case (b.93) the scheduling between the beats somehow does the trick, but in b.96 the same thing does not do the trick - the bars and beats are messed up.
what am I doing wrong?

(

s.waitForBoot({
	~tempo1 = 66/60;
	t = TempoClock.new(~tempo1, 0);
	s.sync;
	t.beats = ((t.bar) + 92 ) * t.beatsPerBar; //bars offset
	s.sync;
	~postInfo = {
		
		var  tbeat, eighth;
		~tbar = (t.bar);
		
		~tbeat = (((t.beats.floor)%t.beatsPerBar)+1);
		("beat :" + ~tbeat).postln;
		("bar :" + ~tbar).postln;
		
		case
		{ (~tbar == 93.0) && ((((t.beats)%(t.beatsPerBar)+1) > 2.0)) } {
			t.schedAbs(t.nextBar, {t.beatsPerBar = 2;});
		}
		{(~tbar == 94.0) && (~tbeat == 1.0)}{
			// ~metronome.play(t);
		}
		
		{ (~tbar == 95.0) && (~tbeat == 1.0) } {
			
			
		}
		{ (~tbar == 96.0) &&  ((((t.beats)%(t.beatsPerBar)+1) > 1.0))  } {
			t.schedAbs(t.nextBar, {t.beatsPerBar = 3;});
			
		}
		
		{ (~tbar == 97.0) && (~tbeat == 1.0) } {
			
		}
		
		;
		"".postln;
		
		1.0;
	}
	;
	
	
	t.schedAbs(t.nextBar, {
		~postInfo.value;
	});
	
}))
1 Like

upd. solved.
had made mistake in the ~tbeat calculation.
works fine with :

~tbeat =  t.beatInBar;

it starts also each bar from the beat 0 instead of the beat 1, so case conditionals should be updated.

Ah right, I read this post earlier but I would have missed that. After changing beatsPerBar, it’s no longer safe to assume that the origin of the timeline is 0. % t.beatsPerBar assumes a 0 origin; beatInBar is correctly relative to the clock’s baseBarBeat (which is updated at every meter change).

hjh