Mulitple supercollider instances (ALSA MIDI port | JACK client name, Linux)

One issue I currently face when launching multiple instances of sclang via the command line (which boots scsynth) is connecting Midi ports on Linux using the patchbay (for flexibility), across different sessions.

Supercollider is using the same port names and ALSA is adding a port number to each instance [129] and [130] for example. But after rebooting the two instances of supercollider, the ALSA port numbers could be changed, to [134] and [135] or vice versa, for example. So a tool which tries to restore the MIDI connections, fails to do so.

Not sure how and if this could be solved, but I was thinking would it be possible to add a method to sclang (MIDIClient?) which allows you to set a custom ALSA midi port name? (Then the MIDI connection restore tool, should still do some regex to filter out the port numbers probably).

Edit: Same is true for the JACK client name probably:

A ALSA MIDI client name could maybe be added to MIDIClient.init or as similar method (MIDIClient.initWithName)?

A JACK client name could maybe be set via a environment variable, as that is the way custom JACK settings seems to be handled.

One could do that. ā€œSuperCollider_1ā€, ā€œsupercollider_2ā€ etc.

Or, you could have another process receiving all input control data, and rerouting freely to the other 2 processes, maybe via OSC. Maybe more flexible?

" NOTES

ALSA does not guarantee client names to by unique. I.e. it is possible to have two apps that create two clients with same ALSA client name. JACK however requires port names to be unqiue. To ensure this uniqueness, a2jmidid will add the unique numeric ALSA client ID to the JACK port name. However this behaviour is known to be problematic when restoring connections using simplistic tools like aj-snapshot and jack_connect. In order to make them work, the -u option can be used. This option will cause a2jmidid to omit the numeric ALSA Client ID from JACK port names. In this mode, ALSA client name uniqueness must be guartanteed externally."

So a2jmidid is adding the port id numbers.

A other solution would be to add JACK MIDI support to SuperCollider.

It would be a good new feature.

Only if youā€™re explicitly requesting it by running a2jmidid yourself, but that wasnā€™t the case in the original post? Unless Iā€™m missing something.

Yeah, the restriction to ALSA MIDI is occasionally uncomfortable. Adding (or switching to) JACK MIDI is likely to be a do-ocracy task though (itā€™ll happen when someone needs it, and does it, and puts in a PR).

hjh

I think the easiest and probably the best solution now is to add support for a environment variable which (if available) sets the JACK client name and the MIDI client name (both are ā€œSuperColliderā€ by default).

These are two distinct things, though.

The JACK client name is for the server, and this is already set by s.options.device (documented here). So thereā€™s no need for an environment variable, because itā€™s already configurable.

Iā€™m not sure how MIDI clients appear in other OSes. Only Linux by default supports inter-app patching, so in Linux, apps must appear as ports. In MacOS, thereā€™s IAC Bus; in Windows, loopMIDI. Certainly itā€™s possible to run multiple sclang clients in every OS, so, identifying multiple sclang MIDI clients could be a cross-platform issue. In that case, a language-side variable would make more sense, but this may need confirmation. (If this problem is specific to Linux, then Iā€™d probably go with the environment variable ā€“ it wouldnā€™t make sense to add a MIDIClient.clientName for everybody, if it would be ignored in the vast majority of installations.)

hjh

Oh nice, I didnā€™t knew that.

If you look at JACK clients which have session manager support on Linux (NSM, RaySession), they use the same client name for JACK as for the MIDI client name.

I think it makes sense to automatically use the same name for the MIDI client, as is set via s.options.device in supercollider to. So if you set the device name to ā€œSuperCollider.drumsā€, your supercollider midi client name is also named ā€œSuperCollider.drumsā€.

Having the same names will also be the case with JACK MIDI support probably, as the JACK client name is the same for audio as for MIDI then (same JACK client).

1 Like

What do you think @jamshark70?

A downside I can think of is that it might break some existing code of people who expect the MIDI client name always contains ā€œSuperColliderā€. But a custom device name can still contain ā€œSuperColliderā€ of course.

I have a bit icky feeling about that ā€“ coupling two entities that are not substantially related, but only in Linux (it would be 100% wrong in Mac and Windows to do anything like this), and only because of the accident that audio and MIDI connections can be made in the same JACK interfaces, doesnā€™t strike me as something to enforce as a default situation.

I think it would be fine if a user wants this to have a method in a linux/ directory that sets both the server device name and (future, after making it settable) MIDI client name to the same string.

hjh

I agree with this I think.

Iā€™ve no clue about other platforms, but I would expect them to mirror the JACK MIDI situation, where the audio client is the same as the midi client, while with ALSA, midi is a other layer, which is typical Linux.
Renaming the device name doesnā€™t rename the MIDI client name in OSX/ Windows automatically?

It would be good to have that option, this is currently the biggest obstacle for me to run SC as some sort of standalone application in a linuxaudio session. You want reliable restoration of MIDI connections, also if you use the patchbay and not MIDIOut.connect().

How should that method be named?

Server.default.options.deviceName 
Server.default.options.deviceClientName 
Server.default.options.deviceMidiClientName
Server.default.options.deviceAndMidiClientName
Server.default.options.deviceAndMidiDeviceName

It belongs in MIDIClient. I strongly disagree with any notion of folding a MIDI option into ServerOptions. MIDI is language-only and has nothing to do with the server. The fact that they both appear in JACK UIs is purely an accident of the evolution of audio and MIDI subsystems in Linux. This should not influence SC architecture.

There could be a convenience method to set both at once, but these two entities should not be modeled in the same place.

hjh

Some Apps work better because they support. For example, many apps save their status when receiving ā€œSIGUSR1ā€ Unix signal, which non-section-manager does etc.

So something like MIDIClient.initWithName()?

You can set save and stop signal in NSM-Proxy indeed. It might be nice for instance if it was possible to handle SIGTERM in sclang. Then a SIGTERM signal could be sent from NSM-Proxy and it could be handled in sclang, by for example, sending \quit to the belonging scsynth.

Not sure how useful a SIGURS1 signal would be when it comes to SC. Ideally OSC would be used instead I think in this case.

Or MIDIClient.name_("APopular80sTechnology").init;

Iā€™m not sure if this is relevant to other OSes. I think (in both Mac and Windows) that apps can see only device names, not other apps, and devices typically donā€™t have access to app names (the connection is via a physical cable), so the SC client name is probably invisible and thus irrelevant (except maybe in MacOS Audio MIDI Setup). This may be why MIDIClient never had an interface for setting a name.

hjh

Itā€™s true. non-session-manager can also be controlled by OSC, but I donā€™t know much about compatibility/features on NSM yet. Iā€™ve been using just non-mixer.

The non-mixer and non-timelines are good software and can fit many different situations since they are so clean and modular. Checking out NSM now. Letā€™s see.

@flower share some tips on how you use NSM, Iā€™m just considering it right now. The other pieces are more obviously useful for me.

Add supported NSM clients to your session (non-mixer, non-sequencer, zynaddsubfx, ardour, qtractor, carla, seq192 etc.).
Add applications without NSM support using nsm-proxy
Restore JACK connections by adding jackpatch to your session.
https://non.tuxfamily.org/wiki/Non%20Session%20Manager

Btw: sclang doesnā€™t launch scsynth detached, so when sclang is started in a terminal and you kill the terminal, both sclang and scsynth are gone.

1 Like