String from M4L Device to Custom Control Script
-
LukasRothMusic
- Posts: 5
- Joined: Fri Sep 20, 2024 9:48 am
String from M4L Device to Custom Control Script
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.
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.
Re: String from M4L Device to Custom Control Script
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.
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
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?
Re: String from M4L Device to Custom Control Script
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.")
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.")
Re: String from M4L Device to Custom Control Script
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.
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
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!dr_kant wrote: ↑Sat Oct 19, 2024 1:13 pmAgain, 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.")
-
LukasRothMusic
- Posts: 5
- Joined: Fri Sep 20, 2024 9:48 am
Re: String from M4L Device to Custom Control Script
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.Angstrom wrote: ↑Sat Oct 19, 2024 1:24 pmAn 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.
Re: String from M4L Device to Custom Control Script
Yes it's handy, no need to bother with sysex messages locally.LukasRothMusic wrote: ↑Sun Oct 20, 2024 10:19 amI 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!