source/alo.c
static void
update_position(Alo* self, const LV2_Atom_Object* obj)
{
	AloURIs* const uris = &self->uris;

	// Received new transport position/speed
	LV2_Atom *beat = NULL, *bpm = NULL, *bpb = NULL, *speed = NULL;
	lv2_atom_object_get(obj,
			    uris->time_barBeat, &beat,
			    uris->time_beatsPerMinute, &bpm,
			    uris->time_speed, &speed,
			    uris->time_beatsPerBar, &bpb,
			    NULL);

	if (bpb && bpb->type == uris->atom_Float) {
		if (self->bpb != ((LV2_Atom_Float*)bpb)->body) {
			self->bpb = ((LV2_Atom_Float*)bpb)->body;
			reset(self);
		}
	}

	if ((uint32_t)floorf(self->bpb) * (uint32_t)floorf(*(self->ports.bars)) != self->loop_beats){
		reset(self);
	}

	if (bpm && bpm->type == uris->atom_Float) {
		if (round(self->bpm) != round(((LV2_Atom_Float*)bpm)->body)) {
			// Tempo changed, update BPM
			self->bpm = ((LV2_Atom_Float*)bpm)->body;
			reset(self);
		}
	}

	if ((uint32_t)floorf(self->bpb) * (uint32_t)floorf(*(self->ports.bars)) != self->loop_beats) {
		reset(self);
	}

	if (speed && speed->type == uris->atom_Float) {
		if (self->speed != ((LV2_Atom_Float*)speed)->body) {
			// Speed changed, e.g. 0 (stop) to 1 (play)
			// reset the loop start
			self->speed = ((LV2_Atom_Float*)speed)->body;
			reset(self);
			log("Speed change: %G", self->speed);
			log("Loop: [%d][%d]", self->loop_beats, self->loop_samples);
		};
	}
	if (beat && beat->type == uris->atom_Float) {
		// Received a beat position, synchronise
//		const float frames_per_beat = 60.0f / self->bpm * self->rate;
		self->current_position = ((LV2_Atom_Float*)beat)->body;
//		const float beat_beats	    = bar_beats - floorf(bar_beats);
		if (self->current_bb != (uint32_t)self->current_position) {
			// we are onto the next beat
			self->current_bb = (uint32_t)self->current_position;
			if (self->current_lb == self->loop_beats) {
				self->current_lb = 0;
			}
			log("Beat:[%d][%d] index[%d] beat[%G]\n", self->current_bb, self->current_lb, self->loop_index, self->current_position);
			self->current_lb += 1;
		}
	}
}
/**
   Update the current (midi) position based on a host message.	This is called
   by run() when a time:Position is received.
*/
Update the current (midi) position based on a host message.  This is called
by run() when a time:Position is received.
Update the current ( midi ) position based on a host message . This is called by run () when a time : Position is received .
static void
update_position(Alo* self, const LV2_Atom_Object* obj)
{
	AloURIs* const uris = &self->uris;
	LV2_Atom *beat = NULL, *bpm = NULL, *bpb = NULL, *speed = NULL;
	lv2_atom_object_get(obj,
			    uris->time_barBeat, &beat,
			    uris->time_beatsPerMinute, &bpm,
			    uris->time_speed, &speed,
			    uris->time_beatsPerBar, &bpb,
			    NULL);
	if (bpb && bpb->type == uris->atom_Float) {
		if (self->bpb != ((LV2_Atom_Float*)bpb)->body) {
			self->bpb = ((LV2_Atom_Float*)bpb)->body;
			reset(self);
		}
	}
	if ((uint32_t)floorf(self->bpb) * (uint32_t)floorf(*(self->ports.bars)) != self->loop_beats){
		reset(self);
	}
	if (bpm && bpm->type == uris->atom_Float) {
		if (round(self->bpm) != round(((LV2_Atom_Float*)bpm)->body)) {
			self->bpm = ((LV2_Atom_Float*)bpm)->body;
			reset(self);
		}
	}
	if ((uint32_t)floorf(self->bpb) * (uint32_t)floorf(*(self->ports.bars)) != self->loop_beats) {
		reset(self);
	}
	if (speed && speed->type == uris->atom_Float) {
		if (self->speed != ((LV2_Atom_Float*)speed)->body) {
			self->speed = ((LV2_Atom_Float*)speed)->body;
			reset(self);
			log("Speed change: %G", self->speed);
			log("Loop: [%d][%d]", self->loop_beats, self->loop_samples);
		};
	}
	if (beat && beat->type == uris->atom_Float) {
		self->current_position = ((LV2_Atom_Float*)beat)->body;
		if (self->current_bb != (uint32_t)self->current_position) {
			self->current_bb = (uint32_t)self->current_position;
			if (self->current_lb == self->loop_beats) {
				self->current_lb = 0;
			}
			log("Beat:[%d][%d] index[%d] beat[%G]\n", self->current_bb, self->current_lb, self->loop_index, self->current_position);
			self->current_lb += 1;
		}
	}
}
static void update_position ( Alo * self , const LV2_Atom_Object * obj ) { AloURIs * const uris = & self -> uris ; LV2_Atom * beat = NULL , * bpm = NULL , * bpb = NULL , * speed = NULL ; lv2_atom_object_get ( obj , uris -> time_barBeat , & beat , uris -> time_beatsPerMinute , & bpm , uris -> time_speed , & speed , uris -> time_beatsPerBar , & bpb , NULL ) ; if ( bpb && bpb -> type == uris -> atom_Float ) { if ( self -> bpb != ( ( LV2_Atom_Float * ) bpb ) -> body ) { self -> bpb = ( ( LV2_Atom_Float * ) bpb ) -> body ; reset ( self ) ; } } if ( ( uint32_t ) floorf ( self -> bpb ) * ( uint32_t ) floorf ( * ( self -> ports . bars ) ) != self -> loop_beats ) { reset ( self ) ; } if ( bpm && bpm -> type == uris -> atom_Float ) { if ( round ( self -> bpm ) != round ( ( ( LV2_Atom_Float * ) bpm ) -> body ) ) { self -> bpm = ( ( LV2_Atom_Float * ) bpm ) -> body ; reset ( self ) ; } } if ( ( uint32_t ) floorf ( self -> bpb ) * ( uint32_t ) floorf ( * ( self -> ports . bars ) ) != self -> loop_beats ) { reset ( self ) ; } if ( speed && speed -> type == uris -> atom_Float ) { if ( self -> speed != ( ( LV2_Atom_Float * ) speed ) -> body ) { self -> speed = ( ( LV2_Atom_Float * ) speed ) -> body ; reset ( self ) ; log ( " " , self -> speed ) ; log ( " " , self -> loop_beats , self -> loop_samples ) ; } ; } if ( beat && beat -> type == uris -> atom_Float ) { self -> current_position = ( ( LV2_Atom_Float * ) beat ) -> body ; if ( self -> current_bb != ( uint32_t ) self -> current_position ) { self -> current_bb = ( uint32_t ) self -> current_position ; if ( self -> current_lb == self -> loop_beats ) { self -> current_lb = 0 ; } log ( " \n " , self -> current_bb , self -> current_lb , self -> loop_index , self -> current_position ) ; self -> current_lb += 1 ; } } }
Update the current (midi) position based on a host message.
Update the current ( midi ) position based on a host message .
// Received new transport position/speed // Tempo changed, update BPM // Speed changed, e.g. 0 (stop) to 1 (play) // reset the loop start // Received a beat position, synchronise //		const float frames_per_beat = 60.0f / self->bpm * self->rate; //		const float beat_beats	    = bar_beats - floorf(bar_beats); // we are onto the next beat