lzulauf / MidiRouter

Control routing of USB MIDI on a raspberry pi
https://github.com/lzulauf/midirouter
0 stars 0 forks source link

Fail on rpi 400 with MPK mini #1

Closed pmackinney closed 2 weeks ago

pmackinney commented 2 weeks ago

Thanks for writing this utility, I'm hoping to use my RPI 400 as a portable headless midi-router.

My first attempt has failed and I don't have a clue, and advice appreciated. I installed midi-router, created and modified a config file. midi-router started without error but the Neutron doesn't respond to keyboard input from the mini. What to try next? Is any logging available?

Hardware: RPI 400, newly installed Raspbian system AKAI MPK mini (the very first one, I think. 8 buttons, pads, 8 knobs, 25 keys) Behringer Neutron

$ uname -a Linux myHost 6.6.31+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.31-1+rpt1 (2024-05-29) aarch64 GNU/Linux

$ midi-router info MIDI Input Ports: Midi Through:Midi Through Port-0 14:0 MPK mini:MPK mini MIDI 1 24:0 Neutron(1):Neutron(1) MIDI 1 28:0 RtMidiOut Client:RtMidi output 131:0 RtMidiOut Client:RtMidi output 132:0 RtMidiOut Client:RtMidi output 133:0 MIDI Output Ports: Midi Through:Midi Through Port-0 14:0 MPK mini:MPK mini MIDI 1 24:0 Neutron(1):Neutron(1) MIDI 1 28:0 RtMidiIn Client:RtMidi input 128:0 RtMidiIn Client:RtMidi input 129:0 RtMidiIn Client:RtMidi input 130:0

$ cat config.yaml (midi-router-venv) paul@myHost:~/Documents/MidiRouter $ cat config.yaml

ports:
  inputs:
  - identifier: in_through
    name: Midi Through:Midi Through Port-0
    port: '14:0'
    port_type: USB
  - identifier: in_mpk
    name: MPK mini:MPK mini MIDI 1
    port: '24:0'
    port_type: USB
  - identifier: in_neutron
    name: Neutron(1):Neutron(1) MIDI 1
    port: '28:0'
    port_type: USB
  outputs:
  - identifier: out_through
    name: Midi Through:Midi Through Port-0
    port: '14:0'
    port_type: USB
  - identifier: out_mpk
    name: MPK mini:MPK mini MIDI 1
    port: '24:0'
    port_type: USB
  - identifier: out_neutron
    name: Neutron(1):Neutron(1) MIDI 1
    port: '28:0'
    port_type: USB
mappings:

##################
# MPK to Neutron #
##################
- from_port: 
    identifier: in_mpk
  to_port: 
    identifier: out_neutron
  from_channel: 0
  to_channel: 0
lzulauf commented 2 weeks ago

Hello 👋

If you're executing the script manually on the command line, you can use verbose output to see more of what's going on:

$ midi-router -vv start

If you followed the "Running on Startup" instructions, then you're likely executing via systemd rather than invoking the script manually. If so, you can use journalctl to see the log messages

$ sudo journalctl -u midi-router.service

It's possible that you're being too specific on the channels. You might consider removing the from_channel and to_channel from your mapping (it will default to routing all channels).

mappings:

##################
# MPK to Neutron #
##################
- from_port: 
    identifier: in_mpk
  to_port: 
    identifier: out_neutron

I hope that helps! Let me know how it goes.

pmackinney commented 2 weeks ago

Thanks for the reply. Here's how I set up before testing again:

  1. Test hardware with alsa-utils.
  2. Result: While the connection was active playing the MPK activated the Neutron OSC1&2 as expected.
    $ aconnect -l
    client 0: 'System' [type=kernel]
    0 'Timer           '
        Connecting To: 142:0
    1 'Announce        '
        Connecting To: 142:0
    client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
    client 24: 'MPK mini' [type=kernel,card=2]
    0 'MPK mini MIDI 1 '
    client 28: 'Neutron(1)' [type=kernel,card=3]
    0 'Neutron(1) MIDI 1'
    client 142: 'PipeWire-System' [type=user,pid=910]
    0 'input           '
        Connected From: 0:1, 0:0
    client 143: 'PipeWire-RT-Event' [type=user,pid=910]
    0 'input           '
    $ aconnect 24:0 28:0

Testing midi-router with -vv option:

  1. Restart
  2. Delete old MidiRouter folders
  3. Reinstall and run with -vv option
  4. Result: Playing the MPK has no effect on the Neutron, doesn't generate any stdout or stderr messages. I noticed that the end of the stderr log, the mapping section, only mentions the Neutron, which seems odd.

$ source midi-router-venv/bin/activate
$ git clone https://github.com/lzulauf/MidiRouter
$ cd MidiRouter/
$ pip install -e .
$ midi-router generate-config
$ vi config.yaml ## Recreated config file as above. Omitting the channel directions had no effect.
$ midi-router -vv start 2>&1
$  midi-router -vv start
Starting using config config.yaml
DEBUG:midi_router:available_long_names before assigning long-named identifiers: {'Midi Through:Midi Through Port-0': ['Midi Through:Midi Through Port-0 14:0'], 'MPK mini:MPK mini MIDI 1': ['MPK mini:MPK mini MIDI 1 24:0'], 'Neutron(1):Neutron(1) MIDI 1': ['Neutron(1):Neutron(1) MIDI 1 28:0']}
DEBUG:midi_router:available_long_names after assigning long-named identifiers: {'Midi Through:Midi Through Port-0': [], 'MPK mini:MPK mini MIDI 1': [], 'Neutron(1):Neutron(1) MIDI 1': []}
DEBUG:midi_router:available_long_names before assigning long-named identifiers: {'Midi Through:Midi Through Port-0': ['Midi Through:Midi Through Port-0 14:0'], 'MPK mini:MPK mini MIDI 1': ['MPK mini:MPK mini MIDI 1 24:0'], 'Neutron(1):Neutron(1) MIDI 1': ['Neutron(1):Neutron(1) MIDI 1 28:0']}
DEBUG:midi_router:available_long_names after assigning long-named identifiers: {'Midi Through:Midi Through Port-0': [], 'MPK mini:MPK mini MIDI 1': [], 'Neutron(1):Neutron(1) MIDI 1': []}
DEBUG:midi_router:input_port_names_by_identifier={
  "in_through": "Neutron(1):Neutron(1) MIDI 1 28:0",
  "in_mpk": "Neutron(1):Neutron(1) MIDI 1 28:0",
  "in_neutron": "Neutron(1):Neutron(1) MIDI 1 28:0"
}
DEBUG:midi_router:output_port_names_by_identifier={
  "out_through": "Neutron(1):Neutron(1) MIDI 1 28:0",
  "out_mpk": "Neutron(1):Neutron(1) MIDI 1 28:0",
  "out_neutron": "Neutron(1):Neutron(1) MIDI 1 28:0"
}
DEBUG:midi_router:input_ports_by_identifier={
  "in_through": "Neutron(1):Neutron(1) MIDI 1 28:0",
  "in_mpk": "Neutron(1):Neutron(1) MIDI 1 28:0",
  "in_neutron": "Neutron(1):Neutron(1) MIDI 1 28:0"
}
DEBUG:midi_router:output_ports_by_identifier={
  "out_through": "Neutron(1):Neutron(1) MIDI 1 28:0",
  "out_mpk": "Neutron(1):Neutron(1) MIDI 1 28:0",
  "out_neutron": "Neutron(1):Neutron(1) MIDI 1 28:0"
}
DEBUG:midi_router:mappers_by_input_port_name={
  "Neutron(1):Neutron(1) MIDI 1 28:0": [
    {
      "from_ports": [
        "Neutron(1):Neutron(1) MIDI 1 28:0"
      ],
      "to_ports": [
        "Neutron(1):Neutron(1) MIDI 1 28:0"
      ],
      "transform": "<noop>"
    }
  ]
}
DEBUG:asyncio:Using selector: EpollSelector```
lzulauf commented 2 weeks ago

Ah, your debug output was very helpful! I think I see the bug - it only shows up when you specify an explicit port in the config (as opposed to just the name). I just opened a PR with the fix.

lzulauf commented 2 weeks ago

Can you do a git pull to get the latest code change and try again?

The underlying issue was in code that only runs when you include a port. I've found that the port assignments are unreliable, especially if you disconnect/reconnect devices, so I rarely use them in my config (though, unfortunately, the config generator puts them in by default at the moment).

The fix I just put in should fix that codepath, but you may want to remove the ports from you config as well.

e.g. replace this:

  - identifier: in_mpk
    name: MPK mini:MPK mini MIDI 1
    port: '24:0'
    port_type: USB

with this.

  - identifier: in_mpk
    name: MPK mini:MPK mini MIDI 1
    port_type: USB

It will find the first port that has the given name (regardless of which numerical port number it has).

pmackinney commented 2 weeks ago

Success, works exactly as expected. I did leave the ports in the defs but didn't use them in the mapping.

My procedure: Clean Rasbian Install & configuration, apt update & upgrade. Then:


$ sudo apt install jackd2 libjack-jackd2-dev
$ python3 -m venv midi-router-venv
$ source midi-router-venv/bin/activate
$ git clone https://github.com/lzulauf/MidiRouter
$ cd MidiRouter/
$ pip install -e .
$ midi-router generate-config
Edit config file as previous, ending with
mappings:
- from_port: 
    identifier: in_mpk
  to_port: 
    identifier: out_neutron
$ midi-router -vv start
xcb_connection_has_error() returned true
DEBUG:midi_router:available_long_names before assigning long-named identifiers: {'Midi Through:Midi Through Port-0': ['Midi Through:Midi Through Port-0 14:0'], 'Neutron(1):Neutron(1) MIDI 1': ['Neutron(1):Neutron(1) MIDI 1 24:0'], 'MPK mini:MPK mini MIDI 1': ['MPK mini:MPK mini MIDI 1 28:0']}
DEBUG:midi_router:available_long_names after assigning long-named identifiers: {'Midi Through:Midi Through Port-0': [], 'Neutron(1):Neutron(1) MIDI 1': [], 'MPK mini:MPK mini MIDI 1': []}
DEBUG:midi_router:available_long_names before assigning long-named identifiers: {'Midi Through:Midi Through Port-0': ['Midi Through:Midi Through Port-0 14:0'], 'Neutron(1):Neutron(1) MIDI 1': ['Neutron(1):Neutron(1) MIDI 1 24:0'], 'MPK mini:MPK mini MIDI 1': ['MPK mini:MPK mini MIDI 1 28:0']}
DEBUG:midi_router:available_long_names after assigning long-named identifiers: {'Midi Through:Midi Through Port-0': [], 'Neutron(1):Neutron(1) MIDI 1': [], 'MPK mini:MPK mini MIDI 1': []}
DEBUG:midi_router:input_port_names_by_identifier={
  "in_through": "Midi Through:Midi Through Port-0 14:0",
  "in_neutron": "Neutron(1):Neutron(1) MIDI 1 24:0",
  "in_mpk": "MPK mini:MPK mini MIDI 1 28:0"
}
DEBUG:midi_router:output_port_names_by_identifier={
  "out_through": "Midi Through:Midi Through Port-0 14:0",
  "out_neutron": "Neutron(1):Neutron(1) MIDI 1 24:0",
  "out_mpk": "MPK mini:MPK mini MIDI 1 28:0"
}
DEBUG:midi_router:input_ports_by_identifier={
  "in_through": "Midi Through:Midi Through Port-0 14:0",
  "in_neutron": "Neutron(1):Neutron(1) MIDI 1 24:0",
  "in_mpk": "MPK mini:MPK mini MIDI 1 28:0"
}
DEBUG:midi_router:output_ports_by_identifier={
  "out_through": "Midi Through:Midi Through Port-0 14:0",
  "out_neutron": "Neutron(1):Neutron(1) MIDI 1 24:0",
  "out_mpk": "MPK mini:MPK mini MIDI 1 28:0"
}
DEBUG:midi_router:mappers_by_input_port_name={
  "Midi Through:Midi Through Port-0 14:0": [],
  "Neutron(1):Neutron(1) MIDI 1 24:0": [],
  "MPK mini:MPK mini MIDI 1 28:0": [
    {
      "from_ports": [
        "MPK mini:MPK mini MIDI 1 28:0"
      ],
      "to_ports": [
        "Neutron(1):Neutron(1) MIDI 1 24:0"
      ],
      "transform": "<noop>"
    }
  ]
}
DEBUG:asyncio:Using selector: EpollSelector```
lzulauf commented 2 weeks ago

Glad it worked out!