Conditional OSC message

Hello friends!

I am looking to capture a list of OSC messages that obtain the device names (effects or instruments) of a selected track on Ableton Live. For this purpose, I am using the following objects from Ableton Live (obtained through the LOM / Live API).

song.view.selected_track.devices [0] .class_display_name
song.view.selected_track.devices [1] .class_display_name
song.view.selected_track.devices [2] .class_display_name
song.view.selected_track.devices [3] .class_display_name

This information shows the name of the effects or instruments in a text widget for a control interface that I am developing on my iPad.

If the selected track contains 4 effects or instruments, I can get the message on the iPad screen with the name of the effect or instrument correctly in the text widgets, as shown in the image below.

However, for example: if the selected track contains only 3 devices, instead of the message that should be corresponding to the missing device, I do not receive a message like “null” or even an “empty” message (which would serve my purpose). When the track has only 3 devices, what is displayed in the message regarding the missing device is exactly the same syntax as the Ableton Live API, that is, as you can see below: song.view.selected_track.devices [3].class_display_name.

I believe it is an inconsistency of the Live API itself. The absence of this object should be automatically detected. But, as we can see, this is not the case.

I wonder if through O-S-C I can solve this problem. Is it possible to assign a script that replaces OSC messages that have characters like “.”, “_” Or “[]” for a specific message like “Missing device”?

You’ll have to write a custom module module to handle this from O-S-C.

1 Like

Thanks for the quick response! I’m already scouring the comunity with posts about it =D

After a sequence of posts here on the forum, many things I learned on my own and spent a few days away, developing very cool things that I will release soon :slight_smile:

But this question caught me haha ​​… Custom Module is a very interesting possibility, however, I am having some difficulties to understand its applicability (header, correct sequences, etc.). I understand, however, that, after configured correctly, I must load it into the server’s custom-module field …

I tried to find in the community some example related to osc message filtering for text widgets, but, I couldn’t find … Judging by doing a correct search, I searched the internet for javascript syntax for character replacement. I found several, among which, the one that I think may serve my purpose:

var str = “Text 1”;
var res = str.replace (“Text 1”, “Text 2”);

I’m in the right way?

The addresses of the text widgets that I intend to make the changes to prevent the missing device from generating the message “song.view.selected_track.devices [3] .class_display_name” are, respectively:

/ devname0
/ devname1
/ devname2
/ devname3

Maybe I looked it up wrong in the community search field. Do you happen to remember any topic on which I can better base myself on these first steps for this application?

There are some exemples here that could help understand what can be done.

Figuring out when a message is not received can be tricky. You could circumvent the issue by emptying the 4 labels before live sends them, this way any missing label will appear as empty. Isn’t there a message prior to these that informs the selected track has changed ? It would be a good candidate:

module.exports = {
   
   oscInFilter: function(data) {

       var {address, args, host, port} = data

       if (address == '/SELECTED_TRACK_CHANGED') {

           receive('/devname0', '')
           receive('/devname1', '')
           receive('/devname2', '')
           receive('/devname3', '')

       }

       return data
       
   }
   
}
1 Like

Oh man, thank you very much. I’ll test it right now. I’ll be back

I returned! In fact, those OSC messages that I’m working on at this stage are sent (and received) as normal.

I can get this information using the variable feature that Clyphx Pro offers.

With these variables I can capture some aspects of Ableton Live through the LOM / Live API … Things like BPM, channel routing list in and out, scene name, and in this case, the name of the devices. For example, for these specific variables, I use the following script:

%dev0% = song.view.selected_track.devices [0].class_display_name
%dev1% = song.view.selected_track.devices [1].class_display_name
%dev2% = song.view.selected_track.devices [2].class_display_name
%dev3% = song.view.selected_track.devices [3].class_display_name

So, if there are 4 devices on the track, I can capture their name perfectly by updating the content of the O-S-C text widget.

The problem I’m having is that, if one or all devices are missing from the track, then the OSC message is sent as if it were just a phrase, a text, a sequence of characters exactly as described in the script (song.view.selected_track.devices [0].class_display_name) so this is being printed directly on the text widget.

In addition to the module, I observed this case in the community:

host {

{OSC {/ hide, 0}? “display: none;” : “”}

}

I did some tests using this syntax above, but it didn’t work.

I’m not sure, but, I think a solution would be a script that promotes an exchange of messages … For example: if a received OSC message contains “. _ [” (Characters present in the message sent when a device is absent) then , would be stamped on the “no device” text widget. But, I don’t know if that would be possible.

In fact, during the research I did trying to find a solution, I saw that even on remotify there is this problem. As O-S-C is “power” I believe I can solve this without having to look like an “unfinished” thing like in this case:

Anyway, I will try this script you sent me more. Thank you for the support!

@rimasinc I’m on Ableton too,
I don’t know so much about LOM, is Clyphx a must hav to use LOM with OSC ?
Could it be possible to get the clip name for examples or track name

I found this resources : https://kblivesolutions.com/lom-francais

Yes. With Clyphx you can access any aspect of Ableton via LOM. Some things are automatic when related to OSC like current track name, current device and device parameters as value (as long as you have the Clyphx Bindings accessory - which must be purchased separately)

1 Like

ok thank you for your explanation
It could be amazing to get access to this natively

1 Like

There's indeed a very simple way to solve this, this set the text widget's script as follows, it will check the received value and override if it contains "class_display_name":

if (String(value).includes('class_display_name')) {
  set('this', 'no device')
}

Note: using String(value) instead of just value to prevent errors in case the received is not a string (numbers for instance, don't have the include method)

Worked perfectly! Thanks for the great guidance :raised_hands:

Hi Jean! This code is being perfect for updating text widgets when, for example, I create a new blank project in Ableton. However, the update only occurs on /devname0 and /devname3 ... The messages /devname1 and /devname2 do not update ... I'm not sure, but, maybe this gap may have something to do with the way Clyphx handles OSC bindings (always directing the selected track and / or device). Something is causing the central text widgets not to be updated. Is there any way around this?

Messages are sent, but appear only once and disappear

Yesterday I managed to correct! Very simple: I just changed "track / name" to "device / name" and it worked! :slight_smile:

Hi Jean!

Initially, in this topic, my problem was with the device names. You instructed me to do the following:

  1. Place in the text widget:

if (String (value) .includes ('class_display_name')) {
set ('this', 'no device')
}

AND

  1. Create module with the following syntax:

module.exports = {

oscInFilter: function (data) {

   var {address, args, host, port} = data

   if (address == '/ device/name') {

       receive ('/devname0', '')
       receive ('/devname1', '')
       receive ('/devname2', '')
       receive ('/devname3', '')
   }
   return data

}
}

This solved the problem. When a device is missing, the text widget updates to "no device".

This time the problem is related to OSC messages with the name of the clips from ableton live.

When a clip is missing, I come across the same string of characters exactly as described in my script, for example:% clipname_tr00% = song.tracks [0] .clip_slots [0] .clip.name.

To print the name of the clips on each button I used in the label field:
OSC {/clipname_tr00}

This time, I intend to capture the names of the clips by naming button widgets. These buttons work with the script to make a button disable the others when it is activated, making the buttons look like this:

if (value) set ('clip _ / *', 0, send ('midi: RimasOSC', '/control', 14, 0, 127))

  1. Is it possible to add to this script above to check the message received for the button label making it replace if it contains "class_display_name"? I tested some ways to add the script that worked for "no device", but without success.

  2. Is it possible to expand the module to also check the clips by emptying the button labels before the live sends them? I tried adding the following to the initial module, but without success:

module.exports = {

oscInFilter: function (data) {

   var {address, args, host, port} = data

   if (address == '/device/name') {

       receive ('/devname0', '')
       receive ('/devname1', '')
       receive ('/devname2', '')
       receive ('/devname3', '')

   }

   return data

},

oscInFilter: function (data) {

   var {address, args, host, port} = data

   if (address == '/track /name') {

       receive ('/clipname_tr00', '')
     
   }

   return data

}

}

It seems the main issue you're facing is learning / getting familiar with the javascript syntax, which unfortunately I don't teach (there are better places/persons for this and it goes beyond what I'm willing to offer as "support" for open stage control).

if (value) set ('clip _ / *', 0, send ('midi: RimasOSC', '/control', 14, 0, 127))

You are calling send() in the set() call, there no reason to do that here. See block statements (this should also help figuring how to add this to the previous script).

oscInFilter: function (data) {

You are defining the oscInFilter property twice, you have to do it only once and put the different conditional blocks in it, one after the other.

1 Like

I'm really not very familiar with javascript. I am committed to studying more to need less help from other people. In advance, I really appreciate your willingness to help.

I bring some more details to know from you if it really is not something related to support.

In the documentation / community I found that by using ** label OSC {/ address} ** I can get the name of the ableton clip on a button widget (according to the Clyphx Pro scripts I use for this purpose).

However, I could see that, only with this script ** if (value) ('clip _ / *', 0, send ('midi: RimasOSC', '/ control', 14, 0, 127)) ** the label of button widget is able to update the name for an existing clip (or for song.tracks [0] .clip_slots [0] .clip.name when it is missing) while maintaining the "disable the others when it is" behavior activated "and also send the midi cc.

If I configure the script only with ** if (value) set ('clip _ / *', 0, {send: true}) ** and the OSC inspector for this button contains midi information for address, preArgs and target, the label will not it's updated.

So, opting for ** if (value) ('clip _ / *', 0, send ('midi: RimasOSC', '/ control', 14, 0, 127)) ** I'm trying to prevent the label from the widget button appears the character string sent via the OSC message when a clip is missing.

I tested the following script for a text widget and it works perfectly:

if (String (value) .includes ("_ slot")) {
set ('this', 'empty')
}

But the same script above does not work for the button label configured with OSC {/ clipname_tr00}

I made it !! Thank you for your help :raised_hands:

JS{{
var nameOsc = OSC{/clipname_tr00};
if (nameOsc.includes("slot")) {
nameOsc = "empty";
} else {
return nameOsc;
}
}}

Hello Jean! I'm back.

Everything you say has opened my mind more and more to the understanding of the universe that is Open Stage Control.

Would you be able to tell me why this sequence of scripts below is updating the color and name of the clips ...

colorWidget:
JS {{
var intColor = OSC {/clipcolor_tr0_0}
var cssColor = "#" + intColor.toString (16)
return cssColor
}}

label:
JS {{
var nameOsc = OSC {/clipname_tr0_0};
if (nameOsc.includes ("slot")) {
nameOsc = "empty";
} else {
return nameOsc;
}
}}

script:
if (value) set ('clip _ / *', 0, send ('midi: RimasOSC', '/control', 14, 0, 127))

Osc inspector: empty

While, does this script sequence shown below not update?

colorWidget:
JS {{
var intColor = OSC {/clipcolor_tr0_0}
var cssColor = "#" + intColor.toString (16)
return cssColor
}}

label:
JS {{
var nameOsc = OSC {/clipname_tr0_0};
if (nameOsc.includes ("slot")) {
nameOsc = "empty";
} else {
return nameOsc;
}
}}

script:
if (value) set ('clip _ / *', 0, {send: true})

Osc inspector:
address: /control
preArgs: [14.0]
target: midi:RimasOSC

The only difference in the case is the content of the "script" and "osc inspector".

In the first script sequence, when I restart sessions or or create a new live set in ableton, the feedback-related operation is perfect (although I'm not sure if the syntaxes are correct).

Everything would be fine, however, I detected that if I use the first sequence of scripts, I gain visual feedback, but I lose another linked action (which is the display of the scene name)

In the second sequence of scripts, everything works, except the update of the OSC messages (color and name of the clips)

I managed to make it work. Almost a trick haha. I added a 17th button to the set of 16x16 buttons for the clips. "I hid" that button in a corner, applying alpha 100% only with the specifications:

script:
if (value) set ('clip _ / *', 0, {send: true})

Osc inspector:
address: / control
preArgs: [14.0]
target: midi: RimasOSC

This additional button "corrected" the others by allowing visual feedback along with the linked action that displays the scene name.

Thank you Jean!