Script to assign a modifier to a track based on its name

Solved240 viewsCSS Community Scriptslist modifier
0

Good morning. I’m looking to create a script that assigns a modifier based on the track name. Let me explain in my set I want to be able to control only certain tracks with my launch control XL. I thought to see select the tracks to control with their name. Here is an example:
Track name “MIX1″=M1
Track name “MIX2″=M2
etc….
I have so far managed to create a script but I don’t use a list and I think this will cause problems for me to be able to add future functions. I am providing you with the script made for the MIX1=M1 track. If you have any suggestions I’m interested. At the moment I have to press a button to update the script when I change the name of a track or change its position. Thanks in advance

gwen971 Selected answer as best October 7, 2024
Attached Files:
0

I deleted my previous comment because there was a small error in the code + I added some things. So I’m going to start over, fresh, with examples this time.

How the Reaction works

Listener

Instead of listening to the Tracks (if their names are being changed), the Reactions are going to listen to the knobs or buttons that you want to be using.

Action Block 1

When the value of the knob or button changes, the reaction will check if the modifier that corresponds to this button (for example, Mod “m1” corresponds with knob 1) contains the Track position of the Track with name “MIX1”.

If this is not the case, the Reaction wil loop through the Tracks, search for the Track named “MIX1” (if there is one), and set the found Track position to Mod “m1”.

If no Track with name “MIX1” was found, the Reaction is exited + a message will appear in Live’s status bar “No Track with name MIX1 found.”. Also, the value of the corresponding Modifier will be set to None, because we don’t want there to be a Track Position in the Modifier while there is no Track with the name MIX1.

If the Modifier contains the correct Track position, then our Reaction is happy and we can continue.

Action Block 2 (optional, see Example 1)

If you want to continue using Reactions to set up the rest of your script with, then you can just add Action Blocks that change Track Parameters using the Modifier that was set up in the previous Action Block.

In Example 1 I’ve set up Track Volume control using the “values from ranges” feature to map the 128 values of the knob to the range of 0.0 to 1.0 of the volume.

Example 2

Example 2 shows a combination of the Reaction described above (only containing Action Block 1, to check and setup the corresponding Modifier with) and non-Reaction Mappings (in this case, Mappings to change Track Volume with) that uses the Modifier to find the correct Track.

Important in this Example is that the Reactions should be above the Mappings in the list. Because we first want to check if the Modifier contains the correct position before we use that Modifier in the Mapping.

The Code

Here’s the code that’s in Action Block 1 of the Reactions.

# The following variables make it easier to re-use the code in different Reactions.
name_to_match = "MIX1"
modifier = "m1"

# Code checks if the track_num stored in the modifier has the correct name.
# If it does, we simply continue to the next Action Block.
# If it doesn't, an Error/Exception is raised.
tracks = self.song().tracks
try:
    track_num = self.get_modifier_value(modifier)
    if tracks[track_num].name != name_to_match:
        raise

# When an Error/Exception is raised for any reason, the code loops
# through the Tracks searching for a Track with the correct name.
except Exception:
    for loop_num in range(len(tracks)):
        # If the code finds the correct Track, it stores its number in the modifier
        # and breaks out of the loop.
        if tracks[loop_num].name == name_to_match:
            self.set_modifier_value(modifier, loop_num)
            break
        # If the end of the loop is reached without finding the correct Track
        # we set the Modifier to None, display a warning in Ableton 
        # and exit the Reaction entirely.
        if loop_num + 1 == len(tracks):
            self.set_modifier_value(modifier, None)
            self.show_message(f"No Track with name \"{name_to_match}\" found.")
            return

For each Reaction you’ll need to change the name_to_match to the Track name you want to match with and the modifier to the Modifier you want to store the Track’s position in.

Questions or comments

If you have any questions or are having trouble getting it to work in a particular way, feel free to make a comment.

Glenn Verhaeghe Posted new comment October 7, 2024

Hello Glen
Thanks for your feedback. In the meantime I have made progress on my script and changed my way of selecting tracks to a simpler method. When I press a specific button, in this case button 23, the script scans all the tracks and only selects the tracks containing “MIX”, then stores the track number in a list. I then assign item 1 of the list to M1 then item 2 to M2 etc. So it works well. But I come across a new problem that several people have had as I have read in the posts. And I do not know if it is a problem due to my script or a bug. Let me explain:
I have the feedback from the LEDs that does not work when I use “highlight selected track as M1” if I select “highlight selected track = track 1” on the other hand it is good it works. I attach my script to you. So I’m going to try your scripts to see if it works with yours.
Waiting for your feedback
Gwen

I don’t know how to send a script in comment like you ?

Unfortunately, the person who made a post can’t write comments with any formatting options (including the option to add files). Only commenters get this ability. I’ve already brought it up once to the devs in a post with feedback about the forum.

You can, however, still update your original post. So you could add files that way. But I think this will replace the older files you had already added.

You are viewing 1 out of 2 answers, click here to view all answers.