[Tutorial] Loops, in Reactions, start numbering at 0
Hello everyone,
Here’s a little tutorial about something that caused people some headaches in the past.
Something to be aware of when setting up mappings is the way the numbering of tracks, devices, parameters, … works.
The numbering in the more common Mappings that have been set up by the devs (like Track Volume, Select Device, etc…) differs a bit from how numbering is handled inside a Reaction Mapping. I think that’s because the common Mappings were set up to be more user-friendly while Reaction Mappings follow the rules set up by the Python language on which the software is built.
This difference is important to keep in mind when you want to store numbers from a Reaction Mapping (for example, a number gotten from Looping through Tracks) inside a Modifier for use inside one of the common Mappings.
Numbering in common Mappings
In common Mappings, the numbering has been set up to start at the number 1.
This means that, for example, Track Number 1 refers to the first Track in your Song.
Numbering in Reaction Mappings
In the Python language, numbering/indexing starts at the number 0. For example, the first item in a list has the index 0, the second item in the list has index 1, etc…
Reaction Mappings also handle numbers this way. When you loop through Tracks, you’re essentially looping through a Python list object.
In the following example I have a Set with 2 Tracks. Using a Reaction I Loop through the Tracks and Log the loop_number
accompanied by the name of the Track this number is referring to.
I used a custom made Log function here, it takes 2 arguments:
loop_number
- self.song().tracks[loop_number].name = the Track’s name at the position of that loop_number
It will output as loop_number
>> track_name. Following image shows the output in the Log.
How to use a loop_number
inside a common Mapping?
If you’re wondering how you can store a loop_number
inside a Modifier to use it in one of the common Mappings, then the answer is simply to add 1 to the loop_number
.
First, start by setting up an action to store the loop_number
inside a Modifier. But before clicking Save, click on the button with the angled brackets, < >
. This will let you customize the code.
In the new window, type + 1
next to the loop_number and Save.
In this example, the number at Modifier m1 can now be used to refer to the correct Track Number inside a common Mapping.
Hope this helps.
Awesome tutorial Glenn and you’re spot on about Reactions numbering from 0 (aka how Python counts) compared to the other mapping types.
One thing I can add to this is, rather than switching the entire action to code view,
you can just change the ‘value to set’ section to custom coding and simply add + 1 to it:
You get the same result, just that you have a little more flexibility this way i.e, you can change the modifier to save to.
That would be great, your tutorial is very clear and valuable for everyone
Sign up
User registration is currently not allowed.
Thank you for the comment and addition, John! I totally forgot about this feature. I might make more little tutorials in the future. If you ever see me posting a mistake or something incomplete, please don’t hesitate to leave a comment about it.
Or if anyone has any questions on the topic, please ask them.
I can always edit the post to be more clear or correct. It is sometimes difficult to find the right words or amount of steps for creating a tutorial that everyone can understand.