Fix sync problems

This commit is contained in:
2023-10-26 02:09:33 +03:00
parent c03315c1d0
commit 4fd9f01a28
5 changed files with 29 additions and 18 deletions

View File

@ -39,7 +39,7 @@
"tone": "^14.8.49",
"unique-names-generator": "^4.7.1",
"vite-plugin-markdown": "^2.1.0",
"zifferjs": "^0.0.33",
"zifferjs": "^0.0.34",
"zzfx": "^1.2.0"
}
}

View File

@ -683,6 +683,10 @@ export class UserAPI {
return args.map((arg) => JSON.stringify(arg)).join(",");
};
public resetAllFromCache = (): void => {
this.patternCache.forEach((player) => (player as Player).reset());
}
public z = (
input: string,
options: InputOptions = {},
@ -701,7 +705,7 @@ export class UserAPI {
}
if (!player) {
player = new Player(input, options, this.app);
player = new Player(input, options, this.app, zid);
this.app.api.patternCache.set(key, player);
}
@ -709,7 +713,7 @@ export class UserAPI {
player.updateLastCallTime();
if (id !== "") {
if (id !== "" && zid !== "z0") {
// Sync named patterns to z0 by default
player.sync("z0");
}

View File

@ -201,6 +201,7 @@ export class Clock {
* @remark also sends a MIDI message if a port is declared
*/
this.app.clock.tick = -1;
this.time_position = { bar: -1, beat: -1, pulse: -1 };
this.app.api.MidiConnection.sendStopMessage();
this.transportNode?.stop();
}

View File

@ -15,7 +15,6 @@ export class Player extends Event {
startCallTime: number = 0;
lastCallTime: number = 0;
waitTime = 0;
startBeat: number = 0;
played: boolean = false;
current!: Pitch | Chord | ZRest;
retro: boolean = false;
@ -23,13 +22,25 @@ export class Player extends Event {
zid: string = "";
options: InputOptions = {};
skipIndex = 0;
endTime = 0;
constructor(input: string, options: InputOptions, public app: Editor) {
constructor(input: string, options: InputOptions, public app: Editor, zid: string = "") {
super(app);
this.input = input;
this.options = options;
this.ziffers = new Ziffers(input, options);
this.zid = zid;
}
reset() {
this.initCallTime = 0;
this.startCallTime = 0;
this.lastCallTime = 0;
this.waitTime = 0;
this.index = 0;
this.skipIndex = 0;
this.played = false;
this.skipIndex = 0;
this.ziffers.reset();
}
get ticks(): number {
@ -94,12 +105,7 @@ export class Player extends Event {
areWeThereYet = (): boolean => {
// If clock has stopped
if (this.app.clock.pulses_since_origin < this.lastCallTime) {
this.lastCallTime = 0;
this.startCallTime = 0;
this.index = 0;
this.waitTime = 0;
this.skipIndex = 0;
this.ziffers.index = 0;
this.app.api.resetAllFromCache();
}
const patternIsStarting = (this.notStarted() &&

View File

@ -1451,10 +1451,10 @@ yaml@^2.1.1:
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b"
integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==
zifferjs@^0.0.33:
version "0.0.33"
resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.33.tgz#286e3c9ccaebe88d4acaad59f99db0cff5cc1884"
integrity sha512-sYD4wOSKTip4GTkK3epMNAzlRWN3YpQlgR9sCGvyj6xdHzaaEHdU8F/PvkI092UbfYi4NNM/pVZKF1RLUlJPAw==
zifferjs@^0.0.34:
version "0.0.34"
resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.34.tgz#887fb2db1ec2aff21ff1742cbbbbc4621838588f"
integrity sha512-q2eFi+j+yXkPTXU53at3Agrh67JmBJ5zloZ13kc5ObT9R8R9L/if21mbnFxpDJC6Sjugql40aM0Ko4p/zBTs4w==
zzfx@^1.2.0:
version "1.2.0"