Recent

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

Fred vS

  • Hero Member
  • *****
  • Posts: 3721
    • StrumPract is the musicians best friend
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #30 on: April 17, 2023, 04:42:35 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

In fact, I get all I need with vkeybd, I did have a little bemol about the number of octave displayed  (default = 3) but there is a parameter to define it (see picture):
Code: Bash  [Select][+][-]
  1. > vkeybd --octave 5

So, for me, I am happy with vkeybd.

Hum, new things are not always better:
Code: Bash  [Select][+][-]
  1. > vkeybd --help
  2. vkeybd -- virtual keyboard
  3.   version 0.1.18d
  4. Copyright (c) 1997-2000 Takashi Iwai

Code: Bash  [Select][+][-]
  1. > vmpk -h
  2. VMPK v0.8.7
  3. Virtual MIDI Piano Keyboard
  4. Copyright (C) 2006-2022 Pedro Lopez-Cabanillas
« Last Edit: April 17, 2023, 04:52:12 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 #31 on: April 18, 2023, 12:00:42 pm »
Hello Mark,
Have a look to ChannelSelector and LazRtmidi  which use rtmidi library :
Quote
A set of C++ classes that provide a common API for realtime MIDI input/output across Linux (ALSA & JACK), Macintosh OS X (CoreMIDI & JACK) and Windows (Multimedia).
The pascal  Source code of these projects can help you.
Friendly, J.P
« Last Edit: April 18, 2023, 12:06:00 pm 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 #32 on: April 18, 2023, 12:26:56 pm »
Hello Mark,
Have a look to ChannelSelector and LazRtmidi  which use rtmidi library :
Quote
A set of C++ classes that provide a common API for realtime MIDI input/output across Linux (ALSA & JACK), Macintosh OS X (CoreMIDI & JACK) and Windows (Multimedia).
The pascal  Source code of these projects can help you.
Friendly, J.P

Apart from the declarations I don't see anything about setting up a filter :-/

As a general point I'd remark that I'm trying to implement this interface to be a straight transcription of the ALSA headers, since that provides the best chance of subsequently being able to ask the developers for help without being bluntly told that we should be using a supported language.

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 #33 on: April 18, 2023, 12:32:10 pm »
for filters with rtmidi you can see here but it is in python language  :(
« Last Edit: April 18, 2023, 12:33:57 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 #34 on: April 18, 2023, 01:54:27 pm »
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

Ooops, I did not see this post!  :o

Salut J.P.

Hum, indeed strange.
I noted that there is a kind of random with aconnect -l and VMPK.
Some time I get value for  'VMPK Output' , some time it does not appear.

I will use vkeybd for the test, there no problems.

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

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #35 on: April 18, 2023, 02:14:58 pm »
It appears not to work if vmpk doesn't present an output as well as an input port.

Code: [Select]
client 129: 'VMPK Input' [type=utilisateur,pid=4584]
    0 'in              '
client 130: 'VMPK Output' [type=utilisateur,pid=4584]
    0 'out             '

I don't know whether to blame vmpk or something flaky in the ALSA API :-/

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 #36 on: April 18, 2023, 02:20:44 pm »
It appears not to work if vmpk doesn't present an output as well as an input port.

Code: [Select]
client 129: 'VMPK Input' [type=utilisateur,pid=4584]
    0 'in              '
client 130: 'VMPK Output' [type=utilisateur,pid=4584]
    0 'out             '

I don't know whether to blame vmpk or something flaky in the ALSA API :-/

MarkMLl

I propose to trust the ALSA API and forget vmpk for the moment.
« Last Edit: April 18, 2023, 02:26:55 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

Fred vS

  • Hero Member
  • *****
  • Posts: 3721
    • StrumPract is the musicians best friend
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #37 on: April 18, 2023, 03:59:36 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

Hello Mark.

I did try with SND_SEQ_EVENT_NOTE and all seems to work in the terminal amidi -p virtual -d;D

Code: Pascal  [Select][+][-]
  1. procedure GetFilteredEvents(out ets: seq_event_type_set);
  2. begin
  3. // Default for debugging.
  4. //  ets := [SND_SEQ_EVENT_CONTROLLER] ;
  5.  
  6.   ets := [SND_SEQ_EVENT_NOTE]  ; // here changed
  7. end ;

Code: Bash  [Select][+][-]
  1. ~> amidi -p virtual -d
  2.  
  3. 903C7F
  4. 803C00
  5. 903C7F
  6. 803C00
  7. 90477F
  8. 804700
  9. 90477F
  10. 804700
  11. 90477F
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 #38 on: April 18, 2023, 04:09:25 pm »
Yes, but what you're seeing there is that the note events are still going through to amidi, rather than being filtered and potentially dumped as hex by the filter program... try setting a breakpoint in the filter procedure.

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 #39 on: April 18, 2023, 04:16:33 pm »
Quote from: MarkMLI.msg477553#msg477553 date=1681826965
Yes, but what you're seeing there is that the note events are still going through to amidi, rather than being filtered and potentially dumped as hex by the filter program... try setting a breakpoint in the filter procedure.

MarkMLl

Indeed.
But I am sure you will find the trick how to do 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

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: Interfacing to MIDI (sequencer) devices via ALSA on Linux
« Reply #40 on: April 18, 2023, 04:32:24 pm »
Quote from: MarkMLI.msg477553#msg477553 date=1681826965
Yes, but what you're seeing there is that the note events are still going through to amidi, rather than being filtered and potentially dumped as hex by the filter program... try setting a breakpoint in the filter procedure.

MarkMLl

Indeed.
But I am sure you will find the trick how to do it.  ;)

Fre;D

Well I certainly haven't yet :-(

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 #41 on: April 18, 2023, 05:24:20 pm »
with python and the mido library it is easy to do a filter. Here is a python script to create a virtual port and wait for notes messages to display them :
Code: Python  [Select][+][-]
  1. import mido
  2. def accept_notes(port):
  3.     """Only let note_on and note_off messages through."""
  4.     for message in port:
  5.         if message.type in ('note_on', 'note_off'):    
  6.             yield message
  7. """Create a New Midi Virtual Port and wait for filtered messages"""        
  8. with mido.open_input('New Port', virtual=True) as inport:
  9.     for message in  accept_notes(inport):
  10.         print(message)
When i change the channel on the virtual midi keyboard the message doen't display.
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 #42 on: April 18, 2023, 05:47:09 pm »
I have less than zero interest in doing it in Python, and from what I can see that doesn't use the ALSA filtering facility which is what I'm asking for help with.

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 #43 on: April 18, 2023, 06:08:10 pm »
Code: Pascal  [Select][+][-]
  1. procedure GetFilteredEvents(out ets: seq_event_type_set);
  2. begin
  3.   ets := [SND_SEQ_EVENT_CONTROLLER]
  4. end { GetFilteredEvents } ;
  5.  
  6. function ApplyFilter(var seq: Psnd_seq_t; var event: snd_seq_event_t): boolean;
  7. begin
  8.   result := true;
  9.   WriteLn(event.type_:3);
  10. end { ApplyFilter } ;
  11. // ...
  12.          if ApplyFilter(seq, ev^) then begin
  13. //            snd_seq_ev_set_source(ev, my_port);
  14.             AsoundSeq.snd_seq_ev_set_subs(ev);
  15.             AsoundSeq.snd_seq_ev_set_direct(ev);
  16.             AsoundSeq.snd_seq_event_output(seq, ev);
  17.             AsoundSeq.snd_seq_drain_output(seq)
  18.           end
  19. // ...
  20.  

in the ApplyFilter function you can add a parameter of type seq_event_type_set , you can check if the event is in the set and if not return false ?
« Last Edit: April 18, 2023, 06:11:21 pm 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 #44 on: April 18, 2023, 06:37:13 pm »
in the ApplyFilter function you can add a parameter of type seq_event_type_set , you can check if the event is in the set and if not return false ?

ApplyFilter() is not being called. My suspicion is that it's incompatible with subscriptions (which are handled internal to ALSA itself), but the documentation doesn't say what it /is/ compatible with.

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