Recent

Author Topic: Interfacing to MIDI (sequencer) devices via ALSA on Linux  (Read 12514 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3721
    • StrumPract is the musicians best friend
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #15 on: April 16, 2023, 10:33:40 pm »
Hello Mark.

What do you think about working together with the same (virtual) keyboard?
It could be easier to share our result.

Do you have vmpk installed?

If you have a Debian distro, just do:
Code: Bash  [Select][+][-]
  1. > sudo apt install vmpk

I use this soundfont:
Code: Bash  [Select][+][-]
  1. > sudo apt install fluid-soundfont-gm fluid-soundfont-gs

To load/run it, just type vmpk.

And later, do test with a real keyboard.

[EDIT] In attachment my config of vmpk using ALSA.  It works using synthesizer qsynth with this command: qsynth -a alsa
« Last Edit: April 16, 2023, 11:23:29 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #16 on: April 17, 2023, 06:39:49 am »
Hello Fred,
Strange, for VMPK you have no output with aconnect -l command. Under Ubuntu 20.04 , it seems ok for me :
Quote
ubuntu$aconnect -l
client 0: 'System' [type=noyau]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=noyau]
    0 'Midi Through Port-0'
client 128: 'FLUID Synth (8160)' [type=utilisateur,pid=8160]
    0 'Synth input port (8160:0)'
client 129: 'VMPK Input' [type=utilisateur,pid=4584]
    0 'in              '
client 130: 'VMPK Output' [type=utilisateur,pid=4584]
    0 'out             '
ubuntu$aconnect 130:0 128:0
ubuntu$aconnect -l
client 0: 'System' [type=noyau]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=noyau]
    0 'Midi Through Port-0'
client 128: 'FLUID Synth (8160)' [type=utilisateur,pid=8160]
    0 'Synth input port (8160:0)'
   Connecté Depuis: 130:0
client 129: 'VMPK Input' [type=utilisateur,pid=4584]
    0 'in              '
client 130: 'VMPK Output' [type=utilisateur,pid=4584]
    0 'out             '
   Connexion À: 128:0

i have installed VMPK with synaptic some other packages have been installed (qsynth, soundfont etc...)

Friendly, J.P
« Last Edit: April 17, 2023, 06:43:28 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #17 on: April 17, 2023, 09:31:32 am »
Debian 12: I only have "In" on vmpk, and that appears to be the client ID (i.e. set by the program) rather than a list of properties.

What appears to be happening is that if a source or destination device explicitly sets up its own mappings it can't also be managed using a connect: I can duplicate the behaviour using BeepDemo (another of the examples). It might be connected with exclusive access... I'm not touching the filter program while somebody else is looking at it but I'll see if I can stop BeepDemo working like that to make it more useful as a test program.

Use vkeybd which appears to work and has few dependencies.

Slightly later: Another possibility is probably Rosegarden, although that's almost certainly overkill unless  one is already editing scores.

I'm still not certain what's causing this. As far as I can tell the code used in BeepDemo doesn't (at least explicitly) grab exclusive access, and adding extra options doesn't help. Neither does explicitly disconnecting the port after use. I think I need to take a bit of a look at vkeybd's sourcecode, but that isn't going to happen right now.

I notice that BeepDemo does use some of the dedicated malloc/free calls, although not necessarily the subscription one that's causing the problem.

MarkMLl
« Last Edit: April 17, 2023, 11:13:09 am by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #18 on: April 17, 2023, 11:10:01 am »
hello,
Debian 12: I only have "In" on vmpk, and that appears to be the client ID (i.e. set by the program) rather than a list of properties.
using the last stable version of vmpk (0.8.8 ) under Ubuntu 20.04 i have this :
Quote
ubuntu$aconnect -l
client 0: 'System' [type=noyau]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=noyau]
    0 'Midi Through Port-0'
client 128: 'MIDI In' [type=utilisateur,pid=5413]
    0 'in              '
client 129: 'MIDI Out' [type=utilisateur,pid=5413]
    0 'out             '
ubuntu$
only vmpk launched.

Friendly, J.P
« Last Edit: April 17, 2023, 11:13:58 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #19 on: April 17, 2023, 11:19:42 am »
vmpk /looks/ much the same on Debian, but it doesn't behave the same. There's obviously some sort of stylistic trap into which one can fall when writing that type of program, until I have time to look at the relevant sources I won't speculate as to whether it's Ubuntu or Debian that's changing the default behaviour, or if it's based on vmpk's upstream version.

I spent a distasteful few hours a couple of weeks ago trying to work out how to get a Debian package to build with non-default options. I got something working, but then made the mistake of asking on StackExchange if anybody knew the "correct" way of grafting in that sort of thing... only to be told that my question wasn't specific enough. Jeez...

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Fred vS

  • Hero Member
  • *****
  • Posts: 3721
    • StrumPract is the musicians best friend
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #20 on: April 17, 2023, 11:39:07 am »
Use vkeybd which appears to work and has few dependencies.

Hello Mark.

Ok,  vkeybd installed and working.  ;D
Let do test with it.

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #21 on: April 17, 2023, 12:29:07 pm »
Debian 12: I only have "In" on vmpk, and that appears to be the client ID (i.e. set by the program) rather than a list of properties.
Debian 12 isn't the stable version of debian:   Ubuntu 20.04 use Debian 11
« Last Edit: April 17, 2023, 12:34:49 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Fred vS

  • Hero Member
  • *****
  • Posts: 3721
    • StrumPract is the musicians best friend
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #22 on: April 17, 2023, 12:38:47 pm »
Hello Mark.

With vkeybd loaded:

Code: Bash  [Select][+][-]
  1. > aconnect -l
  2. client 0: 'System' [type=kernel]
  3.     0 'Timer           '
  4.         Connecting To: 142:0
  5.     1 'Announce        '
  6.         Connecting To: 142:0
  7. client 14: 'Midi Through' [type=kernel]
  8.     0 'Midi Through Port-0'
  9. client 128: 'FLUID Synth (1086)' [type=user,pid=1086]
  10.     0 'Synth input port (1086:0)'
  11. client 129: 'Client-129' [type=user,pid=13388]
  12.     0 'Virtual RawMIDI '
  13. client 130: 'Virtual Keyboard' [type=user,pid=13404]
  14.     0 'Virtual Keyboard'
  15. client 142: 'PipeWire-System' [type=user,pid=1087]
  16.     0 'input           '
  17.         Connected From: 0:1, 0:0
  18. client 143: 'PipeWire-RT-Event' [type=user,pid=1087]
  19.     0 'input           '

Connecting with aconnect (no error message):

Code: Bash  [Select][+][-]
  1. > aconnect 130:0 129:0

Connecting with your MidiFilter ( It works,  ;D,  but I did not catch how to disconnect first)

Code: Bash  [Select][+][-]
  1. ~>MidiFilter-x86_64-linux-gtk2 -d 130:0 129:0
  2. Subscribing 1 sources, PID 13667
  3. Invalid ALSA subscription for source 0 (130:0): Device or resource busy.
  4. free(): invalid pointer
  5. fish: Job 1, '/home/fred/Downloads/asound/tru…' terminated by signal SIGABRT (Abort)
  6.  

OK, I am ready to go further.

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #23 on: April 17, 2023, 12:40:54 pm »
Debian 12 isn't a stable version :   Ubuntu 20.04 use Debian 11
Just a small correction/addition: That remark would implicate that Debian 12 would be (designated) unstable, which isn't true either. It is in testing, and in state of hard freeze per mar 12th 2023.
Today is tomorrow's yesterday.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #24 on: April 17, 2023, 12:45:08 pm »
Debian 12 isn't a stable version :   Ubuntu 20.04 use Debian 11
Just a small correction/addition: That remark would implicate that Debian 12 would be (designated) unstable, which isn't true either. It is in testing, and in state of hard freeze per mar 12th 2023.
Exact : Debian 12 isn't unstable but in testing state. Debian 11 is the version in the stable state.
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #25 on: April 17, 2023, 01:02:40 pm »
Enough of the API works to make me think that I've not totally screwed up my pointer handling: if anything I'm tending to be rather "un-Pascal" in order to keep the API as similar to the C-based one as possible to make asking questions of the upstream maintainers a bit less fraught.

If the API interface in the .pas files needs to be changed, I'll post the program that generates them automatically from the .inc file.

MarkMLl
« Last Edit: April 17, 2023, 04:36:41 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Fred vS

  • Hero Member
  • *****
  • Posts: 3721
    • StrumPract is the musicians best friend
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #26 on: April 17, 2023, 01:25:05 pm »
Hello Mark.

OK, I did the test with a fresh reboot.

1) In terminal, load amidi (OK, loaded):
Code: Bash  [Select][+][-]
  1. > amidi -p virtual -d

2) In other terminal, load vkeybd (OK, loaded)
Code: Bash  [Select][+][-]
  1.  > vkeybd

3) In other terminal, check devices with aconnect -l
Code: Bash  [Select][+][-]
  1. ~> aconnect -l
  2. client 0: 'System' [type=kernel]
  3.     0 'Timer           '
  4.         Connecting To: 142:0
  5.     1 'Announce        '
  6.         Connecting To: 142:0
  7. client 14: 'Midi Through' [type=kernel]
  8.     0 'Midi Through Port-0'
  9. client 128: 'FLUID Synth (1086)' [type=user,pid=1086]
  10.     0 'Synth input port (1086:0)'
  11. client 129: 'Client-129' [type=user,pid=17057]
  12.     0 'Virtual RawMIDI '
  13. client 131: 'Virtual Keyboard' [type=user,pid=17076]
  14.     0 'Virtual Keyboard'
  15. client 142: 'PipeWire-System' [type=user,pid=1087]
  16.     0 'input           '
  17.         Connected From: 0:1, 0:0
  18. client 143: 'PipeWire-RT-Event' [type=user,pid=1087]
  19.     0 'input  


4) In previous terminal 3), connect the keyboard with your MidiFilter:
Code: Bash  [Select][+][-]
  1. > MidiFilter-x86_64-linux-gtk2 -d 131:0 142:0
  2. Subscribing 1 sources, PID 17120

5) Playing some notes on the vkeybd keyboard, here the result from the waiting amidi first terminal 1):
Code: Bash  [Select][+][-]
  1. > amidi -p virtual -d
  2. 90397F
  3. 803900
  4. 903C7F
  5. 803C00
  6. 903E7F
  7. 803E00
  8. 90407F
  9. 804000
  10. 90417F
  11. 804100
  12. 90437F
  13. 804300
  14. 90437F
  15. 804300
  16. 90457F

Conclusion: your code works, let go further...

Fre;D
« Last Edit: April 17, 2023, 01:37:42 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #27 on: April 17, 2023, 01:57:02 pm »
If you edit GetFilteredEvents() you can select event types which /should/ get filtered out: the fact that I've not worked out how to do that is one of the issues.

I'm watching, but if I go quiet for a day or so it's because some "legal crap" has arrived which has to be dealt with promptly.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Fred vS

  • Hero Member
  • *****
  • Posts: 3721
    • StrumPract is the musicians best friend
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #28 on: April 17, 2023, 01:57:49 pm »
Re-hello Mark.

It works with vmpk too !  ;D

Doing the same as previous post but using vmpk instead of vkeybd:

1) In terminal, run:
Code: Bash  [Select][+][-]
  1. > amidi -p virtual

2) In other terminal,  run:
Code: Bash  [Select][+][-]
  1. > vmpk

3) In other terminal, check devices with aconnect -l:
Code: Bash  [Select][+][-]
  1. > aconnect -l
  2. client 0: 'System' [type=kernel]
  3.     0 'Timer           '
  4.         Connecting To: 142:0
  5.     1 'Announce        '
  6.         Connecting To: 142:0
  7. client 14: 'Midi Through' [type=kernel]
  8.     0 'Midi Through Port-0'
  9.         Connected From: 134:0
  10. client 128: 'FLUID Synth (1086)' [type=user,pid=1086]
  11.     0 'Synth input port (1086:0)'
  12. client 129: 'Client-129' [type=user,pid=17492]
  13.     0 'Virtual RawMIDI '
  14. client 131: 'VMPK Input' [type=user,pid=17511]
  15.     0 'in              '
  16. client 134: 'VMPK Output' [type=user,pid=17511]
  17.     0 'out             '
  18.         Connecting To: 14:0
  19. client 142: 'PipeWire-System' [type=user,pid=1087]
  20.     0 'input           '
  21.         Connected From: 0:1, 0:0
  22. client 143: 'PipeWire-RT-Event' [type=user,pid=1087]
  23.     0 'input
          '

4) In previous terminal 3), connect the keyboard with your MidiFilter (strange but it works with VMPK Output):
Code: Bash  [Select][+][-]
  1. > MidiFilter-x86_64-linux-gtk2 -d 134:0 129:0
  2. Subscribing 1 sources, PID 17590

5) Playing some notes on the vmpk keyboard, here the result from the waiting amidi first terminal 1):
Code: Bash  [Select][+][-]
  1. > amidi -p virtual -d
  2.  
  3. 922E64
  4. 822E00
  5. 922F64
  6. 822F00
  7. 923064
  8. 823000
  9. 923164
  10. 823100
  11. 923264
  12. 823200
  13. 923364
  14. 823300
  15. 923464
  16. 823400
« Last Edit: April 17, 2023, 02:04:20 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #29 on: April 17, 2023, 03:27:16 pm »
It works with vmpk too !  ;D

That's odd... it depends on whether vmpk's showing only an "in" or both an "In" and an "Out"... JP's example and your working ones are the latter case. Most likely a bug in vmpk, which isn't encouraging.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018