Round Circular Knob Object

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Round Circular Knob Object

Post by magice » Sat Apr 20, 2013 10:19 am

Thanks Bernd. Here it is in zip. I'm not so much worried about other ways to make it work. Really I just want to understand why it doesn't work the way it is written. I just like to try new things, and when they don't work the way I expect I want to know why.

EDIT: actually this is several steps behind the best working stack I made, unfortunately I can't seem to find the others. I must have accidentally overwritten them. I'm a bit embarrassed. Due to excessive trial and error, there is a lot of redundant code in this example, but you should still get the idea.
Attachments
Knob 04.zip
(1.21 KiB) Downloaded 210 times

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Round Circular Knob Object

Post by magice » Sat Apr 20, 2013 10:52 am

OK I found the "slightly reduced" version, this one is better
Attachments
Knob 04.zip
(1.1 KiB) Downloaded 219 times

MouseUp
Posts: 41
Joined: Sun Feb 14, 2010 3:41 pm

"The Knob!" Version 101

Post by MouseUp » Sat Apr 20, 2013 4:19 pm

Here is version 101 of "The Knob!". It includes an additional smaller knob size and some alternate color ideas. (You can try various colors and shadings by playing around with the Gradient property in the LiveCode editor.)

I pulled out the double click blocking code as it was not working as desired. If anyone knows of a better way to block a double click (while still being able to drag), let me know and I will update the script.
Attachments
TheKnobV101.zip
(2.8 KiB) Downloaded 243 times
Thanks,

MouseUp

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Round Circular Knob Object

Post by magice » Sun Apr 21, 2013 4:36 am

In case anyone wants it, here is a version of MouseUp's knob with circular motion instead of up and down motion and stops. It was an awesome learning process for me but I think I worked out all the bugs.
Attachments
Knob_CircularMotion.zip
(1.32 KiB) Downloaded 259 times

MouseUp
Posts: 41
Joined: Sun Feb 14, 2010 3:41 pm

Re: Round Circular Knob Object

Post by MouseUp » Mon Apr 22, 2013 5:46 pm

Bernd and Dave or anyone else,

I am attempting to improve "The Knob!" by moving the knob script out to the stack and parameterizing it with Custom Properties so that it can be called upon from the script of each knob object. This is going to be useful if there is a card with many knobs since the main code will be written only once. I have put in Custom Properties for the min and max angle and the max decimal value so what were Constants declared in the script, are now settable for each knob in its properties editor box.

I have successfully moved the main script to the stack and can call it and it works as desired sending a data stream to a pre-set destination field or the msg box. The big problem I am facing now is in returning the knob value back to the original button script as a CONTINUOUS stream. Right now I can update a field with the knob value or "put" value in the msg box in realtime. But when I try to update this stream to a variable or to a Custom Property, only the initial mouseDown updates them. I am not able to update CONTINUOUSLY to these destinations.

Any advice on the best way to do this?
Last edited by MouseUp on Tue Apr 23, 2013 4:38 am, edited 2 times in total.
Thanks,

MouseUp

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Round Circular Knob Object

Post by magice » Mon Apr 22, 2013 6:05 pm

Try storing the knob value as a custom property of the knob.

MouseUp
Posts: 41
Joined: Sun Feb 14, 2010 3:41 pm

Re: Round Circular Knob Object

Post by MouseUp » Mon Apr 22, 2013 6:40 pm

Yep, I did. I am setting the custom property and calling it up in the knob's script but the value is only updating once in the value field at the bottom of the window when I mouseDown. We want it to update continuously.

I have attached the (broken) code... Any ideas?
Attachments
TheKnobV101ScriptInStack.zip
(2.84 KiB) Downloaded 237 times
Thanks,

MouseUp

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Round Circular Knob Object

Post by magice » Mon Apr 22, 2013 7:05 pm

Like this? You might also consider giving each knob its own output field. You can then group each with the knob and refer to them as fld KnobValue of target group (That is from memory so might be wrong. Check target group in the dictionary.)
Attachments
TheKnobV101ScriptInStack.zip
(2.35 KiB) Downloaded 208 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Round Circular Knob Object

Post by bn » Mon Apr 22, 2013 7:19 pm

mouseUp,

just storing the custom property will not update the display. You would have to make the update a special script.

I post here a version of your stack with all the knobs using the same behavior button. This is a perfect example for using behaviors. You can easily store custom properties if you want persistence of the values. Right now it works as it used to work for single buttons.
The only problem with behaviors is that the depend on the long id of a button. That is only a problem if you rename the stack. That is why I put the script into the card on preOpenCard. This script sets the behavior of every graphic whose name is "knob" to the long id of btn "BehaviorBtn". That way it will work even if you rename the button.

Of course if you copy the button to a different stack you would also have to copy the behavior button and set the behavior of the "knob" to the long id of btn "behaviorBtn".

It takes a little to get used to but behaviors is a very powerful means of doing similar things with many objects.

If you want to trigger specific actions for the different knobs you could probably do that by setting a custom property e.g. uWhatParameter = "volume" and in the behavior script you say: put the put the uWhatParameter of me into tWhatParameter
then set the tWhatParameter of "myRadio" to the current reading of your knob. Same for bass etc.

KInd regards

Bernd
Attachments
The Knob!WBehavior.livecode.zip
(3.1 KiB) Downloaded 218 times

MouseUp
Posts: 41
Joined: Sun Feb 14, 2010 3:41 pm

Re: Round Circular Knob Object

Post by MouseUp » Mon Apr 22, 2013 7:39 pm

Magice,

(My original response was premature.) Thanks for the tip but unfortunately it is not what I need to do. I want to be able to do something with the current value from within the script of EACH KNOB and not from within the main stack script. I want the main script to remain generic so I don't want to specify the destination inside the stack script. So the question remains, how can I get the stream of values from the knob in realtime back to the original knob script?

Bernd, thanks and I will look into your suggestions. I need to learn what a behavior is still.

Perhaps can I change the "on trackTheMouse" script into a function then "return" the current knob value as a "the result"? I just need to get the knob value stream back to the original script somehow.
Thanks,

MouseUp

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Round Circular Knob Object

Post by magice » Tue Apr 23, 2013 12:56 am

Ok, I understand what you are asking now. You are correct, a function is the answer. unfortunately, the way you are using a polling system to continue the "TrackTheMouse" execution I don't see any way to send even a function return back to the original script. Basically The mouse up is done executing but trackTheMouse continues. You might look into using "on mouseMove" instead. Then the new value could be acted upon from the mouseMove script as it is being moved.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Round Circular Knob Object

Post by magice » Tue Apr 23, 2013 1:29 am

on second read, that last post was a bit confusing. Put this in your knob image script.

Code: Select all

on mouseMove
   if tTrack then put the currValue of me
end mouseMove

MouseUp
Posts: 41
Joined: Sun Feb 14, 2010 3:41 pm

TheKnob! v102

Post by MouseUp » Tue Apr 23, 2013 4:25 am

Hi Folks,

Here's "The Knob" version 102. Thanks to magice's suggestion, I have it working pretty well and the knob value is coming back to just one spot (my goal) which is the "mouseMove" handler in the knob's script where the knob's value can be directed and used as further needed in your stack.

The generic knob script is now contained once for the entire stack in the stack script area but each knob accesses it from each knob's own script.

I have also added some Custom Properties for each knob, but the only one that should be changed at this time is "cMaxDecimal" which sets the maximum range value of the knob. The default is 100 so the TheKnob sends back a value from 0 to 100. Feel free to try different range values- this feature works very well. The other Custom Properties still need to be addressed in a future version.

This version feels just slightly slower than the version 101 that I posted a couple days ago. I imagine this decrease in speed is due to the constant getting and setting of the Custom Properties of the target knob. Or perhaps it is a speed limitation of using mouseMove instead of mouseDown. (mouseDown was used previously in version 101 to turn the knob.) If anyone has any tips to increase the response speed please share and I will update again.

When holding down the mouse and not moving, I see more messages listing quickly in the Message Watcher in this version than in the 101 version. Anyone know why?

Attached "TheKnob" version 102
Attachments
TheKnobV102.zip
(2.87 KiB) Downloaded 216 times
Last edited by MouseUp on Tue Apr 23, 2013 5:12 am, edited 4 times in total.
Thanks,

MouseUp

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Round Circular Knob Object

Post by magice » Tue Apr 23, 2013 4:54 am

To speed things up, you might try eliminating the trackTheMouse polling system altogether, and do everything from the mouseMove command. doing both is kind of redundant. Also look into the behaviors that Bernd mentioned. One other thing that bothers me about the script is the variable tTrack. It really just begs to be a custom property of the knob.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Round Circular Knob Object

Post by sturgis » Tue Apr 23, 2013 5:44 am

As an alternative you might try something like this.

May not function as you wish, but is simpler to implement.

Code: Select all

on mouseMove
   if the mouse is down then
      put the loc of me & comma & the mouseloc into tPoints -- grab the points of the object and the mouse
      put ((pointsToAngle(tPoints) - 90 )) into tAngle -- - 90 to match the 0 point orientation, find the angle
      set the angle of me to  tAngle -- Set the angle. will point the line at the mouse allowing full rotation ability
   end if
end mouseMove

function pointsToAngle pPoints -- converts the object loc and the mouseloc to an angle.
   put item 3 of pPoints - item 1 of pPoints into vx --get x vector from center of button to the mouseloc
   put item 4 of pPoints - item 2 of pPoints into vy -- same for y vector
   return (atan2(vx,vy) * 180/pi) -- convert vector to degrees. 
end pointsToAngle


Post Reply