Add wait method to ziffers
This commit is contained in:
@ -554,10 +554,7 @@ export class UserAPI {
|
||||
player = new Player(input, options, this.app);
|
||||
this.app.api.patternCache.set(key, player);
|
||||
}
|
||||
if ((player && player.notStarted()) || player.played) {
|
||||
player.callTime = this.epulse();
|
||||
player.played = false;
|
||||
}
|
||||
if(player) player.updateLastCallTime();
|
||||
return player;
|
||||
};
|
||||
|
||||
|
||||
@ -121,7 +121,6 @@ export class Clock {
|
||||
return n * this.pulse_duration
|
||||
}
|
||||
|
||||
|
||||
public start(): void {
|
||||
/**
|
||||
* Starts the TransportNode (starts the clock).
|
||||
|
||||
@ -9,12 +9,14 @@ import { RestEvent } from "./RestEvent";
|
||||
export class Player extends Event {
|
||||
input: string;
|
||||
ziffers: Ziffers;
|
||||
callTime: number = 0;
|
||||
firstCallTime: number = 0;
|
||||
lastCallTime: number = 0;
|
||||
waitTime = 0;
|
||||
startBeat: number = 0;
|
||||
played: boolean = false;
|
||||
current!: Pitch|Chord|ZRest;
|
||||
retro: boolean = false;
|
||||
tick: number = 0;
|
||||
index: number = -1;
|
||||
|
||||
constructor(input: string, options: object, public app: Editor) {
|
||||
super(app);
|
||||
@ -22,6 +24,22 @@ export class Player extends Event {
|
||||
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 {
|
||||
return this.ziffers.notStarted();
|
||||
}
|
||||
@ -39,28 +57,34 @@ export class Player extends Event {
|
||||
// Check if it's time to play the event
|
||||
areWeThereYet = (): boolean => {
|
||||
// If clock has stopped
|
||||
if(this.app.clock.pulses_since_origin<this.callTime) {
|
||||
this.callTime = 0;
|
||||
this.tick = 0;
|
||||
if(this.app.clock.pulses_since_origin<this.lastCallTime) {
|
||||
this.lastCallTime = 0;
|
||||
this.index = 0;
|
||||
}
|
||||
|
||||
// Main logic
|
||||
const howAboutNow = (
|
||||
( // If pattern is just starting
|
||||
this.notStarted() &&
|
||||
(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
|
||||
this.current &&
|
||||
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())
|
||||
)
|
||||
);
|
||||
|
||||
// Increment local tick (how many times sound/midi has been called)
|
||||
this.tick = howAboutNow ? 0 : this.tick+1;
|
||||
// Increment index of how many times sound/midi have been called
|
||||
this.index = howAboutNow ? this.index+1 : this.index;
|
||||
|
||||
if(howAboutNow && this.notStarted()) {
|
||||
this.firstCallTime = this.app.clock.pulses_since_origin+1;
|
||||
}
|
||||
|
||||
return howAboutNow;
|
||||
}
|
||||
@ -110,12 +134,33 @@ export class Player extends Event {
|
||||
}
|
||||
|
||||
retrograde() {
|
||||
if(this.tick === 0 && this.ziffers.index === 0) {
|
||||
if(this.index === -1 && this.ziffers.index === -1) {
|
||||
this.ziffers.retrograde();
|
||||
}
|
||||
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 => {
|
||||
// TODO?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user