javascript - Leap Motion: Volume Control jPlayer (need to create smooth incremental values?) -


i building leap motion controlled music player , have come roadblock.

the volume, want work on 'circle' gestures clockwise being volume , anticlockwise being volume down, cannot work out how 'right' values set volume to.

i using jplayer audio player, volume set so: $("#jquery_jplayer_1").jplayer("volume", volumevalue); volumevalue needing between 0 , 1

i have working if rotate clockwise sets volume 0.75 , if rotate left 0.25, cant work out how increase volume incrementally rotation.

to number of rotations, function can used circlecount = gesture.progress.tofixed(2);

below code... (obviously realise doesn't atm)

if (gesture.type == 'circle') {          gesture.pointable = frame.pointable(gesture.pointableids[i]);          if(gesture.state == 'start') {             clockwise = true;         } else if (gesture.state == 'update') {             direction = gesture.pointable.direction;              if(direction) {                 normal = gesture.normal;                  clockwise = leap.vec3.dot(direction, normal) > 0;                 if(clockwise) {                     if (gesture.progress.tofixed(2) > 1) {                         //volume                           ("#jquery_jplayer_1").jplayer("volume", 0.75);                      }                 } else {                     if (gesture.progress.tofixed(2) > 1) {                         //volume down                          ("#jquery_jplayer_1").jplayer("volume", 0.25);                      }                 }             }              }         } 

when put:

gesture.progress.tofixed(2) > 1 

that means volume ever change after complete circle. progress value isn't integer, though, varies smoothly make circle. if want 1 full circle change volume between minimum , maximum, use progress value directly. if wanted take, example, 3 full turns go minimum maximum value, divide progress three.

[edit] comment, sounds want circle progress reach threshold value , there, affects volume. use like:

var threshold = 1; if (gesture.type == 'circle') {      gesture.pointable = frame.pointable(gesture.pointableids[i]);      if(gesture.state == 'start') {         clockwise = true;     } else if (gesture.state == 'update') {         direction = gesture.pointable.direction;         var newvolume = 0;         if(direction) {             normal = gesture.normal;              clockwise = leap.vec3.dot(direction, normal) > 0;             if(clockwise) {                 if (gesture.progress > threshold) {                     //volume                     newvolume = gesture.progress - threshold;                     if(newvolume > 1) newvolume = 1;                   }             } else {                 if (gesture.progress > threshold) {                     //volume down                     newvolume = 1 - (gesture.progress - threshold);                     if(newvolume < 0) newvolume = 0;                  }             }         }         ("#jquery_jplayer_1").jplayer("volume", newvolume);          }     } 

(i didn't test this, out syntax errors).


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -