Home Forums Logelloop 6 (English spoken) Dynamic playback/stretch control of a current Korpus looper Reply To: Dynamic playback/stretch control of a current Korpus looper

#6658
Patrick KiznyPacocreative
Participant

Here’s a version 2 of the Speed Changer

# requires 2 expression pedals or similar signals on CC1 and CC2 variable
# CC2 adjusts speed in tape mode and in ETS mode
# CC1 allows to scrub through the sample in ETS freeze mode
# Triggered once, and working in a loop, so a proper implementation
# If looper is in freeze mode, CC1 allows to dynamically scrub through the buffer
$ if speed is lifted up from freeze, or is in any of the tape modes, it ignores CC1
# It does not mess up on looper change, as I implemented change listeners, so unless you start messing with CC1V CC2V, it does not automatically alter current looper settings

Hell yeah!


// Find current looper index
Declare int $k_index$ = $Korpus_data1_rank1_Counter_state$

Declare float $spd_min1$ = 0.25  // Edit this to set min speed in Standard modes
Declare float $spd_max1$ = 4     // Edit this to set max speed in Extreme Stretch Mode
Declare float $spd_max2$ = 25    // Edit this to set max speed in Extreme Stretch Mode

Declare int $p_mode$ = 0         // Play mode
Declare float $p_pos$ = 0        // ETS Freeze mode position scrubbing
Declare float $p_pos_last$ = 0

Declare int $frz$  = 0           // Looper will freeze when reaching max speed
Declare float $spd$ = 1
Declare float $bufsize$ = 0      // Buffer length in samples

Declare float $midiv_cc1_last$ = $midiv_cc1$
Declare float $midiv_cc2_last$ = $midiv_cc2$

DoRepeat

	// Get current player mode
	// PlayerMode 0 ⇀ Tape
	// PlayerMode 2 ⇀ Stretch

	$k_index$ = $Korpus_data1_rank1_Counter_state$

	IfThen { $k_index$ == 1 } Do $p_mode$ = $Looper_fx1_rank1_PlayerMode_state$
	IfThen { $k_index$ == 2 } Do $p_mode$ = $Looper_fx2_rank1_PlayerMode_state$
	IfThen { $k_index$ == 3 } Do $p_mode$ = $Looper_fx3_rank1_PlayerMode_state$
	IfThen { $k_index$ == 4 } Do $p_mode$ = $Looper_fx4_rank1_PlayerMode_state$

	IfThen { $k_index$ == 1 } Do $bufsize$ = $Looper_fx1_rank1_current_length$
	IfThen { $k_index$ == 2 } Do $bufsize$ = $Looper_fx2_rank1_current_length$
	IfThen { $k_index$ == 3 } Do $bufsize$ = $Looper_fx3_rank1_current_length$
	IfThen { $k_index$ == 4 } Do $bufsize$ = $Looper_fx4_rank1_current_length$

	// If { $p_mode$ == 2 and $midiv_cc1$ == $midiv_cc1_last$ }
	//	Message "speed no change"
	// EndIf
	
        // Freeze player
	// Set speeds in ETS Mode
	If { $p_mode$ == 2 and $midiv_cc1$ != $midiv_cc1_last$ }
		$spd$ = {scale($midiv_cc1$, 3, 126, $spd_max2$, 1)}
		$frz$ = {$spd$ > ($spd_max2$ * 0.95) ? 1 : 0 }

		InsertSendMessage fx[$k_index$] 1 HTSSpeed $spd$
		InsertSendMessage fx[$k_index$] 1 HTSFreeze $frz$
		$midiv_cc1_last$ = $midiv_cc1$

	EndIf

	// Store last position if playing
	If { $p_mode$ == 2 and $frz$ == 0 and $midiv_cc1$ != $midiv_cc1_last$}
		IfThen { $k_index$ == 1 } Do $p_pos_last$ = $Looper_fx1_rank1_Playing_head_position_samples$
		IfThen { $k_index$ == 2 } Do $p_pos_last$ = $Looper_fx2_rank1_Playing_head_position_samples$
		IfThen { $k_index$ == 3 } Do $p_pos_last$ = $Looper_fx3_rank1_Playing_head_position_samples$
		IfThen { $k_index$ == 4 } Do $p_pos_last$ = $Looper_fx4_rank1_Playing_head_position_samples$
		$midiv_cc2_last$ = $midiv_cc2$
	EndIf

	// Position scrubbing via midiv CC2 only on pedal change
	If { $p_mode$ == 2 and $frz$ == 1 and $midiv_cc2$ != $midiv_cc2_last$}
		$p_pos$ = {scale($midiv_cc2$, 0, 127, 0, $bufsize$)}
		InsertController fx[$k_index$] 1 4 = $p_pos$
	EndIf

	// Tape or similar
	If {$p_mode$ != 2 and $midiv_cc1$ != $midiv_cc1_last$}

		// Calculate target speed
		$spd$ = {scale($midiv_cc1$, 3, 126, $spd_min1$, $spd_max1$)}

		// Check current speed to see if it's reversed or not
		IfThen { $Korpus_data1_rank1_Counter_state$ == 1 } Do $c_speed$ = $Looper_fx1_rank1_SpeedFloat_state$
		IfThen { $Korpus_data1_rank1_Counter_state$ == 2 } Do $c_speed$ = $Looper_fx2_rank1_SpeedFloat_state$
		IfThen { $Korpus_data1_rank1_Counter_state$ == 3 } Do $c_speed$ = $Looper_fx3_rank1_SpeedFloat_state$
		IfThen { $Korpus_data1_rank1_Counter_state$ == 4 } Do $c_speed$ = $Looper_fx4_rank1_SpeedFloat_state$

		// Reverse if current speed was negative
		IfThen { $c_speed$ < 0 } Do $spd$ = { $spd$ * -1 }

		// Set Speed
		InsertSendMessage fx[$Korpus_data1_rank1_Counter_state$] 1 SpeedFloat $spd$

		$midiv_cc1_last$ = $midiv_cc1$
	EndIf

	Sleep 50
While true