adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
530 stars 127 forks source link

Midi input from keyboard #281

Closed andre2007 closed 3 years ago

andre2007 commented 3 years ago

In a "this week in D" article I saw you work on a midi keyboard teaching program. By chance I was looking into the midi module from you to see whether i can use to use it with my e-piano. From your article I understand I can use it for midi input from a physical device (usb cable). Do you have by chance some sample coding to get started?

adamdruppe commented 3 years ago

I'll post my little program up here later but the core of it is fairly simple:

                MidiInput mi = MidiInput("hw:4,0"); // string dfevice name on Linux, on Windows it just always uses the default device which probably just works anyway, it does on my computer, so i never implemented device switching

                // so im not supposed to call a midi out function from inside the callback...
                mi.record((ts, status, data1, data2) {
                        // time stamp, midi status, data1 data 2 make up the midi message
              });

Of course doing stuff with the messages gets trickier but even this minimal thing should give you something to writeln to prove it works with your hardware too.

andre2007 commented 3 years ago

Fantastic, thanks a lot!

adamdruppe commented 3 years ago

This is my very much work-in-progress program:

midi.zip

shoud be able to compile with dmd -i midi.d with the arsd directory in the search path.

Run it as midi.exe program.mid to play one (I included one midi you can try) or midi.exe record with a midi device plugged in to see it respond to your key presses on the midi hardware.

Tons of bugs, I wanted to go back and work on it more after the blog but have just been too busy with other things.

andre2007 commented 3 years ago

Fantastic, thank you so much!

adamdruppe commented 3 years ago

lemme know if you get it all working.

andre2007 commented 3 years ago

I started the midi app as single dub package and it was working fine. The app already looks really great! Thank you so much.