Ejemplo n.º 1
0
        private void WriteSysEx(Int32 when, byte[] sysEx)
        {
            var ret = PortMidiMarshal.Pm_WriteSysEx(stream, when, sysEx);

            if (ret != MidiErrorType.NoError)
            {
                throw new MidiException(ret,
                                        $"Failed to write sysEx message : {PortMidiMarshal.Pm_GetErrorText((MidiErrorType) ret)}");
            }
        }
Ejemplo n.º 2
0
        private void Write(Int32 when, MidiMessage msg)
        {
            var ret = PortMidiMarshal.Pm_WriteShort(stream, when, msg);

            if (ret != MidiErrorType.NoError)
            {
                throw new MidiException(ret,
                                        $"Failed to write message {msg.Value} : {PortMidiMarshal.Pm_GetErrorText((MidiErrorType) ret)}");
            }
        }
        public static MidiOutput OpenOutput(PmDeviceID outputDevice)
        {
            PortMidiStream stream;
            var            e = PortMidiMarshal.Pm_OpenOutput(out stream, outputDevice, IntPtr.Zero, 0, null, IntPtr.Zero, 0);

            if (e != PmError.NoError)
            {
                throw new MidiException(e, $"Failed to open MIDI output device {e}");
            }
            return(new MidiOutput(stream, outputDevice, 0));
        }
        private static MidiInput OpenInput(PmDeviceID inputDevice, int bufferSize)
        {
            PortMidiStream stream = default;
            var            e      = PortMidiMarshal.Pm_OpenInput(out stream, inputDevice, IntPtr.Zero, bufferSize, null, IntPtr.Zero);

            if (e != PmError.NoError)
            {
                throw new MidiException(e, $"Failed to open MIDI input device {e}");
            }

            return(new MidiInput(stream, inputDevice));
        }
Ejemplo n.º 5
0
        private void Write(MidiEvent[] buffer, int index, int length)
        {
            var gch = GCHandle.Alloc(buffer);

            try
            {
                var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, index);
                var ret = PortMidiMarshal.Pm_Write(stream, ptr, length);
                if (ret != MidiErrorType.NoError)
                {
                    throw new MidiException(ret,
                                            $"Failed to write messages : {PortMidiMarshal.Pm_GetErrorText((MidiErrorType) ret)}");
                }
            }
            finally
            {
                gch.Free();
            }
        }
Ejemplo n.º 6
0
        public int Read(byte[] buffer, int index, int length)
        {
            var gch = GCHandle.Alloc(buffer);

            try
            {
                var ptr  = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, index);
                int size = PortMidiMarshal.Pm_Read(stream, ptr, length);
                if (size < 0)
                {
                    throw new MidiException((MidiErrorType)size,
                                            PortMidiMarshal.Pm_GetErrorText((MidiErrorType)size));
                }
                return(size * 4);
            }
            finally
            {
                gch.Free();
            }
        }
Ejemplo n.º 7
0
 public void SetChannelMask(int mask)
 {
     PortMidiMarshal.Pm_SetChannelMask(stream, mask);
 }
Ejemplo n.º 8
0
 public void SetFilter(MidiFilter filters)
 {
     PortMidiMarshal.Pm_SetFilter(stream, filters);
 }
Ejemplo n.º 9
0
 public void Dispose()
 {
     PortMidiMarshal.Pm_Close(stream);
 }
Ejemplo n.º 10
0
 public void Abort()
 {
     PortMidiMarshal.Pm_Abort(stream);
 }
 private static MidiDeviceInfo GetDeviceInfo(PmDeviceID id)
 {
     return(new MidiDeviceInfo(id, PortMidiMarshal.Pm_GetDeviceInfo(id)));
 }
 static MidiDeviceManager()
 {
     PortMidiMarshal.Pm_Initialize();
     AppDomain.CurrentDomain.DomainUnload += delegate { PortMidiMarshal.Pm_Terminate(); };
 }