using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Threading; using Jacobi.Vst.Core; using Jacobi.Vst.Core.Host; using QuikDawEditor.VST; using static QuikDawEditor.EDITING.MiscMethods; using static QuikDawEditor.EDITING.StaticProperties; namespace QuikDawEditor; public partial class EditorHostWindow : Window { private IVstPluginCommandStub myplugstub; internal ActiveVstPlugin myActiveVstPlugin; //public ObservableCollection currentPluginParameters; private DispatcherTimer parameterChangeMonitorTimer = new DispatcherTimer(); private void Window_PreviewMouseDown(object sender, MouseButtonEventArgs e) { this.Topmost = true; } //public EditorHostWindow(Point openWinLoc, IVstPluginCommandStub plugstub, ObservableCollection currPlugInParams, string pinID) public EditorHostWindow(Point openWinLoc, IVstPluginCommandStub plugstub, ActiveVstPlugin activePlugin, string pinID) { InitializeComponent(); myplugstub = plugstub; //currentPluginParameters = currPlugInParams; myActiveVstPlugin = activePlugin; this.Left = openWinLoc.X; this.Top = openWinLoc.Y; } private void Window_ContentRendered(object sender, EventArgs e) { myplugstub.Commands.EditorOpen(new WindowInteropHelper(this).Handle); myplugstub.Commands.MainsChanged(true); if (myplugstub.Commands.EditorGetRect(out System.Drawing.Rectangle wndRect)) { WinFormsHost.Width = wndRect.Width / dpiXFac; WinFormsHost.Height = wndRect.Height / dpiYFac; } //Debug.WriteLine("\nWinformshostWidth=" + WinFormsHost.Width.ToString() + "/////formrectwidth=" + wndRect.Width.ToString() + " (" + (wndRect.Width / dpiXFac).ToString()); this.Title = myplugstub.Commands.GetEffectName(); parameterChangeMonitorTimer.Interval = new TimeSpan(0, 0, 0, 1); //Update every second parameterChangeMonitorTimer.Tick += ParameterChangeMonitorTimer_Tick; parameterChangeMonitorTimer.Start(); } private void ParameterChangeMonitorTimer_Tick(object sender, EventArgs e) { try { //Check and update only changed parameters for (int paramno = 0; paramno < myplugstub.PluginContext.PluginInfo.ParameterCount; paramno++) { float paramval = myplugstub.Commands.GetParameter(paramno); if (myActiveVstPlugin.VstParameters[paramno].ParameterValue != paramval) myActiveVstPlugin.VstParameters[paramno].ParameterValue = paramval; } myActiveVstPlugin.UpdateGetProgName(); } catch (Exception ex) { Debug.WriteLine("error in parameter timer: " + ex.Message); parameterChangeMonitorTimer.Stop(); } } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { parameterChangeMonitorTimer.Stop(); parameterChangeMonitorTimer = null; if (!e.Cancel) myplugstub.Commands.EditorClose(); editingProject.NeedsSaving = true; } private void Window_LocationChanged(object sender, EventArgs e) { editingProject.NeedsSaving = true; } }