Skip to content

Commit

Permalink
Adaptation to the head FL Studio + bugfixing
Browse files Browse the repository at this point in the history
- Adapted to compatibility with the FL Studio Midi scripting version 30
- Switched to the usage of the FL Studio v21.1.1
- Fixed bug with not saved MIDI mappings, when re-saving preset from one slot to another
- Removed trailing spaces throughout the project
- Added new presets to the FL Studio project for Mic and Synth
  • Loading branch information
svlad-90 committed Oct 4, 2023
1 parent d8407f2 commit e41a42b
Show file tree
Hide file tree
Showing 22 changed files with 423 additions and 397 deletions.
46 changes: 15 additions & 31 deletions common/fl_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

def printAllPluginParameters(mixer_track, slot):

number_of_params = plugins.getParamCount(mixer_track, slot)
plugin_name = plugins.getPluginName(mixer_track, slot)
number_of_params = plugins.getParamCount(mixer_track, slot, True)
plugin_name = plugins.getPluginName(mixer_track, slot, True)

print("Parameters of the plugin \"" + plugin_name + "\":")

for param_index in range(number_of_params):
print( "#" + str(param_index) + ": param name - " + plugins.getParamName(param_index, mixer_track, slot) + \
" param value - " + str( plugins.getParamValue(param_index, mixer_track, slot) ) )
print( "#" + str(param_index) + ": param name - " + plugins.getParamName(param_index, mixer_track, slot, True) + \
" param value - " + str( plugins.getParamValue(param_index, mixer_track, slot) ) , True)

class PluginParametersCache:

Expand All @@ -21,9 +21,9 @@ class PluginParametersCache:
@staticmethod
def findParameterByName(mixer_channel, parameter_name, slot_index):
plugin_key = PluginParametersCache.CachePluginKey(mixer_channel, slot_index)

found_item = PluginParametersCache.__cache.get(plugin_key)

if found_item != None:
return found_item.getPluginParameterId(parameter_name)
else:
Expand All @@ -35,10 +35,10 @@ class CachePluginKey:
def __init__(self, mixer_track, slot):
self.__mixer_track = mixer_track
self.__slot = slot

def __hash__(self):
return hash((self.__mixer_track, self.__slot))

def __eq__(self, other):
return (self.__mixer_track, self.__slot) == (other.__mixer_track, other.__slot)

Expand All @@ -48,18 +48,18 @@ def __init__(self, mixer_channel, slot_index):
self.__slot_index = slot_index
self.__fetched_up_to = 0
self.__fetched_parameter_ids = {}
def __cacheAndGetPluginParmaters(self, parameter_name):
number_of_parameters = plugins.getParamCount(self.__mixer_channel, self.__slot_index)

def __cacheAndGetPluginParmaters(self, parameter_name):
number_of_parameters = plugins.getParamCount(self.__mixer_channel, self.__slot_index, True)

for parameter_id in range(self.__fetched_up_to, number_of_parameters):
fetched_parameter_name = plugins.getParamName(parameter_id, self.__mixer_channel, self.__slot_index)
fetched_parameter_name = plugins.getParamName(parameter_id, self.__mixer_channel, self.__slot_index, True)
self.__fetched_up_to = parameter_id
self.__fetched_parameter_ids[fetched_parameter_name] = parameter_id
if(fetched_parameter_name == parameter_name):
return parameter_id
raise Exception("Parameter id for '" + parameter_name + "' was not found")

def getPluginParameterId(self, parameter_name):
found_plugin_id = self.__fetched_parameter_ids.get(parameter_name)

Expand All @@ -73,20 +73,4 @@ def getPluginParameterId(self, parameter_name):
return result

def findParameterByName(mixer_channel, parameter_name, slot_index):
return PluginParametersCache.findParameterByName(mixer_channel, parameter_name, slot_index)

# mapping formula from 0<->1016 to 0<->1 values
def externalParamMapping(param_value):

base = param_value / 8.0
base_int = int(base)
base_diff = base - base_int

if base_int == 127.0:
return 1.0
elif base_int == 0.0:
return 0.0
else:
first_part = 1 / pow( 2, ( 127.0 - base_int ) )
second_part = first_part * base_diff
return first_part + second_part
return PluginParametersCache.findParameterByName(mixer_channel, parameter_name, slot_index)
6 changes: 3 additions & 3 deletions copy_scripts_to_target.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
xcopy "D:\Development\Projects\Live-looping\Livelooping\device_KorgKaossPad3Plus_LooperMux\" "C:\Users\Dream Machines\Documents\Image-Line\FL Studio\Settings\Hardware\device_KorgKaossPad3Plus_LooperMux\" /E /Y
xcopy "D:\Development\Projects\Live-looping\Livelooping\device_KorgKaossPad3Plus_SynthController\" "C:\Users\Dream Machines\Documents\Image-Line\FL Studio\Settings\Hardware\device_KorgKaossPad3Plus_SynthController\" /E /Y
xcopy "D:\Development\Projects\Live-looping\Livelooping\device_KorgKaossPad3Plus_MicController\" "C:\Users\Dream Machines\Documents\Image-Line\FL Studio\Settings\Hardware\device_KorgKaossPad3Plus_MicController\" /E /Y
xcopy "D:\Development\Projects\Live-looping\Livelooping\common\" "D:\Music development\FL Studio 20\Shared\Python\Lib\common\" /E /Y
xcopy "D:\Development\Projects\Live-looping\Livelooping\input_controller\" "D:\Music development\FL Studio 20\Shared\Python\Lib\input_controller\" /E /Y
xcopy "D:\Development\Projects\Live-looping\Livelooping\looper_mux\" "D:\Music development\FL Studio 20\Shared\Python\Lib\looper_mux\" /E /Y
xcopy "D:\Development\Projects\Live-looping\Livelooping\common\" "D:\Music development\FL Studio 21\Shared\Python\Lib\common\" /E /Y
xcopy "D:\Development\Projects\Live-looping\Livelooping\input_controller\" "D:\Music development\FL Studio 21\Shared\Python\Lib\input_controller\" /E /Y
xcopy "D:\Development\Projects\Live-looping\Livelooping\looper_mux\" "D:\Music development\FL Studio 21\Shared\Python\Lib\looper_mux\" /E /Y
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
device_name="device_KorgKaossPad3Plus_LooperMux"
print(device_name + ': started')

# internal imports
# internal imports
from looper_mux.korg_kaoss_pad_3_plus_looper_mux import KorgKaossPad3PlusLooperMux
from looper_mux.context import Context

context = Context(device_name)

looper_mux = KorgKaossPad3PlusLooperMux(context)

def OnMidiMsg(event):
looper_mux.OnMidiMsg(event)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
PARAMS_FIRST_STORAGE_TRACK_ID)

mic_controller = KorgKaossPad3Plus_InputController(context)

def OnMidiMsg(event):
mic_controller.OnMidiMsg(event)
1 change: 0 additions & 1 deletion input_controller/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ def __init__(self, device_name, main_channel, fx1_channel, fx2_channel, params_f
self.fx1_channel = fx1_channel
self.fx2_channel = fx2_channel
self.params_first_storage_track_id = params_first_storage_track_id

7 changes: 4 additions & 3 deletions input_controller/fx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import math

import midi
import plugins

from input_controller import constants
Expand Down Expand Up @@ -39,14 +40,14 @@ def setFXLevel(self, fx_level, force = False):

if math.fabs(self.__fx_level - fx_level) >= 0.01 or fx_level == 1.0 or True == force:

fx_activation_status = fl_helper.externalParamMapping( plugins.getParamValue(self.__activation_param_id, self.__context.main_channel, constants.MIDI_ROUTING_CONTROL_SURFACE_MIXER_SLOT_INDEX) )
fx_activation_status = plugins.getParamValue(self.__activation_param_id, self.__context.main_channel, constants.MIDI_ROUTING_CONTROL_SURFACE_MIXER_SLOT_INDEX, True)

if self.__level_param_id == -1:
self.__level_param_id = fl_helper.findParameterByName(self.__context.main_channel, "FX_L" + str(self.__fx_number + 1), constants.MIDI_ROUTING_CONTROL_SURFACE_MIXER_SLOT_INDEX)

if fx_activation_status == 0.0:
plugins.setParamValue(0.0, self.__level_param_id, self.__context.main_channel, constants.MIDI_ROUTING_CONTROL_SURFACE_MIXER_SLOT_INDEX)
plugins.setParamValue(0.0, self.__level_param_id, self.__context.main_channel, constants.MIDI_ROUTING_CONTROL_SURFACE_MIXER_SLOT_INDEX, midi.PIM_None, True)
else:
plugins.setParamValue(fx_level, self.__level_param_id, self.__context.main_channel, constants.MIDI_ROUTING_CONTROL_SURFACE_MIXER_SLOT_INDEX)
plugins.setParamValue(fx_level, self.__level_param_id, self.__context.main_channel, constants.MIDI_ROUTING_CONTROL_SURFACE_MIXER_SLOT_INDEX, midi.PIM_None, True)

self.__fx_level = fx_level
16 changes: 5 additions & 11 deletions input_controller/fx_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@author: Dream Machines
'''

import midi
import plugins

from common import fl_helper
Expand Down Expand Up @@ -95,14 +96,14 @@ def setLevel(self, fx_param_level):
fl_param_id = self.__midi_mapping.getParameterId()

if fl_param_id != constants.INVALID_PARAM:
plugins.setParamValue(fx_param_level, fl_param_id, self.__context.fx1_channel, adjustable_plugin_slot_index)
plugins.setParamValue(fx_param_level, fl_param_id, self.__context.fx1_channel, adjustable_plugin_slot_index, midi.PIM_None, True)
self.__fx_param_level = fx_param_level
self.__view.setFXParameterLevel(self.__fx_param_id, fx_param_level)

def onInitScript(self):

if False == self.__initialized:

self.setLevel(self.__fx_param_level)
self.__initialized = True

Expand All @@ -120,14 +121,7 @@ def updateParamsFromPlugin(self):
fl_param_id = self.__midi_mapping.getParameterId()

if fl_param_id != constants.INVALID_PARAM:

param_value = plugins.getParamValue(fl_param_id, self.__context.fx1_channel, adjustable_plugin_slot_index)

if adjustable_plugin_slot_index == constants.MANIPULATOR_SLOT_INDEX or \
adjustable_plugin_slot_index == constants.FABFILTER_PRO_Q3_SLOT_INDEX or \
adjustable_plugin_slot_index == constants.FINISHER_VOODOO_SLOT_INDEX:
param_value = fl_helper.externalParamMapping(param_value)

param_value = plugins.getParamValue(fl_param_id, self.__context.fx1_channel, adjustable_plugin_slot_index, True)
self.__fx_param_level = param_value
self.__view.setFXParameterActivationStatus(self.__fx_param_id, 1)
else:
Expand Down
71 changes: 43 additions & 28 deletions input_controller/fx_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@author: Dream Machines
'''

import midi
import plugins

from common import fl_helper
Expand Down Expand Up @@ -44,18 +45,18 @@ def __init__(self, context, fx_page_number, fx_number, view):
self.__initialized = False

def onInitScript(self):

if False == self.__initialized:

self.__persistency_item.init()

self.setActiveFXUnit(self.__persistency_item.getActiveFxUnit())
self.__loadMidiMappingsFromPersistency()
self.view_updateActiveFXUnit()

for fx_parameter_id in self.__fx_parameters:
self.__fx_parameters[fx_parameter_id].onInitScript()

self.__initialized = True

def update(self):
Expand All @@ -69,12 +70,32 @@ def update(self):
def reset(self):
self.__resetData()

def setMidiMappings(self, midi_mappings):
fx_parameter_number = 0
for midi_mapping in midi_mappings:
self.setMidiMapping(fx_parameter_number, midi_mapping)
fx_parameter_number += 1

def getMidiMappings(self):
midi_mappings = []
for fx_parameter in self.__fx_parameters:
midi_mapping = self.__fx_parameters[fx_parameter].getMidiMapping()
midi_mappings.append(midi_mapping)
return midi_mappings

def getMidiMappingsAsLists(self):
midi_mappings = {}
for fx_parameter in self.__fx_parameters:
midi_mapping = self.__fx_parameters[fx_parameter].getMidiMapping()
midi_mappings[self.__fx_parameters[fx_parameter].getFXParamId()] = midi_mapping.convertToList()
return midi_mappings

def setMidiMapping(self, fx_parameter_number, midi_mapping):
self.__fx_parameters[fx_parameter_number].setMidiMapping(midi_mapping)
self.view_updateFXParamsFromPlugins()

def select(self):
plugins.setParamValue(0.0, constants.PANOMATIC_VOLUME_PARAM_INDEX, self.__context.main_channel, constants.PRESET_CHANGE_PROTECTOR_PANOMATIC_SLOT_INDEX)
plugins.setParamValue(0.0, constants.PANOMATIC_VOLUME_PARAM_INDEX, self.__context.main_channel, constants.PRESET_CHANGE_PROTECTOR_PANOMATIC_SLOT_INDEX, midi.PIM_None, True)

if not self.__areParametersLoaded():
self.__loadData()
Expand All @@ -85,7 +106,7 @@ def select(self):
self.__view.selectFXPreset(self.__fx_number)
self.view_updateActiveFXUnit()

plugins.setParamValue(fl_helper.MAX_VOLUME_LEVEL_VALUE, constants.PANOMATIC_VOLUME_PARAM_INDEX, self.__context.main_channel, constants.PRESET_CHANGE_PROTECTOR_PANOMATIC_SLOT_INDEX)
plugins.setParamValue(fl_helper.MAX_VOLUME_LEVEL_VALUE, constants.PANOMATIC_VOLUME_PARAM_INDEX, self.__context.main_channel, constants.PRESET_CHANGE_PROTECTOR_PANOMATIC_SLOT_INDEX, midi.PIM_None, True)

def view_updateFXPresetAvailability(self):
self.__view.setFXPresetAvailability(self.__fx_number, len(self.__persistency_item.getPluginParameters()) > 0)
Expand Down Expand Up @@ -122,7 +143,7 @@ def __getParamsFromPlugins(self):

parameters[mixer_slot] = []

param_count = plugins.getParamCount(self.__context.fx1_channel, mixer_slot)
param_count = plugins.getParamCount(self.__context.fx1_channel, mixer_slot, True)

for param_id in range(param_count):

Expand All @@ -135,17 +156,11 @@ def __getParamsFromPlugins(self):
if mixer_slot == constants.FABFILTER_PRO_Q3_SLOT_INDEX and param_id > constants.FABFILTER_PRO_Q3_PARAMS_LIMIT:
break;

param_value = plugins.getParamValue(param_id, self.__context.fx1_channel, mixer_slot)

if mixer_slot == constants.MANIPULATOR_SLOT_INDEX or \
mixer_slot == constants.FABFILTER_PRO_Q3_SLOT_INDEX or \
mixer_slot == constants.FINISHER_VOODOO_SLOT_INDEX:
param_value = fl_helper.externalParamMapping(param_value)

param_value = plugins.getParamValue(param_id, self.__context.fx1_channel, mixer_slot, True)
param_value_str = str(param_value)

# param_name = plugins.getParamName(param_id, self.__context.fx1_channel, mixer_slot)
# plugin_name = plugins.getPluginName(self.__context.fx1_channel, mixer_slot)
# param_name = plugins.getParamName(param_id, self.__context.fx1_channel, mixer_slot, True)
# plugin_name = plugins.getPluginName(self.__context.fx1_channel, mixer_slot, True)
# print("Get parameter: plugin name - " + plugin_name + ", param - " + param_name + \
# ", param_value - " + param_value_str + ", param_id - " + str(param_id) + \
# ", channel - " + str(self.__context.fx1_channel) + ", mixer_slot - " + str(mixer_slot))
Expand All @@ -154,8 +169,8 @@ def __getParamsFromPlugins(self):


parameter_id = fl_helper.findParameterByName(self.__context.main_channel, "E" + str(mixer_slot+1) + "_TO", constants.MIDI_ROUTING_CONTROL_SURFACE_MIXER_SLOT_INDEX)
fx_activation_state = plugins.getParamValue(parameter_id, self.__context.main_channel, constants.MIDI_ROUTING_CONTROL_SURFACE_MIXER_SLOT_INDEX)
parameters[constants.FX_ACTIVATION_STATE_SLOT_INDEX].append(str( fl_helper.externalParamMapping(fx_activation_state) ))
fx_activation_state = plugins.getParamValue(parameter_id, self.__context.main_channel, constants.MIDI_ROUTING_CONTROL_SURFACE_MIXER_SLOT_INDEX, True)
parameters[constants.FX_ACTIVATION_STATE_SLOT_INDEX].append(str( fx_activation_state ))

self.__persistency_item.setPluginParameters(parameters)

Expand All @@ -172,21 +187,23 @@ def __applyParametersToPlugins(self):
if mixer_slot == constants.FX_ACTIVATION_STATE_SLOT_INDEX:
#print("__applyParametersToPlugins: constants.FX_ACTIVATION_STATE_SLOT_INDEX mixer channel -" + str(self.__context.main_channel) + \
#", param_id - " + str(param_id) + ", param_value - " + str(param_value))
plugins.setParamValue(param_value, param_id, self.__context.main_channel, constants.MIDI_ROUTING_CONTROL_SURFACE_MIXER_SLOT_INDEX)
plugins.setParamValue(param_value, param_id, self.__context.main_channel, constants.MIDI_ROUTING_CONTROL_SURFACE_MIXER_SLOT_INDEX, midi.PIM_None, True)
else:

# plugin_name = plugins.getPluginName(self.__context.fx1_channel, mixer_slot)
# param_name = plugins.getParamName(param_id, self.__context.fx1_channel, mixer_slot)
# plugin_name = plugins.getPluginName(self.__context.fx1_channel, mixer_slot, True)
# param_name = plugins.getParamName(param_id, self.__context.fx1_channel, mixer_slot, True)
#
# print("Apply parameter: plugin name - " + plugin_name + ", param - " + param_name + \
# ", param_value - " + str(param_value) + ", param_id - " + str(param_id) + \
# ", channel - " + str(self.__context.fx1_channel) + ", mixer_slot - " + str(mixer_slot))

plugins.setParamValue(param_value, param_id, self.__context.fx1_channel, mixer_slot)
plugins.setParamValue(param_value, param_id, self.__context.fx1_channel, mixer_slot, midi.PIM_None, True)

def __loadMidiMappingsFromPersistency(self):
midi_mappings = self.__persistency_item.getMidiMapping()

midi_mappings = self.__persistency_item.getMidiMapping()

print(f"loading {str(len(midi_mappings))} midi mappings from persistency - {midi_mappings}")

if len(midi_mappings) == 0:
for fx_parameter in self.__fx_parameters:
self.__fx_parameters[fx_parameter].setMidiMapping(MidiMapping())
Expand All @@ -195,10 +212,8 @@ def __loadMidiMappingsFromPersistency(self):
self.__fx_parameters[fx_parameter_id].setMidiMapping(MidiMapping.createFromList(midi_mappings[fx_parameter_id]))

def __storeMidiMappingsToPersistency(self):
midi_mappings = {}
for fx_parameter in self.__fx_parameters:
midi_mapping = self.__fx_parameters[fx_parameter].getMidiMapping()
midi_mappings[self.__fx_parameters[fx_parameter].getFXParamId()] = midi_mapping.convertToList()
midi_mappings = self.getMidiMappingsAsLists()
print(f"storing {str(len(midi_mappings))} midi mappings from persistency - {midi_mappings}")
self.__persistency_item.setMidiMapping(midi_mappings)

def __loadData(self):
Expand Down
17 changes: 13 additions & 4 deletions input_controller/fx_preset_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,23 @@ def getSelectedFXPresetID(self):
return self.__selected_fx_preset_id

def onInitScript(self):

if False == self.__initialized:

for fx_preset_id in self.__fx_presets:
self.__fx_presets[fx_preset_id].onInitScript()

self.__initialized = True

def setMidiMappings(self, fx_preset_id, midi_mappings):
print(f"setMidiMappings: page - {str(self.__fx_page_number)}; fx_preset_id - {str(fx_preset_id)}; midi_mappings - {str(midi_mappings)}")
self.__fx_presets[fx_preset_id].setMidiMappings(midi_mappings)

def getMidiMappings(self, fx_preset_id):
midi_mappings = self.__fx_presets[fx_preset_id].getMidiMappings()
print(f"getMidiMappings: page - {str(self.__fx_page_number)}; fx_preset_id - {str(fx_preset_id)}; midi_mappings - {str(midi_mappings)}")
return midi_mappings

def updateFXPreset(self, fx_preset_id):
self.__fx_presets[fx_preset_id].update()
self.__fx_presets[fx_preset_id].view_updateFXPresetAvailability()
Expand All @@ -60,7 +69,7 @@ def resetFXPreset(self, fx_preset_id):
def selectFXPreset(self, fx_preset_id, select_preset = True):
print(self.__context.device_name + '_FXPresetPage' + ': ' + FXPresetPage.selectFXPreset.__name__ + " page - " + str(self.__fx_page_number) + ", preset - " + str(fx_preset_id))
self.__selected_fx_preset_id = fx_preset_id

if True == select_preset:
self.__fx_presets[fx_preset_id].select()
self.__fx_presets[fx_preset_id].view_updateFXPresetAvailability()
Expand Down
Loading

0 comments on commit e41a42b

Please sign in to comment.