Ejemplo n.º 1
0
        public void CreateBank(string name)
        {
            Bank bank = new Bank();
            List <ChannelPreset> presets = new List <ChannelPreset>();

            for (int x = 0; x < 8; x++)
            {
                ChannelPreset preset = new ChannelPreset();
                preset.InstrumentVstPreset       = new VSTPreset();
                preset.InstrumentVstPreset.Name  = string.Empty;
                preset.InstrumentVstPreset.State = PluginState.Empty;

                preset.EffectVstPresets = new VSTPreset[VstPluginChannel.NumberOfEffectPlugins];
                for (int i = 0; i < VstPluginChannel.NumberOfEffectPlugins; i++)
                {
                    preset.EffectVstPresets[i]       = new VSTPreset();
                    preset.EffectVstPresets[i].State = PluginState.Empty;
                    preset.EffectVstPresets[i].Name  = string.Empty;
                }
                preset.Volume = 1.0f;
                preset.Pan    = 0.0f;
                presets.Add(preset);
            }
            bank.Presets          = presets.ToArray();
            bank.Name             = name;
            bank.BPM              = 120;
            bank.MultiTrackVolume = 1.0f;
            mBankDict.Add(bank, bank.Name);
            Settings.BankFileNames.Add(GetBankFileName(name));
            SaveBank(bank);
            SaveSettings();
        }
Ejemplo n.º 2
0
        public void SaveBank()
        {
            for (int i = 0; i < 8; i++)
            {
                mActiveBank.Presets[i] = PluginChannels[i].ExportChannelPreset();

                ChannelPreset preset = mActiveBank.Presets[i];
            }
            mSettingsMgr.SaveBank(mActiveBank);
        }
Ejemplo n.º 3
0
        private void cbInstrument_ValueChanged(object sender, EventArgs e)
        {
            if (mCurrentInstrument != cbInstrument.SelectedIndex && cbInstrument.SelectedIndex != -1)
            {
                if (PluginChannel.InstrumentPlugin.State == PluginState.Activated)
                {
                    PluginChannel.InstrumentPlugin.Deactivate();
                }
                if (PluginChannel.InstrumentPlugin.State == PluginState.Deactivated)
                {
                    PluginChannel.InstrumentPlugin.Unload();

                    // Wait untill state becomes empty
                    while (PluginChannel.InstrumentPlugin.State == PluginState.Unloading)           // TODO: [JBK] bugfix; hangs if asio driver failed to load
                    {
                        Thread.Sleep(50);
                    }
                }
            }

            if (cbInstrument.SelectedIndex == 0)
            {
                // Selected index 0 = empty;
                //PluginChannel.InstrumentPlugin.SetVstPluginContext(null, null);
            }
            else if (cbInstrument.SelectedIndex > 0)
            {
                // Selected index 0 = empty;
                // Change of instrument?
                if (mCurrentInstrument != cbInstrument.SelectedIndex)
                {
                    string newInstrumentName = cbInstrument.Items[cbInstrument.SelectedIndex];

                    // Create new preset with activated state
                    ChannelPreset newPreset = new ChannelPreset();
                    newPreset.InstrumentVstPreset.Name  = newInstrumentName;
                    newPreset.InstrumentVstPreset.State = PluginState.Activated;
                    newPreset.InstrumentVstPreset.Data  = null;
                    mAudioPluginEngine.LoadChannelPreset(mVstPluginChannel, newPreset);

                    PluginChannel.InstrumentPlugin.ShowEditor();
                    HighlightControl(true);
                }
            }
            mCurrentInstrument = cbInstrument.SelectedIndex;
        }
Ejemplo n.º 4
0
        public void LoadChannelPreset(VstPluginChannel channel, ChannelPreset channelPreset)
        {
            // First load instrument
            if (channelPreset.InstrumentVstPreset.State != PluginState.Empty)
            {
                channel.InstrumentPlugin.AttachVstPluginContext(GetVstPluginContext(channelPreset.InstrumentVstPreset.Name), channelPreset.InstrumentVstPreset.Name);
            }

            // Then load all effects
            for (int i = 0; i < VstPluginChannel.NumberOfEffectPlugins; i++)
            {
                if (channelPreset.EffectVstPresets[i].State != PluginState.Empty)
                {
                    channel.EffectPlugins[i].AttachVstPluginContext(GetVstPluginContext(channelPreset.EffectVstPresets[i].Name), channelPreset.EffectVstPresets[i].Name);
                }
            }

            channel.ImportChannelPreset(channelPreset);
        }
Ejemplo n.º 5
0
        public void LoadBank(Bank bank)
        {
            mActiveBank = bank;
            bool firstEditorLoaded = false;

            // Make a list of required plugins that can be re-used from currently active plugins. Unload all others
            List <string> requiredPlugins = new List <string>();

            if (bank != null)
            {
                BPM = bank.BPM;
                for (int i = 0; i < 8; i++)
                {
                    if (bank.Presets[i].InstrumentVstPreset.State != PluginState.Empty)
                    {
                        requiredPlugins.Add(bank.Presets[i].InstrumentVstPreset.Name);
                    }
                    var res = bank.Presets[i].EffectVstPresets.Where(n => n.State != PluginState.Empty).Select(x => x.Name);
                    if (res.Count() > 0)
                    {
                        requiredPlugins.AddRange(res.ToArray());
                    }
                }
            }

            // Unload active plugins first
            for (int i = 0; i < 8; i++)
            {
                foreach (var plugin in PluginChannels[i].AllPlugins)
                {
                    if (plugin.State == PluginState.Activated)
                    {
                        plugin.Deactivate();
                    }
                    if (plugin.State == PluginState.Deactivated)
                    {
                        string pluginName = plugin.PluginName;
                        if (requiredPlugins.Contains(pluginName))
                        {
                            // Close the editor if open
                            plugin.CloseEditor();
                            requiredPlugins.Remove(pluginName);
                            // Move pluginContext from plugin class to local dictionary
                            mRecycledPluginContextDictionary.Add(plugin.VstPluginContext, pluginName);
                            // Remove object reference from plugin class and stop plugin audio
                            plugin.DetachVstPluginContext();
                        }
                        else
                        {
                            plugin.Unload();
                        }
                    }
                }
            }

            // Now load new plugins
            for (int i = 0; i < 8; i++)
            {
                if (bank != null)
                {
                    ChannelPreset preset = bank.Presets[i];

                    LoadChannelPreset(PluginChannels[i], preset);

                    // Only the first channel control with a loaded plugin should load an editor.
                    if (preset.InstrumentVstPreset.State != PluginState.Empty && !firstEditorLoaded)
                    {
                        firstEditorLoaded = true;
                        PluginChannels[i].InstrumentPlugin.ShowEditor();
                    }
                }
            }

            if (mRecycledPluginContextDictionary.Count != 0)
            {
                throw new Exception("mRecycledPluginContextDictionary.Count = " + mRecycledPluginContextDictionary.Count);
            }
        }