I'm hoping to use the Bela to take MIDI inputs from the mini-USB port and output them at the USB-A port, using Pd. The project I'm working on happens to be using a Bela and an Arduino both receiving MIDI, so it would be nice to be able to daisy chain them.

Anyway, I did some searching and found how to use the mini-USB for MIDI input, and that is now working. I can send notes to the mini-USB port and my Pd patch sees them.

I know that MIDI ports are determined by channels. The output of amidi -l for me is:

IO  hw:0,0    f_midi
IO  hw:1,0,0 Fastlane MIDI A
IO  hw:1,0,1 Fastlane MIDI B

The Fastlane is what converts USB MIDI to 5-pin MIDI for the Arduino. Fastlane is connected to the USB-A port, f_midi is the mini-USB port.

When I run my project, it tells me that hw:1,0,0 (Fastlane) is Pd channels 0-15, but this page of Pd documentation suggests otherwise:

channel "17" in Pd means midi channel 1 in port 2

so Pd works in terms of 1-16, not 0-15. I know that from experience because [notein 0] works as omni.

But there's still more confusion. I put the following in _main.pd:

[notein 16]
 |
[nouteout 32]

Based on what the Bela says for the two ports, and knowing that Pd 1-16 is Bela 0-15, this should actually take in notes from the Fastlane (hw:1,0,0) and output to the mini-USB (hw:0,0,0). But what I actually see is that it's taking in notes from the mini-USB and (as far as I can tell) not outputting anything to the Fastlane.

What's going on here? Is there a way to get this working?

Thanks!

I think I've figured out some of the confusion. I made the following patch to cycle through various channels: alt text

This was the output running it on the Bela:

 Num                Name  In Out Pd channels
[ 0]            hw:1,0,0   x   x (0-15)
bonk version 1.5
fiddle version 1.1 TEST4
pique 0.1 for PD version 23
sigmund~ version 0.07
noteout _ port: 0, channel: 0, pitch: 60, velocity 127
Pd channel: 1
----------------
noteout _ port: 0, channel: 1, pitch: 60, velocity 127
Pd channel: 2
----------------
noteout _ port: 0, channel: 2, pitch: 60, velocity 127
Pd channel: 3
----------------
noteout _ port: 0, channel: 3, pitch: 60, velocity 127
Pd channel: 4
----------------
noteout _ port: 0, channel: 4, pitch: 60, velocity 127
Pd channel: 5
----------------
noteout _ port: 0, channel: 5, pitch: 60, velocity 127
Pd channel: 6
----------------
noteout _ port: 0, channel: 6, pitch: 60, velocity 127
Pd channel: 7
----------------
noteout _ port: 0, channel: 7, pitch: 60, velocity 127
Pd channel: 8
----------------

...

noteout _ port: 0, channel: 14, pitch: 60, velocity 127
Pd channel: 15
----------------
noteout _ port: 0, channel: 15, pitch: 60, velocity 127
Pd channel: 16
----------------
noteout _ port: 0, channel: 16, pitch: 60, velocity 127
Pd channel: 17
----------------
noteout _ port: 1, channel: 1, pitch: 60, velocity 127
Pd channel: 18
----------------
noteout _ port: 1, channel: 2, pitch: 60, velocity 127
Pd channel: 19
----------------
noteout _ port: 1, channel: 3, pitch: 60, velocity 127
Pd channel: 20
----------------

...

noteout _ port: 1, channel: 14, pitch: 60, velocity 127
Pd channel: 31
----------------
noteout _ port: 1, channel: 15, pitch: 60, velocity 127
Pd channel: 32
----------------
noteout _ port: 1, channel: 16, pitch: 60, velocity 127
Pd channel: 33
----------------
noteout _ port: 2, channel: 1, pitch: 60, velocity 127
Pd channel: 34
----------------
noteout _ port: 2, channel: 2, pitch: 60, velocity 127
Pd channel: 35
----------------

etc. So there's a mismatch here. I thought there were only 16 channels, and it was 0-15 on the Bela, 1-16 in Pd. But in actuality, the Bela outputs 17 channels; 0-16 for port 0, 17-33 for port 1, etc. Very odd. I'll change my patches to reflect this knowledge and I'll report back if it works.

EDIT: Just for the sake of completion, it should be noted that for [notein], cycling through the channels shows that the Bela sees inputs from 0-15 (port 0) and 16-31 (port 1), so this isn't just me not knowing--this is a strange inconsistency between [notein] and [noteout]. Whether it's Pd's fault or Bela's fault, I don't know.

EDIT2: Unless channel 0 for [nouteout] is omni, in which case it makes sense that it would be there? 1-16 plus omni for each port gives 17 "channels" per port. Is that a thing?

UPDATE: I got this working!

So to clarify the setup, I have a DAW outputting MIDI to the Bela through the Bela's mini-USB port. I have channels 1-4 of that port being used for a synth, and I'm using [noteout] to pass channel 16 of that port through to the USB-A port, which is the outputting in turn to the Fastlane.

To make this work, I have the synth using [notein 17] through [notein 20]. For passthrough, I have [notein 32] and [noteout 16]. I tried [noteout 17] and the Bela claimed to be outputting on channel 16 (not 15) the correct port, but nothing got through. So it seems the Bela can handle [noteout 1] (Bela 0) through [noteout 16] (Bela 15) correctly. That means the following is true:

Pd notein channel    Pd noteout channel   Bela input channel    Bela output channel
1                    1                    0, port 0             0, port 0
16                   16                   15, port 0            15, port 0
17                   17                   0, port 1             16, port 0 (Doesn't work?)
18                   18                   1, port 1             0, port 1

So my problem is solved, but is this a bug with the Pd/Bela, or is this intended behavior? Just wondering.

Probably a bug, I will check on it.
The source of confusion is the MIDI standard itself, which, confusingly, defines byte 0x00 to be channel 1, 0x01 to be channel 2 and so on.

libpd (which is what we use to run Pd on Bela) uses 0-15 indexing for the MIDI channels (to mirror the way they are represented in the actual MIDI messages), while Pd uses 1-16 (which is the way they are supposed to be presented to the user according to the standard). So in the Bela wrapper for libpd we are compensating for those behaviours so to make it the same as Pd expects them (so that the patches can run without modifications), and so probably I did something wrong when applying this to the outputs 🙂

https://github.com/BelaPlatform/Bela/issues/564