Example #1
0
        /// <summary>
        /// Retrieves an instance (or null) for the specified type <typeparamref name="T"/>.
        /// </summary>
        /// <typeparam name="T">The type of interface or class.</typeparam>
        /// <returns>Returns null when <typeparamref name="T"/> is not supported.</returns>
        public T?GetInstance <T>() where T : class
        {
            if (HostCommandProxy is T refT)
            {
                return(refT);
            }

            var type = typeof(T);

            if (typeof(IVstHostAutomation).Equals(type))
            {
                return((T)_automation);
            }
            if (typeof(IVstHostSequencer).Equals(type))
            {
                return((T)_sequencer);
            }
            if (typeof(IVstHostShell).Equals(type))
            {
                return((T)_shell);
            }
            if (typeof(IVstMidiProcessor).Equals(type))
            {
                CheckMidiSource();

                // does host support MIDI?
                if (HostCommandProxy.Commands.CanDo(VstCanDoHelper.ToString(VstHostCanDo.ReceiveVstMidiEvent)) != VstCanDoResult.No)
                {
                    return((T)_midiProcessor);
                }
            }

            return(null);
        }
        private IVstMidiProcessor CreateMidiProcessor(IVstMidiProcessor instance)
        {
            if (instance == null &&
                _host.HostCommandStub.CanDo(VstCanDoHelper.ToString(VstHostCanDo.ReceiveVstMidiEvent)) != VstCanDoResult.No)
            {
                return(new VstHostMidiProcessor(_host));
            }

            return(instance);
        }
Example #3
0
        public void Test_VstCanDoHelper_PluginCanDo_ToString()
        {
            VstPluginCanDo cando  = VstPluginCanDo.Bypass;
            string         actual = VstCanDoHelper.ToString(cando);

            Assert.AreEqual("bypass", actual, "PluginCanDo.Bypass failed.");

            cando  = VstPluginCanDo.x1in1out;
            actual = VstCanDoHelper.ToString(cando);
            Assert.AreEqual("1in1out", actual, "PluginCanDo.x1in1out failed.");
        }
Example #4
0
        public void Test_VstCanDoHelper_HostCanDo_ToString()
        {
            VstHostCanDo cando  = VstHostCanDo.EditFile;
            string       actual = VstCanDoHelper.ToString(cando);

            Assert.AreEqual("editFile", actual, "HostCanDo.EditFile failed.");

            cando  = VstHostCanDo.SupplyIdle;
            actual = VstCanDoHelper.ToString(cando);
            Assert.AreEqual("supplyIdle", actual, "HostCanDo.SupplyIdle failed.");
        }
Example #5
0
        public void Test_VstCanDoHelper_PluginCanDo_ToString()
        {
            VstPluginCanDo cando  = VstPluginCanDo.Bypass;
            var            actual = VstCanDoHelper.ToString(cando);

            actual.Should().Be("bypass");

            cando  = VstPluginCanDo.x1in1out;
            actual = VstCanDoHelper.ToString(cando);
            actual.Should().Be("1in1out");
        }
Example #6
0
        public void Test_VstCanDoHelper_HostCanDo_ToString()
        {
            VstHostCanDo cando  = VstHostCanDo.EditFile;
            var          actual = VstCanDoHelper.ToString(cando);

            actual.Should().Be("editFile");

            cando  = VstHostCanDo.SupplyIdle;
            actual = VstCanDoHelper.ToString(cando);
            actual.Should().Be("supplyIdle");
        }
Example #7
0
        public string getPluginInfo()
        {
            if (PluginContext != null)
            {
                List <string> pluginInfo = new List <string>();               // Create new list of strings

                // plugin product
                pluginInfo.Add("Plugin Name " + PluginContext.PluginCommandStub.GetEffectName());
                pluginInfo.Add("Product " + PluginContext.PluginCommandStub.GetProductString());
                pluginInfo.Add("Vendor " + PluginContext.PluginCommandStub.GetVendorString());
                pluginInfo.Add("Vendor Version " + PluginContext.PluginCommandStub.GetVendorVersion().ToString());
                pluginInfo.Add("Vst Support " + PluginContext.PluginCommandStub.GetVstVersion().ToString());
                pluginInfo.Add("Plugin Category " + PluginContext.PluginCommandStub.GetCategory().ToString());

                // plugin info
                pluginInfo.Add("Flags " + PluginContext.PluginInfo.Flags.ToString());
                pluginInfo.Add("Plugin ID " + PluginContext.PluginInfo.PluginID.ToString());
                pluginInfo.Add("Plugin Version " + PluginContext.PluginInfo.PluginVersion.ToString());
                pluginInfo.Add("Audio Input Count " + PluginContext.PluginInfo.AudioInputCount.ToString());
                pluginInfo.Add("Audio Output Count " + PluginContext.PluginInfo.AudioOutputCount.ToString());
                pluginInfo.Add("Initial Delay " + PluginContext.PluginInfo.InitialDelay.ToString());
                pluginInfo.Add("Program Count " + PluginContext.PluginInfo.ProgramCount.ToString());
                pluginInfo.Add("Parameter Count " + PluginContext.PluginInfo.ParameterCount.ToString());
                pluginInfo.Add("Tail Size " + PluginContext.PluginCommandStub.GetTailSize().ToString());

                // can do
                pluginInfo.Add("CanDo: " + VstPluginCanDo.Bypass + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Bypass)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.MidiProgramNames + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.MidiProgramNames)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.Offline + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Offline)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.ReceiveVstEvents + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ReceiveVstEvents)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.ReceiveVstMidiEvent + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ReceiveVstMidiEvent)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.ReceiveVstTimeInfo + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ReceiveVstTimeInfo)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.SendVstEvents + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.SendVstEvents)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.SendVstMidiEvent + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.SendVstMidiEvent)).ToString());

                pluginInfo.Add("CanDo: " + VstPluginCanDo.ConformsToWindowRules + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ConformsToWindowRules)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.Metapass + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Metapass)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.MixDryWet + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.MixDryWet)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.Multipass + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Multipass)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.NoRealTime + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.NoRealTime)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.PlugAsChannelInsert + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.PlugAsChannelInsert)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.PlugAsSend + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.PlugAsSend)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.SendVstTimeInfo + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.SendVstTimeInfo)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.x1in1out + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x1in1out)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.x1in2out + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x1in2out)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.x2in1out + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x2in1out)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.x2in2out + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x2in2out)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.x2in4out + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x2in4out)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.x4in2out + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x4in2out)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.x4in4out + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x4in4out)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.x4in8out + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x4in8out)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.x8in4out + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x8in4out)).ToString());
                pluginInfo.Add("CanDo: " + VstPluginCanDo.x8in8out + PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x8in8out)).ToString());

                pluginInfo.Add("Program: " + PluginContext.PluginCommandStub.GetProgram());
                pluginInfo.Add("Program Name: " + PluginContext.PluginCommandStub.GetProgramName());

                for (int i = 0; i < PluginContext.PluginInfo.ParameterCount; i++)
                {
                    string name           = PluginContext.PluginCommandStub.GetParameterName(i);
                    string label          = PluginContext.PluginCommandStub.GetParameterLabel(i);
                    string display        = PluginContext.PluginCommandStub.GetParameterDisplay(i);
                    bool   canBeAutomated = PluginContext.PluginCommandStub.CanParameterBeAutomated(i);

                    pluginInfo.Add(String.Format("Parameter Index: {0} Parameter Name: {1} Display: {2} Label: {3} Can be automated: {4}", i, name, display, label, canBeAutomated));
                }
                return(string.Join("\n", pluginInfo.ToArray()));
            }
            return("Nothing");
        }
Example #8
0
        private void addPath(string path)
        {
            Boolean saveSettings = false;

            if (!Directory.Exists(path))
            {
                return;
            }

            // Recursive
            foreach (var dir in new DirectoryInfo(path).GetDirectories())
            {
                addPath(dir.FullName);
            }

            foreach (FileInfo file in new DirectoryInfo(path).GetFiles())
            {
                if (file.Extension == ".dll")
                {
                    if (mSettingsMgr.Settings.KnownVSTPluginDlls.Contains(file.FullName))
                    {
                        continue;
                    }

                    try
                    {
                        //VstHostCommandBase tmpHostCmdStub = new VstHostCommandBase(this);
                        using (VstPluginContext ctx = VstPluginContext.Create(file.FullName, this))
                        {
                            // add custom data to the context
                            ctx.Set("PluginPath", file.FullName);
                            ctx.Set("HostCmdStub", this);

                            VstInfo info = new VstInfo();

                            info.AudioInputCount        = ctx.PluginInfo.AudioInputCount;
                            info.AudioOutputCount       = ctx.PluginInfo.AudioOutputCount;
                            info.CanReceiveVstMidiEvent = ctx.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ReceiveVstMidiEvent)) == VstCanDoResult.Yes;
                            info.Name    = file.Name.Replace(".dll", string.Empty); // ctx.PluginCommandStub.GetEffectName();
                            info.DLLPath = file.FullName;

                            // Effect?
                            if (info.AudioInputCount > 0 && info.AudioOutputCount > 0)
                            {
                                mSettingsMgr.Settings.Effects.Add(info);
                            }

                            // VSTi?
                            if (info.CanReceiveVstMidiEvent)
                            {
                                mSettingsMgr.Settings.Instruments.Add(info);
                            }

                            if ((ctx.PluginInfo.Flags & VstPluginFlags.ProgramChunks) != VstPluginFlags.ProgramChunks)
                            {
                                MessageBox.Show(string.Format("{0} does not support chunks", info.Name));
                            }
                        }
                    }
                    catch
                    {
                        // Do nothing
                    }

                    // Files to exclude from future search
                    mSettingsMgr.Settings.KnownVSTPluginDlls.Add(file.FullName);
                    saveSettings = true;
                }
            }

            if (saveSettings)
            {
                mSettingsMgr.SaveSettings();
            }
        }
Example #9
0
        private void FillPropertyList()
        {
            PluginContext.AcceptPluginInfoData(false);
            PluginPropertyListVw.Items.Clear();

            // plugin product
            AddProperty("Plugin Name", PluginContext.PluginCommandStub.GetEffectName());
            AddProperty("Product", PluginContext.PluginCommandStub.GetProductString());
            AddProperty("Vendor", PluginContext.PluginCommandStub.GetVendorString());
            AddProperty("Vendor Version", PluginContext.PluginCommandStub.GetVendorVersion().ToString());
            AddProperty("Vst Support", PluginContext.PluginCommandStub.GetVstVersion().ToString());
            AddProperty("Plugin Category", PluginContext.PluginCommandStub.GetCategory().ToString());


            // plugin info
            AddProperty("Flags", PluginContext.PluginInfo.Flags.ToString());
            AddProperty("Plugin ID", PluginContext.PluginInfo.PluginID.ToString());
            AddProperty("Plugin Version", PluginContext.PluginInfo.PluginVersion.ToString());
            AddProperty("Audio Input Count", PluginContext.PluginInfo.AudioInputCount.ToString());
            AddProperty("Audio Output Count", PluginContext.PluginInfo.AudioOutputCount.ToString());
            AddProperty("Initial Delay", PluginContext.PluginInfo.InitialDelay.ToString());
            AddProperty("Program Count", PluginContext.PluginInfo.ProgramCount.ToString());
            AddProperty("Parameter Count", PluginContext.PluginInfo.ParameterCount.ToString());
            AddProperty("Tail Size", PluginContext.PluginCommandStub.GetTailSize().ToString());

            // can do
            AddProperty("CanDo:" + VstPluginCanDo.Bypass,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Bypass)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.MidiProgramNames,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.MidiProgramNames))
                        .ToString());
            AddProperty("CanDo:" + VstPluginCanDo.Offline,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Offline)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.ReceiveVstEvents,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ReceiveVstEvents))
                        .ToString());
            AddProperty("CanDo:" + VstPluginCanDo.ReceiveVstMidiEvent,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ReceiveVstMidiEvent))
                        .ToString());
            AddProperty("CanDo:" + VstPluginCanDo.ReceiveVstTimeInfo,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ReceiveVstTimeInfo))
                        .ToString());
            AddProperty("CanDo:" + VstPluginCanDo.SendVstEvents,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.SendVstEvents))
                        .ToString());
            AddProperty("CanDo:" + VstPluginCanDo.SendVstMidiEvent,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.SendVstMidiEvent))
                        .ToString());

            AddProperty("CanDo:" + VstPluginCanDo.ConformsToWindowRules,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ConformsToWindowRules))
                        .ToString());
            AddProperty("CanDo:" + VstPluginCanDo.Metapass,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Metapass)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.MixDryWet,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.MixDryWet)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.Multipass,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Multipass)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.NoRealTime,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.NoRealTime)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.PlugAsChannelInsert,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.PlugAsChannelInsert))
                        .ToString());
            AddProperty("CanDo:" + VstPluginCanDo.PlugAsSend,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.PlugAsSend)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.SendVstTimeInfo,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.SendVstTimeInfo))
                        .ToString());
            AddProperty("CanDo:" + VstPluginCanDo.x1in1out,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x1in1out)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.x1in2out,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x1in2out)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.x2in1out,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x2in1out)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.x2in2out,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x2in2out)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.x2in4out,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x2in4out)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.x4in2out,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x4in2out)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.x4in4out,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x4in4out)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.x4in8out,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x4in8out)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.x8in4out,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x8in4out)).ToString());
            AddProperty("CanDo:" + VstPluginCanDo.x8in8out,
                        PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x8in8out)).ToString());
        }
Example #10
0
        public static int ProcessWaveFile(
            CallParameters parameters,
            System.Threading.CancellationToken cancellationToken
            )
        {
            string pluginPath = parameters.VstPluginPath;

            if (!System.IO.File.Exists(parameters.FxbFile))
            {
                Console.Error.WriteLine("Can not find Bank/Preset file {0}", parameters.FxbFile);

                return(ReturnCodeOffset + 0);
            }

            if (!System.IO.File.Exists(pluginPath))
            {
                Console.Error.WriteLine("Can not find VST-plugin file {0}", pluginPath);

                return(ReturnCodeOffset + 1);
            }

            if (parameters.InputWavFile == null)
            {
                Console.Error.WriteLine("InputWavFile param is missing");

                return(ReturnCodeOffset + 2);
            }

            if (!System.IO.File.Exists(parameters.InputWavFile))
            {
                Console.Error.WriteLine("Can not find wave file {0}", parameters.InputWavFile);

                return(ReturnCodeOffset + 3);
            }

            if (parameters.OutputWavFile == null)
            {
                Console.Error.WriteLine("OutputWavFile param is missing");

                return(ReturnCodeOffset + 4);
            }

            var hostCmdStub = new HostCommandStub();
            var vstPlugin   = VstPluginContext.Create(pluginPath, hostCmdStub);

            vstPlugin.PluginCommandStub.Open();

            // add custom data to the context
            vstPlugin.Set("PluginPath", pluginPath);
            vstPlugin.Set("HostCmdStub", hostCmdStub);


            #region Draw VST Plugin Information

            // plugin product
            Console.WriteLine("{0,-20}\t{1}", "Plugin Name", vstPlugin.PluginCommandStub.GetEffectName());
            Console.WriteLine("{0,-20}\t{1}", "Product", vstPlugin.PluginCommandStub.GetProductString());
            Console.WriteLine("{0,-20}\t{1}", "Vendor", vstPlugin.PluginCommandStub.GetVendorString());
            Console.WriteLine("{0,-20}\t{1}", "Vendor Version",
                              vstPlugin.PluginCommandStub.GetVendorVersion().ToString());
            Console.WriteLine("{0,-20}\t{1}", "Vst Support", vstPlugin.PluginCommandStub.GetVstVersion().ToString());
            Console.WriteLine("{0,-20}\t{1}", "Plugin Category", vstPlugin.PluginCommandStub.GetCategory().ToString());

            // plugin info
            Console.WriteLine("{0,-20}\t{1}", "Flags", vstPlugin.PluginInfo.Flags.ToString());
            Console.WriteLine("{0,-20}\t{1}", "Plugin ID", vstPlugin.PluginInfo.PluginID.ToString());
            Console.WriteLine("{0,-20}\t{1}", "Plugin Version", vstPlugin.PluginInfo.PluginVersion.ToString());

            #endregion

            {
                var t = vstPlugin.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Offline));
                if (t == VstCanDoResult.No)
                {
                    Console.Error.WriteLine("This VST Plugin does not support offline convertation");

                    return(ReturnCodeOffset + 6);
                }

                if (!vstPlugin.PluginInfo.Flags.HasFlag(VstPluginFlags.CanReplacing) &&
                    !vstPlugin.PluginInfo.Flags.HasFlag(VstPluginFlags.CanDoubleReplacing))
                {
                    Console.Error.WriteLine("This VST Plugin does not replacing samples");

                    return(ReturnCodeOffset + 7);
                }
            }

            vstPlugin.PluginCommandStub.MainsChanged(true);
            int result = FxbReader.ReadFileIntoPluginStub(
                parameters.FxbFile,
                (uint)vstPlugin.PluginInfo.PluginID,
                (uint)vstPlugin.PluginInfo.PluginVersion,
                parameters.IgnorePluginVersion,
                vstPlugin.PluginCommandStub
                );
            vstPlugin.PluginCommandStub.MainsChanged(false);
            if (result != 0)
            {
                vstPlugin.PluginCommandStub.Close();
                return(result);
            }

            if (cancellationToken.IsCancellationRequested)
            {
                // Был затребован выход из программы
                vstPlugin.PluginCommandStub.Close();
                return(ReturnCodeOffset + 5);
            }

            result = ProcessFile(parameters.InputWavFile, parameters.OutputWavFile, vstPlugin, cancellationToken);
            vstPlugin.PluginCommandStub.Close();

            return(result);
        }
Example #11
0
        public bool ProcessOffline(String waveInputFilePath, String waveOutputFilePath, String pluginPath, String fxpFilePath = null, float volume = 1.0f)
        {
            var wavFileReader = new WaveFileReader(waveInputFilePath);

            // reuse if batch processing
            bool doUpdateVstPlugin = false;

            if (_pluginPath != null)
            {
                if (_pluginPath.Equals(pluginPath))
                {
                    // plugin has not changed
                }
                else
                {
                    // plugin has changed!
                    doUpdateVstPlugin = true;
                }
            }
            else
            {
                _pluginPath       = pluginPath;
                doUpdateVstPlugin = true;
            }

            if (doUpdateVstPlugin)
            {
                var hcs = new HostCommandStub();
                hcs.Directory = Path.GetDirectoryName(pluginPath);
                vst           = new VST();

                try
                {
                    vst.PluginContext = VstPluginContext.Create(pluginPath, hcs);

                    if (vst.PluginContext == null)
                    {
                        Console.Out.WriteLine("Could not open up the plugin specified by {0}!", pluginPath);
                        return(false);
                    }

                    // plugin does not support processing audio
                    if ((vst.PluginContext.PluginInfo.Flags & VstPluginFlags.CanReplacing) == 0)
                    {
                        Console.Out.WriteLine("This plugin does not process any audio.");
                        return(false);
                    }

                    // check if the plugin supports offline proccesing
                    if (vst.PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Offline)) == VstCanDoResult.No)
                    {
                        Console.Out.WriteLine("This plugin does not support offline processing.");
                        Console.Out.WriteLine("Try use realtime (-play) instead!");
                        return(false);
                    }

                    // add custom data to the context
                    vst.PluginContext.Set("PluginPath", pluginPath);
                    vst.PluginContext.Set("HostCmdStub", hcs);

                    // actually open the plugin itself
                    vst.PluginContext.PluginCommandStub.Open();

                    Console.Out.WriteLine("Enabling the audio output on the VST!");
                    vst.PluginContext.PluginCommandStub.MainsChanged(true);

                    // setup the VSTStream
                    vstStream = new VSTStream();
                    vstStream.ProcessCalled  += vst_ProcessCalled;
                    vstStream.PlayingStarted += vst_PlayingStarted;
                    vstStream.PlayingStopped += vst_PlayingStopped;
                    vstStream.pluginContext   = vst.PluginContext;

                    vstStream.SetWaveFormat(wavFileReader.WaveFormat.SampleRate, wavFileReader.WaveFormat.Channels);
                } catch (Exception ex) {
                    Console.Out.WriteLine("Could not load VST! ({0})", ex.Message);
                    return(false);
                }
            }

            if (File.Exists(fxpFilePath))
            {
                vst.LoadFXP(fxpFilePath);
            }
            else
            {
                Console.Out.WriteLine("Could not find preset file (fxp|fxb) ({0})", fxpFilePath);
            }

            // each float is 4 bytes
            var buffer = new byte[512 * 4];

            using (var ms = new MemoryStream())
            {
                vstStream.SetInputWave(waveInputFilePath, volume);
                vstStream.DoProcess = true;

                // wait a little while
                Thread.Sleep(1000);

                // keep on reading until it stops playing.
                while (!stoppedPlaying)
                {
                    int read = vstStream.Read(buffer, 0, buffer.Length);
                    if (read <= 0)
                    {
                        break;
                    }
                    ms.Write(buffer, 0, read);
                }

                // save
                using (WaveStream ws = new RawSourceWaveStream(ms, vstStream.WaveFormat))
                {
                    ws.Position = 0;
                    WaveFileWriter.CreateWaveFile(waveOutputFilePath, ws);
                }
            }

            // reset the input wave file
            vstStream.DoProcess = false;
            vstStream.DisposeInputWave();

            // reset if calling this method multiple times
            stoppedPlaying = false;
            return(true);
        }
Example #12
0
        public bool ProcessRealTime(String waveInputFilePath, String waveOutputFilePath, String pluginPath, String fxpFilePath = null, float volume = 1.0f)
        {
            var wavFileReader = new WaveFileReader(waveInputFilePath);

            // reuse if batch processing
            bool doUpdateVstPlugin  = false;
            bool doUpdateSampleRate = false;
            bool doUpdateNoChannels = false;

            if (_pluginPath != null)
            {
                if (_pluginPath.Equals(pluginPath))
                {
                    // plugin has not changed
                }
                else
                {
                    // plugin has changed!
                    doUpdateVstPlugin = true;
                }
            }
            else
            {
                _pluginPath       = pluginPath;
                doUpdateVstPlugin = true;
            }

            if (_sampleRate != 0)
            {
                if (_sampleRate == wavFileReader.WaveFormat.SampleRate)
                {
                    // same sample rate
                }
                else
                {
                    // sample rate has changed!
                    doUpdateSampleRate = true;
                }
            }
            else
            {
                _sampleRate        = wavFileReader.WaveFormat.SampleRate;
                doUpdateSampleRate = true;
            }

            if (_channels != 0)
            {
                if (_channels == wavFileReader.WaveFormat.Channels)
                {
                    // same number of channels
                }
                else
                {
                    // number of channels has changed!
                    doUpdateNoChannels = true;
                }
            }
            else
            {
                _channels          = wavFileReader.WaveFormat.Channels;
                doUpdateNoChannels = true;
            }

            if (doUpdateNoChannels || doUpdateSampleRate)
            {
                Console.Out.WriteLine("Opening Audio driver using samplerate {0} and {1} channels.", _sampleRate, _channels);
                UtilityAudio.OpenAudio(AudioLibrary.NAudio, _sampleRate, _channels);
            }

            if (doUpdateVstPlugin || doUpdateNoChannels || doUpdateSampleRate)
            {
                Console.Out.WriteLine("Loading Vstplugin using samplerate {0} and {1} channels.", _sampleRate, _channels);
                vst = UtilityAudio.LoadVST(_pluginPath, _sampleRate, _channels);
                UtilityAudio.VstStream.ProcessCalled  += vst_ProcessCalled;
                UtilityAudio.VstStream.PlayingStarted += vst_PlayingStarted;
                UtilityAudio.VstStream.PlayingStopped += vst_PlayingStopped;

                // plugin does not support processing audio
                if ((vst.PluginContext.PluginInfo.Flags & VstPluginFlags.CanReplacing) == 0)
                {
                    Console.Out.WriteLine("This plugin does not process any audio.");
                    return(false);
                }

                // check if the plugin supports real time proccesing
                if (vst.PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.NoRealTime)) == VstCanDoResult.Yes)
                {
                    Console.Out.WriteLine("This plugin does not support realtime processing.");
                    return(false);
                }
            }

            if (File.Exists(fxpFilePath))
            {
                Console.Out.WriteLine("Loading preset file {0}.", fxpFilePath);
                vst.LoadFXP(fxpFilePath);
            }
            else
            {
                Console.Out.WriteLine("Could not find preset file (fxp|fxb) ({0})", fxpFilePath);
            }

            if (UtilityAudio.PlaybackDevice.PlaybackState != PlaybackState.Playing)
            {
                Console.Out.WriteLine("Starting audio playback engine.");
                UtilityAudio.StartAudio();
            }

            Console.Out.WriteLine("Setting input wave {0}.", waveInputFilePath);
            UtilityAudio.VstStream.SetInputWave(waveInputFilePath, volume);

            Console.Out.WriteLine("Setting output wave {0}.", waveOutputFilePath);
            UtilityAudio.SaveStream(waveOutputFilePath);

            UtilityAudio.VstStream.DoProcess = true;

            // just wait while the stream is playing
            // the events will trigger and set the stoppedPlaying flag
            while (!stoppedPlaying)
            {
                Thread.Sleep(50);
            }

            // reset if calling this method multiple times
            stoppedPlaying = false;
            return(true);
        }
        public void ExportPresetAudioPreviewRealtime(RemoteVstPlugin plugin, PresetExportInfo preset, byte[] data,
                                                     int initialDelay)
        {
            var ctx = plugin.PluginContext;

            if ((ctx.PluginCommandStub.PluginContext.PluginInfo.Flags & VstPluginFlags.IsSynth) == 0)
            {
                throw new EffectsNotSupportedException();
            }

            // check if the plugin supports real time processing
            if (ctx.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.NoRealTime)) == VstCanDoResult.Yes)
            {
                throw new NoRealtimeProcessingException();
            }

            //ctx.PluginCommandStub.SetChunk(data, false);


            var tempFileName = preset.GetPreviewFilename(true);

            Directory.CreateDirectory(Path.GetDirectoryName(tempFileName));

            var noteOnEvents  = new List <(int loop, int offset, byte note)>();
            var noteOffEvents = new List <(int loop, int offset, byte note)>();

            foreach (var note in preset.PreviewNotePlayer.PreviewNotes)
            {
                var onLoop   = (double)VstHost.SampleRate * note.Start / VstHost.BlockSize;
                var onOffset = (int)((onLoop - (int)onLoop) * VstHost.BlockSize);

                noteOnEvents.Add((loop: (int)onLoop, offset: onOffset, note: (byte)(note.NoteNumber + 12)));
                var offLoop   = (double)VstHost.SampleRate * (note.Start + note.Duration) / VstHost.BlockSize;
                var offOffset = (int)((offLoop - (int)offLoop) * VstHost.BlockSize);

                noteOffEvents.Add((loop: (int)offLoop, offset: offOffset, note: (byte)(note.NoteNumber + 12)));
            }

            var hasExportedAudio = false;

            for (var i = 0; i < 10; i++)
            {
                if (DoAudioWaveExport(plugin, tempFileName, noteOnEvents, noteOffEvents, initialDelay,
                                      preset.PreviewNotePlayer.MaxDuration))
                {
                    hasExportedAudio = true;
                    break;
                }
            }


            if (hasExportedAudio)
            {
                ConvertToOGG(tempFileName, preset.GetPreviewFilename());
            }
            else
            {
                plugin.Logger.Error("No audio data was returned by the plugin. Most likely it was still loading " +
                                    "the preset data; try to increase the audio preview pre-delay in the plugin " +
                                    "settings and try again");
            }

            File.Delete(tempFileName);
        }
Example #14
0
        public List <PluginInfoItem> GetPluginInfoItems(IVstPluginContext pluginContext)
        {
            var pluginInfoItems = new List <PluginInfoItem>();

            if (pluginContext == null)
            {
                return(pluginInfoItems);
            }

            // plugin product
            pluginInfoItems.Add(new PluginInfoItem("Base", "Plugin Name",
                                                   pluginContext.PluginCommandStub.GetEffectName()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Product",
                                                   pluginContext.PluginCommandStub.GetProductString()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Vendor",
                                                   pluginContext.PluginCommandStub.GetVendorString()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Vendor Version",
                                                   pluginContext.PluginCommandStub.GetVendorVersion().ToString()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Vst Support",
                                                   pluginContext.PluginCommandStub.GetVstVersion().ToString()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Plugin Category",
                                                   pluginContext.PluginCommandStub.GetCategory().ToString()));

            // plugin info
            pluginInfoItems.Add(new PluginInfoItem("Base", "Flags", pluginContext.PluginInfo.Flags.ToString()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Plugin ID",
                                                   pluginContext.PluginInfo.PluginID.ToString()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Plugin ID String",
                                                   VstUtils.PluginIdNumberToIdString(pluginContext.PluginInfo.PluginID)));

            pluginInfoItems.Add(new PluginInfoItem("Base", "Plugin Version",
                                                   pluginContext.PluginInfo.PluginVersion.ToString()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Audio Input Count",
                                                   pluginContext.PluginInfo.AudioInputCount.ToString()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Audio Output Count",
                                                   pluginContext.PluginInfo.AudioOutputCount.ToString()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Initial Delay",
                                                   pluginContext.PluginInfo.InitialDelay.ToString()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Program Count",
                                                   pluginContext.PluginInfo.ProgramCount.ToString()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Parameter Count",
                                                   pluginContext.PluginInfo.ParameterCount.ToString()));
            pluginInfoItems.Add(new PluginInfoItem("Base", "Tail Size",
                                                   pluginContext.PluginCommandStub.GetTailSize().ToString()));

            // can do
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.Bypass),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Bypass)).ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.MidiProgramNames),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.MidiProgramNames))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.Offline),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Offline)).ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.ReceiveVstEvents),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ReceiveVstEvents))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.ReceiveVstMidiEvent),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ReceiveVstMidiEvent))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.ReceiveVstTimeInfo),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ReceiveVstTimeInfo))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.SendVstEvents),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.SendVstEvents))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.SendVstMidiEvent),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.SendVstMidiEvent))
                                                   .ToString()));

            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.ConformsToWindowRules),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.ConformsToWindowRules))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.Metapass),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Metapass))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.MixDryWet),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.MixDryWet))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.Multipass),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.Multipass))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.NoRealTime),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.NoRealTime))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.PlugAsChannelInsert),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.PlugAsChannelInsert))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.PlugAsSend),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.PlugAsSend))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.SendVstTimeInfo),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.SendVstTimeInfo))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.x1in1out),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x1in1out))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.x1in2out),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x1in2out))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.x2in1out),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x2in1out))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.x2in2out),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x2in2out))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.x2in4out),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x2in4out))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.x4in2out),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x4in2out))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.x4in4out),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x4in4out))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.x4in8out),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x4in8out))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.x8in4out),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x8in4out))
                                                   .ToString()));
            pluginInfoItems.Add(new PluginInfoItem("CanDo", nameof(VstPluginCanDo.x8in8out),
                                                   pluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.x8in8out))
                                                   .ToString()));

            pluginInfoItems.Add(new PluginInfoItem("Program", "Current Program Index",
                                                   pluginContext.PluginCommandStub.GetProgram().ToString()));
            pluginInfoItems.Add(new PluginInfoItem("Program", "Current Program Name",
                                                   pluginContext.PluginCommandStub.GetProgramName()));

            return(pluginInfoItems);
        }