Click here to Skip to main content
15,171,664 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6911-Oct-12 8:18
professionalDaveyM6911-Oct-12 8:18 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff11-Oct-12 9:21
MemberJumpin' Jeff11-Oct-12 9:21 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6911-Oct-12 11:40
professionalDaveyM6911-Oct-12 11:40 
OK, as simple as I can make it. MIDI input (without SysEx), no error checking:
C#
using System;
using System.Runtime.InteropServices;

class Program
{
    private static MidiTest midiTest;

    static void Main(string[] args)
    {
        midiTest = new MidiTest();
        midiTest.Start();
        Console.ReadKey();
        midiTest.Stop();
    } 
}

internal class MidiTest
{
    private delegate void MidiInProc(IntPtr hMidiIn, int wMsg, IntPtr dwInstance, IntPtr dwParam1, IntPtr dwParam2);

    private IntPtr handle;
    private MidiInProc callback;

    public void Start()
    {
        callback = new MidiInProc(Callback);
        midiInOpen(out handle, 0, callback, IntPtr.Zero, 0x00030000); // 0x00030000 = callback is a function (delegate)
        midiInStart(handle);
    }
    public void Stop()
    {
        midiInStop(handle);
        midiInClose(handle);
        handle = IntPtr.Zero;
        callback = null;
    }
    private void Callback(IntPtr hMidiIn, int wMsg, IntPtr dwInstance, IntPtr dwParam1, IntPtr dwParam2)
    {
        switch (wMsg)
        {
            case 0x3C3: // Short message received
                int data = (int)dwParam1;
                int timestamp = (int)dwParam2;
                break;
        }
    }

    [DllImport("Winmm.dll")]
    private static extern int midiInOpen(out IntPtr lphMidiIn, int uDeviceID, MidiInProc dwCallback, IntPtr dwCallbackInstance, int dwFlags);
    [DllImport("Winmm.dll")]
    private static extern int midiInStart(IntPtr hMidiIn);
    [DllImport("Winmm.dll")]
    private static extern int midiInStop(IntPtr hMidiIn);
    [DllImport("Winmm.dll")]
    private static extern int midiInClose(IntPtr hMidiIn);
}

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)



GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff12-Oct-12 2:42
MemberJumpin' Jeff12-Oct-12 2:42 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6911-Oct-12 11:51
professionalDaveyM6911-Oct-12 11:51 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff11-Oct-12 15:34
MemberJumpin' Jeff11-Oct-12 15:34 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff11-Oct-12 11:20
MemberJumpin' Jeff11-Oct-12 11:20 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6911-Oct-12 11:52
professionalDaveyM6911-Oct-12 11:52 
GeneralRe: C# MIDI controller interface. Pin
DaveyM692-Nov-12 9:54
professionalDaveyM692-Nov-12 9:54 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff2-Nov-12 13:23
MemberJumpin' Jeff2-Nov-12 13:23 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff16-Nov-12 6:36
MemberJumpin' Jeff16-Nov-12 6:36 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6916-Nov-12 7:22
professionalDaveyM6916-Nov-12 7:22 
GeneralRe: C# MIDI controller interface. Pin
Jumpin' Jeff16-Nov-12 14:17
MemberJumpin' Jeff16-Nov-12 14:17 
GeneralRe: C# MIDI controller interface. Pin
DaveyM6916-Nov-12 21:32
professionalDaveyM6916-Nov-12 21:32 
QuestionC# 2008 with linq reference problem Pin
dcof5-Sep-12 13:17
Memberdcof5-Sep-12 13:17 
AnswerRe: C# 2008 with linq reference problem Pin
Shameel5-Sep-12 21:35
professionalShameel5-Sep-12 21:35 
QuestionLoosley Coupled Events Pin
Member 81371055-Sep-12 11:21
MemberMember 81371055-Sep-12 11:21 
AnswerRe: Loosley Coupled Events Pin
Pete O'Hanlon5-Sep-12 11:27
mvaPete O'Hanlon5-Sep-12 11:27 
GeneralRe: Loosley Coupled Events Pin
Member 81371055-Sep-12 11:30
MemberMember 81371055-Sep-12 11:30 
GeneralRe: Loosley Coupled Events Pin
Pete O'Hanlon5-Sep-12 11:33
mvaPete O'Hanlon5-Sep-12 11:33 

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.