A Kind Of Round Robin Replacement (In Development)

Options
supervillain
supervillain Member Posts: 3 Newcomer
edited July 2023 in Scripting Workshop

Hi everyone!

As I'm learning to script KSP, I've been reading through some posts and speaking with a few people. I've noticed that many people are unhappy with the performance of Round Robin. So for my jump into KSP, I've decided to take on the challenge of reinventing the Round Robin feature (and giving it a kick!).

I've only been scripting KSP for about a week, so Switcharoo is still very rigid. However, the basic functionality is beginning to shine through.

Switcharoo divides 10 groups into 2 pools of 5 groups (this will be expanded in later versions). Each group in the pool can hold up to 5 samples each (this will also be expanded). Currently, Switcharoo cycles through the samples in each group and then advances to the next group in the pool.

The functionality is there, but it's still shaky. Nonetheless, it cycles samples in groups and groups within a confined pool. You can change between Group Pool 1 and Group Pool 2 by double-tapping C#0. You can turn Switcharoo on by double-tapping C0, and you can turn it off by pressing C0 once.

If Switcharoo is turned off, double-tapping C#0 will swap between the first sample in the first group of each pool.

This is still being developed, but I wanted to share my progress. I only have one arm, you see, and I am developing Switcharoo not just to be a replacement for Round Robin, but to make it easier to switch and mix my samples during a live performance or even just while recording. Of course, I'm not a musician; I used to be a mechanic until the Michelin man tried to run away with my left arm. I started teaching myself how to code after my accident 5 years ago.

I hope this script can be of some use to you, and I will be developing the functionality over the coming weeks.

Here's what I've achieved so far:


{Switcharoo v1.0.8.9 - By Hushaboom}


on init
	
	make_perfview
	declare $label

	{Real numbers/Float Variables}
	declare ~threshold := 0.0
	declare ~messages := 0.0

	{Switches}
	declare $endZone	{Zone we are currently on}
	declare $outcast	{Zone sent to stand-by}
	declare $onGroup	{Active Zone}
	declare $oldNote	{Flag: last note played}
	declare $currNote	{Flag: Currnet note being played}
	declare $group_Pool := 0	{Select which group pool to draw samples from}
	declare $freeSwitch := 0	{Swaps Group Pool switching between Free Mode and manual}
	declare $switcharoo_on := 0		{Turn it on/off}
	declare $sam_count		{Keeps track of samples for Round Robin replacement}
	
	declare $groupCount := -1
	declare $array_count := 0
	declare $onInit := 0
	declare $ringer := 0
	declare $count := 0
	declare $grpcount := 0
	declare $note_id
	

	
	declare %act_group[5]

	declare %grpArray0[5]
		%grpArray0[0] := 0
		%grpArray0[1] := 1
		%grpArray0[2] := 2
		%grpArray0[3] := 3
		%grpArray0[4] := 4
 
	declare %grpArray1[5]
		%grpArray1[0] := 5
		%grpArray1[1] := 6
		%grpArray1[2] := 7
		%grpArray1[3] := 8
		%grpArray1[4] := 9
 
	
	{Count Groups}	{Leaving this in for ease in testing}
	while ($groupCount < $NUM_GROUPS)
		$groupCount := $groupCount + 1
		end while
	
	{Set Primary Group and Group Pool}
	
	$onGroup := %act_group[0]
	
	
	{Listener Config}
	set_listener($NI_SIGNAL_TIMER_MS,10000)	{Kontakt reads time in microseconds, not miliseconds}
	
end on


{----------Begin Functions----------}

function SS_func_grouper()

	$grpcount := 0

	if ($group_Pool = 1)
 
		message("Switching to sample pool 1")
 
		%act_group[0] := 0
		%act_group[1] := 1
		%act_group[2] := 2
		%act_group[3] := 3
		%act_group[4] := 4
 
		$group_Pool := 0
		$grpcount := 0
		$onGroup := %act_group[0]
 
	else
	
		$grpcount := 0
 
		message("Switching to sample pool 2")
 
		%act_group[0] := 5
		%act_group[1] := 6
		%act_group[2] := 7
		%act_group[3] := 8
		%act_group[4] := 9
 
		$group_pool := 1
		$count := 0
		$onGroup := %act_group[0]
	
	end if

end function



function SS_func_flip()

	if ($switcharoo_on = 1)
	
		if ($sam_count < 5)
	
			$onGroup := %act_group[$sam_count]
			inc($sam_count)
 
		else
 
			$onGroup := %act_group[$count]
			inc($count)
			$sam_count := 0
	
			if ($count = 5)
 
				$count := 0
 
			end if
 
		end if
 
	end if
	
 


	if (($oldNote = 25) and ($currNote = 25))
	
		call SS_func_grouper()
	
	end if

	if (($oldNote = 24) and ($currNote = 24))
 
		if ($switcharoo_on = 0)
			change_listener_par($NI_SIGNAL_TIMER_MS, 1)
			$switcharoo_on := 1
			$ringer := 0
 
		else
 
			$switcharoo_on := 0
			$ringer := 0
			change_listener_par($NI_SIGNAL_TIMER_MS, 100000)
			$onGroup := %grpArray0[0]
 
		end if
 
	end if


end function

{----------End Functions----------}
	

{----------Note Callbacks----------}
on note

disallow_group($ALL_GROUPS)	
~messages := ~messages + 0.5	{Log the key press}
$currNote := $EVENT_NOTE

if (($switcharoo_on = 1) and ($currNote = 24))
	
	$switcharoo_on := 0
	$ringer := 0
	change_listener_par($NI_SIGNAL_TIMER_MS, 100000)
	$onGroup := %grpArray0[0]
	
else

	$ringer := 0
	
end if

if ($switcharoo_on = 1)

	message("Switcharoo is On")
	

else
	
	message($currNote)
	
end if

if ((($onGroup = 4) or ($onGroup = 9)) and ($freeSwitch = 1))
	
		call SS_func_grouper()
		~messages := 0.0
 
end if

allow_group($onGroup)	{Activate zone}
	
call SS_func_flip()

end on 


on release

~messages := ~messages + 0.5	{Log the key release}
$oldNote := $currNote

end on

{----------End Note Callbacks----------}


{----------Time----------}
on listener

$ringer := $ringer + 1	{Counting time cycles; $ringer*$NI_SIGNAL_TIMER_MS = our clock}

{Time Based Conditions - Raise flags here for 'on note' or 'on release' to respond}


end on

{----------EOF----------}
Back To Top