/// <summary> /// plugin.PluginCommandStub.ProcessReplacing(inputs, outputs); /// </summary> /// <param name="plugin"></param> /// <param name="inputs"></param> /// <param name="outputs"></param> VstAudioBuffer[] PluginPreProcess2(VstPlugin plugin, VstAudioBuffer[] inputs, VstAudioBuffer[] outputs) { plugin.PluginCommandStub.StartProcess(); plugin.PluginCommandStub.ProcessReplacing(inputs, outputs); plugin.PluginCommandStub.StopProcess(); return(outputs); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { service = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; if (service == null) { return(value); } var list = new ListBox(); list.Click += List_Click; lock (InstrumentBase.VstPluginContextLockObject) { VstPlugin inst = (VstPlugin)context.Instance; var ctx = inst.PluginContext.Context; if (ctx != null) { for (int i = 0; i < ctx.PluginInfo.ProgramCount; i++) { list.Items.Add(ctx.PluginCommandStub.GetProgramNameIndexed(i)); } } } service.DropDownControl(list); return((list.SelectedItem != null) ? list.SelectedItem : value); }
// ============== // Methods // ============== /// <summary> /// Step 5 / N /// </summary> /// <param name="plugin"></param> /// <param name="buffer"></param> /// <returns></returns> float[] ProcessToMixer(VstPlugin plugin, VstAudioBuffer[] buffer) { int indexOutput = 0; int oc = plugin.PluginInfo.AudioOutputCount; for (int j = 0; j < BlockSize; j++) { if (oc <= 2) { actualOutput[indexOutput] = buffer[0][j] * volume; actualOutput[indexOutput + 1] = buffer[(oc > 1)?1:0][j] * volume; } else if (oc >= 4) { actualOutput[indexOutput] = FloatMathExtension.Combine(volume, buffer[0][j], buffer[2][j]); actualOutput[indexOutput + 1] = FloatMathExtension.Combine(volume, buffer[1][j], buffer[3][j]); } indexOutput += 2; Parent.BufferIncrement++; } return(actualOutput); }
void PluginResetBuffers(VstPlugin input, VstPlugin output, int blockSize) { if (Inputs != null) { if (Inputs.BlockSize != blockSize && input != null) { Inputs = PluginResetBuffer(input, blockSize); } } else if (input != null) { Inputs = PluginResetBuffer(input, blockSize); } if (Outputs != null) { if (Outputs.BlockSize != blockSize && output != null) { Outputs = PluginResetBuffer(output, blockSize); } } else if (output != null) { Outputs = PluginResetBuffer(output, blockSize); } }
public EffectPluginControl(AudioPluginEngine audioPluginEngine, VstPlugin vstPlugin, string[] effectNames) { mAudioPluginEngine = audioPluginEngine; InitializeComponent(); mVstPlugin = vstPlugin; cbEnabled.Checked = (vstPlugin.State == Common.PluginState.Activated); cbEffectNames.Items.AddRange(effectNames); if (vstPlugin.State == PluginState.Empty) { cbEffectNames.SelectedIndex = 0; } else { try { cbEffectNames.SelectedItem = vstPlugin.PluginName; } catch (Exception ex) { MessageBox.Show(ex.Message); } } cbEnabled.Enabled = cbEffectNames.SelectedIndex != 0; btnEdit.Enabled = vstPlugin.State != PluginState.Empty; mIgnoreEvents = false; }
public EditorFrame(INaudioVstContainer owner, VstPlugin ctx) : this() { Context = ctx; VstContainer = owner; // plugin.SetBlockSize(512); Context.InitializeComboBox(-1, comboBox1); }
IEnumerable <int> ParameterCount(VstPlugin plugin) { for (int i = 0; i < plugin.PluginInfo.ParameterCount; i++) { yield return(i); } }
private static void LoadPluginParameters(VstPlugin plugin) { plugin.Parameters = new List <VstPlugin.VstPluginParameter>(); if (plugin.Name.Contains("mania")) { Console.WriteLine("mani"); } 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); } }
/// <summary> /// Ignore nulll entries. /// Convert output to 2 channel if necessary. /// </summary> /// <param name="plugin"></param> /// <param name="inputs"></param> /// <param name="outputs">VstAudioBuffer[2]</param> VstAudioBuffer[] PluginProcess(VstPlugin plugin, VstAudioBuffer[] inputs, VstAudioBuffer[] outputs) { VstAudioBuffer[] newinputs = inputs.Length == 1 ? new VstAudioBuffer[] { inputs[0], inputs[0] } : inputs; return(plugin == null ? newinputs : PluginPreProcess2(plugin, newinputs, outputs)); }
void UpdateBlockSize(NAudioVST naudiovst, VstPlugin plugin, AudioProcess parent) { VstAudioBufferManager io = new VstAudioBufferManager(plugin.PluginInfo.AudioOutputCount, BlockSize); UpdateBlock(naudiovst, plugin); binput = parent.boutput; boutput = io.ToArray(); }
AudioModule PluginResetBuffer(VstPlugin plugin, int blockSize) { if (plugin != null) { return(new AudioModule(plugin, blockSize, plugin.Host.VstPlayer.Settings.Rate)); } return(null); }
/// <summary> /// With midi info /// </summary> /// <param name="plugin"></param> /// <param name="blockSize"></param> /// <param name="inputs"></param> /// <param name="outputs"></param> VstAudioBuffer[] PluginPreProcess1(VstPlugin plugin, int blockSize, VstAudioBuffer[] inputs, VstAudioBuffer[] outputs) { if (HasMidi(plugin.Host.Parent)) { VstMidiEnumerator.SendMidi2Plugin(plugin, plugin.Host.Parent, blockSize); } return(PluginPreProcess2(plugin, inputs, outputs)); }
public static void Initialize(INaudioVstContainer owner, VstPlugin ctx) { PluginProgram pgm = new PluginProgram(); pgm.Plugin = ctx; ctx.PluginCommandStub.SetBlockSize(512); owner.VstHost.ProcessIdle(); pgm.PgmInit(owner,ctx,-1); }
public EditorFrame(INaudioVstContainer owner, VstPlugin ctx) : this() { Context = ctx; VstContainer = owner; // plugin.SetBlockSize(512); Context.InitializeComboBox(-1,comboBox1); }
public VstCCPgm(VstPlugin plugin, int id) { this.plugin = plugin; // begin(); ID = id; Name = Stub.GetProgramName(); // end(); }
static public void Initialize(INaudioVstContainer owner, VstPlugin ctx) { PluginProgram pgm = new PluginProgram(); pgm.Plugin = ctx; ctx.PluginCommandStub.SetBlockSize(512); owner.VstHost.ProcessIdle(); pgm.PgmInit(owner, ctx, -1); }
public Plugin(VstPlugin source) : this() { if (!string.IsNullOrEmpty(source.Title)) Title = source.Title; else Title = "(Unknown Plugin)"; PgmID = (source.ActiveProgram==null) ? 0 : source.ActiveProgram.ID; byte[] ck = source.PgmData; if (ck!=null) ProgramDump = ck; }
public VstAudioBuffer[] GeneralProcess(VstPlugin vstInput, VstPlugin vstOutput) { if (Inputs == null || Inputs.BlockSize != BlockSize) { PluginResetBuffers(vstInput, vstOutput, BlockSize); } PluginPreProcess1(vstInput, BlockSize, Inputs[0].ToArray(), Inputs[1].ToArray()); return(PluginProcess(vstOutput, Inputs[1].ToArray(), Outputs[1].ToArray())); }
/// <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); }
public void ParamTest(System.Windows.Forms.ComboBox cbActiveParams, VstPlugin plugin) { cbActiveParams.Items.Clear(); var ccp = new VstCCPgm(plugin, plugin.ProgramIndex); foreach (int i in ParameterCount(plugin)) { VstCCParam para = ccp[i]; cbActiveParams.Items.Add(para); } }
public void ShowPlugin(VstPlugin plugin) { if (plugin == null) { ShowPluginsForm(); } else { PluginHelper.ShowVstPluginConfig(plugin); } }
private void StopPlugin(VstPlugin plugin) { if (plugin.State == PluginState.Activated) { plugin.Deactivate(); } if (plugin.State == PluginState.Deactivated) { plugin.Unload(); } }
void UpdateBlockSize(NAudioVST naudiovst, VstPlugin plugin) { VstAudioBufferManager ii = null, io = null; ii = new VstAudioBufferManager(plugin.PluginInfo.AudioInputCount, BlockSize); io = new VstAudioBufferManager(plugin.PluginInfo.AudioOutputCount, BlockSize); UpdateBlock(naudiovst, plugin); binput = ii.ToArray(); boutput = io.ToArray(); }
void PgmInit(INaudioVstContainer owner, VstPlugin Context, int selectedPgm) { if (selectedPgm!=-1) { VstCCPgm backupPgm = new VstCCPgm( Context, selectedPgm ); pgmBackup = backupPgm.GetChunk(true); } Notify("Initialized"); // foreach (VstCCPgm program in VstCCPgm.EnumPrograms(Context)) // comboBox1.Items.Add(program); // if (selectedPgm != -1) comboBox1.SelectedIndex = selectedPgm; // comboBox1.SelectedIndexChanged += new EventHandler(PgmChanged); }
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; } }
void PgmInit(INaudioVstContainer owner, VstPlugin Context, int selectedPgm) { if (selectedPgm != -1) { VstCCPgm backupPgm = new VstCCPgm(Context, selectedPgm); pgmBackup = backupPgm.GetChunk(true); } Notify("Initialized"); // foreach (VstCCPgm program in VstCCPgm.EnumPrograms(Context)) // comboBox1.Items.Add(program); // if (selectedPgm != -1) comboBox1.SelectedIndex = selectedPgm; // comboBox1.SelectedIndexChanged += new EventHandler(PgmChanged); }
void InitializeBufferManagers(VstPlugin plugin, int blockSize) { this.InputsCount = plugin.PluginInfo.AudioInputCount; this.OutputsCount = plugin.PluginInfo.AudioOutputCount; this.BlockSize = blockSize; // this.Inputs = new VstAudioBufferManager(InputsCount, blockSize); if (OutputsCount > 0) { this.Outputs = new VstAudioBufferManager(OutputsCount, blockSize); } PluginProcessPrepare(plugin, blockSize); }
public Plugin(VstPlugin source) : this() { if (!string.IsNullOrEmpty(source.Title)) { Title = source.Title; } else { Title = "(Unknown Plugin)"; } PgmID = (source.ActiveProgram == null) ? 0 : source.ActiveProgram.ID; byte[] ck = source.PgmData; if (ck != null) { ProgramDump = ck; } }
public VstModule(VstPlugin plugin) { title = plugin.Title; patchId = plugin.PluginCommandStub.GetProgram(); category = plugin.PluginCommandStub.GetCategory().ToString(); // var result = plugin.PluginCommandStub.BeginLoadBank( // new VstPatchChunkInfo( // 1, // plugin.PluginInfo.PluginID, // plugin.PluginInfo.PluginVersion, // plugin.PluginInfo.ProgramCount // ) // ); // if (result== VstCanDoResult.Yes) { } try { this.ProgramDump = plugin.PluginCommandStub.GetChunk(false); } catch { } try { this.PatchDump = plugin.PluginCommandStub.GetChunk(true); } catch { } }
static public VstPluginBank Read(VstPlugin plugin, string fileName) { VstPatchChunkInfo x; VstPluginBank bank = VstPluginBank.Prepare(plugin); using (FileStream stream = new FileStream(fileName,FileMode.Open,FileAccess.Read,FileShare.ReadWrite)) using (BinaryReader reader = new BinaryReader(stream,System.Text.Encoding.Unicode)) { bank.ChunkMagic = reader.ReadInt32(); bank.ChunkSize = reader.ReadInt32(); bank.PluginMagic = reader.ReadInt32(); bank.Version = reader.ReadInt32(); bank.PluginId = reader.ReadInt32(); bank.PluginVersion = reader.ReadInt32(); bank.NumPrograms = reader.ReadInt32(); } return bank; }
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); }
static public void SendMidi2Plugin(VstPlugin vstMidiPlugin, IMidiParserUI ui, int blockSize) { if (vstMidiPlugin == null) { return; } var EventR = new List <NVstEvent>( GetSampleOffsetBlock(ui, vstMidiPlugin.IgnoreMidiProgramChange, blockSize) ); NVstEvent[] range = EventR.ToArray(); EventR.Clear(); EventR = null; if (range != null && range.Length > 0) { vstMidiPlugin.PluginCommandStub.ProcessEvents(range); } }
/// <summary> /// /// </summary> /// <param name="vp"></param> /// <param name="controlNo">1~5</param> /// <returns></returns> public string[] GetProperties(VstPlugin vp, int controlNo) { switch (controlNo) { case 1: return(getPropertiesInfo(vp, VstEffectSoundControl1)); case 2: return(getPropertiesInfo(vp, VstEffectSoundControl2)); case 3: return(getPropertiesInfo(vp, VstEffectSoundControl3)); case 4: return(getPropertiesInfo(vp, VstEffectSoundControl4)); case 5: return(getPropertiesInfo(vp, VstEffectSoundControl5)); } return(null); }
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); } }
/// <summary> /// /// </summary> /// <param name="vp"></param> /// <param name="propertyName"></param> /// <returns></returns> private string[] getPropertiesInfo(VstPlugin vp, string propertyNames) { List <string> plist = new List <string>(); var tt = vp.GetType(); if (!string.IsNullOrWhiteSpace(propertyNames)) { string[] propNameParts = propertyNames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var propertyName in propNameParts) { string pn = propertyName.Trim(); if (propertyInfoTable.ContainsKey(pn)) { if (propertyInfoTable[pn] != null) { plist.Add(pn); } continue; } foreach (var rp in vp.Settings.GetAllRawProperties()) { if (pn.Equals(rp.Key.Trim())) { plist.Add(pn); propertyInfoTable.Add(pn, new object()); break; } } if (!propertyInfoTable.ContainsKey(pn)) { propertyInfoTable.Add(pn, null); } } } return(plist.ToArray()); }
public void RemovePlugin(VstPlugin ctx) { if ( ctx != null ) { string path = ctx.PluginPath; // checkme ctx.PrsData = null; // checkme ctx.Dispose(); pluginsList.Remove(path); // checkme _plugins.Remove(ctx); OnPropertyChanged("RemovePlugin"); } }
public IOModule Reset(int blockSize, VstPlugin vstI, VstPlugin vstO) { BlockSize = blockSize; PluginResetBuffers(vstI,vstO,blockSize); return this; }
void UpdateBlockSize( NAudioVST naudiovst, VstPlugin plugin, AudioProcess parent) { VstAudioBufferManager io = new VstAudioBufferManager(plugin.PluginInfo.AudioOutputCount, BlockSize); UpdateBlock(naudiovst,plugin); binput = parent.boutput; boutput = io.ToArray(); }
public AudioProcess(NAudioVST naudiovst, VstPlugin plugin, AudioProcess parent) { this.nch = parent.nch; this.BlockSize = parent.BlockSize; UpdateBlockSize(naudiovst,plugin,parent); }
public void Process(VstPlugin plugin) { Process(plugin, binput, boutput); }
public void Process(VstPlugin plugin, VstAudioBuffer[] insI, VstAudioBuffer[] insO) { plugin.PluginCommandStub.StartProcess(); plugin.PluginCommandStub.ProcessReplacing(insI, insO); plugin.PluginCommandStub.StopProcess(); }
void UpdateBlock(VstPlugin plugin, int blockSize) { plugin.PluginCommandStub.SetBlockSize(blockSize); plugin.PluginCommandStub.SetSampleRate(Parent.Settings.Rate); plugin.PluginCommandStub.SetProcessPrecision(VstProcessPrecision.Process32); }
public static IEnumerable<VstCCPgm> EnumPrograms(VstPlugin ctx) { for (int i = 0; i < ctx.PluginInfo.ProgramCount; i++) yield return new VstCCPgm( ctx, i ); }
void PluginResetBuffers(VstPlugin input, VstPlugin output, int blockSize) { if (Inputs!=null) { if (Inputs.BlockSize!=blockSize && input!=null) Inputs = PluginResetBuffer(input,blockSize); } else if (input!=null) Inputs = PluginResetBuffer(input,blockSize); if (Outputs!=null) { if (Outputs.BlockSize!=blockSize && output!=null) Outputs = PluginResetBuffer(output,blockSize); } else if (output!=null) Outputs = PluginResetBuffer(output,blockSize); }
public static IOModule Create(int blockSize, VstPlugin vstI, VstPlugin vstO) { var module = new IOModule(); return module.Reset(blockSize,vstI,vstO); }
/// <summary> /// With midi info /// </summary> /// <param name="plugin"></param> /// <param name="blockSize"></param> /// <param name="inputs"></param> /// <param name="outputs"></param> VstAudioBuffer[] PluginPreProcess1(VstPlugin plugin, int blockSize, VstAudioBuffer[] inputs, VstAudioBuffer[] outputs) { if (HasMidi(plugin.Host.Parent)) VstMidiEnumerator.SendMidi2Plugin( plugin, plugin.Host.Parent, blockSize ); return PluginPreProcess2(plugin,inputs,outputs); }
public VstPlugin OpenPlugin(string pluginPath, bool ignoreAdd) { bool haserror = false; VstPlugin ctx = null; try { ctx = new VstPlugin(pluginPath,Parent); } catch (Exception xx) { haserror = true; // System.Diagnostics.Debug.Print("{0}",xx); // System.Windows.Forms.MessageBox.Show( // xx.ToString(), "VstPluginManager", System.Windows.Forms.MessageBoxButtons.OK, // System.Windows.Forms.MessageBoxIcon.Error // ); Console.Out.WriteLine("Had an error loading"); } if (!ignoreAdd && !haserror) PluginsList.Add(pluginPath); if (ctx!=null) ctx.PluginCommandStub.Open(); return ctx; }
IEnumerable<int> ParameterCount(VstPlugin plugin) { for (int i = 0; i < plugin.PluginInfo.ParameterCount; i++) yield return i; }
static ChannelAssigner Assigner(int midifileindex, VstPlugin module, MidiChannelSet inputs, MidiChannelSet outputs) { ChannelAssigner assigner = new ModestForm.ChannelAssigner(); assigner.Inputs = inputs; assigner.Outputs = outputs; return assigner; }
public void ParamTest(System.Windows.Forms.ComboBox cbActiveParams, VstPlugin plugin) { cbActiveParams.Items.Clear(); var ccp = new VstCCPgm(plugin,plugin.ProgramIndex); foreach (int i in ParameterCount(plugin)) { VstCCParam para = ccp[i]; cbActiveParams.Items.Add(para); } }
public void TrySetProgram(MidiSmfFile newfile, VstPlugin plugin) { try { plugin.PluginCommandStub.BeginSetProgram(); if (plugin.ActiveProgram == null) { plugin.ActiveProgram = new VstCCPgm(PluginManager.MasterPluginInstrument, 0); } plugin.PgmData = newfile.Settings.Plugin.ProgramDump; plugin.PluginCommandStub.EndSetProgram(); } catch { MessageBox.Show("Error setting program", null, MessageBoxButtons.OK); } }
public void Process(VstPlugin plugin, VstAudioBuffer[] inputs) { Process(plugin,inputs,boutput); }
void UpdateBlockSize( NAudioVST naudiovst, VstPlugin plugin ) { VstAudioBufferManager ii = null, io = null; ii = new VstAudioBufferManager(plugin.PluginInfo.AudioInputCount, BlockSize); io = new VstAudioBufferManager(plugin.PluginInfo.AudioOutputCount, BlockSize); UpdateBlock(naudiovst,plugin); binput = ii.ToArray(); boutput = io.ToArray(); }
/// <summary> /// Handle ASIO update event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void asio_BufferUpdateHandler(object sender, EventArgs e) { mCpuLoadStopWatch.Restart(); //long elapsedticksoutsidehandler = mCpuLoadStopWatch.ElapsedTicks; //ticksArray[ticksArrayIndex++] = elapsedticksoutsidehandler - prevTicks; //if (ticksArrayIndex == 344) //{ // ticksArrayIndex = 0; //} //prevTicks = elapsedticksoutsidehandler; #endif if (mFirstAsioBufferUpdateHandlerCall) { uint taskIndex; Thread.CurrentThread.Priority = ThreadPriority.Highest; IntPtr handle = AvSetMmThreadCharacteristics("Pro Audio", out taskIndex); mFirstAsioBufferUpdateHandlerCall = false; } // Clear output buffer for (int index = 0; index < mAsioBuffSize; index++) { mAsioOutputLeft[index] = 0.0f; mAsioOutputRight[index] = 0.0f; } // Dequeue all midi in messages int midiInCount = mMidiDevice.MidiInMessagesCount(); // Expand array if required if (midiInCount > mMidiInMessages.Length) { mMidiInMessages = new MidiMessage[midiInCount]; } // Now dequeue midi messages midiInCount = mMidiDevice.DequeueMidiInMessages(mMidiInMessages, 0, midiInCount); for (int i = 0; i < NrOfPluginChannels; i++) { bool midiPanic = mMidiPanic[i]; mMidiPanic[i] = false; VstPluginChannel channel = PluginChannels[i]; // Copy Asio input to channel input // todo: [JBK] point the VstChannel input buffer directly tot the input buffer from the asio driver to prevent all the copying. // For now just try this if it works if (channel.InputBuffers.Count > 0) { for (int n = 0; n < mAsioBuffSize; ++n) { channel.InputBuffers.Raw[0][n] = mAsioInputLeft[n]; channel.InputBuffers.Raw[1][n] = mAsioInputRight[n]; } } if (channel.InstrumentPlugin.State == PluginState.Empty) { continue; } else if (channel.InstrumentPlugin.State == PluginState.Unloading) { channel.InstrumentPlugin.FinishUnloading(); continue; } // Activated OR deactivated (still receiving note-off messages): VstEvent[] filteredMidiEvents = filterMidiInMessages(midiInCount, channel.InstrumentPlugin); if (midiPanic) { channel.InstrumentPlugin.VstPluginContext.PluginCommandStub.ProcessEvents(mMidiPanicEvents); } else { channel.InstrumentPlugin.VstPluginContext.PluginCommandStub.ProcessEvents(filteredMidiEvents); } // Get audio from the instrument plugin channel.InstrumentPlugin.VstPluginContext.PluginCommandStub.ProcessReplacing(channel.InstrumentPlugin.InputBuffers.Buffers, channel.InstrumentPlugin.OutputBuffers.Buffers); bool swappedBuffers = false; // Effect plugins for (int n = 0; n < VstPluginChannel.NumberOfEffectPlugins; n++) { VstPlugin effectPlugin = channel.EffectPlugins[n]; if (effectPlugin.State == PluginState.Empty) { continue; } else if (effectPlugin.State == PluginState.Unloading) { effectPlugin.FinishUnloading(); continue; } else if (effectPlugin.State == PluginState.Activated) { if (midiPanic) { channel.InstrumentPlugin.VstPluginContext.PluginCommandStub.ProcessEvents(mMidiPanicEvents); } else { channel.InstrumentPlugin.VstPluginContext.PluginCommandStub.ProcessEvents(filteredMidiEvents); } if (!swappedBuffers) { // Take outputbuffer of the previous 'process replacing' as input, and write output to the other (input) buffer. effectPlugin.VstPluginContext.PluginCommandStub.ProcessReplacing(effectPlugin.OutputBuffers.Buffers, effectPlugin.InputBuffers.Buffers); swappedBuffers = true; } else { // Take inputbuffer of the previous 'process replacing' as input, and write output to the other (output) buffer. effectPlugin.VstPluginContext.PluginCommandStub.ProcessReplacing(effectPlugin.InputBuffers.Buffers, effectPlugin.OutputBuffers.Buffers); swappedBuffers = false; } } } // Now copy to mix for (int index = 0; index < mAsioBuffSize; index++) { if (swappedBuffers) { // todo: Pan mAsioOutputLeft[index] += channel.InputBuffers.Raw[0][index] * channel.InstrumentPlugin.Volume; mAsioOutputRight[index] += channel.InputBuffers.Raw[1][index] * channel.InstrumentPlugin.Volume; } else { // todo: Pan mAsioOutputLeft[index] += channel.OutputBuffers.Raw[0][index] * channel.InstrumentPlugin.Volume; mAsioOutputRight[index] += channel.OutputBuffers.Raw[1][index] * channel.InstrumentPlugin.Volume; } } } //mMidiEventsAll.Free (midiEventsAllCount ); //mMidiEventsAllExceptNoteOn.Free(midiEventsAllExceptNoteOnCount); // Master pan + measure max volume levels + mMaxVolLeft = 0.0f; mMaxVolRight = 0.0f; for (int index = 0; index < mAsioBuffSize; index++) { // Master pan mAsioOutputLeft[index] *= mPanLeft; mAsioOutputRight[index] *= mPanRight; // Get max volume levels if (mAsioOutputLeft[index] > mMaxVolLeft) { mMaxVolLeft = mAsioOutputLeft[index]; } if (mAsioOutputRight[index] > mMaxVolRight) { mMaxVolRight = mAsioOutputRight[index]; } } mVUMeters[0].Value = mMaxVolLeft; mVUMeters[1].Value = mMaxVolRight; lock (mMP3RecorderLockObj) { if (mMp3Recorder != null) { mMp3Recorder.WriteSamples(mAsioOutputLeft, mAsioOutputRight, mAsioBuffSize); } } #if NAUDIO_ASIO // Copy mix for (int index = 0; index < mMixLeft.Length; index++) { // First copy left sample Buffer.BlockCopy(sampleToInt32Bytes(mMixLeft[index]), 0, mAsioLeftInt32LSBBuff, index * 4, 4); // Then copy right sample Buffer.BlockCopy(sampleToInt32Bytes(mMixRight[index]), 0, mAsioRightInt32LSBBuff, index * 4, 4); } // Copy left buff Marshal.Copy(mAsioLeftInt32LSBBuff, 0, e.OutputBuffers[0], e.SamplesPerBuffer * 4); // Copy right buff Marshal.Copy(mAsioRightInt32LSBBuff, 0, e.OutputBuffers[1], e.SamplesPerBuffer * 4); mVstTimeInfo.SamplePosition++; e.WrittenToOutputBuffers = true; #else // Start buffer calculations for next asio call. VstTimeInfo.SamplePosition++; #endif int cpuLoad = 0; long elapsedTicksDuringHandler = mCpuLoadStopWatch.ElapsedTicks; cpuLoad = (int)(elapsedTicksDuringHandler * 100 / stopWatchTicksForOneAsioBuffer); if (cpuLoad > mMaxCpuLoad) { mMaxCpuLoad = cpuLoad; } }
/// <summary> /// Ignore nulll entries. /// Convert output to 2 channel if necessary. /// </summary> /// <param name="plugin"></param> /// <param name="inputs"></param> /// <param name="outputs">VstAudioBuffer[2]</param> VstAudioBuffer[] PluginProcess(VstPlugin plugin, VstAudioBuffer[] inputs, VstAudioBuffer[] outputs) { VstAudioBuffer[] newinputs = inputs.Length == 1 ? new VstAudioBuffer[] { inputs[0], inputs[0] } : inputs; return plugin == null ? newinputs : PluginPreProcess2(plugin, newinputs, outputs); }
public AudioProcess(NAudioVST naudiovst, VstPlugin plugin, int nch, int blockSize) { this.nch = nch; this.BlockSize = blockSize; UpdateBlockSize(naudiovst,plugin); }
/// <summary> /// plugin.PluginCommandStub.ProcessReplacing(inputs, outputs); /// </summary> /// <param name="plugin"></param> /// <param name="inputs"></param> /// <param name="outputs"></param> VstAudioBuffer[] PluginPreProcess2(VstPlugin plugin, VstAudioBuffer[] inputs, VstAudioBuffer[] outputs) { plugin.PluginCommandStub.StartProcess(); plugin.PluginCommandStub.ProcessReplacing(inputs, outputs); plugin.PluginCommandStub.StopProcess(); return outputs; }
AudioModule PluginResetBuffer(VstPlugin plugin, int blockSize) { if (plugin!=null) return new AudioModule(plugin,blockSize,plugin.Host.VstPlayer.Settings.Rate); return null; }
public VstAudioBuffer[] GeneralProcess(VstPlugin vstInput, VstPlugin vstOutput) { if (Inputs==null || Inputs.BlockSize!=BlockSize) PluginResetBuffers(vstInput,vstOutput,BlockSize); PluginPreProcess1(vstInput,BlockSize,Inputs[0].ToArray(),Inputs[1].ToArray()); return PluginProcess(vstOutput,Inputs[1].ToArray(),Outputs[1].ToArray()); }