Fix for bpm change issue
This commit is contained in:
11
src/Clock.ts
11
src/Clock.ts
@ -131,6 +131,13 @@ export class Clock {
|
|||||||
return 60 / this.bpm / this.ppqn;
|
return 60 / this.bpm / this.ppqn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public pulse_duration_at_bpm(bpm: number = this.bpm): number {
|
||||||
|
/**
|
||||||
|
* Returns the duration of a pulse in seconds at a specific bpm.
|
||||||
|
*/
|
||||||
|
return 60 / bpm / this.ppqn;
|
||||||
|
}
|
||||||
|
|
||||||
get bpm(): number {
|
get bpm(): number {
|
||||||
return this._bpm;
|
return this._bpm;
|
||||||
}
|
}
|
||||||
@ -167,9 +174,9 @@ export class Clock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public incrementTick() {
|
public incrementTick(bpm: number) {
|
||||||
this.tick++;
|
this.tick++;
|
||||||
this.logicalTime += this.pulse_duration;
|
this.logicalTime += this.pulse_duration_at_bpm(bpm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public nextTickFrom(time: number, nudge: number): number {
|
public nextTickFrom(time: number, nudge: number): number {
|
||||||
|
|||||||
@ -31,7 +31,7 @@ export class TransportNode extends AudioWorkletNode {
|
|||||||
} else {
|
} else {
|
||||||
tryEvaluate(this.app, this.app.global_buffer);
|
tryEvaluate(this.app, this.app.global_buffer);
|
||||||
}
|
}
|
||||||
this.app.clock.incrementTick();
|
this.app.clock.incrementTick(message.data.bpm);
|
||||||
} else {
|
} else {
|
||||||
console.log("STILLLLLLLLLLLLLLLL BANGING!");
|
console.log("STILLLLLLLLLLLLLLLL BANGING!");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,6 @@ class TransportProcessor extends AudioWorkletProcessor {
|
|||||||
this.currentPulsePosition = 0;
|
this.currentPulsePosition = 0;
|
||||||
this.totalPausedTime = 0;
|
this.totalPausedTime = 0;
|
||||||
this.lastPauseTime = null;
|
this.lastPauseTime = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMessage = (message) => {
|
handleMessage = (message) => {
|
||||||
@ -35,13 +34,13 @@ class TransportProcessor extends AudioWorkletProcessor {
|
|||||||
this.started = false;
|
this.started = false;
|
||||||
} else if (message.data.type === 'bpm') {
|
} else if (message.data.type === 'bpm') {
|
||||||
this.bpm = message.data.value;
|
this.bpm = message.data.value;
|
||||||
|
this.currentPulsePosition = currentTime;
|
||||||
} else if (message.data.type === 'ppqn') {
|
} else if (message.data.type === 'ppqn') {
|
||||||
this.ppqn = message.data.value;
|
this.ppqn = message.data.value;
|
||||||
} else if (message.data.type === 'nudge') {
|
} else if (message.data.type === 'nudge') {
|
||||||
this.nudge = message.data.value
|
this.nudge = message.data.value;
|
||||||
}
|
}
|
||||||
// Log difference between currentTime and message.data.sentAt
|
console.log("Message delay: ", currentTime - message.data.sentAt);
|
||||||
console.log("Message delay: ", currentTime - message.data.sentAt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process(inputs, outputs, parameters) {
|
process(inputs, outputs, parameters) {
|
||||||
@ -50,10 +49,12 @@ class TransportProcessor extends AudioWorkletProcessor {
|
|||||||
const beatNumber = adjustedCurrentTime / (60 / this.bpm);
|
const beatNumber = adjustedCurrentTime / (60 / this.bpm);
|
||||||
const currentPulsePosition = Math.ceil(beatNumber * this.ppqn);
|
const currentPulsePosition = Math.ceil(beatNumber * this.ppqn);
|
||||||
const elapsedTime = (currentTime - this.lastPlayPressTime) - this.totalPausedTime;
|
const elapsedTime = (currentTime - this.lastPlayPressTime) - this.totalPausedTime;
|
||||||
this.port.postMessage({ type: "elapsed", value: elapsedTime })
|
this.port.postMessage({ type: "elapsed", value: elapsedTime });
|
||||||
if (currentPulsePosition > this.currentPulsePosition) {
|
if (currentPulsePosition > this.currentPulsePosition) {
|
||||||
this.currentPulsePosition = currentPulsePosition;
|
this.currentPulsePosition = currentPulsePosition;
|
||||||
this.port.postMessage({ type: "bang" });
|
this.port.postMessage({ type: "bang", bpm: this.bpm });
|
||||||
|
} else {
|
||||||
|
console.log("No bang", currentPulsePosition, this.currentPulsePosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user