Skip to content

Commit

Permalink
Fix: Fade to excact target val (and not nearby)
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Apr 15, 2019
1 parent 7f5998e commit feafa5e
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions src/utils/MixerConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class MixerConnection {

this.timer = new Array(this.store.channels[0].channel.length);


}

updateOutLevels() {
Expand Down Expand Up @@ -61,8 +60,17 @@ export class MixerConnection {
if (targetVal<outputLevel) {
this.timer[channelIndex] = setInterval(() => {
outputLevel = outputLevel - FADE_INOUT_STEPS*this.mixerProtocol.fader.step;
if ( outputLevel <= targetVal){
outputLevel = targetVal;
if (outputLevel<targetVal) {
outputLevel=targetVal;
}
window.storeRedux.dispatch({
type:'SET_OUTPUT_LEVEL',
channel: channelIndex,
level: outputLevel
});
this.mixerConnection.updateOutLevel(channelIndex);

if ( outputLevel === targetVal){
clearInterval(this.timer[channelIndex]);
window.storeRedux.dispatch({
type:'FADE_ACTIVE',
Expand All @@ -71,17 +79,21 @@ export class MixerConnection {
});
return true;
}
}, FADE_INOUT_SPEED);
} else {
this.timer[channelIndex] = setInterval(() => {
outputLevel = outputLevel + FADE_INOUT_STEPS*this.mixerProtocol.fader.step;
if (outputLevel>targetVal) {
outputLevel=targetVal;
}
window.storeRedux.dispatch({
type:'SET_OUTPUT_LEVEL',
channel: channelIndex,
level: outputLevel
});
this.mixerConnection.updateOutLevel(channelIndex);
}, FADE_INOUT_SPEED);
} else {
this.timer[channelIndex] = setInterval(() => {
outputLevel = outputLevel + FADE_INOUT_STEPS*this.mixerProtocol.fader.step;
if ( outputLevel >= targetVal){

if ( outputLevel === targetVal){
outputLevel = targetVal;
clearInterval(this.timer[channelIndex]);
window.storeRedux.dispatch({
Expand All @@ -91,20 +103,24 @@ export class MixerConnection {
});
return true;
}
window.storeRedux.dispatch({
type:'SET_OUTPUT_LEVEL',
channel: channelIndex,
level: outputLevel
});
this.mixerConnection.updateOutLevel(channelIndex);

}, FADE_INOUT_SPEED);
}
} else {
let outputLevel = this.store.channels[0].channel[channelIndex].outputLevel;
this.timer[channelIndex] = setInterval(() => {
outputLevel = outputLevel - FADE_INOUT_STEPS*this.mixerProtocol.fader.step;
if ( outputLevel <= this.mixerProtocol.fader.min){
outputLevel = this.mixerProtocol.fader.min;
if (outputLevel<this.mixerProtocol.fader.min) {
outputLevel=this.mixerProtocol.fader.min;
}
window.storeRedux.dispatch({
type:'SET_OUTPUT_LEVEL',
channel: channelIndex,
level: outputLevel
});
this.mixerConnection.updateOutLevel(channelIndex);

if ( outputLevel === this.mixerProtocol.fader.min){
clearInterval(this.timer[channelIndex]);
window.storeRedux.dispatch({
type:'FADE_ACTIVE',
Expand All @@ -113,12 +129,7 @@ export class MixerConnection {
});
return true;
}
window.storeRedux.dispatch({
type:'SET_OUTPUT_LEVEL',
channel: channelIndex,
level: outputLevel
});
this.mixerConnection.updateOutLevel(channelIndex);

}, FADE_INOUT_SPEED);
}
}
Expand Down

0 comments on commit feafa5e

Please sign in to comment.