# Initialize a global variable to store the previous index and value
if 'prev_index' not in globals():
if 'prev_value' not in globals():
def valueChange(channel, sampleIndex, val, prev):
# Check if the value has actually changed
prev_value = val # Update the previous value
# Create a list of possible indices with weighted probabilities
indices = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1] # 70% chance for 0, 30% chance for 1
# Remove the previous index from the list
if prev_index in indices:
indices = [i for i in indices if i != prev_index]
# Shuffle the list and select a new index
random_index = random.choice(indices)
# Set the index of the switch1 CHOP
op('switch1').par.index = random_index
op('switch2').par.index = random_index
# Update the previous index
prev_index = random_index
# Debug statements to print the current and previous index
#print(f"Previous Index: {prev_index}, New Index: {random_index}, New Value: {val}")