Alsa Midi port name ambiguity trouble

MusE is a DAW for Linux with both MIDI and Audio editing. https://muse-sequencer.github.io

Moderators: MattKingUSA, khz, spamatica

folderol
Established Member
Posts: 2083
Joined: Mon Sep 28, 2015 8:06 pm
Location: Here, of course!
Has thanked: 232 times
Been thanked: 400 times
Contact:

Re: Alsa Midi port name ambiguity trouble

Post by folderol »

FWIW wherever possible I compile music software from source - including MusE - I find the gives better results, even if only slightly. Employing a belt+braces policy I always keep a copy of the previous one :D
The Yoshimi guy {apparently now an 'elderly'}
User avatar
Impostor
Established Member
Posts: 1392
Joined: Wed Aug 17, 2022 1:55 pm
Has thanked: 148 times
Been thanked: 366 times

Re: Alsa Midi port name ambiguity trouble

Post by Impostor »

Tim E. Real wrote: Mon Aug 22, 2022 11:26 pm I am running kernel 5.13.8-1 and I have an MAudio MidiSport 2x2 which
shows up as two devices. But I see no trouble with port naming. I should try a later kernel...
Could this issue be distro-specific? Or maybe the manufacturer puts more care in naming the ports of their more expensive devices.
User avatar
Linuxmusician01
Established Member
Posts: 1547
Joined: Mon Feb 23, 2015 2:38 pm
Location: Holland (Europe)
Has thanked: 784 times
Been thanked: 144 times

Re: Alsa Midi port name ambiguity trouble

Post by Linuxmusician01 »

Impostor wrote: Tue Aug 23, 2022 8:45 am [...] Or maybe the manufacturer puts more care in [naming the ports of] their more expensive devices.
I wouldn't count on that. Most expensive devices need a proprietary driver. Possibly because they have non-class-compliant fancy schmancy functionality.
folderol
Established Member
Posts: 2083
Joined: Mon Sep 28, 2015 8:06 pm
Location: Here, of course!
Has thanked: 232 times
Been thanked: 400 times
Contact:

Re: Alsa Midi port name ambiguity trouble

Post by folderol »

Linuxmusician01 wrote: Tue Aug 23, 2022 8:58 am
Impostor wrote: Tue Aug 23, 2022 8:45 am [...] Or maybe the manufacturer puts more care in [naming the ports of] their more expensive devices.
I wouldn't count on that. Most expensive devices need a proprietary driver. Possibly because they have non-class-compliant fancy schmancy functionality.
Indeed. They completely abuse the USB subsystem. From what I've read the improvement is relatively small. A decent quality one would have a Class Compliant fallback.
Just to make it 'interesting' USB2 still has a granularity of 1mS but packet stuffing such as streaming audio can magically end up with a potential latency of 0.125mS (note all the caveats!). USB3 is a whole 'nother game and in theory can achieve latency of approximately 50uS.
With all of these it also depends a lot one what else the USB subsysem is doing... and the OS itself.

Once actually inside the machine all of this is irrelevant and will be determined by buffer sizes and processor speed.

A final point is that unless you are working on headphones, you are adding at least 3mS delay to what you are hearing.
The Yoshimi guy {apparently now an 'elderly'}
User avatar
sunrat
Established Member
Posts: 925
Joined: Wed Jul 22, 2020 2:08 pm
Has thanked: 152 times
Been thanked: 247 times

Re: Alsa Midi port name ambiguity trouble

Post by sunrat »

Life seemed easier when sound cards were all PCI. :roll:
folderol
Established Member
Posts: 2083
Joined: Mon Sep 28, 2015 8:06 pm
Location: Here, of course!
Has thanked: 232 times
Been thanked: 400 times
Contact:

Re: Alsa Midi port name ambiguity trouble

Post by folderol »

Well you can still get PCIe sound cards...
Personally I don't want to take out a second mortgage :(
The Yoshimi guy {apparently now an 'elderly'}
merlyn
Established Member
Posts: 1392
Joined: Thu Oct 11, 2018 4:13 pm
Has thanked: 168 times
Been thanked: 247 times

Re: Alsa Midi port name ambiguity trouble

Post by merlyn »

folderol wrote: Tue Aug 23, 2022 11:21 am Just to make it 'interesting' USB2 still has a granularity of 1mS but packet stuffing such as streaming audio can magically end up with a potential latency of 0.125mS (note all the caveats!). USB3 is a whole 'nother game and in theory can achieve latency of approximately 50uS.
USB 2 and USB 3 use the same audio protocol. Eight packets per millisecond. Thunderbolt is down into microseconds. It's a question that comes up :"Why are there so few USB3 audio interfaces?". Focusrite answered it here :

https://support.focusrite.com/hc/en-gb/ ... t-USB-3-0-

USB 3 gives more bandwidth (more audio channels) but has the same latency as USB 2.
A final point is that unless you are working on headphones, you are adding at least 3mS delay to what you are hearing.
I think that's a reason not to add any more with software buffers. :D
j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 358 times

Re: Alsa Midi port name ambiguity trouble

Post by j_e_f_f_g »

imposter,

As TIm mentioned, you could setup a udev rule which would solve your problem.

But now that I recall, in my code review of alsa, there's LOTS of (undocumented, as usual) things you can do with an asoundrc file. I'm pretty sure you can create an entry to rename your Keystation 49's rawmidi device names. And that should also change the seq device names accordingly. Right now, I'm swamped with work on several projects that I need to get finished soon. So I don't have much time to pour over my commented alsa source code to glean how you'd do it. (And anyway, I didn't dive into the alsa's configuration API, so my notes on that are scant. I concentrated on the wave and midi APIs). But if I get a little lull, I'll try a few asoundrc tests, and see if I can come up with something.

But man, alsa's config files are ugly. They used Lua as an inspiration for the syntax. And I thought that LV2's turtle was bad...

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

folderol
Established Member
Posts: 2083
Joined: Mon Sep 28, 2015 8:06 pm
Location: Here, of course!
Has thanked: 232 times
Been thanked: 400 times
Contact:

Re: Alsa Midi port name ambiguity trouble

Post by folderol »

Did you have to mention LV2 / turtle?
I'll have to go and lie down now :(
The Yoshimi guy {apparently now an 'elderly'}
j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 358 times

Re: Alsa Midi port name ambiguity trouble

Post by j_e_f_f_g »

You'll be ok. It could have been worse. If you were still using ubuntu, your turtle could have gotten stuck in a .NET

https://www.phoronix.com/news/Ubuntu-22.04-LTS-dotNET-6

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

User avatar
Impostor
Established Member
Posts: 1392
Joined: Wed Aug 17, 2022 1:55 pm
Has thanked: 148 times
Been thanked: 366 times

Re: Alsa Midi port name ambiguity trouble

Post by Impostor »

j_e_f_f_g wrote: Tue Aug 23, 2022 9:44 pm .. things you can do with an asoundrc file. I'm pretty sure you can create an entry to rename your Keystation 49's rawmidi device names.
I tried to understand .asoundrc's wikidoc without success, and then tried to simply adjust their example for aliasing a pcm device for midi, also without success. I'll just have to live with it. For now, I've spent enough time on the issue and will simply make use of midi through. Thanks for your efforts. To all others in this thread, also a big thank you!
User avatar
Impostor
Established Member
Posts: 1392
Joined: Wed Aug 17, 2022 1:55 pm
Has thanked: 148 times
Been thanked: 366 times

Re: Alsa Midi port name ambiguity trouble

Post by Impostor »

Got a very easy fix/workaround for the problem (recap: midi out ports of midi controller get identical alsa names, and this leads to those ports being impossible to be individually routed in Qjackctl and MusE):

  1. ensure that enough midi through ports are created
  2. use udev rule to run script on activation of controller, which connects the controller ports to midi through ports with aconnect
  3. ensure Qjackctl does not reset connections on patchbay activation, and do not include controller midi port connections in your patchbay definition. Use the midi through ports instead

Now you can freely connect the relevant midi through output ports individually. And MusE gets its note and transport messages from distinct ports.

Details:

(1) Create file /etc/modprobe.d/midithru.conf with content: options snd-seq-dummy ports=4

(2a) Run lsusb to find out idvendor:idproduct (format vvvv:pppp)

(2b) Create file /etc/udev/rules.d/00-usb-midi.rules with a single line (with the correct data substituted for <...>):
ACTION=="add", ATTRS{idVendor}=="<vvvv>", ATTRS{idProduct}=="<pppp>", ENV{XAUTHORITY}="~/.Xauthority", ENV{DISPLAY}=":0", OWNER="<your user name>", RUN+="<path to script>"

(2c) Create script with aconnect rules for the relevant ports.

(3) Untick "reset all connections on patchbay activation" in Qjackctl options.

(4) Reboot

rtega
Posts: 1
Joined: Sat Mar 23, 2024 7:16 am
Been thanked: 1 time

Re: Alsa Midi port name ambiguity trouble

Post by rtega »

This bug has been solved in 2019: https://github.com/jackaudio/a2jmidid/pull/5. For some reason ubuntu even in their latest version doesn't include the 4 character change in the code that solves this problem. I submitted a bug report to ubuntu: https://bugs.launchpad.net/ubuntu/+sour ... ug/2058799 You can download the code from their github site and compile it yourself. It isn't that difficult.

User avatar
Impostor
Established Member
Posts: 1392
Joined: Wed Aug 17, 2022 1:55 pm
Has thanked: 148 times
Been thanked: 366 times

Re: Alsa Midi port name ambiguity trouble

Post by Impostor »

rtega wrote: Sat Mar 23, 2024 7:19 am

This bug has been solved in 2019: https://github.com/jackaudio/a2jmidid/pull/5. For some reason ubuntu even in their latest version doesn't include the 4 character change in the code that solves this problem. I submitted a bug report to ubuntu: https://bugs.launchpad.net/ubuntu/+sour ... ug/2058799 You can download the code from their github site and compile it yourself. It isn't that difficult.

The OP problem has nothing to do with jack or a2j, but with the very fact of identical port names given by Alsa. Other programs have issue with it, not only a2jmidid.

Even without a2jmidid being installed, my keyboard ports are exposed as (distinct) jack midi ports in qjackctl's graph window. In the "system" box, I get midi_capture_1 to midi_capture_6 ports. Two of which are the jack translations of my two midi keyboard ports, the other four are jack translations of my four alsa midi through ports.

So if I were to use jack midi, I'd have no problems. It's only if I want (or need) to use the Alsa ports themselves which can lead to issues in certain applications.

Post Reply