using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Globalization; using System.Windows; using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Imaging; using static QuikDawEditor.EDITING.StaticProperties; using static QuikDawEditor.EDITING.MiscMethods; using QuikDawEditor.EditingClasses; using QuikDawEditor.MiscClasses; namespace QuikDawEditor.ValueConverters; public class ColorStringToBrushConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return new SolidColorBrush((Color)ColorConverter.ConvertFromString(value.ToString())); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class VisibilityToMinHeightConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (Visibility)value == Visibility.Visible ? 120 : 0; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class BoolToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (bool)value ? Visibility.Visible : Visibility.Hidden; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class BoolToReverseVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (bool)value ? Visibility.Hidden : Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class BoolToReverseCollapsedConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (bool)value ? Visibility.Visible : Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class BoolToBrushConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (bool)value ? new SolidColorBrush(Color.FromArgb(100, Brushes.LightSkyBlue.Color.R, Brushes.LightSkyBlue.Color.G, Brushes.LightSkyBlue.Color.B)) : Brushes.Transparent; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class VolumePercentageToLengthConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values[0] == DependencyProperty.UnsetValue) return 0D; double wVal = (double)values[0]; double pVal = (double)values[1]; return (double)(wVal * pVal); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class ArmedToImageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string imgstring = (bool)value ? "ArmRecordOn.png" : "ArmRecordOff.png"; return new BitmapImage(new Uri("pack://application:,,,/EDITING/images/" + imgstring)); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } } public class MuteToImageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string imgstring = (bool)value ? "MuteButOn.png" : "MuteButOff.png"; return new BitmapImage(new Uri("pack://application:,,,/EDITING/images/" + imgstring)); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } } public class LeftMillisecondsToMarginConverterZoomed : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double leftms = (double)value; return new Thickness(leftms / 1000 * PixelsPerSecond * editingProject.ViewXZoomFac, 0, 0, 0); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return ((Thickness)value).Left / PixelsPerSecond * 1000; } } //public class ClipHeightToScaleYConverter : IValueConverter //{ // public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (double)value / 60; } // //public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (double)value / 60 * 0.85; } // public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } //} public class LeftXToMarginConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return new Thickness((double)value, 0, 0, 0); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return ((Thickness)value).Left / PixelsPerSecond * 1000; } } public class RelLoopStartMillisecondsToClipCanvasMarginConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double leftms = (double)value; return new Thickness(-leftms / 1000 * PixelsPerSecond, -1, 0, 1); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return ((Thickness)value).Left / PixelsPerSecond * 1000; } } public class RelLoopStartMsecToZoomedMarginConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double leftms = (double)value; return new Thickness(-leftms / 1000 * PixelsPerSecond * editingProject.ViewXZoomFac, 0, 0, 0); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return ((Thickness)value).Left / PixelsPerSecond * 1000 / editingProject.ViewXZoomFac; } } public class RelLoopStartMillisecondsToClipUnitBackgroundMarginConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double leftms = (double)value; return new Thickness(-leftms / 1000 * PixelsPerSecond, 0, 0, 0); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class MovedToThicknessConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return (bool)value ? new Thickness(7) : new Thickness(0); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } } public class LengthMillisecondsToWidthConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double lenms = (double)value; return lenms / 1000 * PixelsPerSecond; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return (double)value / PixelsPerSecond * 1000; } } public class RecordingPointsToPathConverter : IValueConverter { public object Convert(object values, Type targetType, object parameter, CultureInfo culture) { try { List pointsList = new List((ObservableCollection)values); pointsList.Insert(0, new Point(0, 0)); pointsList.Add(new Point(pointsList[pointsList.Count - 1].X, 0)); Point[] points = pointsList.ConvertAll(gpt => new Point(gpt.X / 1000D * PixelsPerSecond, 30D * (1D - (double)gpt.Y))).ToArray(); if (points.Length > 0) { StreamGeometry geometry = new StreamGeometry(); geometry.FillRule = FillRule.EvenOdd; using (StreamGeometryContext ctx = geometry.Open()) { Point start = points[0]; ctx.BeginFigure(start, true, true); for (int i = 1; i < points.Length; i++) ctx.LineTo(points[i], true, false); } geometry.Freeze(); // for additional performance benefits. return geometry; } else return null; } catch { Debug.WriteLine("error making gain point path -- num gain points=" + values.ToString()); return null; } } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class DBToWidthConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values[0] == DependencyProperty.UnsetValue) return 0D; if (values[1] == DependencyProperty.UnsetValue) return 0D; double wVal = (double)values[0]; double dbVal = (double)values[1]; //return dbVal <= -36 ? 1000D : (double)(wVal * (48D - (dbVal + 36D)) / 48D); //return dbVal <= -36 ? 1000D : (double)(wVal * (48D - (dbVal + 36D)) / 48D); return (double)(wVal * (48D - (dbVal + 36D)) / 48D); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class SoloToImageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string imgstring = (bool)value ? "SoloButOn.png" : "SoloButOff.png"; return new BitmapImage(new Uri("pack://application:,,,/EDITING/images/" + imgstring)); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } } public class TrackTypeToImageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string imgstring = (TrackType)value == TrackType.Audio ? "Wave.png" : ((TrackType)value == TrackType.Midi ? "Synth.png" : "MixerImageSmall.png"); return new BitmapImage(new Uri("pack://application:,,,/EDITING/images/" + imgstring)); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } } public class DoubleToFloatConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return (double)(float)value; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return (float)(double)value; } } public class BoolToGainPointColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (bool)value ? Brushes.AliceBlue : Brushes.Red; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class XFactorToLayoutTransformConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return new ScaleTransform((double)value, 1); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class XYFactorToLayoutTransformConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return new ScaleTransform((double)value, 0.3); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class BoolToCollapsedConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (bool)value ? Visibility.Collapsed : Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class SecToPixConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (double)((int)value * PixelsPerSecond); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class MilliSecToPixConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (double)((double)value / 1000D * PixelsPerSecond); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class MilliSecToZoomedPixConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (double)((double)value / 1000D * PixelsPerSecond * editingProject.ViewXZoomFac); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class MSecToMargLeftConverterAdjusted : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return new Thickness((double)value / 1000D * PixelsPerSecond - 5, 0, 0, 0); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class MSecToMargLeftConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return new Thickness((double)value / 1000D * PixelsPerSecond, 0, 0, 0); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class ShowUnderscoreConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value is string text ? text.Replace("_", "__") : null; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } public class AutoPointToMarginConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { double left = values[0] == DependencyProperty.UnsetValue ? 0D : (double)values[0]; double top = (double)values[1]; return new Thickness(left, top, 0, 0); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotSupportedException(); } } public class AutoPointToPathConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { double thisClipSourceLenms = PixelsToMsec((double)values[1]); try { List autoPointList = new List((ObservableCollection)values[0]); float min = autoPointList[0].minValue; float max = autoPointList[0].minValue; float range = autoPointList[0].valRange; float mid = autoPointList[0].midValue; double hiddenMarginWidth = 50 * editingProject.ViewXZoomFac; autoPointList.Insert(0, new AutoPoint() { sourcePointms = -hiddenMarginWidth, AutoValue = mid }); //To get the vertical edges out of visual range autoPointList.Insert(0, new AutoPoint() { sourcePointms = -hiddenMarginWidth, AutoValue = min }); autoPointList.Insert(0, new AutoPoint() { sourcePointms = thisClipSourceLenms + hiddenMarginWidth, AutoValue = min }); autoPointList.Insert(0, new AutoPoint() { sourcePointms = thisClipSourceLenms + hiddenMarginWidth, AutoValue = mid }); Point[] points = autoPointList.ConvertAll(ap => new Point(ap.sourcePointms / 1000D * PixelsPerSecond * editingProject.ViewXZoomFac, UnitHeight - (double)(ap.AutoValue - min) / (double)range * (UnitHeight + 1))).ToArray(); if (points.Length > 0) { StreamGeometry geometry = new StreamGeometry(); geometry.FillRule = FillRule.EvenOdd; using (StreamGeometryContext ctx = geometry.Open()) { Point start = points[0]; ctx.BeginFigure(start, true, true); for (int i = 1; i < points.Length; i++) ctx.LineTo(points[i], true, false); } // for additional performance benefits. geometry.Freeze(); return geometry; } else return null; } catch { Debug.WriteLine("num auto points=" + values.Length.ToString()); return null; } } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotSupportedException(); } } public class GainPointToPathConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values[1].GetType() != typeof(double)) return null; double thisClipRelLoopEndms = (double)values[1]; try { List gainPointList = new List((ObservableCollection)values[0]); double hiddenMarginWidth = 50 * editingProject.ViewXZoomFac; double clipAreaHeight = gainPointList.Count == 0 ? 60 : gainPointList[0].ClipAreaHeight; gainPointList.Insert(0, new GainPoint() { sourcePointms = -hiddenMarginWidth, GainValue = 1 }); //To get the vertical edges out of visual range gainPointList.Insert(0, new GainPoint() { sourcePointms = -hiddenMarginWidth, GainValue = 0 }); gainPointList.Insert(0, new GainPoint() { sourcePointms = thisClipRelLoopEndms + hiddenMarginWidth, GainValue = 0 }); gainPointList.Insert(0, new GainPoint() { sourcePointms = thisClipRelLoopEndms + hiddenMarginWidth, GainValue = 1 }); Point[] points = gainPointList.ConvertAll(gp => new Point(gp.sourcePointms / 1000D * PixelsPerSecond * editingProject.ViewXZoomFac, (2D - (double)gp.GainValue) * (clipAreaHeight / 2 + 2))).ToArray(); if (points.Length > 0) { StreamGeometry geometry = new StreamGeometry(); geometry.FillRule = FillRule.EvenOdd; using (StreamGeometryContext ctx = geometry.Open()) { Point start = points[0]; ctx.BeginFigure(start, true, true); for (int i = 1; i < points.Length; i++) ctx.LineTo(points[i], true, false); } // for additional performance benefits. geometry.Freeze(); return geometry; } else return null; } catch (Exception ex) { Debug.WriteLine("GainPointToPathConverter error: Num gain points=" + values.Length.ToString() + "\n" + ex.Message); return null; } } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotSupportedException(); } } public class GainPointToMarginConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { double left = (double)values[0] ; double top = (double)values[1]; return new Thickness(left, top, 0, 0); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotSupportedException(); } } public class BoolToSelectionColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (bool)value ? Brushes.LightBlue : Brushes.White; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class MargLeftToMarginConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return new Thickness((double)value, 0, 0, 0); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class StateToImageBrushConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string state = (string)value; return (state == "Stopped" | state == "Paused") ? new BitmapImage(new Uri("pack://application:,,,/EDITING/images/playIcon.png")) : new BitmapImage(new Uri("pack://application:,,,/EDITING/images/pauseIcon.png")); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class RectConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values[0] == DependencyProperty.UnsetValue) return 0D; if (values[1] == DependencyProperty.UnsetValue) return 0D; return new Rect(0d, 0d, (double)values[0], (double)values[1]); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotSupportedException(); } } public class InverseConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return 1D / (double)value ; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class HalfInverseConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return 1D / (double)value * 0.4D; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }