MIDIIn.connect fails

Hello,

I’m attempting to recall a recurring configuration with a midi controller within my startup file.
I’ve used the same code snippet to successfully connect my prior controller. I cannot get why it either works straight up, or fails at MIDIIn.connect with this error message:

MIDI (ALSA): connect failed (Ressource temporairement non disponible)
ERROR: Primitive '_ConnectMIDIIn' failed.
Failed.
RECEIVER:
class MIDIIn (0x55fd02bfaf80) {
  instance variables [19]
    name : Symbol 'MIDIIn'
    nextclass : instance of Meta_MIDIMTCtoSMPTEDispatcher (0x55fd02daacc0, size=19, set=5)
    superclass : Symbol 'Object'
    subclasses : nil
    methods : nil
    instVarNames : instance of SymbolArray (0x55fd02bfb100, size=1, set=2)
    classVarNames : instance of SymbolArray (0x55fd02bfb280, size=21, set=4)
    iprototype : instance of Array (0x55fd02bfb1c0, size=1, set=2)
    cprototype : instance of Array (0x55fd02bfb400, size=21, set=5)
    constNames : nil
    constValues : nil
    instanceFormat : Integer 0
    instanceFlags : Integer 0
    classIndex : Integer 359
    classFlags : Integer 0
    maxSubclassIndex : Integer 359
    filenameSymbol : Symbol '/usr/local/share/SuperCollider/SCClassLibrary/Common/Control/MIDIOut.sc'
    charPos : Integer 3187
    classVarIndex : Integer 269
}
PATH: /home/pi/.config/SuperCollider/startup.scd

PROTECTED CALL STACK:
	Meta_MethodError:new	0x55fd01fd1200
		arg this = PrimitiveFailedError
		arg what = Failed.
		arg receiver = MIDIIn
	Meta_PrimitiveFailedError:new	0x55fd01fd90c0
		arg this = PrimitiveFailedError
		arg receiver = MIDIIn
	Object:primitiveFailed	0x55fd0145ae80
		arg this = MIDIIn
	Meta_MIDIIn:connect	0x55fd02c08140
		arg this = MIDIIn
		arg inport = 0
		arg device = MIDIEndPoint("UC-33 USB MIDI Controller", "UC-33 USB MIDI Controller MIDI ")
		var uid = 1310720
		var source = nil
	a FunctionDef	0x55fd01744068
		sourceCode = "<an open Function>"
		arg source = MIDIEndPoint("UC-33 USB MIDI Controller", "UC-33 USB MIDI Controller MIDI ")
		arg i = 4
	ArrayedCollection:do	0x55fd0301a2c0
		arg this = [ MIDIEndPoint("System", "Timer"), MIDIEndPoint("System", "Announce"), MIDIEndPoint("Midi Through", "Midi Through Port-0"), MIDIEndPoint("UMC404HD 192k", "UMC404HD 192k MIDI 1"), MIDIEndPoint("UC-33 USB MIDI Controller", "UC-33 USB MIDI Controller MIDI "), MIDIEndPoint("UC-33 USB MIDI Controller", "UC-33 USB MIDI Controller MIDI "), MIDIEndPoint("SuperCollider", "out0"), MIDIEndPoint("SuperCollider", "out1"), MIDIEndPoint("SuperCollider", "out2") ]
		arg function = a Function
		var i = 4
	a FunctionDef	0x55fd01744698
		sourceCode = "{
	\"/home/pi/.local/share/SuperCollider/downloaded-quarks/SuperDirt/hacks/scriptfabien.scd\".load;
	~dirt = SuperDirt(2, s); // ?two output channels, increase if you want to pan across more channels
	~dirt.loadSoundFiles;   // load samples (path containing a wildcard can be passed in)
	// for example: ~dirt.loadSoundFiles(\"/Users/myUserName/Dirt/samples/*\");
	2.wait;
	// s.sync; // optionally: wait for samples to be read
	~dirt.start(57120, [0, 2, 4]);   // start listening on port 57120, ...etc..."
		var on = nil
		var off = nil
		var cc = nil
		var osc = a NetAddr(127.0.0.1, 6010)
		var tidalMidiChan = nil
	a FunctionDef	0x55fd01e7ba00
		sourceCode = "<an open Function>"
	Function:prTry	0x55fd022a89c0
		arg this = a Function
		var result = nil
		var thread = a Thread
		var next = nil
		var wasInProtectedFunc = false
	
CALL STACK:
	MethodError:reportError
		arg this = <instance of PrimitiveFailedError>
	Nil:handleError
		arg this = nil
		arg error = <instance of PrimitiveFailedError>
	Thread:handleError
		arg this = <instance of Thread>
		arg error = <instance of PrimitiveFailedError>
	Object:throw
		arg this = <instance of PrimitiveFailedError>
	Function:protect
		arg this = <instance of Function>
		arg handler = <instance of Function>
		var result = <instance of PrimitiveFailedError>
	Interpreter:executeFile
		arg this = <instance of Interpreter>
		arg pathName = "/home/pi/.config/SuperCollid..."
		arg args = [*0]
		var result = nil
		var saveExecutingPath = nil
	ArrayedCollection:do
		arg this = [*2]
		arg function = <instance of Function>
		var i = 1
	Platform:loadStartupFiles
		arg this = <instance of LinuxPlatform>
	LinuxPlatform:startup
		arg this = <instance of LinuxPlatform>
	Main:startup
		arg this = <instance of Main>
		var didWarnOverwrite = false
^^ The preceding error dump is for ERROR: Primitive '_ConnectMIDIIn' failed.
Failed.
RECEIVER: MIDIIn

I’m on ubuntu 23.10.
The said controller has two ports that both have the same name in Alsa.
Edit: if i recompile the class lib after turning off then back on my controller, it seems to work, but meh.

I’ve had a quick look at similar threads, but no one came cross my problem.
Any help welcome, have a nice weekend !

As far as I can see, this error is caused by something outside of SC.

“Resource temporarily unavailable” means SC is trying to access the resource (the device) and the ALSA MIDI subsystem reports back that it’s not available. At that point, there isn’t anything sclang can do to force it to be available. (The fact that you have to unplug and re-plug the device is consistent with that.)

For cases like this, sometimes differential testing is useful. We know it sporadically fails when sclang’s MIDI implementation tries to connect to the device via ALSA. That suggests a couple of other tests:

  • Try other ALSA MIDI software, e.g. Pure Data or LMMS. (Though Pure Data doesn’t manage its own connections, AFAICS, so you couldn’t reproduce specifically the .connect issue – but, if SC fails to connect, can Pd receive MIDI from that device, without unplugging and replugging?)
  • Try JACK MIDI software, e.g. Reaper.

If it fails in SC but works in Pd or LMMS, then that points (maybe) to an sclang bug.

If it fails in multiple ALSA MIDI software packages but works with JACK MIDI, it would suggest an incompatibility between the device and ALSA MIDI.

hjh

1 Like

An additional piece of information: JACK MIDI only connects applications. It does not connect directly to MIDI hardware. The significant benefit of JACK MIDI is that it works with a much lower latency, equivalent to a JACK audio connection (sample accurate, I believe).

I think sc still lacks implementation for JACK MIDI and other JACK features (for example, “CV” port support)

Thank you for your time and your replies.

It looks that if i wait 1 minute or more between turning on my controller and launching scide, it connects, but i need to investigate it further.

I’ve tried yet with pd 0.51, the ALSA-MIDI settings window asks to open N ports, and that’s it. I could successfully drag a green cable in Catia.
I compiled a recent version of qtractor a few months ago, the connections window still shows the old qjackctl interface, i could successfuly connect my controller by hand and it was confirmed by refreshing the Catia window i’ve opened beforehand.

I’ll upgrade my os in 10 days or so (23.10 repos are shut down) and report how it goes.
Thanks again !