namespace QuikDawEditor.EditingClasses; public partial class Track { public void InitializeTrackAudio() { foreach (VstPluginReference vstref in TrackEffectVsts) vstref.ReturnedWithoutError = File.Exists(vstref.VstDllFileFullPath); foreach (VstPluginReference vstref in TrackInstrumentVsts) vstref.ReturnedWithoutError = File.Exists(vstref.VstDllFileFullPath); InitializeVsts(); foreach (Clip c in Clips) { if (c.IsAudioClip) { c.IsOrphanClip = !File.Exists(c.clipSourceFullPath); if (c.IsOrphanClip) { Debug.WriteLine("Could not find the file...." + c.ClipSourceFileName + " (looking for UNUSED files)"); if (File.Exists(EditingProjectClipsDirectory + "\\UNUSED_" + c.ClipSourceFileName)) File.Move(EditingProjectClipsDirectory + "\\UNUSED_" + c.ClipSourceFileName, c.clipSourceFullPath); } else { AddClipSampleProviderToClip(c); c.ApplyWaveBitmapSourcesToImage(); } c.myTrack = this; } } if (IsSubmixTrack) foreach (Track strack in SubTracks) strack.InitializeTrackAudio(); } public void InitializeVsts() { foreach (ActiveVstPlugin vplugin in this.TrackEffectVsts) { if (vplugin.ReturnedWithoutError) { //Create vst contexts and set their parameters from saved data Application.Current.Dispatcher.Invoke(() => { //must be invoke or else doesn't affect the plugin context try { vplugin.OpenActivePluginContext(); for (int paramno = 0; paramno < vplugin.myContext.PluginInfo.ParameterCount; paramno++) vplugin.myContext.PluginCommandStub.Commands.SetParameter(paramno, vplugin.VstParameters[paramno].ParameterValue); } catch (Exception ex) { Debug.WriteLine("error loading Effect vst:\n" + ex.Message); vplugin.ReturnedWithoutError = false; } }, DispatcherPriority.Normal); } } foreach (ActiveVstPlugin vplugin in this.TrackInstrumentVsts) { if (vplugin.ReturnedWithoutError) { //Create vst contexts and set their parameters from saved data Application.Current.Dispatcher.Invoke(() => { //must be invoke or else doesn't affect the plugin context try { vplugin.OpenActivePluginContext(); for (int paramno = 0; paramno < vplugin.myContext.PluginInfo.ParameterCount; paramno++) vplugin.myContext.PluginCommandStub.Commands.SetParameter(paramno, vplugin.VstParameters[paramno].ParameterValue); if (vplugin.IsGeneralMidi) { //Specific setting for channel 10 as drums vplugin.Channel = vplugin.SelectedVstProgramIndex == 128 ? 10 : 1; //128 ~ Standard Drum Kit if (vplugin.SelectedVstProgramIndex == 128) { int offset = 9 * 0x28; //channel 10 data offset Array.Copy(new byte[] { 0x00, 0x00, 0x00, 0x01 }, 0, vplugin.PluginChunk, 0xA70 + offset, 4); //prog Array.Copy(new byte[] { 0x64 }, 0, vplugin.PluginChunk, 0xA83 + offset, 1); //vol Array.Copy(new byte[] { 0x20 }, 0, vplugin.PluginChunk, 0xA78 + offset, 1); //pitchbend=0 Array.Copy(new byte[] { 0x40 }, 0, vplugin.PluginChunk, 0xA87 + offset, 1); //pan } } else { vplugin.Channel = 1; vplugin.myContext.PluginCommandStub.Commands.SetProgram(vplugin.SelectedVstProgramIndex); } if (vplugin.PluginChunk != null) vplugin.myContext.PluginCommandStub.Commands.SetChunk(vplugin.PluginChunk, false); } catch (Exception ex) { Debug.WriteLine("error loading Instrument vst:\n" + ex.Message); vplugin.ReturnedWithoutError = false; } }, DispatcherPriority.Normal); } } } public void FlushVsts() { foreach (ActiveVstPlugin avp in this.TrackEffectVsts) { avp.myContext.PluginCommandStub.Commands.EditorIdle(); avp.myContext.PluginCommandStub.Commands.StopProcess(); avp.myContext.PluginCommandStub.Commands.MainsChanged(false); avp.myContext.PluginCommandStub.Commands.MainsChanged(true); avp.myContext.PluginCommandStub.Commands.StartProcess(); } foreach (ActiveVstPlugin avp in this.TrackInstrumentVsts) { avp.myContext.PluginCommandStub.Commands.EditorIdle(); avp.myContext.PluginCommandStub.Commands.StopProcess(); avp.myContext.PluginCommandStub.Commands.MainsChanged(false); avp.myContext.PluginCommandStub.Commands.MainsChanged(true); avp.myContext.PluginCommandStub.Commands.StartProcess(); } } }