示例#1
0
        // MidiProcessor's Process is called before this
        // This method is used to push midi events to the host.
        public override void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)
        {
            timeInfo = _plugin.Host.GetInstance <IVstHostCommands20>().GetTimeInfo(
                VstTimeInfoFlags.PpqPositionValid | VstTimeInfoFlags.BarStartPositionValid | VstTimeInfoFlags.TempoValid);

            // MessageBox.Show("tempo:" + timeInfo.Tempo.ToString() + "\n sample rate" + timeInfo.SampleRate.ToString()
            //     + "\n sign. numerator: " + timeInfo.TimeSignatureNumerator.ToString());

            if (_hostProcessor == null)
            {
                _hostProcessor = _plugin.Host.GetInstance <IVstMidiProcessor>();
            }

            if (_midiProcessor != null && _hostProcessor != null)
            {
                _midiProcessor.setTimeInfo(timeInfo);
                _midiProcessor.Arpeggiate();

                if (_midiProcessor.Events.Count > 0)
                {
                    _hostProcessor.Process(_midiProcessor.Events);
                    _midiProcessor.Events.Clear();
                }
            }

            // perform audio-through
            base.Process(inChannels, outChannels);
        }
示例#2
0
 private void EnsureHostProcessor()
 {
     if (_hostProcessor == null)
     {
         _hostProcessor = _plugin.Host.GetInstance <IVstMidiProcessor>();
     }
 }
示例#3
0
        /// <summary>
        /// Creates a default instance and reuses that for all threads.
        /// </summary>
        /// <param name="instance">A reference to the default instance or null.</param>
        /// <returns>Returns the default instance.</returns>
        protected override IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
        {
            if (instance == null)
            {
                return(new MidiProcessor(this));
            }

            return(instance);
        }
示例#4
0
        /// <summary>
        /// Implement this when you do midi processing.
        /// </summary>
        /// <param name="instance">A previous instance returned by this method.
        /// When non-null, return a thread-safe version (or wrapper) for the object.</param>
        /// <returns>Returns null when not supported by the plugin.</returns>
        protected override IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
        {
            if (instance == null)
            {
                return(new MidiProcessor(this));
            }

            // TODO: implement a thread-safe wrapper.
            return(base.CreateMidiProcessor(instance));
        }
        private IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
        {
            if (instance == null &&
                _host.HostCommandStub.CanDo(VstCanDoHelper.ToString(VstHostCanDo.ReceiveVstMidiEvent)) != VstCanDoResult.No)
            {
                return(new VstHostMidiProcessor(_host));
            }

            return(instance);
        }
示例#6
0
        /// <summary>
        /// Implement this when you do midi processing.
        /// </summary>
        /// <param name="instance">A previous instance returned by this method.
        /// When non-null, return a thread-safe version (or wrapper) for the object.</param>
        /// <returns>Returns null when not supported by the plugin.</returns>
        protected override IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
        {
            if (instance == null)
            {
                MidiHandler newMidiHandler = new MidiHandler();
                newMidiHandler.Init(() => this.MssHub.DryMssEventInputPort,
                                    () => this.MssHub.WetMssEventOutputPort,
                                    () => this.MssHub.HostInfoOutputPort);
                return(newMidiHandler);
            }

            return(base.CreateMidiProcessor(instance));
        }
示例#7
0
        /// <summary>
        /// Constructs a new instance of the host class based on the <paramref name="hostCmdProxy"/>
        /// (from Interop) and a reference to the current <paramref name="plugin"/>.
        /// </summary>
        /// <param name="hostCmdProxy">Must not be null.</param>
        /// <param name="plugin">Must not be null.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="hostCmdProxy"/> or
        /// <paramref name="plugin"/> is not set to an instance of an object.</exception>
        public VstHost(IVstHostCommandProxy hostCmdProxy, IVstPlugin plugin)
        {
            Throw.IfArgumentIsNull(hostCmdProxy, nameof(hostCmdProxy));
            Throw.IfArgumentIsNull(plugin, nameof(plugin));

            HostCommandProxy = hostCmdProxy;
            Plugin           = plugin;

            _automation    = new VstHostAutomation(this);
            _sequencer     = new VstHostSequencer(this);
            _shell         = new VstHostShell(this);
            _midiProcessor = new VstHostMidiProcessor(this);
        }
示例#8
0
        /// <summary>
        /// Creates a default instance and reuses that for all threads.
        /// </summary>
        /// <param name="instance">A reference to the default instance or null.</param>
        /// <returns>Returns the default instance.</returns>
        protected override IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
        {
            if (instance == null)
            {
                MidiProcessor = new MidiProcessor(this);
                if (AudioProcessor != null)
                {
                    AudioProcessor.SetUp();
                }
                return(MidiProcessor);
            }

            return(base.CreateMidiProcessor(instance));
        }
示例#9
0
        /// <inheritdoc />
        /// <remarks>This method is used to push midi events to the host.</remarks>
        public override void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)
        {
            if (_hostProcessor == null)
            {
                _hostProcessor = _plugin.Host.GetInstance <IVstMidiProcessor>();
            }

            if (_midiProcessor != null && _hostProcessor != null &&
                _midiProcessor.Events.Count > 0)
            {
                _hostProcessor.Process(_midiProcessor.Events);
                _midiProcessor.Events.Clear();
            }
            // perform audio-through
            base.Process(inChannels, outChannels);
        }
示例#10
0
        /// <inheritdoc />
        /// <remarks>This method is used to push midi inputEvents to the host.</remarks>
        public override void Process(VstAudioBuffer[] inChannels, VstAudioBuffer[] outChannels)
        {
            if (_hostProcessor == null)
            {
                _hostProcessor = _plugin.Host.GetInstance<IVstMidiProcessor>();
            }

            if (_midiProcessor != null && _hostProcessor != null &&
                _midiProcessor.Events.Count > 0)
            {
                _hostProcessor.Process(_midiProcessor.Events);
                _midiProcessor.Events.Clear();
            }

            // perform audio-through
            base.Process(inChannels, outChannels);
        }
示例#11
0
        public void ProcessCurrentEvents()
        {
            if (CurrentEvents == null || CurrentEvents.Count == 0)
            {
                return;
            }

            // a plugin must implement IVstPluginMidiSource or this call will throw an exception.
            IVstMidiProcessor midiHost = _plugin.Host.GetInstance <IVstMidiProcessor>();

            // always expect some hosts not to support this.
            if (midiHost != null)
            {
                VstEventCollection outEvents = new VstEventCollection();

                // NOTE: other types of events could be in the collection!
                foreach (VstEvent evnt in CurrentEvents)
                {
                    switch (evnt.EventType)
                    {
                    case VstEventTypes.MidiEvent:
                        VstMidiEvent midiEvent = (VstMidiEvent)evnt;

                        midiEvent = Gain.ProcessEvent(midiEvent);
                        midiEvent = Transpose.ProcessEvent(midiEvent);

                        outEvents.Add(midiEvent);
                        break;

                    default:
                        // non VstMidiEvent
                        outEvents.Add(evnt);
                        break;
                    }
                }

                midiHost.Process(outEvents);
            }

            // Clear the cache, we've processed the events.
            CurrentEvents = null;
        }
        /// <summary>
        ///     Receives processed MssEvents from the IWetMssEventOutputPort.
        /// </summary>
        /// <param name="mssEvents">List of processed mss events</param>
        /// <param name="sampleTimeAtEndOfProcessingCycle">
        ///     If wetMssEventOutputPort is configured to only output when a processing cycle ends then
        ///     sampleTimeAtEndOfProcessingCycle will contain the end time the cycle that just ended.
        /// </param>
        public void IWetMssEventOutputPort_SendingWetMssEvents(List <MssEvent> mssEvents,
                                                               long sampleTimeAtEndOfProcessingCycle)
        {
            if (this.vstHost == null)
            {
                return;
            }

            // a plugin must implement IVstPluginMidiSource or this call will throw an exception.
            IVstMidiProcessor midiHost = this.vstHost.GetInstance <IVstMidiProcessor>();

            // always expect some hosts not to support this.
            if (midiHost != null)
            {
                //Attempts to convert each MssEvent to a VstMidiEvent and add it to outEvents
                foreach (MssEvent mssEvent in mssEvents)
                {
                    //This will return null if there is no valid conversion.
                    VstMidiEvent midiEvent =
                        ConvertMssEventToVstMidiEvent(mssEvent,
                                                      this.SampleTimeAtStartOfProcessingCycle,
                                                      this.hostInfoOutputPort.SampleRate);
                    if (midiEvent != null)
                    {
                        this.outEvents.Add(midiEvent);
                        //midiHost.Process(outEvents);
                        //outEvents.Clear();
                    }
                }

                //TODO: Figure out why it doesn't work to send all of the events at once.
                //Sends VstMidiEvents to host
                midiHost.Process(outEvents);
                outEvents.Clear();
            }

            OnProcessingCycleEnd(sampleTimeAtEndOfProcessingCycle);
        }
示例#13
0
        /// <summary>
        /// Implement this when you do midi processing.
        /// </summary>
        /// <param name="instance">A previous instance returned by this method. 
        /// When non-null, return a thread-safe version (or wrapper) for the object.</param>
        /// <returns>Returns null when not supported by the plugin.</returns>
        protected override IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
        {
            if (instance == null)
            {
                MidiHandler newMidiHandler = new MidiHandler();
                newMidiHandler.Init(() => this.MssHub.DryMssEventInputPort,
                                    () => this.MssHub.WetMssEventOutputPort,
                                    () => this.MssHub.HostInfoOutputPort);
                return newMidiHandler;
            }

            return base.CreateMidiProcessor(instance);
        }
示例#14
0
 protected override IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
 {
     return(MidiListener);
 }
示例#15
0
 /// <summary>
 /// Creates a default instance and reuses that for all threads.
 /// </summary>
 /// <param name="instance">A reference to the default instance or null.</param>
 /// <returns>Returns the default instance.</returns>
 protected override IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
 {
     if (instance == null) return new MidiProcessor(this);
     return instance;
 }
        ///// <summary>
        ///// Called when an instance of the <see cref="IVstPluginHost"/> interface is requested.
        ///// </summary>
        ///// <param name="instance">The default instance or null.</param>
        ///// <returns>Returns <paramref name="instance"/>.</returns>
        ///// <remarks>Override to create an instance of the <see cref="IVstPluginHost"/> interface.
        ///// When <paramref name="instance"/> is null, create the default instance. When the <paramref name="instance"/>
        ///// is not null, create a Thread Safe instance, possibly wrapping the default <paramref name="instance"/>.</remarks>
        //protected virtual IVstPluginHost CreateHost(IVstPluginHost instance)
        //{
        //    return instance;
        //}

        /// <summary>
        /// Called when an instance of the <see cref="IVstMidiProcessor"/> interface is requested.
        /// </summary>
        /// <param name="instance">The default instance or null.</param>
        /// <returns>Returns <paramref name="instance"/>.</returns>
        /// <remarks>Override to create an instance of the <see cref="IVstMidiProcessor"/> interface.
        /// When <paramref name="instance"/> is null, create the default instance. When the <paramref name="instance"/>
        /// is not null, create a Thread Safe instance, possibly wrapping the default <paramref name="instance"/>.</remarks>
        protected virtual IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
        {
            return(instance);
        }
示例#17
0
        public void ProcessCurrentEvents()
        {
            if (CurrentEvents == null || CurrentEvents.Count == 0)
            {
                return;
            }

            // a plugin must implement IVstPluginMidiSource or this call will throw an exception.
            IVstMidiProcessor midiHost = _plugin.Host.GetInstance <IVstMidiProcessor>();

            // always expect some hosts not to support this.
            if (midiHost != null)
            {
                VstEventCollection outEvents = new VstEventCollection();

                // NOTE: other types of events could be in the collection!
                foreach (VstEvent evnt in CurrentEvents)
                {
                    switch (evnt.EventType)
                    {
                    case VstEventTypes.MidiEvent:
                        VstMidiEvent midiEvent = (VstMidiEvent)evnt;

                        //General midi effects for all inputs
                        midiEvent = Gain.ProcessEvent(midiEvent);
                        midiEvent = Transpose.ProcessEvent(midiEvent);

                        //Process Midi Note in SampleManager
                        if ((midiEvent.Data[0] & 0xF0) == 0x80)
                        {
                            _plugin.SampleManager.ProcessNoteOffEvent(midiEvent.Data[1]);
                        }

                        if ((midiEvent.Data[0] & 0xF0) == 0x90)
                        {
                            // note on with velocity = 0 is a note off
                            if (MidiHelper.IsNoteOff(midiEvent.Data))
                            {
                                _plugin.SampleManager.ProcessNoteOffEvent(midiEvent.Data[1]);
                            }
                            else
                            {
                                _plugin.SampleManager.ProcessNoteOnEvent(midiEvent.Data[1]);
                            }
                        }

                        outEvents.Add(midiEvent);
                        break;

                    default:
                        // non VstMidiEvent
                        outEvents.Add(evnt);
                        break;
                    }
                }

                midiHost.Process(outEvents);
            }

            // Clear the cache, we've processed the events.
            CurrentEvents = null;
        }
示例#18
0
        /// <summary>
        /// Implement this when you do midi processing.
        /// </summary>
        /// <param name="instance">A previous instance returned by this method. 
        /// When non-null, return a thread-safe version (or wrapper) for the object.</param>
        /// <returns>Returns null when not supported by the plugin.</returns>
        protected override IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
        {
            if (instance == null)
            {
                return new MidiProcessor(this);
            }

            // TODO: implement a thread-safe wrapper.
            return base.CreateMidiProcessor(instance);
        }