Exemplo n.º 1
0
        private VstPluginContext OpenPlugin(string pluginPath)
        {
            try
            {
                HostCommandStub hostCmdStub = new HostCommandStub();
                hostCmdStub.PluginCalled += new EventHandler <PluginCalledEventArgs>(HostCmdStub_PluginCalled);

                VstPluginContext ctx = VstPluginContext.Create(pluginPath, hostCmdStub);

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

                // actually open the plugin itself
                ctx.PluginCommandStub.Commands.Open();

                return(ctx);
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(null);
        }
Exemplo n.º 2
0
        public void LoadPlugin(string pluginPath)
        {
            LoadedPluginContext = VstPluginContext.Create(pluginPath, this);

            // update plugin info to loaded plugin
            _hostCmdProxy.UpdatePluginInfo(LoadedPluginContext.PluginInfo);
        }
Exemplo n.º 3
0
        public static VST LoadVST(string VSTPath, IntPtr hWnd)
        {
            DisposeVST();

            GeneralVST = new VST();

            var hcs = new HostCommandStub();

            hcs.Directory = System.IO.Path.GetDirectoryName(VSTPath);

            try
            {
                GeneralVST.pluginContext = VstPluginContext.Create(VSTPath, hcs);
                GeneralVST.pluginContext.PluginCommandStub.Open();
                //pluginContext.PluginCommandStub.SetProgram(0);
                GeneralVST.pluginContext.PluginCommandStub.EditorOpen(hWnd);
                GeneralVST.pluginContext.PluginCommandStub.MainsChanged(true);

                vstStream = new VSTStream();
                vstStream.ProcessCalled += GeneralVST.Stream_ProcessCalled;
                vstStream.pluginContext  = GeneralVST.pluginContext;
                vstStream.SetWaveFormat(44100, 2);

                Mixer32.AddInputStream(vstStream);

                return(GeneralVST);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(null);
        }
Exemplo n.º 4
0
        static void StartAudioOutput(string pluginPath, string waveFilePath)
        {
            try
            {
                var hostCmdStub      = new HostCommandStub();
                VstPluginContext ctx = VstPluginContext.Create(pluginPath, hostCmdStub);

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

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

                var audioOut = new AudioOutput(
                    new List <IVstPluginCommandStub>()
                {
                    ctx.PluginCommandStub
                },
                    waveFilePath);
                Thread.Sleep(100);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Exemplo n.º 5
0
        public VstPluginContext CreateVstPluginContext(string pluginName)
        {
            VstPluginContext pluginContext = null;

            string pluginPath = AvailablePlugins.First(x => x.Name == pluginName).DLLPath;

            try
            {
                //VstHostCommandBase hostCmdStub = new VstHostCommandBase(this);
                //hostCmdStub.PluginCalled += hostCmdStub_PluginCalled;
                pluginContext = VstPluginContext.Create(pluginPath, this);

                // add custom data to the context
                pluginContext.Set("PluginPath", pluginName);
                pluginContext.Set("HostCmdStub", this);

                // actually open the plugin itself
                pluginContext.PluginCommandStub.Open();
                pluginContext.PluginCommandStub.SetBlockSize(mAsioBuffSize);
                if (mAsio != null)
                {
                    pluginContext.PluginCommandStub.SetSampleRate((float)mAsio.SampleRate);
                }
                pluginContext.PluginCommandStub.SetProcessPrecision(VstProcessPrecision.Process32);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(pluginContext);
        }
Exemplo n.º 6
0
        //load from file
        private VstPluginContext OpenPlugin(string pluginPath)
        {
            try
            {
                HostCommandStub hostCmdStub = new HostCommandStub();
                hostCmdStub.PluginCalled += HostCmdStub_PluginCalled;
                hostCmdStub.RaiseSave     = SetNeedsSafe;

                VstPluginContext ctx = VstPluginContext.Create(pluginPath, hostCmdStub);
                var midiOutChannels  = ctx.PluginCommandStub.GetNumberOfMidiOutputChannels();

                //if(midiOutChannels > 0)
                {
                    hostCmdStub.FProcessEventsAction = ReceiveEvents;
                }

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

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

                return(ctx);
            }
            catch (Exception e)
            {
                MessageBox.Show(FOwnerWindow, e.ToString(), "VST Load", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(null);
        }
Exemplo n.º 7
0
        public void Create_InvalidPluginFile_ThrowsExpectedExceptionWithResourceString()
        {
            var hostCmdStub    = new StubHostCommandStub();
            var notaPluginFile = Assembly.GetExecutingAssembly().Location;

            VstPluginContext.Create(notaPluginFile, hostCmdStub);
        }
Exemplo n.º 8
0
        //private void OutPluginInfo(VstPluginContext ctx)
        //{
        //		Debug.Print("Plugin: " + ctx.PluginCommandStub.GetEffectName() + " "
        //		            + ctx.PluginCommandStub.GetProductString()
        //		            + "Version: " + ctx.PluginCommandStub.GetVendorVersion().ToString() + "\n"
        //		            + "***********************************************************************\n");
        //}

        public VstPluginContext OpenPlugin(string pluginPath)
        {
            try
            {
                HostCommandStub hostCmdStub = new HostCommandStub();
                hostCmdStub.PluginCalled += new EventHandler <PluginCalledEventArgs>(HostCmdStub_PluginCalled);

                VstPluginContext ctx = VstPluginContext.Create(pluginPath, hostCmdStub);

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

                // actually open the plugin itself
                ctx.PluginCommandStub.Open();
                Plugin plugin = new Plugin(ctx.PluginInfo.PluginID, ctx.PluginCommandStub.GetProductString(), ctx,
                                           GetParameters(ctx));
                Plugins.Add(ctx.PluginInfo.PluginID, plugin);
                Debug.Print("Plugin: " + pluginPath + " Loaded");
                return(ctx);
            }
            catch (Exception e)
            {
                Debug.Print(e.Message);
            }

            return(null);
        }
Exemplo n.º 9
0
        public static VST LoadVst(string vstPath, IntPtr hWnd)
        {
            DisposeVst();

            _generalVst = new VST();

            var hcs = new HostCommandStub {
                Directory = System.IO.Path.GetDirectoryName(vstPath)
            };

            try
            {
                _generalVst.pluginContext = VstPluginContext.Create(vstPath, hcs);
                _generalVst.pluginContext.PluginCommandStub.Open();
                _generalVst.pluginContext.PluginCommandStub.SetProgram(13000);
                _generalVst.pluginContext.PluginCommandStub.EditorOpen(hWnd);
                _generalVst.pluginContext.PluginCommandStub.MainsChanged(true);

                _vstStream = new VSTStream();
                _vstStream.ProcessCalled += _generalVst.Stream_ProcessCalled;
                _vstStream.pluginContext  = _generalVst.pluginContext;
                _vstStream.SetWaveFormat(44100, 2);

                _mixer32.AddInputStream(_vstStream);

                return(_generalVst);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(null);
        }
Exemplo n.º 10
0
        public void Create_InvalidPluginFile_ThrowsExpectedException()
        {
            var hostCmdStub    = new StubHostCommandStub();
            var notaPluginFile = Assembly.GetExecutingAssembly().Location;

            Action target = () => VstPluginContext.Create(notaPluginFile, hostCmdStub);

            target.Should().Throw <EntryPointNotFoundException>();
        }
Exemplo n.º 11
0
        private VstPluginContext OpenPlugin(string pluginPath)
        {
            try
            {
                HostCommandStub hostCmdStub = new HostCommandStub();
                //hostCmdStub.PluginCalled += new EventHandler<PluginCalledEventArgs>(HostCmdStub_PluginCalled);

                VstPluginContext ctx = VstPluginContext.Create(pluginPath, hostCmdStub);

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

                // actually open the plugin itself
                ctx.PluginCommandStub.Open();
                ctx.PluginCommandStub.SetSampleRate(44100f);
                ctx.PluginCommandStub.SetBlockSize(512);

                ctx.PluginCommandStub.MainsChanged(true);
                ctx.PluginCommandStub.StartProcess();

                var sp = new VstSpeakerArrangement();

                sp.Type = VstSpeakerArrangementType.SpeakerArrStereo;


                VstSpeakerProperties[] f = new VstSpeakerProperties[2];

                f[0]             = new VstSpeakerProperties();
                f[1]             = new VstSpeakerProperties();
                f[0].SpeakerType = VstSpeakerTypes.SpeakerL;
                f[1].SpeakerType = VstSpeakerTypes.SpeakerR;

                sp.Speakers = f;

                var spin = new VstSpeakerArrangement();
                spin.Type = VstSpeakerArrangementType.SpeakerArrEmpty;

                VstSpeakerProperties[] f2 = new VstSpeakerProperties[0];

                spin.Speakers = f2;

                //ctx.PluginCommandStub.SetSpeakerArrangement(spin, sp);

                return(ctx);
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(null);
        }
Exemplo n.º 12
0
        void CreateContext(string path)
        {
            if (context != null)
            {
                try{ context.PluginCommandStub.Close(); } catch {}
                try{ context.Dispose(); } catch {}
                try{ context = null; } catch {}
            }
            context = VstPluginContext.Create(path, Host.VstHost);
            PluginCommandStub.SetSampleRate(Convert.ToSingle(Host.VstPlayer.Settings.Rate));
            Set("PluginPath", PluginPath = path);
            Set("HostCmdStub", Host.VstHost);
//			if (context!=null) Open();
        }
Exemplo n.º 13
0
        public VSTiInterface(string pluginPath)
        {
            HostCommandStub hostCmdStub = new HostCommandStub();

            hostCmdStub.PluginCalled += new EventHandler <PluginCalledEventArgs>(HostCmdStub_PluginCalled);

            ctx = VstPluginContext.Create(pluginPath, hostCmdStub);

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

            // actually open the plugin itself
            ctx.PluginCommandStub.Open();
        }
Exemplo n.º 14
0
        private VstPluginContext OpenPlugin(string pluginPath)
        {
            _host = new HostCommandStub();

            var ctx = VstPluginContext.Create(pluginPath, _host);

            ctx.Set("PluginPath", pluginPath);
            ctx.Set("HostCmdStub", _host);

            ctx.PluginCommandStub.SetSampleRate(1000 * _host.GetSampleRate());

            ctx.PluginCommandStub.Open();

            return(ctx);
        }
Exemplo n.º 15
0
        public void OpenPlugin(string pluginPath, Jacobi.Vst.Core.Host.IVstHostCommandStub hostCmdStub)
        {
            try
            {
                VstPluginContext ctx = VstPluginContext.Create(pluginPath, hostCmdStub);

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

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

                // there is a question whether we should "turn on" the plugin here or later
                // by "turn on" i mean do MainsChanged(true)
                // a working Vst Host (see MidiVstTest, a copy from the microDRUM project)
                // does the following:
                //
                // GeneralVST.pluginContext = VstPluginContext.Create(VSTPath, hcs);
                // GeneralVST.pluginContext.PluginCommandStub.Open();
                // GeneralVST.pluginContext.PluginCommandStub.EditorOpen(hWnd);
                // GeneralVST.pluginContext.PluginCommandStub.MainsChanged(true);

                // While a forum entry suggested the following:
                // [plugin.Open()]
                // plugin.MainsChanged(true) // turn on 'power' on plugin.
                // plugin.StartProcess() // let the plugin know the audio engine has started
                // PluginContext.PluginCommandStub.ProcessEvents(ve); // process events (like VstMidiEvent)
                //
                // while(audioEngineIsRunning)
                // {
                //     plugin.ProcessReplacing(inputBuffers, outputBuffers)  // letplugin process audio stream
                // }
                //
                // plugin.StopProcess()
                // plugin.MainsChanged(false)
                //
                // [plugin.Close()]

                //doPluginOpen();
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(e.ToString(), e.InnerException);
            }
        }
Exemplo n.º 16
0
        private static void LoadVstInternal(RemoteVstPlugin remoteVst, bool debug = false)
        {
            var hostCommandStub = new NewHostCommandStub(remoteVst.Logger);

            hostCommandStub.PluginDll = Path.GetFileName(remoteVst.DllPath);

            remoteVst.Logger.Debug($"{hostCommandStub.PluginDll}: Loading plugin");


            var ctx = VstPluginContext.Create(remoteVst.DllPath, hostCommandStub);

            ctx.Set("Plugin", remoteVst);

            remoteVst.PluginContext = ctx;
            ctx.Set("PluginPath", remoteVst.DllPath);
            ctx.Set("HostCmdStub", hostCommandStub);

            remoteVst.Logger.Debug($"{hostCommandStub.PluginDll}: Opening plugin");

            ctx.PluginCommandStub.Open();

            remoteVst.Logger.Debug($"{hostCommandStub.PluginDll}: Setting Sample Rate {SampleRate}");


            ctx.PluginCommandStub.SetSampleRate(SampleRate);

            remoteVst.Logger.Debug($"{hostCommandStub.PluginDll}: Setting Block Size {BlockSize}");

            ctx.PluginCommandStub.SetBlockSize(BlockSize);

            remoteVst.Logger.Debug($"{hostCommandStub.PluginDll}: Setting 32 bit precision");

            ctx.PluginCommandStub.SetProcessPrecision(VstProcessPrecision.Process32);

            remoteVst.Logger.Debug($"{hostCommandStub.PluginDll}: Activating output");


            remoteVst.PluginContext.PluginCommandStub.MainsChanged(true);

            remoteVst.Logger.Debug($"{hostCommandStub.PluginDll}: Start Processing");

            ctx.PluginCommandStub.StartProcess();

            remoteVst.IsLoaded = true;
        }
Exemplo n.º 17
0
        public VstPluginInfo GetPluginInfo(IVstHostCommandProxy hostCmdProxy)
        {
            //
            // get the path to the wrapped plugin from config
            //

            if (PluginConfiguration == null)
            {
                throw new InvalidOperationException("No plugin configuration found.");
            }

            var pluginPath = PluginConfiguration["PluginPath"];

            Host.HostCommandStubAdapter hostCmdAdapter = new Host.HostCommandStubAdapter(hostCmdProxy);
            _pluginCtx = VstPluginContext.Create(pluginPath, hostCmdAdapter);

            return(_pluginCtx.PluginInfo);
        }
Exemplo n.º 18
0
        private VstPluginContext OpenPlugin(string pluginPath)
        {
            try
            {
                HostCommandStub hostCmdStub = new HostCommandStub();
                hostCmdStub.PluginCalled += new EventHandler <PluginCalledEventArgs>(HostCmdStub_PluginCalled);

                VstPluginContext ctx = VstPluginContext.Create(pluginPath, hostCmdStub);

                ctx.Set("PluginPath", pluginPath);
                ctx.Set("HostCmdStub", hostCmdStub);

                ctx.PluginCommandStub.Open();

                return(ctx);
            }
            catch (Exception) { }

            return(null);
        }
        public static VST LoadVST(string VSTPath, int sampleRate, int channels)
        {
            DisposeVST();

            GeneralVST = new VST();

            var hcs = new HostCommandStub();

            hcs.Directory = System.IO.Path.GetDirectoryName(VSTPath);

            try
            {
                GeneralVST.PluginContext = VstPluginContext.Create(VSTPath, hcs);

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

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

                // Method arguments used to contain the following to allow
                // opening the vst plugin editor - not supported in this commanline processor
                // public static VST LoadVST(string VSTPath, IntPtr hWnd)
                // GeneralVST.pluginContext.PluginCommandStub.EditorOpen(hWnd);
                GeneralVST.PluginContext.PluginCommandStub.MainsChanged(true);

                vstStream = new VSTStream();
                vstStream.pluginContext = GeneralVST.PluginContext;
                vstStream.SetWaveFormat(sampleRate, channels);

                Mixer32.AddInputStream(vstStream);

                return(GeneralVST);
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine("Could not load VST! ({0})", ex.Message);
            }
            return(null);
        }
Exemplo n.º 20
0
        private VstPluginContext LoadPlugin(string pluginPath)
        {
            try
            {
                HostCommandStub hostCommandStub = new HostCommandStub();
                hostCommandStub.PluginCalled += new EventHandler <PluginCalledEventArgs>(hostCommandStub_PluginCalled);
                VstPluginContext ctx = VstPluginContext.Create(pluginPath, hostCommandStub);
                ctx.Set("PluginPath", pluginPath);
                ctx.Set("HostCmdStub", hostCommandStub);
                ctx.PluginCommandStub.Commands.Open();

                selectVSTButton.Enabled = false;
                loadVSTButton.Enabled   = false;

                return(ctx);
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(null);
        }
Exemplo n.º 21
0
        public VstPluginInfo GetPluginInfo(IVstHostCommandStub hostCmdStub)
        {
            //
            // get the path to the wrapped plugin from config
            //

            if (PluginConfiguration == null)
            {
                throw new ApplicationException("No plugin configuration found.");
            }

            KeyValueConfigurationElement configElem = PluginConfiguration.AppSettings.Settings["PluginPath"];

            if (configElem == null)
            {
                throw new ApplicationException("The 'PluginPath' configuration (app) setting was not found.");
            }

            Host.HostCommandStubAdapter hostCmdAdapter = new Host.HostCommandStubAdapter(hostCmdStub);
            _pluginCtx = VstPluginContext.Create(configElem.Value, hostCmdAdapter);

            return(_pluginCtx.PluginInfo);
        }
Exemplo n.º 22
0
        public void OpenPlugin(string pluginPath, Jacobi.Vst.Core.Host.IVstHostCommandStub hostCmdStub)
        {
            try
            {
                //HostCommandStub hostCmdStub = new HostCommandStub();
                //hostCmdStub.PluginCalled += new EventHandler<PluginCalledEventArgs>(HostCmdStub_PluginCalled);

                VstPluginContext ctx = VstPluginContext.Create(pluginPath, hostCmdStub);

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

                // actually open the plugin itself
                ctx.PluginCommandStub.Open();
                //doPluginOpen();

                PluginContext = ctx;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
        }
Exemplo n.º 23
0
        private VstPluginContext OpenPlugin(string pluginPath)
        {
            try
            {
                _host = new HostCommandStub();

                var ctx = VstPluginContext.Create(pluginPath, _host);

                ctx.Set("PluginPath", pluginPath);
                ctx.Set("HostCmdStub", _host);

                ctx.PluginCommandStub.SetSampleRate(1000 * _host.GetSampleRate());

                ctx.PluginCommandStub.Open();

                return(ctx);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace);
            }

            return(null);
        }
Exemplo n.º 24
0
        public static int SetUpPlugin(
            CallParameters parameters,
            System.Threading.CancellationToken cancellationToken
            )
        {
            var cancellationTaskSource = new CancellationTokenSource();

            Task.Run(() =>
            {
                cancellationToken.WaitHandle.WaitOne();
                form.Close();
            }, cancellationTaskSource.Token);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string pluginPath = parameters.VstPluginPath;

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

            ctx.PluginCommandStub.Open();

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

            ctx.PluginCommandStub.MainsChanged(true);
            form = new InvisibleForm(ctx);
            Application.Run(form);
            ctx.PluginCommandStub.MainsChanged(false);
            if (cancellationToken.IsCancellationRequested)
            {
                // Был затребован выход из программы
                ctx.PluginCommandStub.Close();
                cancellationTaskSource.Cancel();
                return(ReturnCodeOffset + 1);
            }

            byte[]  vstSaveState  = null;
            float[] vstParameters = null;

            if (!parameters.FxbFileAsParams)
            {
                vstSaveState = ctx.PluginCommandStub.GetChunk(true);
            }
            else
            {
                var vstParametersList = new List <float>();
                var paramCount        = ctx.PluginInfo.ParameterCount;
                for (int i = 0; i < paramCount; i++)
                {
                    vstParametersList.Add(ctx.PluginCommandStub.GetParameter(i));
                }

                vstParameters = vstParametersList.ToArray();
            }

            // VST навм больше не нужен, закрываем
            ctx.PluginCommandStub.Close();
            if (cancellationToken.IsCancellationRequested)
            {
                // Был затребован выход из программы
                cancellationTaskSource.Cancel();
                return(ReturnCodeOffset + 1);
            }

            int result;

            switch (parameters.FxbFileFormat.ToLowerInvariant())
            {
            case "fxb":
                result = SaveStateAsFxb(parameters.FxbFile, vstSaveState, vstParameters,
                                        !parameters.FxbFileAsParams,
                                        (uint)ctx.PluginInfo.PluginID, (uint)ctx.PluginInfo.PluginVersion);
                break;

            case "fxp":
                result = SaveStateAsFxp(parameters.FxbFile, vstSaveState, vstParameters,
                                        !parameters.FxbFileAsParams,
                                        (uint)ctx.PluginInfo.PluginID, (uint)ctx.PluginInfo.PluginVersion);
                break;

            default:
                Console.Error.WriteLine("Save state format {0} does not supported", parameters.FxbFileFormat);
                cancellationTaskSource.Cancel();
                return(ReturnCodeOffset + 2);
            }

            Console.WriteLine(
                "VST plugin settings saved to {0} (file format {1}; file subformat: {2})",
                parameters.FxbFile,
                parameters.FxbFileFormat,
                (parameters.FxbFileFormat.ToLowerInvariant() == "fxb")
                    ? "bank param with " + (parameters.FxbFileAsParams ? "preset param" : "preset opaque")
                    : (parameters.FxbFileAsParams ? "preset param" : "preset opaque")
                );

            cancellationTaskSource.Cancel();

            return((result > 0) ? ReturnCodeOffset + result : 0);
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
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();
            }
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
0
        private VstPluginContextWrapper OpenPlugin(string pluginPath)
        {
            try
            {
                if (File.Exists(pluginPath))
                {
                    HostCommandStub  hostCmdStub = new HostCommandStub();
                    VstPluginContext ctx         = VstPluginContext.Create(pluginPath, hostCmdStub);
                    if (ctx.PluginInfo.AudioInputCount != 2)
                    {
                        return(null);
                    }
                    if (ctx.PluginInfo.AudioOutputCount != 2)
                    {
                        return(null);
                    }
                    if ((ctx.PluginInfo.Flags & VstPluginFlags.CanReplacing) == 0)
                    {
                        return(null);
                    }

                    hostCmdStub.PluginCalled += (s, e) =>
                    {
                        HostCommandStub stub = (HostCommandStub)s;

                        // can be null when called from inside the plugin main entry point.
                        if (stub.PluginContext.PluginInfo != null)
                        {
                            //Debug.WriteLine("Plugin " + hostCmdStub.PluginContext.PluginInfo.PluginID + " called:" + e.Message);
                        }
                        else
                        {
                            //Debug.WriteLine("The loading Plugin called:" + e.Message);
                        }
                    };

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

                    // actually open the plugin itself
                    ctx.PluginCommandStub.Open();
                    ctx.PluginCommandStub.SetSampleRate(Program.CurrentSamplingRate);
                    ctx.PluginCommandStub.MainsChanged(true);
                    ctx.PluginCommandStub.StartProcess();
                    initVECCSS();
                    return(new VstPluginContextWrapper(ctx));
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(Exception))
                {
                    throw;
                }
                else if (ex.GetType() == typeof(SystemException))
                {
                    throw;
                }

                //ignore
            }

            return(null);
        }