Knob

Aug 3, 2015 at 12:05 PM
Where can I get a good WPF knob?

I tried this but can't get it to work...
https://knob.codeplex.com/

This one works to an extent, but I think it would win UI disaster of the year!
https://alala666888.wordpress.com/2010/05/31/a-knob-slider-control/
Coordinator
Aug 3, 2015 at 12:30 PM
Aug 3, 2015 at 10:42 PM
Woot!

Can't wait to grab this tonight.
Aug 4, 2015 at 9:23 AM
I can't download it. The download link just times out.

:(

Has anyone got the project lying around?
Aug 4, 2015 at 9:24 AM
This one doesn't not look right, but functionally, it's good!

Most importantly, it can be styled!

http://www.codeproject.com/Articles/69048/Tutorial-Creating-a-Lookless-WPF-Custom-Rotate-Con
Aug 5, 2015 at 12:17 PM
Edited Aug 5, 2015 at 12:18 PM
I edited this knob a fair bit - mainly so I can get a value from it and bind it to stuff. It's a hatchet job but this is a place holder control anyway.
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace MySynth.UI
{
    /// <summary>
    /// Control for displaying and setting an Angle
    /// </summary>
    public class RotateControl : Control
    {
        #region Fields 

        // Using a DependencyProperty as the backing store for Angle.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty AngleProperty =
            DependencyProperty.Register("Angle", typeof(double), typeof(RotateControl), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, null, coerceValueCallback));

        public static readonly DependencyProperty ValueProperty =
    DependencyProperty.Register("Value", typeof(float), typeof(RotateControl), new FrameworkPropertyMetadata((float)0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, ValueProperty_Changed, null));



        private static void ValueProperty_Changed(DependencyObject dobj, DependencyPropertyChangedEventArgs e)
        {
            var control = (RotateControl)dobj;
            control.Value = (float)e.NewValue;
        }

        private float _Min = 0;
        private float _Max = 2;

        public Point arrowCenterPoint;

        bool isMouseRotating;

        double mouseDownAngle;

        private Vector mouseDownVector;

        #endregion Fields 


        public float Min
        {
            get
            {
                return _Min;
            }

            set
            {
                _Min = value;
            }
        }

        public float Max
        {
            get
            {
                return _Max;
            }

            set
            {
                _Max = value;
            }
        }

        #region Constructors 

        static RotateControl()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(RotateControl), new FrameworkPropertyMetadata(typeof(RotateControl)));
        }

        #endregion Constructors 

        #region Properties 

        public double Angle
        {
            get
            {
                return (double)GetValue(AngleProperty);
            }
            set
            {
                SetValue(AngleProperty, value);
            }
        }

        public float Value
        {
            get
            {
                return (float)GetValue(ValueProperty);
            }
            set
            {

                var diff = _Max - _Min;

                var perc = value / diff;

                Angle = 360 * perc;

                SetValue(ValueProperty, value);
            }
        }

        #endregion Properties 

        #region Methods 

        protected override void OnLostMouseCapture(MouseEventArgs e)
        {
            isMouseRotating = false;
            base.OnLostMouseCapture(e);
        }

        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            var mouseDownPoint = e.GetPosition(this);
            mouseDownVector = mouseDownPoint - arrowCenterPoint;
            mouseDownAngle = Angle;
            e.MouseDevice.Capture(this);
            isMouseRotating = true;
            base.OnMouseDown(e);
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (isMouseRotating)
            {
                Point curPos = e.GetPosition(this);
                Vector currentVector = curPos - arrowCenterPoint;
                var angle = Vector.AngleBetween(mouseDownVector, currentVector) + mouseDownAngle;
                Angle = angle;


                var percentage = Angle / 360;
                var diff = _Max - _Min;
                SetValue(ValueProperty, (float)diff * (float)percentage);

                Debug.WriteLine("Angle: " + Angle.ToString());
            }
            base.OnMouseMove(e);
        }

        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            if (isMouseRotating)
            {
                e.MouseDevice.Capture(null);
                isMouseRotating = false;
            }
            base.OnMouseUp(e);
        }

        protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
        {
            base.OnRenderSizeChanged(sizeInfo);
            arrowCenterPoint = new Point(ActualWidth / 2, ActualHeight / 2);
        }

        static object coerceValueCallback(DependencyObject d, object baseValue)
        {
            var angle = (double)baseValue % 360;
            if (angle < 0)
                return angle + 360;
            else
                return angle;




        }

        #endregion Methods 
    }
}
You still need to style it with Xaml though - or it won't do shit. The style is on the website.
Coordinator
Aug 5, 2015 at 1:37 PM
Yeah, its hard to find a control that fits your needs straight away. Lucky you have the source code.

There are of course a lot of WPF toolkits out there.

One is this: http://wpftoolkit.codeplex.com/

It might be worth it to look a bit more?
Aug 5, 2015 at 7:22 PM
I might be a fool... I ended up coding most UI controls from scratch as a WPF user control derived class through composition.
I find WPF very fast, stable and easy to use from code behind.
The XAML / Binding stuff not so much... it's a bit of a cluster fuck both at design-time and run-time.
Aug 5, 2015 at 11:21 PM
I've been building controls in Silverlight for many years, and I find the binding functionality to be an excellent way to separate the code/behavior of a control from the design of it. For example, some of our customers are even at the point where they can design their own UIs on our platform because of binding. I feel that as long as it's not too much of a performance hit, binding will be an excellent way to decouple code from the UI.
Aug 6, 2015 at 3:16 AM
Yes. Perhaps I wasn't thinking about LOB apps. XAML is certainly productive and powerful; puts to shame stuff like css. Binding could be more intutive though. My gripe is that it tends to spout performance impacting binding errors; look in output window when running debug build. Happens mostly in pre-bind conditions between the logical and visual tree initialization using XAML bindings. Think X rely on Y and Y isn't fully initialized, X is initialized and calls uninitialized Y, error occurs. Some bindings like the command IsEnabled event handler is pulled at regular interval (instead of push event signallīng) so your UI thread dispatcher is always busy.

WPF is the best UI framework out there IMO. Here is a crowded view of my host:
Image
Coordinator
Aug 6, 2015 at 6:24 AM
WOW!
Aug 6, 2015 at 6:40 AM
Yeah! Wow alright!

Is this tool available somewhere to have a look at?
Aug 6, 2015 at 11:02 PM
A lot of people would pay money for that!
Where's the project at?
Aug 7, 2015 at 2:17 AM
Thanks for your feedback my goal is to make a proprietary commercial software and it takes a lot of time.

There's a lot of work to be done before I can put out a version. Here's another screenshot with hosted Xhip Vst plugin.
Image
Aug 9, 2015 at 1:06 AM
Yury, what you are building here is more or less what I have wanted to build for a long time. This looks like an incredibly rich toolset. I've used a lot of modular synths in the past and have given up because of the lack of a few key ingredients. This synth looks as though it has those key ingredients.

Basically, I'm jealous.

Are you interested in having a beta tester?

Have you considered developing this with Windows 10 Touch enabled UI in mind?
Aug 9, 2015 at 1:20 AM
Also Yury, are you planning on making this an actual VST? Or is this going to purely be a host?
Aug 10, 2015 at 6:52 AM
@Kruddler I sent you a private message