using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text.Json.Serialization; using static QuikDawEditor.EDITING.StaticProperties; namespace QuikDawEditor.EditingClasses; public partial class Clip { private ObservableCollection _gainPoints = new ObservableCollection(); public ObservableCollection GainPoints { get { return _gainPoints; } set { _gainPoints = value; SortGainPoints(); NotifyPropertyChanged(nameof(GainPoints)); GainPoints.CollectionChanged += GainPoints_CollectionChanged; } } private bool _GainPointsVisible = false; [JsonIgnore(Condition = JsonIgnoreCondition.Always)] public bool GainPointsVisible { get { return _GainPointsVisible; } set { _GainPointsVisible = value; NotifyPropertyChanged(nameof(GainPointsVisible)); } } private void GainPoints_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) foreach (GainPoint addedGP in e.NewItems) { //addedGP.clipType = this.clipType; addedGP.ClipAreaHeight = this.ClipAreaHeight; } } public GainPoint ClipStartGainPoint { get { return GainPoints.Where(gp => gp.IsLeftEdgeGainPoint).FirstOrDefault(); } } public GainPoint ClipEndGainPoint { get { return GainPoints.Where(gp => gp.IsRightEdgeGainPoint).FirstOrDefault(); } } public void NotifyGainPointsChanged() { NotifyPropertyChanged(nameof(ClipRelativeLoopEndMs)); NotifyPropertyChanged(nameof(GainPoints)); NotifyPropertyChanged(nameof(ClipWidthMs)); NotifyPropertyChanged(nameof(ClipWidthInfo)); foreach (GainPoint gp in GainPoints) gp.UpdateGainPointLeft(); } public void RedrawGainPoints() { foreach (GainPoint gp in GainPoints) { gp.UpdateGainPointLeft(); gp.UpdateGainPointTop(ClipAreaHeight); } NotifyGainPointsChanged(); } public void SortGainPoints() { List sortedGPs = new List(GainPoints.OrderBy(gp1 => gp1.sourcePointms)); GainPoints.Clear(); foreach (GainPoint gp in sortedGPs) GainPoints.Add(gp); NotifyGainPointsChanged(); } }