Пример #1
0
        public bool AddSysExBuffer()
        {
            if (this._closing)
            {
                return(true);
            }
            if (this._device == IntPtr.Zero || this._disposing)
            {
                return(false);
            }
            bool result = false;

            try
            {
                MidiSysExMessage midiSysExMessage = new MidiSysExMessage(true, this._device);
                midiSysExMessage.CreateBuffer(this._sysexBufferSize);
                if (midiSysExMessage.Prepare(this._user))
                {
                    result = midiSysExMessage.Send();
                }
            }
            catch
            {
            }
            return(result);
        }
Пример #2
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);
 }
Пример #3
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);
        }
Пример #4
0
        public MidiSysExMessage(bool input, IntPtr handle, IntPtr headerPtr, MidiSysExMessage previous)
        {
            this.InitID();
            this._input  = input;
            this._device = handle;
            MIDI_HEADER midi_HEADER = new MIDI_HEADER(headerPtr);

            if (midi_HEADER.IsDone)
            {
                this._user = midi_HEADER.User;
                if (previous == null || previous.IsDone)
                {
                    this._data = midi_HEADER.Data;
                }
                else
                {
                    byte[] data = midi_HEADER.Data;
                    if (data == null && previous.Message != null)
                    {
                        this._data = new byte[previous.Message.Length];
                        Array.Copy(previous.Message, 0, this._data, 0, previous.Message.Length);
                    }
                    else if (previous.Message != null)
                    {
                        this._data = new byte[data.Length + previous.Message.Length];
                        Array.Copy(previous.Message, 0, this._data, 0, previous.Message.Length);
                        Array.Copy(data, 0, this._data, previous.Message.Length, data.Length);
                    }
                    else
                    {
                        this._data = data;
                    }
                }
            }
            midi_HEADER.Unprepare(input, handle);
        }
Пример #5
0
 private void MidiInProc(IntPtr handle, MIDIMessage msg, IntPtr user, IntPtr param1, IntPtr param2)
 {
     if (msg == MIDIMessage.MIM_OPEN)
     {
         this.RaiseMessageReceived(MidiMessageEventType.Opened, null);
         return;
     }
     if (msg == MIDIMessage.MIM_CLOSE)
     {
         this.FlushShortMsgStack();
         this.RaiseMessageReceived(MidiMessageEventType.Closed, null);
         return;
     }
     if (msg == MIDIMessage.MIM_DATA || msg == MIDIMessage.MIM_MOREDATA)
     {
         this._shortMsg = new MidiShortMessage(param1, param2, this._shortMsg);
         if ((this._shortMsg.MessageType & this.MessageFilter) == MIDIMessageType.Unknown)
         {
             this._pairedResult = this.IsPairedControllerMessage(this._shortMsg);
             if (this._pairedResult == 0)
             {
                 this.FlushShortMsgStack();
                 this.RaiseMessageReceived(MidiMessageEventType.ShortMessage, this._shortMsg);
                 return;
             }
             if (this._pairedResult == -1)
             {
                 this._shortMsgOnStack = this._shortMsg;
                 return;
             }
             this._shortMsgOnStack = null;
             this.RaiseMessageReceived(MidiMessageEventType.ShortMessage, this._shortMsg);
             return;
         }
     }
     else
     {
         if (msg == MIDIMessage.MIM_LONGDATA)
         {
             this.FlushShortMsgStack();
             this._sysexMsg = new MidiSysExMessage(true, handle, param1, this._sysexMsg);
             if (this._sysexMsg.IsDone && (this._sysexMsg.MessageType & this.MessageFilter) == MIDIMessageType.Unknown)
             {
                 this.RaiseMessageReceived(MidiMessageEventType.SystemExclusive, this._sysexMsg);
             }
             this.AddSysExBuffer();
             return;
         }
         if (msg == MIDIMessage.MIM_ERROR)
         {
             this.FlushShortMsgStack();
             if (this.ProcessErrorMessages)
             {
                 MidiShortMessage midiShortMessage = new MidiShortMessage(param1, param2);
                 if ((midiShortMessage.MessageType & this.MessageFilter) == MIDIMessageType.Unknown)
                 {
                     this.RaiseMessageReceived(MidiMessageEventType.ShortMessageError, midiShortMessage);
                     return;
                 }
             }
         }
         else if (msg == MIDIMessage.MIM_LONGERROR)
         {
             this.FlushShortMsgStack();
             MidiSysExMessage midiSysExMessage = new MidiSysExMessage(true, handle, param1);
             if (midiSysExMessage.IsDone && this.ProcessErrorMessages && (midiSysExMessage.MessageType & this.MessageFilter) == MIDIMessageType.Unknown)
             {
                 this.RaiseMessageReceived(MidiMessageEventType.SystemExclusiveError, midiSysExMessage);
             }
             this.AddSysExBuffer();
         }
     }
 }