Get MIDI track name to send over OSC

Learn about building and using Max for Live devices.
Post Reply
trossenink
Posts: 5
Joined: Thu Dec 01, 2022 9:37 pm

Get MIDI track name to send over OSC

Post by trossenink » Thu Dec 01, 2022 9:50 pm

Hello All,

I'm working on a custom Max device. I've altered a copy of the default device called "OSC MIDI Send" which comes with the Ableton Connection Kit:
https://www.ableton.com/en/packs/connection-kit/

I added one link (circled in pic) so that it would also send out the port number with the note in the OSC message and that works. (I also deleted the velocity, don't need it)

I would love to send the Midi track name out instead of the port number since that is static. Being new I'm having difficulty traversing the object model and formatting things correctly. Does anyone know the correct nodes to get that information over?

Secondly, but not as important, the way I have it set up now the port number is being appended with a '1' which is the combine function adding the 1. I'm not sure how to fix this. That will likely still be there and append onto the MIDI track name unless someone knows how to fix that.

(Picture attached of my OSC Device)
https://imgur.com/a/97jWICR

Thanks!

Image

chapelier fou
Posts: 6003
Joined: Mon May 15, 2006 12:15 pm

Re: Get MIDI track name to send over OSC

Post by chapelier fou » Fri Dec 02, 2022 10:31 am

To get the track id you want to get the canonical parent of the max device. Feed this id to a live.object and request the object's name.

<pre><code>
----------begin_max5_patcher----------
551.3ocsV1raaCCC.9r8SgfN6F3eSb54doG1SvPggrCQhJrkMjjyxPQe2mDk
85VShqyb1gHCQQIxOJRp7luGsr8DnnjGIem348lumGJxJvaXtGsgcpploP0n
B3GskuRCbKogSZTrrsWCDAqAFWRz2vE0fF2V7GBMJ9Yo7c3YXN2GhRG2uSO8
O6.m6QoAlejWFVtioqNvE6KjPk1oQbZ3pv.Rz501OqisiwFQjWra4cee6Pvx
3TSJI0WDwnYiXxUQrjI1OWL2jYGy1rJaAT1.JEaObFlQO7sme54a3pL5BbFe
8qxI4KbKdMtMAALbQWiWCv8f9VyVuDhg+iHNjoFgex9ujoVyOBqLKXM5hfLe
YLljOjm9aFG1ihcD1U37vBlVK4kldHpARGP0iVzAREWoAQEZ2HTNFit0Hk47
0shIqd6XRSVgFjEffUViVLbtQpMSWXOUzJJKEiVXQcb533cOgvX5CD8AtpXG
bjWAjJlnUvqX0EFzAg9F5skbdDHY5t2eUqsgnPpKVrM5h0E3AXnQ74GtvCzJ
+uiMp1dY0naL9FC4i7vcfRyELM2jZ7GJY5dQhtR7etVJeNFZvaVjgruoX81I
sT9cfHzPeIRg2AjlCQidyxPJbFHkeGLzlYXmyAxkty55NZ6C5TFMgon+0Voc
Zd.NkKbSw5RpzTeOpuSBSZp2zlhsdI5VzSqc+aKZS6NPJ54C8WMvYLI1Pw9F
opi43.663+t+unjMdwA
-----------end_max5_patcher-----------
</code></pre>

Regarding the combine adding a "1", it's caused by the fact that the poly object outputs a 1.

Also, with UI elements, like textedit, you can "parameter mode enable" them from the inspector. This way, their content will be saved with the live set, so no need to initialize them. You can also give them an initial value from the inspector.

Hope this helps.
MacBook Pro 13" Retina i7 2.8 GHz OS 10.13, L10.0.1, M4L.
MacStudio M1Max 32Go OS 12.3.1

trossenink
Posts: 5
Joined: Thu Dec 01, 2022 9:37 pm

Re: Get MIDI track name to send over OSC

Post by trossenink » Fri Dec 02, 2022 9:20 pm

Thanks for your reply. What you said makes sense. Is that a code block in your post of an example? If so, I'm not sure how to take that and use it in a patch/device.

chapelier fou
Posts: 6003
Joined: Mon May 15, 2006 12:15 pm

Re: Get MIDI track name to send over OSC

Post by chapelier fou » Sat Dec 03, 2022 7:06 am

Copy the text. Paste in a patch.
MacBook Pro 13" Retina i7 2.8 GHz OS 10.13, L10.0.1, M4L.
MacStudio M1Max 32Go OS 12.3.1

trossenink
Posts: 5
Joined: Thu Dec 01, 2022 9:37 pm

Re: Get MIDI track name to send over OSC

Post by trossenink » Sat Dec 03, 2022 10:33 pm

Thanks. I got it into my patch.

Apologize for being so brand new. I tried to print it to the console to test, but that isn't printing anything. (I'm holding control and clicking the button to fire it) So I'm not sure why that isn't returning the name. IT works for my button on the left to trigger the OSC message.

I'm guessing also that to incorporate this into my patch I would replace where I have print with a link into the first input on the "combine /port number" node? Then fire it by running a link from poly to where your button is?

I've been coding for 20 years and this type of coding in MAX is so very foreign to me.

Current patch pic:
https://imgur.com/a/kcgR2LV

chapelier fou
Posts: 6003
Joined: Mon May 15, 2006 12:15 pm

Re: Get MIDI track name to send over OSC

Post by chapelier fou » Sat Dec 03, 2022 10:45 pm

Attach your print object to the output ou the 'route name' object instead. When you set a message content via its second input, it doesn't output anything. It's simply commonly used this way to display stuff in the main patch.
MacBook Pro 13" Retina i7 2.8 GHz OS 10.13, L10.0.1, M4L.
MacStudio M1Max 32Go OS 12.3.1

trossenink
Posts: 5
Joined: Thu Dec 01, 2022 9:37 pm

Re: Get MIDI track name to send over OSC

Post by trossenink » Mon Dec 05, 2022 4:22 am

As I was lying in bed last night I thought about how that box was showing the track name and realized exactly what you just replied, lol. Made that change and it works! Thank you very much.

I haven't been able to figure out one other programming thing. I haven't been able to find where the '2346' in the box for the port number is hard coded. I've looked all around and can't find it. It would be nice to be able to change that in code.

I have one last item to tackle. I couldn't figure out why I was getting double messages for every note. I did some research and discovered that Ableton sends out a message for begin note and a second one for end note. That is likely going to be a big problem for the receiving program. So I need to figure out how to differentiate the messages somehow. Even if I can't turn it off in Ableton, if I can append the message somehow I can identify the 'end note' message and ignore them in the receiving program.

Screenshot of current patch:
https://imgur.com/a/tQTgwuJ

chapelier fou
Posts: 6003
Joined: Mon May 15, 2006 12:15 pm

Re: Get MIDI track name to send over OSC

Post by chapelier fou » Mon Dec 05, 2022 8:19 am

Absolutely no offense, but I think there are some basic stuff that you should learn. (But still, I'm impressed you've gotten that far given what you seem to don't know)
Midi notes consist of two messages : a note on (note, velocity, channel) and a note off (note, 0, channel). That's how MIDI closes notes.
Not sure about you final goal, but if you want to trigger your algorithm with a MIDI note, you'll likely want to use a 'stripnote' object that will ignore note-off messages.
In your case, I'm pretty sure that live.thisdevice should trigger the output, and not a midi note.
MacBook Pro 13" Retina i7 2.8 GHz OS 10.13, L10.0.1, M4L.
MacStudio M1Max 32Go OS 12.3.1

trossenink
Posts: 5
Joined: Thu Dec 01, 2022 9:37 pm

Re: Get MIDI track name to send over OSC

Post by trossenink » Mon Dec 05, 2022 4:33 pm

None taken. Of course I do and that is what I'm doing. I have to research and ask questions to learn and I've learned a great deal in a few weeks :) I just wish there were more sources than asking in this forum. I've looked at what there is online to learn the max programming system and have found very little. There are just screenshots of "examples" for the nodes and they really explain very little. But I power on :)

The final goal is to take in the messages in Unreal Engine to trigger lighting events which are synchronized to the song. (SO much to learn over there) I'm 95% there at the moment. I just need to be able to identify and ignore the end note messages. Currently, Unreal Engine will think they are new notes.

What you said is very helpful. I can add velocity back in and simply look for value higher than 0. I will just need to figure out how to put the message together in the right format. Or, as you said, try out the strip note. I'll look at both next.

Appreciate the continued help.

chapelier fou
Posts: 6003
Joined: Mon May 15, 2006 12:15 pm

Re: Get MIDI track name to send over OSC

Post by chapelier fou » Mon Dec 05, 2022 5:13 pm

(Hit me up with a PM)
MacBook Pro 13" Retina i7 2.8 GHz OS 10.13, L10.0.1, M4L.
MacStudio M1Max 32Go OS 12.3.1

Post Reply