private static object CoerceValue(DependencyObject element, object value) { double newValue = (double)value; KnobControl control = (KnobControl)element; return(newValue); }
/* * Methods that make the ValueChange event in this control */ protected static void OnValueChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { KnobControl control = (KnobControl)obj; RoutedPropertyChangedEventArgs <double> e = new RoutedPropertyChangedEventArgs <double>((double)args.OldValue, (double)args.NewValue, ValueChangedEvent); control.OnValueChanged(e); }
/* * Method that will move the central frequency of a filter and will make the transfer function curve represent again. */ private void Knob_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { //Get the sender element as a KnobControl KnobControl cknob = (KnobControl)sender; //The value of the KnobControl set the central frequency of its band eq.GetFilter(Knobtoint(cknob.Name)).SetFrequency(cknob.Value); //Make an instance of Equalizer drawer and calculate the points EqualizerDrawer drawer = EqualizerDrawer.Instance(eq); drawer.CalculatePoints(); List <Point> listPoints = drawer.GetPoints(); if (this.Points == null) { this.Points = new List <DataPoint>(); } //If there is not curve we add new points //else we change the points if (this.Points.Count == 0) { for (int i = 0; i < listPoints.Count; i++) { this.Points.Add(new DataPoint(listPoints[i].X, listPoints[i].Y)); } } else { for (int i = 0; i < this.Points.Count; i++) { this.Points[i] = new DataPoint(listPoints[i].X, listPoints[i].Y); } } //Points refering the filter properties if (this.CirclePoint == null) { this.CirclePoint = new List <DataPoint>(); } if (this.CirclePoint.Count == 0) { for (int band = 0; band < eq.GetNumberOfBands(); band++) { this.CirclePoint.Add(new DataPoint(eq.GetFilter(band).GetFrequency(), eq.GetFilter(band).GetBoost())); } } else { for (int band = 0; band < eq.GetNumberOfBands(); band++) { this.CirclePoint[band] = new DataPoint(eq.GetFilter(band).GetFrequency(), eq.GetFilter(band).GetBoost()); } } //Redrawing if (plotter != null) { plotter.InvalidatePlot(); } }