Keylab Mk1 FL Studio Python Code Start

Hi. I managed to get Bing AI to create the following, but it then stopped and refused to do any more. Is anyone able to complete this please?! I know nothing about coding and do not know where to start.

Import the fl studio module

import flstudio

Define the midi channel and port for the Keylab

KEYLAB_CHANNEL = 1
KEYLAB_PORT = 0

Define the midi messages for the Keylab knobs, faders, and buttons

You can use a midi monitor software to find out the exact values for your device

KNOB_1 = 74
KNOB_2 = 71
KNOB_3 = 76
KNOB_4 = 77
KNOB_5 = 93
KNOB_6 = 73
KNOB_7 = 75
KNOB_8 = 114
KNOB_9 = 18

FADER_1 = 81
FADER_2 = 82
FADER_3 = 83
FADER_4 = 84
FADER_5 = 85
FADER_6 = 86
FADER_7 = 87
FADER_8 = 88
FADER_9 = 89

BUTTON_1 = 112
BUTTON_2 = 113
BUTTON_3 = 114
BUTTON_4 = 115
BUTTON_5 = 116
BUTTON_6 = 117
BUTTON_7 = 118
BUTTON_8 = 119
BUTTON_9 = 102

Define the functions to handle the midi messages from the Keylab

def knob_handler(event):
# This function will map the knobs to the selected channel’s volume, pan, filter cutoff, filter resonance, and some plugin parameters

# Get the selected channel object from fl studio
channel = flstudio.channel(flstudio.channelNumber())

# Get the knob number and value from the event data
knob_number = event.data1 # This is the midi control change number (CC)
knob_value = event.data2 # This is the midi control change value (0-127)

# Map the knob value to a range of 0.0 to 1.0 for convenience
knob_value_normalized = knob_value / 127.0

# Check which knob is being turned and assign it to a parameter

if knob_number == KNOB_1:
    # Map knob 1 to channel volume
    channel.setVolume(knob_value_normalized)
    
elif knob_number == KNOB_2:
    # Map knob 2 to channel pan
    channel.setPan(knob_value_normalized)
    
elif knob_number == KNOB_3:
    # Map knob 3 to channel filter cutoff frequency (in Hz)
    # You can change the min and max values according to your preference
    min_freq = 20.0 # Minimum frequency in Hz
    max_freq = 20000.0 # Maximum frequency in Hz
    
    # Calculate the frequency value from the knob value using a logarithmic scale
    freq_value = min_freq * (max_freq / min_freq) ** knob_value_normalized
    
    # Set the channel filter cutoff frequency using fl studio's built-in function (in cents)
    channel.setFilterCutoff(flstudio.freqToCents(freq_value))
    
elif knob_number == KNOB_4:
    # Map knob 4 to channel filter resonance (Q factor)
    # You can change the min and max values according to your preference
    min_q = 0.1 # Minimum Q factor
    max_q = 10.0 # Maximum Q factor
    
    # Calculate the Q factor value from the knob value using a linear scale
    q_value = min_q + (max_q - min_q) * knob_value_normalized
    
    # Set the channel filter resonance using fl studio's built-in function (in cents)
    channel.setFilterResonance(flstudio.qToCents(q_value))
    
elif knob_number == KNOB_5:
    # Map knob 5 to a plugin parameter of your choice on the selected channel's first mixer insert slot
    
    # Get the plugin object from fl studio using the mixer track number and plugin index (starting from zero)
    plugin = flstudio.plugin(flstudio.channelRouteNumber(),0)
    
    # Get the parameter index of your choice from the plugin interface or documentation (starting from zero)
    param_index = 0
    
    # Set the plugin parameter value using fl studio's built-in function (in normalized units)
    plugin.setParameter(param_index,knob_value_normalized)
    
elif knob_number == KNOB_6:
    # Map knob 6 to another plugin parameter of your choice on the selected channel's first mixer insert slot
    
    # Get the plugin object from fl studio using the mixer track number and plugin index (starting from zero)
    plugin = flstudio.plugin(flstudio.channelRouteNumber(),0)
    
    # Get the parameter index of your choice from the plugin interface or documentation (starting from zero)
    param_index = 1
    
    # Set the plugin parameter value using fl studio's built-in function (in normalized units)
    plugin.setParameter(param_index,knob_value_normalized)
    
elif knob_number == KNOB_7:
    # Map knob 7 to another plugin parameter of your choice on the selected channel's first mixer insert slot
    
    # Get the plugin object from fl studio using the mixer track number and plugin index (starting from zero)
    plugin = flstudio.plugin(flstudio.channelRouteNumber(),0)
    
    # Get the parameter index of your choice from the plugin interface or documentation (starting from zero)
    param_index = 2
    
    # Set the plugin parameter value using fl studio's built-in function (in normalized units)
    plugin.setParameter(param_index,knob_value_normalized)
    
elif knob_number == KNOB_8:
    # Map knob 8 to another plugin parameter of your choice on the selected channel's first mixer insert slot
    
    # Get the plugin object from fl studio using the mixer track number and plugin index (starting from zero)
    plugin = flstudio.plugin(flstudio.channelRouteNumber(),0)
    
    # Get the parameter index of your choice from the plugin interface or documentation (starting from zero)
    param_index = 3
    
    # Set the plugin parameter value using fl studio's built-in function (in normalized units)
    plugin.setParameter(param_index,knob_value_normalized)
    
elif knob_number == KNOB_9:
    # Map knob 9 to another plugin parameter of your choice on the selected channel's first mixer insert slot
    
    # Get the plugin object from fl studio using the mixer track number and plugin index (starting from zero)
    plugin = flstudio.plugin(flstudio.channelRouteNumber(),0)
    
    # Get the parameter index of your choice from the plugin interface or documentation (starting from zero)
    param_index = 4
    
    # Set the plugin parameter value using fl studio's built-in function (in normalized units)
    plugin.setParameter(param_index,knob_value_normalized)

def fader_handler(event):
# This function will map the faders to the mixer track volumes

# Get the fader number and value from the event data
fader_number = event.data1 # This is the midi control change number (CC)
fader_value = event.data2 # This is the midi control change value (0-127)

# Map the fader value to a range of 0.0 to 1.0 for convenience
fader_value_normalized = fader_value / 127.0

# Check which fader is being moved and assign it to a mixer track volume

if fader_number == FADER_1:
    # Map fader 1 to mixer track 1 volume
    flstudio.setTrackVolume(1,fader_value_normalized)
    
elif fader_number == FADER_2:
    # Map fader 2 to mixer track 2 volume
    flstudio.setTrackVolume(2,fader_value_normalized)
    
elif fader_number == FADER_3:
    # Map fader 3 to mixer track 3 volume
    flstudio.setTrackVolume(3,fader_value_normalized)
    
elif fader_number == FADER_4:
    # Map fader 4 to mixer track 4 volume
    flstudio.setTrackVolume(4,fader_value_normalized)
    
elif fader_number == FADER_5:
    # Map fader 5 to mixer track 5 volume
    flstudio.setTrackVolume(5,fader_value_normalized)
    
elif fader_number == FADER_6:
    # Map fader 6 to mixer track 6 volume
    flstudio.setTrackVolume(6,fader_value_normalized)
    
elif fader_number == FADER_7:
    # Map fader 7 to mixer track 7 volume
    flstudio.setTrackVolume(7,fader_value_normalized)
    
elif fader_number == FADER_8:
    # Map fader 8 to mixer track 8 volume
    flstudio.setTrackVolume(8,fader_value_normalized)

def button_handler(event):
# This function will map the buttons to some transport and navigation functions

# Get the button number and value from the event data
button_number = event.data1 # This is the midi note number
button_value = event.data2 # This is the midi note velocity (0-127)

# Check if the button is pressed or released
if button_value > 0: 
    # The button is pressed, so execute the