using QuikDawEditor.EditingClasses; using QuikDawEditor.MiscClasses; using QuikDawEditor.VST; using System; using System.Collections.ObjectModel; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using static QuikDawEditor.EDITING.MiscMethods; using static QuikDawEditor.EDITING.StaticProperties; using static QuikDawEditor.EDITING.VstMethods; namespace QuikDawEditor; public partial class MasterTrackFXWindow : Window { public ObservableCollection VstEffectReferences { get; set; } public string RelRes() { ReleaseResources(); return "Resources released"; } public MasterTrackFXWindow() { InitializeComponent(); VstEffectReferences = new ObservableCollection(ScannedVstEffectReferences); vstsLV.ItemsSource = VstEffectReferences; } private void CloseButton_Click(object sender, RoutedEventArgs e) { this.Close(); } private MasterTrack thisMT { get { return (MasterTrack)this.DataContext; } } private void Window_LocationChanged(object sender, EventArgs e) { thisMT.FxWinLocation = new IntPair() { int1 = (int)this.Left, int2 = (int)this.Top }; editingProject.NeedsSaving = true; } private void EQCB_CheckedUnchecked(object sender, RoutedEventArgs e) { CheckBox thisCB = (CheckBox)sender; thisMT.IsTrackEQActive = (bool)thisCB.IsChecked; editingProject.NeedsSaving = true; } public bool receivingAdjustment = false; private void EqExpanderBut_Click(object sender, RoutedEventArgs e) { EqIF.Visibility = EqIF.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible; } public void AddVSTEffect(ObservableCollection trackeffectvsts, VstPluginReference vstPluginRef) { try { ActiveVstPlugin newVstPlugin = vstPluginRef.CreateActivePlugin(); newVstPlugin.OpenActivePluginContext(); trackeffectvsts.Add(newVstPlugin); //set initial parameters when opening vst window if (newVstPlugin.VstParameters.Count == 0) for (int paramno = 0; paramno < newVstPlugin.myContext.PluginInfo.ParameterCount; paramno++) { newVstPlugin.VstParameters.Add(new VstParameter()); newVstPlugin.VstParameters[paramno].ParameterName = newVstPlugin.myContext.PluginCommandStub.Commands.GetParameterName(paramno); newVstPlugin.VstParameters[paramno].ParameterValue = newVstPlugin.myContext.PluginCommandStub.Commands.GetParameter(paramno); } else for (int paramno = 0; paramno < newVstPlugin.myContext.PluginInfo.ParameterCount; paramno++) newVstPlugin.myContext.PluginCommandStub.Commands.SetParameter(paramno, newVstPlugin.VstParameters[paramno].ParameterValue); Debug.WriteLine("Added new vstplugin: " + newVstPlugin.PluginName + " :: " + newVstPlugin.VstDllFileFullPath); } catch (Exception ex) { Debug.WriteLine("Error adding vst plugin\n" + ex.Message); } editingProject.NeedsSaving = true; } private void fxMenu_SubmenuOpened(object sender, RoutedEventArgs e) { //CheckSelected(); } private void OpenVstBut_Click(object sender, RoutedEventArgs e) { try { ActiveVstPlugin thisactivevst = (ActiveVstPlugin)((Button)e.OriginalSource).DataContext; if (thisactivevst.IsEditorOpen) thisactivevst.edHostWin.Activate(); else thisactivevst.OpenEditor(this); paramsLV.ItemsSource = thisactivevst.VstParameters; editingProject.NeedsSaving = true; } catch (Exception ex) { MessageBox.Show("Error opening Vst window:\n" + ex.Message); } } private void ActiveCheckBox_Checked(object sender, RoutedEventArgs e) { CheckBox thisCB = (CheckBox)sender; ActiveVstPlugin thisVSTPlugin = (ActiveVstPlugin)thisCB.DataContext; thisVSTPlugin.IsActive = true; editingProject.NeedsSaving = true; } private void ActiveCheckBox_Unchecked(object sender, RoutedEventArgs e) { CheckBox thisCB = (CheckBox)sender; ActiveVstPlugin thisVSTPlugin = (ActiveVstPlugin)thisCB.DataContext; thisVSTPlugin.IsActive = false; editingProject.NeedsSaving = true; } private void AddVstEffectBut_Clicked(object sender, RoutedEventArgs e) { Button thisBut = (Button)sender; VstPluginReference thisVSTRef = (VstPluginReference)thisBut.DataContext; if (thisVSTRef.isNotifying) return; AddVSTEffect(thisMT.MasterTrackEffectVsts, thisVSTRef); fxMenu.IsSubmenuOpen = false; editingProject.NeedsSaving = true; } private void RemoveVstBut_Click(object sender, RoutedEventArgs e) { Button thisBut = (Button)sender; ActiveVstPlugin thisVSTEffect = (ActiveVstPlugin)thisBut.DataContext; thisMT.MasterTrackEffectVsts.Remove(thisVSTEffect); editingProject.NeedsSaving = true; } private void SelectedVstsLV_SelectionChanged(object sender, SelectionChangedEventArgs e) { paramsLV.ItemsSource = SelectedVstsLV.SelectedIndex == -1 ? null : thisMT.MasterTrackEffectVsts[SelectedVstsLV.SelectedIndex].VstParameters; } private void fxWin_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) this.Close(); if (Keyboard.IsKeyDown(Key.LeftCtrl) && e.Key == Key.S) editingProject.Save(); } private void FxMasterWin_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) this.Close(); if (Keyboard.IsKeyDown(Key.LeftCtrl) && e.Key == Key.S) editingProject.Save(); } private void FxMasterWin_Activated(object sender, EventArgs e) { //this.Topmost = true; } bool mouseDownInTitleBar = false; System.Windows.Point MouseDownPos; private void TitleLabel_PreviewMouseDown(object sender, MouseButtonEventArgs e) { mouseDownInTitleBar = true; MouseDownPos = e.GetPosition(this); Mouse.Capture(this.TitleLabel); } private void TitleLabel_PreviewMouseMove(object sender, MouseEventArgs e) { if (mouseDownInTitleBar) { var newPoint = e.GetPosition(this) - MouseDownPos; this.Left += newPoint.X; this.Top += newPoint.Y; } } private void TitleLabel_PreviewMouseUp(object sender, MouseButtonEventArgs e) { mouseDownInTitleBar = false; Mouse.Capture(this.TitleLabel, CaptureMode.None); } }