Exemple #1
0
        public virtual void Write(MidiShortMessage message, int deltaTime)
        {
            Contract.Requires(message != null);
            Check.IfArgumentNull(message, "message");

            this.StreamWriter.WriteShort(message.Data, deltaTime);
        }
        public static void Send(MidiShortMessage message)
        {
            if (!IsOutputEnabled)
            {
                return;
            }

            if (midiOut == null)
            {
                string[] devices = MidiOutputDevice.GetDeviceDescriptions();
                int      index   = devices.ToList().IndexOf("Microsoft GS Wavetable Synth");
                if (index != -1)
                {
                    midiOut = new MidiOutputDevice(index);
                    isMidiOutInitialized = midiOut.Open();
                }
            }

            if (!isMidiOutInitialized || !midiOut.IsOpened)
            {
                return;
            }

            if (message.StatusType == MIDIStatus.NoteOff)
            {
                message.Velocity = 0;
            }

            midiOut.Send(message);
        }
Exemple #3
0
 public bool Send(MidiShortMessage shortMessage)
 {
     if (!this.IsOpened || shortMessage == null)
     {
         return(false);
     }
     this._lastError = Midi.MIDI_OutShortMsg(this._device, shortMessage.Message);
     return(this._lastError == MIDIError.MIDI_OK);
 }
Exemple #4
0
        public static bool BASS_VST_ProcessEventRaw(int vstHandle, MidiShortMessage msg)
        {
            int num = 0;

            num |= (int)msg.Data2;
            num |= (int)msg.Data1 << 8;
            num |= (int)msg.Status << 16;
            return(BassVst.BASS_VST_ProcessEventRaw(vstHandle, new IntPtr(num), 0));
        }
Exemple #5
0
        public void SendControlChange(byte midistatus, byte controller, byte data2)
        {
            MidiShortMessage msg = new MidiShortMessage();

            msg.Channel    = 1;
            msg.Status     = midistatus;
            msg.Controller = controller;
            msg.Data2      = data2;
            _outDevice.Send(msg);
        }
Exemple #6
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);
        }
Exemple #7
0
        public void SendMsg(byte channel, byte note, byte volume, byte color)
        {
            MidiShortMessage msg = new MidiShortMessage();

            msg.Channel = 1;
            if ((volume == 1))
            {
                msg.Status = (byte)MIDIStatus.NoteOn;
            }
            else
            {
                msg.Status = (byte)MIDIStatus.NoteOff;
            }
            msg.Note     = note;
            msg.Velocity = color;
            _outDevice.Send(msg);
        }
        public int IsPairedControllerMessage(MidiShortMessage msg)
        {
            if (!this.AutoPairController || msg == null || this._controllerPairs == null || msg.StatusType != MIDIStatus.ControlChange)
            {
                return(0);
            }
            int  num        = 0;
            byte controller = msg.Controller;

            for (int i = 0; i < this._controllerPairs.GetLength(0); i++)
            {
                byte b  = this._controllerPairs[i, 0];
                byte b2 = this._controllerPairs[i, 1];
                if (controller == b || controller == b2)
                {
                    num = -1;
                    if (msg.PreviousShortMessage != null && msg.PreviousShortMessage.StatusType == MIDIStatus.ControlChange && msg.PreviousShortMessage.Channel == msg.Channel)
                    {
                        byte controller2 = msg.PreviousShortMessage.Controller;
                        if (controller2 == b && controller == b2)
                        {
                            num = 2;
                            msg.SetContinuousController(false, true);
                        }
                        else if (controller2 == b2 && controller == b)
                        {
                            num = 1;
                            msg.SetContinuousController(true, false);
                        }
                    }
                }
                if (num != 0)
                {
                    break;
                }
            }
            return(num);
        }
        public void ShortData(int data, long timestamp)
        {
            MidiShortMessage message = _factory.CreateShortMessage(data);

            if (128 <= message.Status && message.Status <= 159)
            {
                bool on      = message.Status >= 144;
                int  fddChan = ((message.Status >= 144) ? (message.Status - 144) : (message.Status - 128)) % 4;

                int noteNumber = message.Parameter1;
                int velocity   = message.Parameter2;

                if (on && velocity > 0)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        NoteOn((fddChan + i) % 4, noteNumber);
                        if (Polyphony)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 4; i++)
                    {
                        NoteOff((fddChan + i) % 4, noteNumber);
                        if (Polyphony)
                        {
                            break;
                        }
                    }
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Writes a new event to the stream for the <paramref name="message"/>.
        /// </summary>
        /// <param name="message">Must not be null.</param>
        /// <param name="deltaTime">The delta-time for the event.</param>
        public virtual void Write(MidiShortMessage message, int deltaTime)
        {
            Check.IfArgumentNull(message, nameof(message));

            StreamWriter.WriteShort(message.Data, deltaTime);
        }
 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();
         }
     }
 }