Add wait method to ziffers
This commit is contained in:
@ -38,7 +38,7 @@
|
|||||||
"tone": "^14.8.49",
|
"tone": "^14.8.49",
|
||||||
"unique-names-generator": "^4.7.1",
|
"unique-names-generator": "^4.7.1",
|
||||||
"vite-plugin-markdown": "^2.1.0",
|
"vite-plugin-markdown": "^2.1.0",
|
||||||
"zifferjs": "^0.0.13",
|
"zifferjs": "^0.0.14",
|
||||||
"zzfx": "^1.2.0"
|
"zzfx": "^1.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -554,10 +554,7 @@ export class UserAPI {
|
|||||||
player = new Player(input, options, this.app);
|
player = new Player(input, options, this.app);
|
||||||
this.app.api.patternCache.set(key, player);
|
this.app.api.patternCache.set(key, player);
|
||||||
}
|
}
|
||||||
if ((player && player.notStarted()) || player.played) {
|
if(player) player.updateLastCallTime();
|
||||||
player.callTime = this.epulse();
|
|
||||||
player.played = false;
|
|
||||||
}
|
|
||||||
return player;
|
return player;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -121,7 +121,6 @@ export class Clock {
|
|||||||
return n * this.pulse_duration
|
return n * this.pulse_duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public start(): void {
|
public start(): void {
|
||||||
/**
|
/**
|
||||||
* Starts the TransportNode (starts the clock).
|
* Starts the TransportNode (starts the clock).
|
||||||
|
|||||||
@ -9,12 +9,14 @@ import { RestEvent } from "./RestEvent";
|
|||||||
export class Player extends Event {
|
export class Player extends Event {
|
||||||
input: string;
|
input: string;
|
||||||
ziffers: Ziffers;
|
ziffers: Ziffers;
|
||||||
callTime: number = 0;
|
firstCallTime: number = 0;
|
||||||
|
lastCallTime: number = 0;
|
||||||
|
waitTime = 0;
|
||||||
startBeat: number = 0;
|
startBeat: number = 0;
|
||||||
played: boolean = false;
|
played: boolean = false;
|
||||||
current!: Pitch|Chord|ZRest;
|
current!: Pitch|Chord|ZRest;
|
||||||
retro: boolean = false;
|
retro: boolean = false;
|
||||||
tick: number = 0;
|
index: number = -1;
|
||||||
|
|
||||||
constructor(input: string, options: object, public app: Editor) {
|
constructor(input: string, options: object, public app: Editor) {
|
||||||
super(app);
|
super(app);
|
||||||
@ -22,6 +24,22 @@ export class Player extends Event {
|
|||||||
this.ziffers = new Ziffers(input, options);
|
this.ziffers = new Ziffers(input, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get ticks(): number {
|
||||||
|
const dur = this.ziffers.duration;
|
||||||
|
return dur * 4 * this.app.clock.ppqn;
|
||||||
|
}
|
||||||
|
|
||||||
|
nextEndTime(): number {
|
||||||
|
return this.firstCallTime + this.ticks;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateLastCallTime(): void {
|
||||||
|
if (this.notStarted() || this.played) {
|
||||||
|
this.lastCallTime = this.app.clock.pulses_since_origin;
|
||||||
|
this.played = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
notStarted(): boolean {
|
notStarted(): boolean {
|
||||||
return this.ziffers.notStarted();
|
return this.ziffers.notStarted();
|
||||||
}
|
}
|
||||||
@ -39,28 +57,34 @@ export class Player extends Event {
|
|||||||
// Check if it's time to play the event
|
// Check if it's time to play the event
|
||||||
areWeThereYet = (): boolean => {
|
areWeThereYet = (): boolean => {
|
||||||
// If clock has stopped
|
// If clock has stopped
|
||||||
if(this.app.clock.pulses_since_origin<this.callTime) {
|
if(this.app.clock.pulses_since_origin<this.lastCallTime) {
|
||||||
this.callTime = 0;
|
this.lastCallTime = 0;
|
||||||
this.tick = 0;
|
this.index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main logic
|
// Main logic
|
||||||
const howAboutNow = (
|
const howAboutNow = (
|
||||||
( // If pattern is just starting
|
( // If pattern is just starting
|
||||||
this.notStarted() &&
|
this.notStarted() &&
|
||||||
(this.app.clock.time_position.pulse === 1 ||
|
(this.app.clock.time_position.pulse === 1 ||
|
||||||
this.app.clock.pulses_since_origin+1 >= this.app.clock.next_beat_in_ticks)
|
this.app.clock.pulses_since_origin+1 >= this.app.clock.next_beat_in_ticks) &&
|
||||||
|
(this.app.clock.pulses_since_origin+1 >= this.firstCallTime+this.waitTime)
|
||||||
)
|
)
|
||||||
||
|
||
|
||||||
( // If pattern is already playing
|
( // If pattern is already playing
|
||||||
this.current &&
|
this.current &&
|
||||||
this.pulseToSecond(this.app.clock.pulses_since_origin+1) >=
|
this.pulseToSecond(this.app.clock.pulses_since_origin+1) >=
|
||||||
this.pulseToSecond(this.callTime) +
|
this.pulseToSecond(this.lastCallTime) +
|
||||||
(this.current.duration*4) * this.pulseToSecond(this.app.api.ppqn())
|
(this.current.duration*4) * this.pulseToSecond(this.app.api.ppqn())
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Increment local tick (how many times sound/midi has been called)
|
// Increment index of how many times sound/midi have been called
|
||||||
this.tick = howAboutNow ? 0 : this.tick+1;
|
this.index = howAboutNow ? this.index+1 : this.index;
|
||||||
|
|
||||||
|
if(howAboutNow && this.notStarted()) {
|
||||||
|
this.firstCallTime = this.app.clock.pulses_since_origin+1;
|
||||||
|
}
|
||||||
|
|
||||||
return howAboutNow;
|
return howAboutNow;
|
||||||
}
|
}
|
||||||
@ -110,12 +134,33 @@ export class Player extends Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
retrograde() {
|
retrograde() {
|
||||||
if(this.tick === 0 && this.ziffers.index === 0) {
|
if(this.index === -1 && this.ziffers.index === -1) {
|
||||||
this.ziffers.retrograde();
|
this.ziffers.retrograde();
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wait(value: number) {
|
||||||
|
if(this.index === -1 && this.ziffers.index === -1) {
|
||||||
|
|
||||||
|
// TODO: THIS LATER!
|
||||||
|
|
||||||
|
/* if(typeof value === "string") {
|
||||||
|
const cueKey = this.app.api.patternCues.get(value);
|
||||||
|
if(cueKey) {
|
||||||
|
const waitedPatter = this.app.api.patternCache.get(cueKey) as Player;
|
||||||
|
if(waitedPatter) {
|
||||||
|
this.waitTime = waitedPatter.nextEndTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} */
|
||||||
|
|
||||||
|
this.waitTime = Math.ceil(value*4*this.app.clock.ppqn);
|
||||||
|
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
out = (): void => {
|
out = (): void => {
|
||||||
// TODO?
|
// TODO?
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1446,10 +1446,10 @@ yaml@^2.1.1:
|
|||||||
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b"
|
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b"
|
||||||
integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==
|
integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==
|
||||||
|
|
||||||
zifferjs@^0.0.13:
|
zifferjs@^0.0.14:
|
||||||
version "0.0.13"
|
version "0.0.14"
|
||||||
resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.13.tgz#af155633357c95da6a4e5aaa84f23013b5574236"
|
resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.14.tgz#7876c799a08e799be7af22b65f4cb6f0b44f79ca"
|
||||||
integrity sha512-eNOQOn+NM4L3v2FqQEf0RSiJOKiZMaotGLGj1VBCPHi5WhHp3N61R7k9ZrnQKhPnfSI80NBoplhQ1Q1sdEjFlQ==
|
integrity sha512-CpS3zTm8Btm8aTxd7sSUgVCF/S/jJ3hqwgp7uRzbZI8k6yJWhzo/rjMlEZoOmeBhs7Qy4XsVk7pfrLdS8AAIVA==
|
||||||
|
|
||||||
zzfx@^1.2.0:
|
zzfx@^1.2.0:
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user