String from M4L Device to Custom Control Script

Discuss Live-ready controllers other than Push.
Post Reply
LukasRothMusic
Posts: 5
Joined: Fri Sep 20, 2024 9:48 am

String from M4L Device to Custom Control Script

Post by LukasRothMusic » Wed Oct 16, 2024 6:31 pm

Hi everybody,

I'm currently in the middle of developing my own MIDI Remote Control Script in Python and ran into the following problem:

I want to send a basic string from a self-made M4L device to my Control Script or at least expose the string, so it can be read by the script.
The LOM Documentation mentions "send_receive_sysex", although I don't know whether this message actually passes through the control script or is directly forwarded to the ports of the hardware controller? At least I couldn't find a way to catch or intercept the message (event listener or anything)...

And on the M4L side of things I haven't managed to find a way to expose a modifyable(!) string somewhere in the LOM, so it could be read by the script. The only workaround I've found so far are paramter names (which cannot be changed in Max afaik) and device names (which are super unreliable to pass a variable with...). Like, can I make a simple live.comment accessible to the LOM?

I know this is a rather niche topic but maybe someone here can point me into the right direction?
Any advice would be appreciated.

dr_kant
Posts: 33
Joined: Wed Jan 05, 2005 9:17 am
Location: France
Contact:

Re: String from M4L Device to Custom Control Script

Post by dr_kant » Sat Oct 19, 2024 8:00 am

I don't know m4l at all but you can try to look at the Application.control_surfaces property of the api.
It lists all the connected controllers references so if you can access it from m4l then you should be able to send messages to remote scripts.

LukasRothMusic
Posts: 5
Joined: Fri Sep 20, 2024 9:48 am

Re: String from M4L Device to Custom Control Script

Post by LukasRothMusic » Sat Oct 19, 2024 12:39 pm

dr_kant wrote:
Sat Oct 19, 2024 8:00 am
I don't know m4l at all but you can try to look at the Application.control_surfaces property of the api.
It lists all the connected controllers references so if you can access it from m4l then you should be able to send messages to remote scripts.
Thanks for the suggestion. Had the same thought and discovered the "send_receive_sysex" method, that can be called on Application.control_surfaces elements (that's what I meant in the original post) but I didn't manage to find out how to properly receive the message in the control script or if it is possible at all. Do you know if there is such a thing as an event handler, listener or something?

dr_kant
Posts: 33
Joined: Wed Jan 05, 2005 9:17 am
Location: France
Contact:

Re: String from M4L Device to Custom Control Script

Post by dr_kant » Sat Oct 19, 2024 1:13 pm

Again, i didn't test with m4l but it works for me between two remote scripts instances.

Just create your own function in the remote script:

def receive_string(self, string):
self.log_message("receive_string: " + string)


And call the function from the other script:

for index, c_s in enumerate(self.application().control_surfaces):
self.log_message("C_S [" + str(index) + "] " + c_s.__class__.__name__)
if c_s.__class__.__name__ == "My_Control_Surface_1":
c_s.receive_string("Test string.")

Angstrom
Posts: 14987
Joined: Mon Oct 04, 2004 2:22 pm
Contact:

Re: String from M4L Device to Custom Control Script

Post by Angstrom » Sat Oct 19, 2024 1:24 pm

An alternative approach...

As you are using M4L as well you could make use of OSC to send the data a bit more flexibly around your system. I certainly recommend installing the CNMAT external for Max so that you get full OSC capabilities. Without that it's very limited.

I send information to and from Live to an iPad this way , also some arduino stuff. I found it best to build on an established protocol for both strings and other structured data . It's more future proof.

LukasRothMusic
Posts: 5
Joined: Fri Sep 20, 2024 9:48 am

Re: String from M4L Device to Custom Control Script

Post by LukasRothMusic » Sun Oct 20, 2024 10:19 am

dr_kant wrote:
Sat Oct 19, 2024 1:13 pm
Again, i didn't test with m4l but it works for me between two remote scripts instances.

Just create your own function in the remote script:

def receive_string(self, string):
self.log_message("receive_string: " + string)


And call the function from the other script:

for index, c_s in enumerate(self.application().control_surfaces):
self.log_message("C_S [" + str(index) + "] " + c_s.__class__.__name__)
if c_s.__class__.__name__ == "My_Control_Surface_1":
c_s.receive_string("Test string.")
I see. Didn't know it was possible to call functions custom functions on Application.control_surfaces elements but that works flawlessly and solves my problem very well. Thank you very much!

LukasRothMusic
Posts: 5
Joined: Fri Sep 20, 2024 9:48 am

Re: String from M4L Device to Custom Control Script

Post by LukasRothMusic » Sun Oct 20, 2024 10:20 am

Angstrom wrote:
Sat Oct 19, 2024 1:24 pm
An alternative approach...

As you are using M4L as well you could make use of OSC to send the data a bit more flexibly around your system. I certainly recommend installing the CNMAT external for Max so that you get full OSC capabilities. Without that it's very limited.

I send information to and from Live to an iPad this way , also some arduino stuff. I found it best to build on an established protocol for both strings and other structured data . It's more future proof.
Thanks for the suggestion. I am now quite satisfied with the solution that dr_kant suggested but I will definitely look into it for future (potentially more network-based) projects, looks like a handy implementation.

dr_kant
Posts: 33
Joined: Wed Jan 05, 2005 9:17 am
Location: France
Contact:

Re: String from M4L Device to Custom Control Script

Post by dr_kant » Sun Oct 20, 2024 10:52 am

LukasRothMusic wrote:
Sun Oct 20, 2024 10:19 am
I see. Didn't know it was possible to call functions custom functions on Application.control_surfaces elements but that works flawlessly and solves my problem very well. Thank you very much!
Yes it's handy, no need to bother with sysex messages locally.

Post Reply