Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

keyboard in adding to a slider value

Still a little green? Ask your beginner's questions here

keyboard in adding to a slider value

Postby swampmonster » Tue Dec 05, 2017 4:55 pm

My goal is to have a slider and keyboard inputs updating a float variable. who doesn't want an excessive number of ways to change a variable at run-time?
It seemed most reasonable to have a local variable which the slider and the keyboard could change. Despite Matt Ragan's excellent tutorial on the subject (and this of course reflects on my abilities to understand rather than his to demonstrate), i could never get a reference to the variable in a CHOP or TOP to update dynamically.
So, then i tried having the keyboard change the slider value directly. I tried two different approaches to this. Neither produced errors, but neither worked.
See the attached toe file
Attachments
sliders&keyboards&variables.toe
(9.45 KiB) Downloaded 7 times
swampmonster
 
Posts: 18
Joined: Sun May 13, 2012 5:18 pm
Location: new orleans, LA, USA

Re: keyboard in adding to a slider value

Postby raganmd » Tue Dec 05, 2017 10:05 pm

Hey Swampmonster,

I think you're issue here is your reference in your local variables. You want:

Code: Select all
op('../UI/levelsSlider/out1')['Value1']


not

Code: Select all
op('../UI/levelsSlider/out1')['v1']


Give that a try to see if that gets your slider -> local var update working.

I had to dig into that UI element to find the value that was actually changing when moving the slider. :)
raganmd
 
Posts: 1056
Joined: Thu Mar 28, 2013 5:21 am
Location: San Francisco, CA

Re: keyboard in adding to a slider value

Postby swampmonster » Wed Dec 06, 2017 3:56 pm

thanks Matt. that worked. the 'v1' was probably the result of following your tutorial too closely.
one problem down....
swampmonster
 
Posts: 18
Joined: Sun May 13, 2012 5:18 pm
Location: new orleans, LA, USA

Re: keyboard in adding to a slider value

Postby raganmd » Thu Dec 07, 2017 9:36 am

Hey swampmonster,

Take a look at this:

Code: Select all
increment = 0.01

def offToOn(channel, sampleIndex, val, prev):
   v               = op('UI/levelsSlider').par.Value1   
   fieldValue  = op('UI/levelsSlider/field/string')
   
   if channel.index == 0:
      v -= increment
      
   elif channel.index == 1:
      v += increment
   
   fieldValue[0,0] = v
   
   return


Setting a variable to re-use as your increment will save you some headache if you want to change it in the future (and want it to be the same either up or down).

You also don't need to type your variable (v) again if you don't want to, and can just use += or -=.

While you can point your variable filedValue directly to the cell, I don't usually like doing this as it tends to be a little too granular for my taste. Instead I usually define the entire object and then dive into the granularity of it's use further down the line. Hopefully that helps you get a little closer.

Happy programming!
raganmd
 
Posts: 1056
Joined: Thu Mar 28, 2013 5:21 am
Location: San Francisco, CA


Return to Beginners

Who is online

Users browsing this forum: Google [Bot] and 4 guests