Click here to Skip to main content
15,125,273 members
Home / Discussions / C#
   

C#

 
QuestionC# MIDI controller interface. Pin
Jumpin' Jeff5-Sep-12 17:38
MemberJumpin' Jeff5-Sep-12 17:38 
AnswerRe: C# MIDI controller interface. Pin
DaveyM695-Sep-12 23:17
professionalDaveyM695-Sep-12 23:17 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff6-Sep-12 15:26
MemberJumpin' Jeff6-Sep-12 15:26 
GeneralRe: C# MIDI controller interface. Pin
DaveyM697-Sep-12 1:57
professionalDaveyM697-Sep-12 1:57 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff7-Sep-12 2:36
MemberJumpin' Jeff7-Sep-12 2:36 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff7-Sep-12 13:42
MemberJumpin' Jeff7-Sep-12 13:42 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff7-Sep-12 16:04
MemberJumpin' Jeff7-Sep-12 16:04 
AnswerRe: C# MIDI controller interface. Pin
DaveyM697-Sep-12 23:07
professionalDaveyM697-Sep-12 23: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 16:18
MemberJumpin' Jeff8-Sep-12 16:18 
GeneralRe: C# MIDI controller interface. Pin
DaveyM699-Sep-12 1:03
professionalDaveyM699-Sep-12 1:03 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff10-Sep-12 2:49
MemberJumpin' Jeff10-Sep-12 2:49 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6915-Sep-12 8:44
professionalDaveyM6915-Sep-12 8:44 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff15-Sep-12 9:58
MemberJumpin' Jeff15-Sep-12 9:58 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6918-Sep-12 11:31
professionalDaveyM6918-Sep-12 11:31 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff19-Sep-12 6:57
MemberJumpin' Jeff19-Sep-12 6:57 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff28-Sep-12 10:19
MemberJumpin' Jeff28-Sep-12 10:19 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6929-Sep-12 4:12
professionalDaveyM6929-Sep-12 4:12 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff29-Sep-12 10:42
MemberJumpin' Jeff29-Sep-12 10:42 
AnswerRe: C# MIDI controller interface. Pin
DaveyM6930-Sep-12 4:53
professionalDaveyM6930-Sep-12 4:53 
GeneralRe: C# MIDI controller interface. Pin
DaveyM697-Oct-12 3:42
professionalDaveyM697-Oct-12 3:42 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff8-Oct-12 2:21
MemberJumpin' Jeff8-Oct-12 2:21 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff10-Oct-12 4:46
MemberJumpin' Jeff10-Oct-12 4:46 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6910-Oct-12 15:13
professionalDaveyM6910-Oct-12 15:13 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff11-Oct-12 2:49
MemberJumpin' Jeff11-Oct-12 2:49 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff11-Oct-12 3:13
MemberJumpin' Jeff11-Oct-12 3: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.