source/alo.c
static void
button_logic(LV2_Handle instance, bool new_button_state, int i)
{
	Alo* self = (Alo*)instance;

	struct timeval te;
	gettimeofday(&te, NULL); // get current time
	long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000;

	log("[%d] Button logic", i);
	self->button_state[i] = new_button_state;


	int difference = milliseconds - self->button_time[i];
	self->button_time[i] = milliseconds;
	if (new_button_state == true) {
		log("[%d] Button ON", i);
	} else {
		log("[%d] Button OFF", i);
	}

	// Free running mode: when a button is pressed,
	// if there is a button recording, set loop size and start based on its loop
	if (self->loop_samples == LOOP_SIZE) {
		for (int j = 0; j < NUM_LOOPS; j++) {
			if (self->phrase_start[j] != 0) {
				self->loop_samples = LOOP_SIZE + self->loop_index - self->phrase_start[j];
				self->loop_samples = self->loop_samples % LOOP_SIZE;
				self->loop_start = self->phrase_start[j];
			}
		}
	}

	int on_loops = 0;
	for (int j = 0; j < NUM_LOOPS; j++) {
		if (self->button_state[j] == true) {
			on_loops += 1;
		}
	}

	if (on_loops == 0 && *(self->ports.reset_mode) == 1.0) {
		// reset if all loops are off
		reset(self);
		log("[%d] STATE: RESET mode 0", i);
	}

	if (difference < 1000) {
		if (*(self->ports.reset_mode) == 2.0 || on_loops == 1) {
			reset(self);
			log("[%d] STATE: RESET mode 2", i);
		}
		if (*(self->ports.reset_mode) == 3.0) {
			self->state[i] = STATE_RECORDING;
			self->phrase_start[i] = 0;
			log("[%d] STATE: RECORDING (button reset)", i);
		}
	}
	log("[%d] Button logic ends", i);
}
/**
   Adjust self->state based on button presses.
*/
Adjust self->state based on button presses.
Adjust self - > state based on button presses .
static void
button_logic(LV2_Handle instance, bool new_button_state, int i)
{
	Alo* self = (Alo*)instance;
	struct timeval te;
	gettimeofday(&te, NULL); 
	long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000;
	log("[%d] Button logic", i);
	self->button_state[i] = new_button_state;
	int difference = milliseconds - self->button_time[i];
	self->button_time[i] = milliseconds;
	if (new_button_state == true) {
		log("[%d] Button ON", i);
	} else {
		log("[%d] Button OFF", i);
	}
	if (self->loop_samples == LOOP_SIZE) {
		for (int j = 0; j < NUM_LOOPS; j++) {
			if (self->phrase_start[j] != 0) {
				self->loop_samples = LOOP_SIZE + self->loop_index - self->phrase_start[j];
				self->loop_samples = self->loop_samples % LOOP_SIZE;
				self->loop_start = self->phrase_start[j];
			}
		}
	}
	int on_loops = 0;
	for (int j = 0; j < NUM_LOOPS; j++) {
		if (self->button_state[j] == true) {
			on_loops += 1;
		}
	}
	if (on_loops == 0 && *(self->ports.reset_mode) == 1.0) {
		reset(self);
		log("[%d] STATE: RESET mode 0", i);
	}
	if (difference < 1000) {
		if (*(self->ports.reset_mode) == 2.0 || on_loops == 1) {
			reset(self);
			log("[%d] STATE: RESET mode 2", i);
		}
		if (*(self->ports.reset_mode) == 3.0) {
			self->state[i] = STATE_RECORDING;
			self->phrase_start[i] = 0;
			log("[%d] STATE: RECORDING (button reset)", i);
		}
	}
	log("[%d] Button logic ends", i);
}
static void button_logic ( LV2_Handle instance , bool new_button_state , int i ) { Alo * self = ( Alo * ) instance ; struct timeval te ; gettimeofday ( & te , NULL ) ; long long milliseconds = te . tv_sec * 1000LL + te . tv_usec / 1000 ; log ( " " , i ) ; self -> button_state [ i ] = new_button_state ; int difference = milliseconds - self -> button_time [ i ] ; self -> button_time [ i ] = milliseconds ; if ( new_button_state == true ) { log ( " " , i ) ; } else { log ( " " , i ) ; } if ( self -> loop_samples == LOOP_SIZE ) { for ( int j = 0 ; j < NUM_LOOPS ; j ++ ) { if ( self -> phrase_start [ j ] != 0 ) { self -> loop_samples = LOOP_SIZE + self -> loop_index - self -> phrase_start [ j ] ; self -> loop_samples = self -> loop_samples % LOOP_SIZE ; self -> loop_start = self -> phrase_start [ j ] ; } } } int on_loops = 0 ; for ( int j = 0 ; j < NUM_LOOPS ; j ++ ) { if ( self -> button_state [ j ] == true ) { on_loops += 1 ; } } if ( on_loops == 0 && * ( self -> ports . reset_mode ) == 1.0 ) { reset ( self ) ; log ( " " , i ) ; } if ( difference < 1000 ) { if ( * ( self -> ports . reset_mode ) == 2.0 || on_loops == 1 ) { reset ( self ) ; log ( " " , i ) ; } if ( * ( self -> ports . reset_mode ) == 3.0 ) { self -> state [ i ] = STATE_RECORDING ; self -> phrase_start [ i ] = 0 ; log ( " " , i ) ; } } log ( " " , i ) ; }
Adjust self->state based on button presses.
Adjust self - > state based on button presses .
// get current time // Free running mode: when a button is pressed, // if there is a button recording, set loop size and start based on its loop // reset if all loops are off