using System; using System.IO; using System.Linq; using System.Windows; using System.Windows.Controls; using static QuikDawEditor.EDITING.StaticProperties; using static QuikDawEditor.EDITING.MiscMethods; using QuikDawEditor.EditingClasses; using System.CodeDom; namespace QuikDawEditor; public partial class EqualizerIF : UserControl { public MasterTrackFXWindow owningFXWindow; public string RelRes() { ReleaseResources(); return "Resources released"; } public EqualizerIF() { InitializeComponent(); } private void EQSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { EqualizerBand eqb = (EqualizerBand)((Slider)sender).DataContext; switch (this.DataContext.GetType()) { case Type t when t == typeof(MasterTrack): // "SharedClasses.MasterTrack": MasterTrack thisMT = (MasterTrack)this.DataContext; if (thisMT.ReceivingAdjustment) return; ChangeMasterEQBand(eqb); break; default: Track thisTrack = (Track)this.DataContext; if (thisTrack.ReceivingAdjustment) return; ChangeEQBand(thisTrack, eqb); break; } } public void ChangeEQBand(Track thisTrack, EqualizerBand eqband) { EqualizerBand foundEQband = thisTrack.EQBands.FirstOrDefault(eqb => eqb.Frequency == eqband.Frequency); if (foundEQband != null) { foundEQband.Gain = eqband.Gain; thisTrack.UpdateFilters(); } } public void ChangeMasterEQBand(EqualizerBand eqband) { EqualizerBand foundEQband = editingProject.MasterTrack.EQBands.FirstOrDefault(eqb => eqb.Frequency == eqband.Frequency); if (foundEQband != null) { foundEQband.Gain = eqband.Gain; editingProject.MasterTrack.UpdateFilters(); } } bool deleteButPressed = false; private void DeleteEQPresetBut_Click(object sender, RoutedEventArgs e) { Button thisBut = (Button)sender; EQPreset thisEQPreset = (EQPreset)thisBut.DataContext; EQPresets.Remove(thisEQPreset); File.WriteAllLines(EQPresetsFile, EQPresets.ToList().ConvertAll(eqp => eqp.saveString)); e.Handled = true; deleteButPressed = true; } private void EQPresetCB_DropDownClosed(object sender, EventArgs e) { if (deleteButPressed) { deleteButPressed = false; return; } ComboBox cbox = (ComboBox)sender; if (cbox.SelectedIndex == -1) return; switch (this.DataContext.GetType()) { case Type t when t == typeof(MasterTrack): MasterTrack thisMT = (MasterTrack)cbox.DataContext; for (int i = 0; i < thisMT.EQBands.Length; i++) thisMT.EQBands[i].Gain = (float)EQPresets[cbox.SelectedIndex].EQVals[i]; break; default: Track thisTrack = (Track)cbox.DataContext; for (int i = 0; i < thisTrack.EQBands.Length; i++) thisTrack.EQBands[i].Gain = (float)EQPresets[cbox.SelectedIndex].EQVals[i]; break; } } private void SaveEQPresetBut_Click(object sender, RoutedEventArgs e) { InputBox inpB = new InputBox("New preset name") { Owner = owningFXWindow }; inpB.ShowDialog(); if (inpB.Result == "Cancel") return; string newEQPresetname = inpB.TextBoxText; Button thisBut = (Button)sender; EqualizerBand[] eqBands; switch (this.DataContext.GetType()) { case Type t when t == typeof(MasterTrack): MasterTrack thisMT = (MasterTrack)thisBut.DataContext; eqBands = thisMT.EQBands; break; default: Track thisTrack = (Track)thisBut.DataContext; eqBands = thisTrack.EQBands; break; } EQPreset newEQPreset = new EQPreset(newEQPresetname + "\t" + String.Join(',', eqBands.ToList().ConvertAll(eqb => eqb.Gain.ToString()).ToArray())); EQPresets.Add(newEQPreset); File.WriteAllLines(EQPresetsFile, EQPresets.ToList().ConvertAll(eqp => eqp.saveString)); } }