using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace QuikDawEditor { public partial class MidiNoteTransposeKnob : UserControl, INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged([CallerMemberName] String propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public event ValueChangedEventHandler ValueChanged; public delegate void ValueChangedEventHandler(object sender, double Value); private double _ValueFontSize = 12; public double ValueFontSize { get { return _ValueFontSize; } set { _ValueFontSize = value; NotifyPropertyChanged(nameof(ValueFontSize)); } } private Thickness _noteMargin = new Thickness(0); public Thickness noteMargin { get { return _noteMargin; } set { _noteMargin = value; NotifyPropertyChanged(nameof(noteMargin)); } } public void ChangeValue(double newval) { if (ValueChanged != null) ValueChanged(this, newval); } public string Dispstring = ""; public double MaximumValue { get; set; } public double MinimumValue { get; set; } public MidiNoteTransposeKnob() { InitializeComponent(); DataContext = this; } private void aKnob_Loaded(object sender, RoutedEventArgs e) { //Value = MinimumValue; } public string ValueString { get { return Value.ToString(); } } private Point MouseDownLocation; private double DownValue; public bool MouseIsDown; protected override void OnMouseDoubleClick(MouseButtonEventArgs e) { base.OnMouseDoubleClick(e); Value = 0; } private double _RotAngle = 0; public double RotAngle { get { return _RotAngle; } set { _RotAngle = value; NotifyPropertyChanged(nameof(RotAngle)); } } private readonly double changeSpeed = 0.2 ; double unitDegreeVal { get { return RotatableRange / (MaximumValue - MinimumValue); } } private double _Value = 0; private double RotatableRange = 270; private double minRotVal {get{return (360 - RotatableRange) / 2 ;} } public double Value { get { return _Value; } set { _Value = value; RotAngle = minRotVal + (value - MinimumValue) * unitDegreeVal; NotifyPropertyChanged(nameof(ValueString)); } } private void TKnob_PreviewMouseDown(object sender, MouseButtonEventArgs e) { this.CaptureMouse(); MouseIsDown = true; MouseDownLocation = e.GetPosition(this); DownValue = Value; } private void TKnob_PreviewMouseMove(object sender, MouseEventArgs e) { if (MouseIsDown) { double ydiff = (MouseDownLocation.Y - e.GetPosition(this).Y) * changeSpeed; Value = Math.Min(MaximumValue, Math.Max(MinimumValue, Math.Truncate(DownValue + ydiff))); ChangeValue(Value); } } private void TKnob_PreviewMouseUp(object sender, MouseButtonEventArgs e) { MouseIsDown = false; this.ReleaseMouseCapture(); _Value = 0; } private void TKnob_SizeChanged(object sender, SizeChangedEventArgs e) { noteMargin = new Thickness(e.NewSize.Width * 0.24); } } }