Skip to content

Commit

Permalink
[~] - Cue timings are now relative to BPM!
Browse files Browse the repository at this point in the history
  • Loading branch information
timekadel committed Jan 6, 2023
1 parent 9218c95 commit 71a86bf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/models/DMX/cue.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class Cue extends Proxify{
return this._duration || DEFAULT_CUE_DATA.DURATION;
}

get durationMS(){
return this.duration * Live.barDuration;
}

get relative() {
return this._relative || DEFAULT_CUE_DATA.RELATIVE;
}
Expand Down Expand Up @@ -239,7 +243,7 @@ class Cue extends Proxify{
this.deltaStart = t;
}
this.time = t - this.deltaStart
if (this.time > this.duration && this.loopStyle != CUE_LOOP_STYLES.LOOP) {
if (this.time > this.durationMS && this.loopStyle != CUE_LOOP_STYLES.LOOP) {
if (this.animationId != null) {
Live.remove(this.animationId)
this.animationId = null;
Expand Down
4 changes: 2 additions & 2 deletions src/models/DMX/effect.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1077,9 +1077,9 @@ class FX extends Cue {
* @todo memoisation could be an option too ? It might be memory expensive though ?
*/
update(t) {
this.time = t % this.duration;
this.time = t % this.durationMS;
this.DMXActivity = 0;
let percent = (t % this.duration) / this.duration
let percent = (t % this.durationMS) / this.durationMS
this.channels.forEach(channel => {
channel.update(percent);
this.DMXActivity += channel.DMXData;
Expand Down
10 changes: 8 additions & 2 deletions src/models/DMX/fade.model.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Proxify
} from '@/models/utils/proxyfy.utils.model.js'
import Live from './live.model'

/**
* Fade bezier curve preset control point values
Expand Down Expand Up @@ -147,7 +148,7 @@ class Fade extends Proxify {
* @type {Number}
*/
get timePercent() {
return this.time / this.duration
return this.time / this.durationMS
}

/**
Expand Down Expand Up @@ -195,14 +196,19 @@ class Fade extends Proxify {
return this._direction;
}

get durationMS(){
console.log(this.duration*Live.barDuration)
return this.duration * Live.barDuration;
}

/**
* Returns fade's percented value at any given time
*
* @param {Number} time time value in milliseconds
* @return {Number} Percented value over time
*/
getValue(time) {
this.t = time / this.duration;
this.t = time / this.durationMS;
this.getX();
let val = (
Math.pow(1 - this.t, 3) * 0 +
Expand Down
16 changes: 9 additions & 7 deletions src/models/DMX/scene.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,18 @@ class Scene extends Cue {
*/
constructor(sceneData) {
super(sceneData)
this.direction = SCENE_DIRECTIONS.IN;
this.fixtures = sceneData.fixtures;
this.fixtureValues = sceneData.fixtureValues
this.fadeIn = new Fade(Object.assign({
direction: 0,
duration: sceneData.duration
// duration: sceneData.duration
}, sceneData.fadeIn));
this.fadeOut = new Fade(Object.assign({
direction: 1,
duration: sceneData.duration
// duration: sceneData.duration
}, sceneData.fadeOut));
this.direction = SCENE_DIRECTIONS.IN;
this.fixtures = sceneData.fixtures;
this.fixtureValues = sceneData.fixtureValues
this.duration = sceneData.duration
return this.proxify(['time', 'deltaStart', 'animationId', 'state', '_state', 'DMXActivity']);
}

Expand Down Expand Up @@ -312,6 +313,7 @@ class Scene extends Cue {
super.duration = duration
if (this.fadeIn) {
this.fadeIn.duration = this.duration;
this.fadeOut.duration = this.duration;
}
}

Expand Down Expand Up @@ -456,7 +458,7 @@ class Scene extends Cue {
this.state = 1;
}
let fade = this.direction == SCENE_DIRECTIONS.IN ? this.fadeIn : this.fadeOut;
let fadeFactor = time < fade.duration ? fade.getValue(time) : 1;
let fadeFactor = time < fade.durationMS ? fade.getValue(time) : 1;
this.fixtureValues.forEach(fixtureValue => {
Object.keys(fixtureValue.quickChannelsAccessors).forEach(channelType => {
let channels = fixtureValue.quickChannelsAccessors[channelType];
Expand All @@ -472,7 +474,7 @@ class Scene extends Cue {
})
})
})
if (time >= this.duration) {
if (time >= this.durationMS) {
//this.direction = !this.direction;
this.state = this.direction;
}
Expand Down

0 comments on commit 71a86bf

Please sign in to comment.