# MIDI detection



## vertexSymphony (Aug 31, 2010)

Hi everyone !
I'm pretty new to FreeBSD programming, so now I'm looking for some material to read about how to detect a usb midi device and naturally, do some read/write ... libusb/libusb20 could do, right ? caveats of that ? what about oss ? (even if I can't get my keyboard detected through oss)

Thanks for your time, Alex


----------



## davidgurvich (Aug 31, 2010)

I don't know what hardware is supported by the base system oss drivers.  You might need to look at the oss drivers in ports.  You might also want to post the exact hardware you are using.


----------



## vertexSymphony (Aug 31, 2010)

Hi david, thanks for your reply ... 

Actually I forgot to mention that I'm writing this in C (and that I'm porting an application)
I've just wrote the OSS part, but for the usb part ... Well, the libusb manpages really get me lost :(

About the keyboard ... well, I'm testing with a CASIO CTK-4000 and I'm actually using snd_uaudio() to get it working and do some read/write, no OSS support though :(

Thanks again, Alex.


----------



## kdemidofff (Sep 1, 2010)

usb stack seems a bit hacky on FreeBSD frame, not because its broken or smth
prooly better to do some make's here; thanks!



> paying for music is a crime in some areas; u can use windows based toolboxes to make final product etc


----------



## expl (Sep 1, 2010)

Does snd_uaudio driver detect and create device file(s) for your MIDI keyboard? It should. If it doesn't, submit a PR with debugging information. You can forget OSS because its incompatible with the new USB stack (nothing that uses USB will work with OSS).


----------



## honk (Sep 2, 2010)

I'm interested in this topic, too. Some time ago I tried to figure out the current status about approaches to make FreeBSD capable to communicate with MIDI-devices. Saw some information's about a new USB-stack (Petter Selasky?!) including support for USB-MIDI devices. But I was unable to find out what works and what not.

Today I tried the following:

`# kldload snd_uaudio`

Dmesg shows the following output after I connected my Korg microKontrol (MIDI-keyboard with USB-MIDI-interface) :

```
ugen3.2: <KORG INC.> at usbus3
```

It creates device-nodes:

```
crw-------  1 root  operator    0, 109 Sep  2 00:55 /dev/usb/3.2.0
crw-------  1 root  operator    0, 111 Sep  2 00:55 /dev/usb/3.2.2
```

If I try to read from /dev/usb/3.2.2 I get the following output:


```
# hexdump -C /dev/usb/3.2.2
00000000  1f f8 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.Ã¸..............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000040  1f f8 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.Ã¸..............|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000080  1f f8 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.Ã¸..............|
00000090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000000c0  1f f8 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.Ã¸..............|
000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
```

What does this mean? My keyboard is talking MIDI with my FreeBSD-system??? I got other bits when pressing the keys!  Would be happy if someone could enlighten me! What are the next steps, what can I do now? Can I send SysEx data to another midi-device this way? Is this the time where I should start studying how the MIDI-protocol works on bit-level?


----------



## vertexSymphony (Sep 2, 2010)

@expl:
Yes, it works perfectly ... I'm able to read/write through the corresponding device node (/dev/umidi0.0), the thing that I want to do is to detect MIDI devices in C ...
and, I want to be as generic as possible (oss and usb, but if oss is not recommended, I could go only with usb) because I'm trying to port Canorus (fortunately, I'm with luck and is pretty easy to port)

I was reading about libusb, but, I'm not getting the manpages (and googled with no luck) and asked to see if someone could help me with enumerating devices and checking if it's a midi device ...

Thanks for your time !

@honk: 

AFAIK the USB midi stack is not that new, I mean, I remember that I found in google a mail from 2007 or 2006 maybe ?
And yes, what you're getting there is the data that the keyboard sends to your system 
you can send data to the keyboard also (I've already did it sucessfully with the implementation manual that came with the keyboard)

Alex.


----------



## hselasky@ (Sep 2, 2010)

Hi,

There is dedicated MIDI software available for FreeBSD, which is not yet in ports. You can checkout the sources using:


```
svn --username anonsvn --password anonsvn \
      checkout svn://svn.turbocat.net/i4b/trunk/libumidi20

svn --username anonsvn --password anonsvn \
      checkout svn://svn.turbocat.net/i4b/trunk/midipp

svn --username anonsvn --password anonsvn \
      checkout svn://svn.turbocat.net/i4b/trunk/ssynth
```

Dependencies: QT4.x

After build and install:

`mkfifo /midi`

`chown XXX:XXX /midi`

Then you can for example start a software synth, like fluidsynth (which might need some additional patches to interact better with midipp), on /midi which will then communicate with midipp. midipp will connect to the /dev/umidiX.Y. Or you can use midipp alone. Just make sure that local keys feature is off in midipp, because midipp already loops back the required MIDI events.

Good luck!

--HPS


----------



## flyweight (Feb 23, 2011)

Hi hselasky,

This is very good news. Going to try it when I get home.

I am running a FreeBSD box with Absynth, Alchemy. I use SAVIHOST to run the vst plugins. You can use your keypads to play notes, this way I can use it for sound design. 

But music production is very limited on linux and BSD. The problem is that wine doesn't support midi. If FreeBSD got a working midistack and maybe some midi usb interface, then it becomes usable in the studio. But there must be a translation to alsa and to wine because there is no midi suporting audio software in the ports.

I understand that FreeBSD isn't a media platform. but I see why a midi and good audio stack will be conflicting with the way FreeBSD is going.


----------



## hselasky@ (Feb 24, 2011)

*Updated install instructions for MIDIPP*

Hi,

There are updated install instructions available at:

http://www.selasky.org/hans_petter/midistudio

And demo music and video!

--HPS


----------

