Added sync and wait

This commit is contained in:
2023-09-01 00:13:26 +03:00
parent d496d4a9fb
commit 97f6c21993
5 changed files with 66 additions and 12 deletions

View File

@@ -74,8 +74,8 @@ export abstract class Event {
return this.modify(func);
};
duration = (value: number): Event => {
this.values["duration"] = value;
length = (value: number): Event => {
this.values["length"] = value;
return this;
};
}

View File

@@ -2,20 +2,20 @@ import { type Editor } from "../main";
import { Event } from "./AbstractEvents";
export class RestEvent extends Event {
constructor(duration: number, app: Editor) {
constructor(length: number, app: Editor) {
super(app);
this.values["duration"] = duration;
this.values["length"] = length;
}
_fallbackMethod = (): Event => {
return RestEvent.createRestProxy(this.values["duration"], this.app);
return RestEvent.createRestProxy(this.values["length"], this.app);
};
public static createRestProxy = (
duration: number,
length: number,
app: Editor
): RestEvent => {
const instance = new RestEvent(duration, app);
const instance = new RestEvent(length, app);
return new Proxy(instance, {
// @ts-ignore
get(target, propKey, receiver) {

View File

@@ -11,9 +11,9 @@ export type InputOptions = { [key: string]: string | number };
export class Player extends Event {
input: string;
ziffers: Ziffers;
initCallTime: number = 1;
startCallTime: number = 1;
lastCallTime: number = 1;
initCallTime: number = 0;
startCallTime: number = 0;
lastCallTime: number = 0;
waitTime = 0;
startBeat: number = 0;
played: boolean = false;
@@ -98,6 +98,7 @@ export class Player extends Event {
this.startCallTime = 0;
this.index = 0;
this.waitTime = 0;
this.skipIndex = 0;
}
// Main logic
@@ -207,6 +208,23 @@ export class Player extends Event {
return this;
}
sync(value: string|Function) {
if(this.atTheBeginning() && this.notStarted()) {
const origin = this.app.clock.pulses_since_origin;
const syncId = typeof value === "function" ? value.name : value;
if(origin>0) {
const syncPattern = this.app.api.patternCache.get(syncId) as Player;
if(syncPattern) {
const syncPatternDuration = syncPattern.ziffers.duration;
const syncPatternStart = syncPattern.startCallTime;
const syncInPulses = syncPatternDuration*4*this.app.clock.ppqn;
this.waitTime = syncPatternStart + syncInPulses;
}
}
}
return this;
}
out = (): void => {
// TODO?
};