Added sync and wait
This commit is contained in:
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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?
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user