using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Text.Json.Serialization; using System.Windows.Media; namespace QuikDawEditor.EditingClasses; public class AutomationLane : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } private string _AutomationType; public string AutomationType { get { return _AutomationType; } set { _AutomationType = value; NotifyPropertyChanged(nameof(AutomationType)); } } public bool IsMasterTrackAutoClip = false; internal string myTrackID { get { return myTrack == null ? "MASTERTRACK" : myTrack.UndoTrackID; } } internal int InitialInsertIdx; internal int AutoRecordedPointCount = -1; internal List AutoRemovedPoints = new List(); private float _MaxValue; public float MaxValue { get { return _MaxValue; } set { _MaxValue = value; } } private float _MinValue; public float MinValue { get { return _MinValue; } set { _MinValue = value; } } public float MidValue { get { return ValueRange / 2 + MinValue; } } public float ValueRange { get { return Math.Abs(MaxValue - MinValue); } } internal Track myTrack; public AutomationLane(string automationType, float minValue, float maxValue, Track mytrack) { AutomationType = automationType; MaxValue = maxValue; MinValue = minValue; myTrack = mytrack; } [JsonConstructor] public AutomationLane(string automationType, float minValue, float maxValue) { AutomationType = automationType; MaxValue = maxValue; MinValue = minValue; } public void SetAutoPointLayoutTransform() { foreach (AutoPoint ap in autoPoints) { ap.AutoPointReverseTransformX = ReverseTransformFactorX; ap.UpdateAutoValue(); } NotifyAutoPointsChanged(); } public void UpdateAutoPointsFromAutoClip() { foreach (AutoPoint ap in autoPoints) { ap.minValue = MinValue; ap.maxValue = MaxValue; ap.UpdateAutoValue(); } } public AutoPoint ClipStartAutoPoint { get { return autoPoints.Where(ap => ap.IsLeftEdgeAutoPoint).FirstOrDefault(); } } public AutoPoint ClipEndAutoPoint { get { return autoPoints.Where(ap => ap.IsRightEdgeAutoPoint).FirstOrDefault(); } } public AutoPoint RecAnchorAutoPoint = new AutoPoint() { IsRecAnchorAutoPoint = true }; // { get { return autoPoints.Where(ap => ap.IsRecAnchorAutoPoint).FirstOrDefault(); } } private ObservableCollection _autoPoints = new ObservableCollection(); public ObservableCollection autoPoints { get { return _autoPoints; } set { _autoPoints = value; //SortAutoPoints(); NotifyPropertyChanged(nameof(autoPoints)); autoPoints.CollectionChanged += autoPoints_CollectionChanged; foreach (AutoPoint ap in _autoPoints) { ap.maxValue = MaxValue; ap.minValue = MinValue; ap.UpdateAutoValue(); } NotifyAutoPointsChanged(); } } private LinearGradientBrush _AutoClipBackgroundBrush; [JsonIgnore(Condition = JsonIgnoreCondition.Always)] public LinearGradientBrush AutoClipBackgroundBrush { get { return _AutoClipBackgroundBrush; } set { _AutoClipBackgroundBrush = value; NotifyPropertyChanged(nameof(AutoClipBackgroundBrush)); } } private bool _IsShown = false; public bool IsShown { get { return _IsShown; } set { _IsShown = value; NotifyPropertyChanged(nameof(IsShown)); } } private bool _IsActive = true; public bool IsActive { get { return _IsActive; } set { _IsActive = value; NotifyPropertyChanged(nameof(IsActive)); } } private bool _AutoPointsVisible = false; [JsonIgnore(Condition = JsonIgnoreCondition.Always)] public bool AutoPointsVisible { get { return _AutoPointsVisible; } set { _AutoPointsVisible = value; NotifyPropertyChanged(nameof(AutoPointsVisible)); } } public void NotifyAutoPointsChanged() { NotifyPropertyChanged(nameof(autoPoints)); foreach (AutoPoint ap in autoPoints) ap.UpdateAutoValue(); } //public void SortAutoPoints() //{ // List sortedAPs = new List(autoPoints.OrderBy(ap1 => ap1.sourcePointms)); // autoPoints.Clear(); // foreach (AutoPoint ap in sortedAPs) autoPoints.Add(ap); //} private void autoPoints_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) foreach (AutoPoint addedAP in e.NewItems) { addedAP.AutoPointReverseTransformX = ReverseTransformFactorX; addedAP.maxValue = MaxValue; addedAP.minValue = MinValue; addedAP.UpdateAutoValue(); } } private double _ReverseTransformFactorX = 1; [JsonIgnore(Condition = JsonIgnoreCondition.Always)] public double ReverseTransformFactorX { get { return _ReverseTransformFactorX; } set { _ReverseTransformFactorX = value; NotifyPropertyChanged(nameof(ReverseTransformFactorX)); } } }