简体   繁体   English

平滑Tone.js中的值

[英]Smoothing out values in Tone.js

In this ramping example of Tone.js, ramping acts not as a "smoother", but almost like a delay. 在此 Tone.js的斜坡示例中,斜坡不是“平滑”的动作,而是几乎像延迟一样。 It seems like when it receives a value, then instead of starting to ramp towards that, it would schedule another ramp after the current one. 似乎当它接收到一个值时,它会开始在当前值之后再调度一次,而不是开始向该值倾斜。

You can see this behavior when you drag the harmony slider fast enough. 当您足够快地拖动和声滑块时,您会看到此行为。 You'll notice that it insists on going through all the values that it previously had. 您会注意到,它坚持要遍历以前具有的所有值。

How would I get a behavior in which only the last value is considered? 如何获得只考虑最后一个值的行为?

This just has to do with the implementation of the slider. 这只与滑块的实现有关。 A function is called on the "drag" event so that every couple of pixels the slider is moved, the function is called. 在“拖动”事件上调用一个函数,以使滑块移动的每两个像素都被调用一次。 Meaning you are right there are multiple rampTo functions being called one after another. 这意味着您是对的,有多个函数被一个接一个地调用。

If you wanted to get only the last value to be called, you would have to create a dragEnd property on the slider so that once the slider has reached its final value, the function will be called. 如果只想获取最后一个要调用的值,则必须在滑块上创建dragEnd属性,以便一旦滑块达到其最终值,就将调用该函数。 Or check out the Lodash documents on throttle which would call the function a maximum of once every 'x' amount of time ( https://lodash.com/docs/4.16.4#throttle ). 或检查节流阀上的Lodash文档,该文档最多每隔'x'个时间调用一次函数( https://lodash.com/docs/4.16.4#throttle )。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM