Click here to Skip to main content
15,881,709 members
Home / Discussions / C#
   

C#

 
QuestionC# MIDI controller interface. Pin
Jumpin' Jeff5-Sep-12 16:38
Jumpin' Jeff5-Sep-12 16:38 
AnswerRe: C# MIDI controller interface. Pin
DaveyM695-Sep-12 22:17
professionalDaveyM695-Sep-12 22:17 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff6-Sep-12 14:26
Jumpin' Jeff6-Sep-12 14:26 
GeneralRe: C# MIDI controller interface. Pin
DaveyM697-Sep-12 0:57
professionalDaveyM697-Sep-12 0:57 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff7-Sep-12 1:36
Jumpin' Jeff7-Sep-12 1:36 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff7-Sep-12 12:42
Jumpin' Jeff7-Sep-12 12:42 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff7-Sep-12 15:04
Jumpin' Jeff7-Sep-12 15:04 
AnswerRe: C# MIDI controller interface. Pin
DaveyM697-Sep-12 22:07
professionalDaveyM697-Sep-12 22:07 
With MIDI In, the procedure is similar. The problem is you have to prepare a MIDIHDR buffer of x size (x is up to you), add it using midiInAddBuffer and that will be returned to you through a MIM_LONGDATA message in a MidiInProc callback - dwParam1 (you will need to cast the IntPtr to int) contains the MIDIHDR (dwParam2 contains the timestamp which you probably don't need). To get a callback, you will need to set CALLBACK_FUNCTION in the dwFlags when using midiInOpen and also call midiInStart.

Checking the dwBytesRecorded (you will need to add a property to expose it) will tell you how much data there actually is in the buffer. The real data can be copied out of the buffer using Marshal.Copy. Don't forget to unprepare the buffer, free the GCHandle and the data pointer! If it is full and the last byte isn't EOX, you will need to quickly add another buffer to get the rest of the sysex data (you can add more than one buffer)!

Once you have all the data and freed everything you can stop and close the input when you're done - one issue though. You may have prepared and added a buffer(s) but received no sysex into it so it's just sitting there. To deal with these you will need to call midiInReset, get the buffers via the callback, unprepare them (and free the GCHandle and data pointer) before calling midiInClose. There is a midiInStop function, this doesn't return unused buffers. I personally call midiInReset, get the buffers in the callback (freeing and unpreparing them) and then call midiInStop to ensure compatibility with all device drivers just in case.

If you get stuck I will happily knock you up some smple code. Based on what I've already given you and this[^] you should be OK though.

Short messages are a doddle. Open, Start, receive MIM_DATA in the callback and extract the bytes from dwParam1, and once you're done Stop (or Reset then Stop) and Close.

Edit: Just checked, calling midiInClose on a MIDI In that still has buffers will not close the device. Instead the function result will be MIDIERR_STILLPLAYING.
Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)




modified 8-Sep-12 4:29am.

GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff8-Sep-12 15:18
Jumpin' Jeff8-Sep-12 15:18 
GeneralRe: C# MIDI controller interface. Pin
DaveyM699-Sep-12 0:03
professionalDaveyM699-Sep-12 0:03 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff10-Sep-12 1:49
Jumpin' Jeff10-Sep-12 1:49 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6915-Sep-12 7:44
professionalDaveyM6915-Sep-12 7:44 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff15-Sep-12 8:58
Jumpin' Jeff15-Sep-12 8:58 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6918-Sep-12 10:31
professionalDaveyM6918-Sep-12 10:31 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff19-Sep-12 5:57
Jumpin' Jeff19-Sep-12 5:57 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff28-Sep-12 9:19
Jumpin' Jeff28-Sep-12 9:19 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6929-Sep-12 3:12
professionalDaveyM6929-Sep-12 3:12 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff29-Sep-12 9:42
Jumpin' Jeff29-Sep-12 9:42 
AnswerRe: C# MIDI controller interface. Pin
DaveyM6930-Sep-12 3:53
professionalDaveyM6930-Sep-12 3:53 
GeneralRe: C# MIDI controller interface. Pin
DaveyM697-Oct-12 2:42
professionalDaveyM697-Oct-12 2:42 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff8-Oct-12 1:21
Jumpin' Jeff8-Oct-12 1:21 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff10-Oct-12 3:46
Jumpin' Jeff10-Oct-12 3:46 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6910-Oct-12 14:13
professionalDaveyM6910-Oct-12 14:13 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff11-Oct-12 1:49
Jumpin' Jeff11-Oct-12 1:49 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff11-Oct-12 2:13
Jumpin' Jeff11-Oct-12 2:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.