Esempio n. 1
0
 internal Info(uint index)
 {
     Win32Midi.MIDIINCAPS caps;
     Win32Midi.midiInGetDevCaps(new UIntPtr(index), out caps);
     Index = index;
     Name  = caps.szPname;
 }
Esempio n. 2
0
    public void WriteShort(MidiStatusByte status, byte data1, byte data2)
    {
        Win32Midi.MMRESULT result;

        uint dwMsg = (uint)((byte)status | (data1 << 8) | (data2 << 16));

        Console.WriteLine("Write {0} {1:X2} {2:X2}", status, data1, data2);
        CheckResult(Win32Midi.midiOutShortMsg(Handle, dwMsg));
    }
Esempio n. 3
0
    public MidiOutputDevice(uint deviceIndex)
    {
        var info = new Info(deviceIndex);

        Name = info.Name;

        var openResult = Win32Midi.midiOutOpen(out Handle, new UIntPtr(deviceIndex), null, UIntPtr.Zero, Win32Midi.MidiOpenFlags.CALLBACK_NULL);

        CheckResult(openResult);
    }
Esempio n. 4
0
    public void Dispose()
    {
        lock (this) {
            if (IsDisposed)
            {
                return;
            }

            IsDisposed = true;
            Win32Midi.midiOutClose(Handle);
        }
    }
Esempio n. 5
0
    public unsafe void WriteSysex(byte[] buffer, int?count = null)
    {
        var _count = count.GetValueOrDefault(buffer.Length);

        if (_count > buffer.Length)
            throw new ArgumentException("count");

        fixed(byte *pBuffer = buffer)
        {
            Win32Midi.MIDIHDR header = new Win32Midi.MIDIHDR {
                lpData          = pBuffer,
                dwBufferLength  = (uint)buffer.Length,
                dwBytesRecorded = (uint)_count
            };
            var sizeOfHeader = (uint)Marshal.SizeOf(header);

            CheckResult(Win32Midi.midiOutPrepareHeader(Handle, ref header, sizeOfHeader));
            CheckResult(Win32Midi.midiOutLongMsg(Handle, ref header, sizeOfHeader));
        }
    }
Esempio n. 6
0
    public MidiInputDevice(uint deviceIndex)
    {
        var info = new Info(deviceIndex);

        Name = info.Name;

        SynchronizationContext = SynchronizationContext.Current;
        if (SynchronizationContext == null)
        {
            throw new InvalidOperationException("No synchronization context");
        }

        Callback = _MidiCallback;
        var openResult = Win32Midi.midiInOpen(out Handle, new UIntPtr(deviceIndex), Callback, UIntPtr.Zero, Win32Midi.MidiOpenFlags.CALLBACK_FUNCTION);

        if (openResult != Win32Midi.MMRESULT.MMSYSERR_NOERROR)
        {
            throw new Exception("Opening midi input device failed with " + openResult.ToString());
        }

        Win32Midi.midiInStart(Handle);
    }