Пример #1
0
        public void WriteSysEx(PmTimestamp when, byte[] sysex)
        {
            var ret = PortMidiMarshal.Pm_WriteSysEx(stream, when, sysex);

            if (ret != PmError.NoError)
            {
                throw new MidiException(ret, String.Format("Failed to write sysex message : {0}", PortMidiMarshal.Pm_GetErrorText((PmError)ret)));
            }
        }
Пример #2
0
 static MidiDeviceManager()
 {
     PortMidiMarshal.Pm_Initialize();
                 #if !PORTABLE // FIXME: what to do for PCLs!?
     AppDomain.CurrentDomain.DomainUnload += delegate(object o, EventArgs e) {
         PortMidiMarshal.Pm_Terminate();
     };
                 #endif
 }
Пример #3
0
        public void Write(PmTimestamp when, MidiMessage msg)
        {
            var ret = PortMidiMarshal.Pm_WriteShort(stream, when, msg);

            if (ret != PmError.NoError)
            {
                throw new MidiException(ret, String.Format("Failed to write message {0} : {1}", msg.Value, PortMidiMarshal.Pm_GetErrorText((PmError)ret)));
            }
        }
Пример #4
0
        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, String.Format("Failed to open MIDI output device {0}", e));
            }
            return(new MidiOutput(stream, outputDevice, 0));
        }
Пример #5
0
        public static MidiInput OpenInput(PmDeviceID inputDevice, int bufferSize)
        {
            PortMidiStream stream;
            var            e = PortMidiMarshal.Pm_OpenInput(out stream, inputDevice, IntPtr.Zero, bufferSize, null, IntPtr.Zero);

            if (e != PmError.NoError)
            {
                throw new MidiException(e, String.Format("Failed to open MIDI input device {0}", e));
            }
            return(new MidiInput(stream, inputDevice));
        }
Пример #6
0
        public 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 != PmError.NoError)
                {
                    throw new MidiException(ret, String.Format("Failed to write messages : {0}", PortMidiMarshal.Pm_GetErrorText((PmError)ret)));
                }
            } finally {
                gch.Free();
            }
        }
Пример #7
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((PmError)size));
                }
                return(size * 4);
            } finally {
                gch.Free();
            }
        }
Пример #8
0
 public static MidiDeviceInfo GetDeviceInfo(PmDeviceID id)
 {
     return(new MidiDeviceInfo(id, PortMidiMarshal.Pm_GetDeviceInfo(id)));
 }
Пример #9
0
 public void SetChannelMask(int mask)
 {
     PortMidiMarshal.Pm_SetChannelMask(stream, mask);
 }
Пример #10
0
 public void SetFilter(MidiFilter filters)
 {
     PortMidiMarshal.Pm_SetFilter(stream, filters);
 }
Пример #11
0
 public void Dispose()
 {
     PortMidiMarshal.Pm_Close(stream);
 }
Пример #12
0
 public void Abort()
 {
     PortMidiMarshal.Pm_Abort(stream);
 }