Пример #1
0
        public bool Close()
        {
            if (this._device == IntPtr.Zero)
            {
                return(true);
            }
            this._closing = true;
            bool started = this._started;

            this._lastError = Midi.MIDI_InReset(this._device);
            if (this._lastError == MIDIError.MIDI_OK)
            {
                this._started = false;
                if (started)
                {
                    this.RaiseMessageReceived(MidiMessageEventType.Stopped, null);
                }
            }
            this._lastError = Midi.MIDI_InClose(this._device);
            if (this._lastError == MIDIError.MIDI_OK)
            {
                this._device = IntPtr.Zero;
            }
            this._closing = false;
            return(this._device == IntPtr.Zero);
        }
Пример #2
0
 public bool Send(int shortMessage)
 {
     if (!this.IsOpened)
     {
         return(false);
     }
     this._lastError = Midi.MIDI_OutShortMsg(this._device, shortMessage);
     return(this._lastError == MIDIError.MIDI_OK);
 }
Пример #3
0
 public bool Disconnect(IntPtr handleFrom)
 {
     if (this._disposing)
     {
         return(false);
     }
     this._lastError = Midi.MIDI_Disconnect(this._device, handleFrom);
     return(this._lastError == MIDIError.MIDI_OK);
 }
Пример #4
0
        public static MIDI_OUTCAPS GetInfo(int deviceID)
        {
            MIDI_OUTCAPS midi_OUTCAPS = new MIDI_OUTCAPS();

            if (Midi.MIDI_OutGetDevCaps(deviceID, midi_OUTCAPS) == MIDIError.MIDI_OK)
            {
                return(midi_OUTCAPS);
            }
            return(null);
        }
Пример #5
0
        public static string GetDeviceDescription(int deviceID)
        {
            MIDI_OUTCAPS midi_OUTCAPS = new MIDI_OUTCAPS();

            if (Midi.MIDI_OutGetDevCaps(deviceID, midi_OUTCAPS) == MIDIError.MIDI_OK)
            {
                return(midi_OUTCAPS.name);
            }
            return(null);
        }
Пример #6
0
        public static MIDIError MIDI_OutOpen(ref IntPtr handle, int deviceID, MIDIOUTPROC proc, IntPtr user)
        {
            MIDIFlags flags = MIDIFlags.MIDI_CALLBACK_FUNCTION;

            if (proc == null)
            {
                flags = MIDIFlags.MIDI_CALLBACK_NULL;
            }
            return(Midi.midiOutOpen(ref handle, new IntPtr(deviceID), proc, user, flags));
        }
Пример #7
0
        public bool Send(byte status, byte data1, byte data2)
        {
            if (!this.IsOpened)
            {
                return(false);
            }
            MidiShortMessage midiShortMessage = new MidiShortMessage(status, data1, data2, 0, 0L);

            this._lastError = Midi.MIDI_OutShortMsg(this._device, midiShortMessage.Message);
            return(this._lastError == MIDIError.MIDI_OK);
        }
Пример #8
0
 public static MIDIError MIDI_InOpen(ref IntPtr handle, int deviceID, MIDIINPROC proc, IntPtr user, MIDIFlags flags)
 {
     if (proc == null)
     {
         flags = MIDIFlags.MIDI_CALLBACK_NULL;
     }
     else
     {
         flags |= MIDIFlags.MIDI_CALLBACK_FUNCTION;
     }
     return(Midi.midiInOpen(ref handle, new IntPtr(deviceID), proc, user, flags));
 }
Пример #9
0
        private bool PrepareHeader(bool input, IntPtr handle, IntPtr headerPtr)
        {
            MIDIError midierror = MIDIError.MIDI_OK;

            if (headerPtr != IntPtr.Zero)
            {
                if (input)
                {
                    midierror = Midi.MIDI_InPrepareHeader(handle, headerPtr);
                }
                else
                {
                    midierror = Midi.MIDI_OutPrepareHeader(handle, headerPtr);
                }
            }
            if (midierror != MIDIError.MIDI_OK)
            {
                MIDIHDR midihdr = null;
                try
                {
                    midihdr = (MIDIHDR)Marshal.PtrToStructure(headerPtr, typeof(MIDIHDR));
                }
                catch
                {
                }
                if (midihdr != null)
                {
                    try
                    {
                        if (midihdr.data != IntPtr.Zero)
                        {
                            Marshal.FreeHGlobal(midihdr.data);
                        }
                    }
                    catch
                    {
                    }
                    midihdr.data = IntPtr.Zero;
                    try
                    {
                        if (headerPtr != IntPtr.Zero)
                        {
                            Marshal.FreeHGlobal(headerPtr);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            return(midierror == MIDIError.MIDI_OK);
        }
Пример #10
0
 public bool Send(MidiSysExMessage sysexMessage)
 {
     if (!this.IsOpened || sysexMessage.IsInput || sysexMessage.Device != this.Device || sysexMessage.IsPrepared)
     {
         return(false);
     }
     if (sysexMessage.Prepare(this._user))
     {
         this._lastError = Midi.MIDI_OutLongMsg(this._device, sysexMessage.MessageAsIntPtr);
         return(this._lastError == MIDIError.MIDI_OK);
     }
     return(false);
 }
Пример #11
0
 public bool Close()
 {
     if (this._device == IntPtr.Zero)
     {
         return(true);
     }
     Midi.MIDI_OutReset(this._device);
     this._lastError = Midi.MIDI_OutClose(this._device);
     if (this._lastError == MIDIError.MIDI_OK)
     {
         this._device = IntPtr.Zero;
     }
     return(this._device == IntPtr.Zero);
 }
Пример #12
0
        private void UnprepareHeader(bool input, IntPtr handle, IntPtr headerPtr)
        {
            if (headerPtr == IntPtr.Zero)
            {
                return;
            }
            MIDIHDR midihdr = null;

            try
            {
                midihdr = (MIDIHDR)Marshal.PtrToStructure(headerPtr, typeof(MIDIHDR));
            }
            catch
            {
            }
            if (midihdr != null)
            {
                try
                {
                    if (input)
                    {
                        Midi.MIDI_InUnprepareHeader(handle, headerPtr);
                    }
                    else
                    {
                        Midi.MIDI_OutUnprepareHeader(handle, headerPtr);
                    }
                }
                catch
                {
                }
                try
                {
                    if (midihdr.data != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(midihdr.data);
                    }
                }
                catch
                {
                }
                try
                {
                    Marshal.FreeHGlobal(headerPtr);
                }
                catch
                {
                }
            }
        }
Пример #13
0
        public static string MIDI_GetErrorText(bool input, int errCode)
        {
            StringBuilder stringBuilder = new StringBuilder(128);

            if (input)
            {
                Midi.midiInGetErrorText(errCode, stringBuilder, stringBuilder.Capacity);
            }
            else
            {
                Midi.midiOutGetErrorText(errCode, stringBuilder, stringBuilder.Capacity);
            }
            return(stringBuilder.ToString());
        }
Пример #14
0
        public static int[] GetMidiPorts()
        {
            List <int>  list = new List <int>();
            int         num  = Midi.MIDI_InGetNumDevs();
            MIDI_INCAPS caps = new MIDI_INCAPS();

            for (int i = 0; i < num; i++)
            {
                if (Midi.MIDI_InGetDevCaps(i, caps) == MIDIError.MIDI_OK)
                {
                    list.Add(i);
                }
            }
            return(list.ToArray());
        }
Пример #15
0
        public static int[] GetMidiPorts()
        {
            List <int>   list         = new List <int>();
            int          num          = Midi.MIDI_OutGetNumDevs();
            MIDI_OUTCAPS midi_OUTCAPS = new MIDI_OUTCAPS();

            for (int i = 0; i < num; i++)
            {
                if (Midi.MIDI_OutGetDevCaps(i, midi_OUTCAPS) == MIDIError.MIDI_OK && midi_OUTCAPS.IsMidiPort)
                {
                    list.Add(i);
                }
            }
            return(list.ToArray());
        }
Пример #16
0
        public static string[] GetDeviceDescriptions()
        {
            List <string> list         = new List <string>();
            int           num          = Midi.MIDI_OutGetNumDevs();
            MIDI_OUTCAPS  midi_OUTCAPS = new MIDI_OUTCAPS();

            for (int i = 0; i < num; i++)
            {
                if (Midi.MIDI_OutGetDevCaps(i, midi_OUTCAPS) == MIDIError.MIDI_OK)
                {
                    list.Add(midi_OUTCAPS.name);
                }
            }
            return(list.ToArray());
        }
Пример #17
0
 public bool Open()
 {
     if (this._disposing)
     {
         return(false);
     }
     if (this._device != IntPtr.Zero)
     {
         return(true);
     }
     this._lastError = Midi.MIDI_OutOpen(ref this._device, this._deviceID, this._midiOutProc, new IntPtr(this._deviceID));
     if (this._lastError != MIDIError.MIDI_OK)
     {
         this._device = IntPtr.Zero;
     }
     return(this._device != IntPtr.Zero);
 }
Пример #18
0
        public bool Send()
        {
            if (this._headerPtr == IntPtr.Zero)
            {
                return(false);
            }
            MIDIError midierror;

            if (this._input)
            {
                midierror = Midi.MIDI_InAddBuffer(this._device, this._headerPtr);
            }
            else
            {
                midierror = Midi.MIDI_OutLongMsg(this._device, this._headerPtr);
            }
            return(midierror == MIDIError.MIDI_OK);
        }
Пример #19
0
        public bool Send(IEnumerable <byte> sysexMessage)
        {
            if (!this.IsOpened || sysexMessage == null)
            {
                return(false);
            }
            MidiSysExMessage midiSysExMessage = new MidiSysExMessage(false, this._device);

            if (!midiSysExMessage.CreateBuffer(sysexMessage))
            {
                return(false);
            }
            if (midiSysExMessage.Prepare(this._user))
            {
                this._lastError = Midi.MIDI_OutLongMsg(this._device, midiSysExMessage.MessageAsIntPtr);
                return(this._lastError == MIDIError.MIDI_OK);
            }
            return(false);
        }
Пример #20
0
 public bool Stop()
 {
     if (this._device == IntPtr.Zero)
     {
         return(true);
     }
     if (!this._started)
     {
         return(true);
     }
     this._closing   = true;
     this._lastError = Midi.MIDI_InStop(this._device);
     if (this._lastError == MIDIError.MIDI_OK)
     {
         this._started = false;
         this.FlushShortMsgStack();
         this.RaiseMessageReceived(MidiMessageEventType.Stopped, null);
     }
     this._closing = false;
     return(!this._started);
 }
Пример #21
0
 public bool Open()
 {
     if (this._disposing)
     {
         return(false);
     }
     if (this._device != IntPtr.Zero)
     {
         return(true);
     }
     this._lastError = Midi.MIDI_InOpen(ref this._device, this._deviceID, this._midiInProc, new IntPtr(this._deviceID), MIDIFlags.MIDI_IO_STATUS);
     if (this._lastError != MIDIError.MIDI_OK)
     {
         this._device = IntPtr.Zero;
     }
     else
     {
         this._shortMsgOnStack = null;
     }
     return(this._device != IntPtr.Zero);
 }
Пример #22
0
 public bool Start()
 {
     if (this._disposing)
     {
         return(false);
     }
     if (this._started)
     {
         return(true);
     }
     this.AddSysExBuffer();
     this.AddSysExBuffer();
     this._lastError = Midi.MIDI_InStart(this._device);
     if (this._lastError == MIDIError.MIDI_OK)
     {
         this._started = true;
         this.RaiseMessageReceived(MidiMessageEventType.Started, null);
     }
     else
     {
         Midi.MIDI_InReset(this._device);
     }
     return(this._started);
 }
Пример #23
0
 public static MIDIError MIDI_InClose(IntPtr handle)
 {
     return(Midi.midiInClose(handle));
 }
Пример #24
0
 public static int GetDeviceCount()
 {
     return(Midi.MIDI_OutGetNumDevs());
 }
Пример #25
0
 public static MIDIError MIDI_InAddBuffer(IntPtr handle, IntPtr headerPtr)
 {
     return(Midi.midiInAddBuffer(handle, headerPtr, Marshal.SizeOf(typeof(MIDIHDR))));
 }
Пример #26
0
 public static MIDIError MIDI_OutUnprepareHeader(IntPtr handle, IntPtr headerPtr)
 {
     return(Midi.midiOutUnprepareHeader(handle, headerPtr, Marshal.SizeOf(typeof(MIDIHDR))));
 }
Пример #27
0
 public static int MIDI_OutMessage(IntPtr handle, MIDIMessage msg, IntPtr param1, IntPtr param2)
 {
     return(Midi.midiOutMessage(handle, msg, param1, param2));
 }
Пример #28
0
 public static int MIDI_InGetNumDevs()
 {
     return(Midi.midiInGetNumDevs());
 }
Пример #29
0
 public static MIDIError MIDI_OutGetDevCaps(int deviceID, MIDI_OUTCAPS caps)
 {
     return(Midi.midiOutGetDevCaps(new IntPtr(deviceID), caps, Marshal.SizeOf(typeof(MIDI_OUTCAPS))));
 }
Пример #30
0
 public static int MIDI_OutGetNumDevs()
 {
     return(Midi.midiOutGetNumDevs());
 }