Exemplo n.º 1
0
        /// <summary>
        ///     Sets the VST plug-in settings.
        /// </summary>
        /// <param name="plugin">The plug-in.</param>
        /// <param name="parameters">The parameters.</param>
        public static void SetVstPluginParameters(VstPlugin plugin, string parameters)
        {
            if (parameters.Trim() == "")
            {
                return;
            }
            var values         = parameters.Split(',').ToList();
            var parameterCount = BassVst.BASS_VST_GetParamCount(plugin.Id);

            for (var i = 0; i < parameterCount; i++)
            {
                try
                {
                    if (i >= values.Count)
                    {
                        continue;
                    }
                    var value = float.Parse(values[i]);
                    BassVst.BASS_VST_SetParam(plugin.Id, i, value);
                }
                catch
                {
                    // ignored
                }
            }
        }
Exemplo n.º 2
0
        private void Initialize(VstPlugin plugin)
        {
            _plugin = plugin;

            CanClose     = false;
            FormClosing += VSTPluginConfigForm_FormClosing;

            MinimizeBox     = true;
            ShowInTaskbar   = true;
            FormBorderStyle = FormBorderStyle.SizableToolWindow;
            TopMost         = true;

            var borderSize = SystemInformation.BorderSize;

            Width  = plugin.EditorWidth + (borderSize.Width * 2) + 15;
            Height = plugin.EditorHeight + _menuStrip.Height + (borderSize.Height * 2) + 35;

            var icon = ApplicationHelper.GetIcon();

            if (icon != null)
            {
                Icon = icon;
            }

            Text = plugin.Name;


            BassVst.BASS_VST_EmbedEditor(plugin.Id, EditorPanelHandle);
            plugin.Form = this;

            LoadPresets(plugin);
        }
        private void Initialize(VstPlugin plugin)
        {
            _plugin = plugin;
            
            CanClose = false;
            FormClosing += VSTPluginConfigForm_FormClosing;

            MinimizeBox = true;
            ShowInTaskbar = true;
            FormBorderStyle = FormBorderStyle.SizableToolWindow;
            TopMost = true;

            var borderSize = SystemInformation.BorderSize;
            Width = plugin.EditorWidth + (borderSize.Width*2) + 15;
            Height = plugin.EditorHeight + _menuStrip.Height + (borderSize.Height*2) + 35;

            var icon = ApplicationHelper.GetIcon();
            if (icon != null) Icon = icon;

            Text = plugin.Name;


            BassVst.BASS_VST_EmbedEditor(plugin.Id, EditorPanelHandle);
            plugin.Form = this;

            LoadPresets(plugin);
        }
Exemplo n.º 4
0
        private static void SetPluginSyncNotes(VstPlugin plugin, decimal syncNotes)
        {
            if (plugin == null)
                return;

            foreach (var parameter in plugin.Parameters.Where(x => x.SyncToBpm && x.VariableSyncNotes))
            {
                parameter.SyncNotes = syncNotes;
            }
        }
Exemplo n.º 5
0
        public static List <VstPluginPreset> GetPluginPresets(VstPlugin plugin)
        {
            var names = BassVst.BASS_VST_GetProgramNames(plugin.Id).ToList();

            return(names.Select(name => new VstPluginPreset()
            {
                Id = names.IndexOf(name),
                Name = name.Trim()
            })
                   .Where(x => x.Name != "")
                   .ToList());
        }
Exemplo n.º 6
0
 private void VSTPluginConfigForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!CanClose)
     {
         e.Cancel = true;
         Visible  = false;
     }
     else
     {
         _plugin = null;
     }
 }
Exemplo n.º 7
0
        /// <summary>
        ///     Gets the VST plug-in settings.
        /// </summary>
        /// <param name="plugin">The plug-in.</param>
        /// <returns>The settings as a key=value comma delimited list</returns>
        public static string GetVstPluginParameters(VstPlugin plugin)
        {
            var values         = new List <string>();
            var parameterCount = BassVst.BASS_VST_GetParamCount(plugin.Id);

            for (var i = 0; i < parameterCount; i++)
            {
                var value = BassVst.BASS_VST_GetParam(plugin.Id, i);
                values.Add(value.ToString(CultureInfo.InvariantCulture));
            }
            return(string.Join(",", values.ToArray()));
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Shows the VST plug-in configuration screen.
        /// </summary>
        /// <param name="plugin">The plug-in.</param>
        public static void ShowVstPluginConfig(VstPlugin plugin)
        {
            if (plugin == null) return;

            if (plugin.Form != null && !plugin.Form.IsDisposed)
            {
                plugin.Form.Show();
                plugin.Form.BringToFront();
                return;
            }

            plugin.Form = null;

            var containerForm = new VstPluginConfigForm(plugin);
            containerForm.Show();
        }
Exemplo n.º 9
0
        /// <summary>
        ///     Shows the VST plug-in configuration screen.
        /// </summary>
        /// <param name="plugin">The plug-in.</param>
        public static void ShowVstPluginConfig(VstPlugin plugin)
        {
            if (plugin == null)
            {
                return;
            }

            if (plugin.Form != null && !plugin.Form.IsDisposed)
            {
                plugin.Form.Show();
                plugin.Form.BringToFront();
                return;
            }

            plugin.Form = null;

            var containerForm = new VstPluginConfigForm(plugin);

            containerForm.Show();
        }
Exemplo n.º 10
0
        private void LoadPresets(VstPlugin plugin)
        {
            var presets = PluginHelper.GetPluginPresets(plugin);

            foreach (var preset in presets)
            {
                var existingMenuItems = _mnuPresets.DropDownItems.Cast <ToolStripItem>().Select(t => t.Text).ToList();

                if (!existingMenuItems.Contains(preset.Name))
                {
                    var menuItem = new ToolStripMenuItem
                    {
                        Text = preset.Name,
                        Tag  = preset.Id
                    };
                    menuItem.Click += mnuPreset_Click;
                    _mnuPresets.DropDownItems.Add(menuItem);
                }
            }
        }
        private void LoadPresets(VstPlugin plugin)
        {
            var presets = PluginHelper.GetPluginPresets(plugin);

            foreach (var preset in presets)
            {
                var existingMenuItems = _mnuPresets.DropDownItems.Cast<ToolStripItem>().Select(t => t.Text).ToList();

                if (!existingMenuItems.Contains(preset.Name))
                {
                    var menuItem = new ToolStripMenuItem
                    {
                        Text = preset.Name,
                        Tag = preset.Id
                    };
                    menuItem.Click += mnuPreset_Click;
                    _mnuPresets.DropDownItems.Add(menuItem);
                }
            }
        }
Exemplo n.º 12
0
 public static void SetVstPluginPreset(VstPlugin plugin, int presetId)
 {
     BassVst.BASS_VST_SetProgram(plugin.Id, presetId);
 }
Exemplo n.º 13
0
 public VstPluginConfigForm(VstPlugin plugin)
 {
     InitializeComponent();
     Initialize(plugin);
 }
Exemplo n.º 14
0
        /// <summary>
        ///     Converts a sync length value to a VST specific percentage (based on the parameter max/min milliseconds)
        /// </summary>
        /// <param name="syncLength">Length of the delay in milliseconds.</param>
        /// <param name="parameter">The parameter.</param>
        /// <returns>
        ///     The VST specific percentage
        /// </returns>
        private static float GetVstSyncValue(double syncLength, VstPlugin.VstPluginParameter parameter)
        {
            var minMs = (double) parameter.MinSyncMilliSeconds;
            var maxMs = (double) parameter.MaxSyncMilliSeconds;

            if (syncLength < minMs) syncLength = minMs;
            if (syncLength > maxMs) syncLength = maxMs;

            return parameter.SyncUsingLogScale
                ? (float) (Math.Log10(syncLength/minMs)/Math.Log10(maxMs/minMs))
                : (float) ((syncLength - minMs)/(maxMs - minMs));
        }
Exemplo n.º 15
0
        private void SetPluginBpm(VstPlugin plugin)
        {
            if (plugin == null)
                return;
            if (BpmProvider == null)
                return;

            if (!plugin.Parameters.Any(x => x.SyncToBpm))
                return;

            var bpm = BpmProvider.GetCurrentBpm();
            var quarterNoteLength = BpmHelper.GetDefaultDelayLength(bpm);
            var fullNoteLength = quarterNoteLength*4;

            var syncParameters = plugin.Parameters.Where(p => p.SyncToBpm).ToList();

            var mutePlugin = syncParameters.Any(p => p.SyncNotes == 0);
            BassVst.BASS_VST_SetBypass(plugin.Id, mutePlugin);

            if (mutePlugin)
                return;

            foreach (var parameter in syncParameters)
            {
                var syncLength = fullNoteLength*(double) parameter.SyncNotes;
                var vstDelayValue = GetVstSyncValue(syncLength, parameter);
                BassVst.BASS_VST_SetParam(plugin.Id, parameter.Id, vstDelayValue);
            }
        }
Exemplo n.º 16
0
        private static void LoadPresetParameterValues(VstPlugin plugin, VstPlugin.VstPluginParameter parameter)
        {
            var presetParameters = new[]
            {
                new
                {
                    PluginName = "Tape Delay",
                    ParameterName = "Time",
                    SyncToBpm = true,
                    MinSyncMilliSeconds = 60M,
                    MaxSyncMilliSeconds = 1500M,
                    SyncUsingLogScale = false,
                    VariableSyncNotes = true,
                    DefaultSyncNotes = (1M/4M)
                },
                new
                {
                    PluginName = "Classic Delay",
                    ParameterName = "Time",
                    SyncToBpm = true,
                    MinSyncMilliSeconds = 50M,
                    MaxSyncMilliSeconds = 5000M,
                    SyncUsingLogScale = true,
                    VariableSyncNotes = true,
                    DefaultSyncNotes = (1M/4M)
                }
            }.ToList();


            var presetParameter = presetParameters
                .FirstOrDefault(p => string.Equals(plugin.Name, p.PluginName, StringComparison.CurrentCultureIgnoreCase)
                                     &&
                                     string.Equals(parameter.Name, p.ParameterName,
                                         StringComparison.CurrentCultureIgnoreCase));

            if (presetParameter == null) return;

            parameter.SyncToBpm = presetParameter.SyncToBpm;
            parameter.MinSyncMilliSeconds = presetParameter.MinSyncMilliSeconds;
            parameter.MaxSyncMilliSeconds = presetParameter.MaxSyncMilliSeconds;
            parameter.SyncUsingLogScale = presetParameter.SyncUsingLogScale;
            parameter.VariableSyncNotes = presetParameter.VariableSyncNotes;
            parameter.SyncNotes = presetParameter.DefaultSyncNotes;
        }
 private void VSTPluginConfigForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!CanClose)
     {
         e.Cancel = true;
         Visible = false;
     }
     else
     {
         _plugin = null;
     }
 }
Exemplo n.º 18
0
        /// <summary>
        ///     Loads a VST plug-in and applies it to the mixer
        /// </summary>
        /// <param name="location">The file location of the VST DLL</param>
        /// <param name="priority">The priority.</param>
        /// <returns>The VST plug-in</returns>
        private VstPlugin LoadAndApplyVstPlugin(string location, int priority)
        {
            if (location == "") return null;

            if (!File.Exists(location)) return null;

            var plugin = new VstPlugin
            {
                Id = BassVst.BASS_VST_ChannelSetDSP(ChannelId, location, BASSVSTDsp.BASS_VST_DEFAULT, priority)
            };

            if (plugin.Id == 0)
                throw new Exception("Cannot load plug-in " + Path.GetFileNameWithoutExtension(location));

            var info = BassVst.BASS_VST_GetInfo(plugin.Id);
            if (info != null)
            {
                plugin.Name = info.effectName;
                plugin.EditorWidth = info.editorWidth;
                plugin.EditorHeight = info.editorHeight;
            }
            else
            {
                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(location);
                if (fileNameWithoutExtension != null)
                    plugin.Name = StringHelper.TitleCase(fileNameWithoutExtension.Replace("_", " "));
            }

            if (plugin.EditorWidth == 0) plugin.EditorWidth = 400;
            if (plugin.EditorHeight == 0) plugin.EditorHeight = 600;

            plugin.Location = location;
            LoadPluginParameters(plugin);

            SetPluginBpm(plugin);

            return plugin;
        }
Exemplo n.º 19
0
        private void RemoveVstPlugin(VstPlugin plugin)
        {
            if (plugin == null) return;
            DebugHelper.WriteLine("Unload plug-in" + plugin.Name);
            if (plugin.Form != null)
            {
                if (!plugin.Form.IsDisposed)
                {
                    plugin.Form.CanClose = true;
                    plugin.Form.Close();
                    plugin.Form.Dispose();
                    plugin.Form = null;
                }
            }

            BassVst.BASS_VST_ChannelRemoveDSP(ChannelId, plugin.Id);
        }
 public VstPluginConfigForm(VstPlugin plugin)
 {
     InitializeComponent();
     Initialize(plugin);
 }
Exemplo n.º 21
0
 public static void SetVstPluginPreset(VstPlugin plugin, int presetId)
 {
     BassVst.BASS_VST_SetProgram(plugin.Id, presetId);
 }
Exemplo n.º 22
0
 /// <summary>
 ///     Sets the VST plug-in settings.
 /// </summary>
 /// <param name="plugin">The plug-in.</param>
 /// <param name="parameters">The parameters.</param>
 public static void SetVstPluginParameters(VstPlugin plugin, string parameters)
 {
     if (parameters.Trim() == "") return;
     var values = parameters.Split(',').ToList();
     var parameterCount = BassVst.BASS_VST_GetParamCount(plugin.Id);
     for (var i = 0; i < parameterCount; i++)
     {
         try
         {
             if (i >= values.Count) continue;
             var value = float.Parse(values[i]);
             BassVst.BASS_VST_SetParam(plugin.Id, i, value);
         }
         catch
         {
             // ignored
         }
     }
 }
Exemplo n.º 23
0
 /// <summary>
 ///     Gets the VST plug-in settings.
 /// </summary>
 /// <param name="plugin">The plug-in.</param>
 /// <returns>The settings as a key=value comma delimited list</returns>
 public static string GetVstPluginParameters(VstPlugin plugin)
 {
     var values = new List<string>();
     var parameterCount = BassVst.BASS_VST_GetParamCount(plugin.Id);
     for (var i = 0; i < parameterCount; i++)
     {
         var value = BassVst.BASS_VST_GetParam(plugin.Id, i);
         values.Add(value.ToString(CultureInfo.InvariantCulture));
     }
     return string.Join(",", values.ToArray());
 }
Exemplo n.º 24
0
 public static List<VstPluginPreset> GetPluginPresets(VstPlugin plugin)
 {
     var names = BassVst.BASS_VST_GetProgramNames(plugin.Id).ToList();
     return names.Select(name => new VstPluginPreset()
     {
         Id = names.IndexOf(name),
         Name = name.Trim()
     })
     .Where(x => x.Name != "")
     .ToList();
 }
Exemplo n.º 25
0
        private static void LoadPluginParameters(VstPlugin plugin)
        {
            plugin.Parameters = new List<VstPlugin.VstPluginParameter>();

            var parameterCount = BassVst.BASS_VST_GetParamCount(plugin.Id);
            for (var i = 0; i < parameterCount; i++)
            {
                var parameterInfo = BassVst.BASS_VST_GetParamInfo(plugin.Id, i);

                var name = parameterInfo.name.Trim();
                if (string.IsNullOrWhiteSpace(name) || name.ToLower().StartsWith("unused"))
                    continue;

                var parameter = new VstPlugin.VstPluginParameter
                {
                    Id = i,
                    Name = parameterInfo.name
                };

                LoadPresetParameterValues(plugin, parameter);

                plugin.Parameters.Add(parameter);
            }
        }