cardonabits / haxo-rs

Software for the haxophone
MIT License
41 stars 10 forks source link

MIDI output via USB #14

Closed zigmhount closed 9 months ago

zigmhount commented 9 months ago

Hey, Just discovered your project today, and I'm very excited about it! I could not see in the documentation or in the source code anything about MIDI output - my use case would be to plug the haxophone to a computer and record MIDI into a DAW, and call the fluidsynth soundfont (or any other synth) in there. As far as I understand you do send midi notes to the built-in fluidsynth, so I guess it should be pretty easy to just output this via USB, wouldn't it? Have you already considered or planned that (or is it already implemented)?

jcard0na commented 9 months ago

Hi @zigmhount,

Thanks for your encouragement. A few people have asked about MIDI capabilities, and at the moment this is not implemented. But as you point out, it should be relatively easy, as we already send midi notes to fluidsyth. This is the exact line in the code where that happens.

You would need to configure the Raspberry Pi to act as a USB device and then implement a USB midi device class protocol on top of it. This library seems to do the latter, so maybe we could send MIDI to a MIDI host without any hardware modifications, just via the second port on the Raspberry Pi Zero.

At the moment I do not have the bandwidth to try this, but I'll be happy to review any Pull Requests or prototype on my haxophone any code that you might want to try.

Best,

zigmhount commented 9 months ago

Thanks for the quick reply! Unfortunately I know nothing about Rust or this kind of programming, but I'll be happy to try to hack something once I get a bit more time (also not much bandwidth on my side at the moment)! I'll let you know (and I'll probably be asking a ton of questions). In the meantime, knowing that it is technically feasible, I may just start with backing the project on CrowdSupply and order the hardware :)

jcard0na commented 9 months ago

Oh! I think it is feasible, but I cannot be 100% certain until we have prototype it. I'll see if I can run a simple experiment on my end to try to de-risk it. I'd hate you get a haxophone and later learn that it would not be useful for you!

zigmhount commented 9 months ago

Haha, thanks a lot, but no rush! For what it's worth, I had trouble with an Arduino-based controller in the past where the chip in my specific board did not support MIDI-USB, so I had to fall back to MIDI over serial, which also works fine as long as something like ttymidi runs on the connected computer.

jcard0na commented 9 months ago

It looks like I will be the one asking you questions about MIDI in general then... 😉

jcard0na commented 9 months ago

Hi @zigmhount,

Actually the prototyping was easier than expected, and the good news is that I am certain now that it will work without hardware changes, only software.

I was able to load the right kernel drivers on the haxophone to make it appear as a midi device on the host:

lsusb | grep Midi
Bus 002 Device 022: ID 17b3:0004 Grey Innovation Linux-USB Midi Gadget

On the haxophone, this shows up as a midi device:

root@haxophone:/sys/kernel/config/usb_gadget/midi/functions# aplaymidi -l                                         
 Port    Client name                      Port name                                                               
 14:0    Midi Through                     Midi Through Port-0                                                     
 24:0    f_midi                           f_midi     ## <<< That's the one!

Which can be used to play midi files that will be received by the host:

# on the haxophone
aplaymidi -p 24:0 send_to_host.mid

# on the host
arecord -p XX:X from_haxophone.mid

The received file (from_haxophone.mid) is different from the one sent (send_to_host.mid), but both sound identical, which is what we want to confirm that midi events are not corrupted or lost.

The last step would be to send the haxophone's MIDI events via this conduit, which probably can be achieved with the right configuration to libsynth, in other words, without changing the code in Rust.

So yes, feeling good about this...

zigmhount commented 9 months ago

Hahaha awesome, thanks for investigating this! I'll order right away :)

zigmhount commented 9 months ago

Just saw the update on the crowdfunding platform yesterday, looks like you've made good progress with the MIDI implementation, congrats! :) Out of curiosity, can the haxophon convert the air flow speed into midi aftertouch signals for e.g. velocity/volume modulation after the attack? Pitchbend signals according to the pressure on the reed would of course be awesome, but would probably need a sensor in the mouthpiece itself.

Le sam. 9 sept. 2023 à 19:49, Javier Cardona @.***> a écrit :

Hi @zigmhount https://github.com/zigmhount,

Actually the prototyping was easier than expected, and the good news is that I am certain now that it will work without hardware changes, only software.

I was able to load the right kernel drivers on the haxophone to make it appear as a midi device on the host:

lsusb | grep Midi Bus 002 Device 022: ID 17b3:0004 Grey Innovation Linux-USB Midi Gadget

On the haxophone, this shows up as a midi device:

@.***:/sys/kernel/config/usb_gadget/midi/functions# aplaymidi -l Port Client name Port name 14:0 Midi Through Midi Through Port-0 24:0 f_midi f_midi ## <<< That's the one!

Which can be used to play midi files that will be received by the host:

on the haxophone

aplaymidi -p 24:0 send_to_host.mid

on the host

arecord -p XX:X from_haxophone.mid

The received file is different, but sounds identical to the file sent.

The last step would be to send the haxophone's MIDI events via this conduit, which probably can be achieved with the right configuration to libsynth, in other words, without changing the code in Rust.

So yes, feeling good about this...

— Reply to this email directly, view it on GitHub https://github.com/cardonabits/haxo-rs/issues/14#issuecomment-1712564985, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN7MZNTNEZPD5CBT6IXPMGTXZST3HANCNFSM6AAAAAA4RLRSZI . You are receiving this because you were mentioned.Message ID: @.***>

jcard0na commented 9 months ago

Thanks!

Currently the air flow speed (actually pressure) is converted into MIDI Continuous Controller Volume messages. This allows for increasing the volume after the initial attack. In principle you could change that to any other MIDI signal.

Regarding pitch bend, yes, we would need a separate sensor for that. I decided against adding a pitch wheel for simplicity, but I would not object if someone decided to add that to the hardware design.

Cheers,

zigmhount commented 9 months ago

Nice, thanks!

Le mer. 20 sept. 2023 à 16:26, Javier Cardona @.***> a écrit :

Thanks!

Currently the air flow speed (actually pressure) is converted into MIDI Continuous Controller Volume messages https://github.com/cardonabits/haxo-rs/blob/main/src/main.rs#L107-L110. This allows for increasing the volume after the initial attack. In principle you could change that to any other MIDI signal.

Regarding pitch bend, yes, we would need a separate sensor for that. I decided against adding a pitch wheel for simplicity, but I would not object if someone decided to add that to the hardware design.

Cheers,

— Reply to this email directly, view it on GitHub https://github.com/cardonabits/haxo-rs/issues/14#issuecomment-1727842454, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN7MZNRBOT4BMD7ACYYAUH3X3L4IFANCNFSM6AAAAAA4RLRSZI . You are receiving this because you were mentioned.Message ID: @.***>