Synced ziffers to onbeat (on start) + merge

This commit is contained in:
2023-08-24 18:34:08 +03:00
parent f579d4a0ff
commit 0e275204fd
5 changed files with 30 additions and 27 deletions

View File

@ -38,7 +38,7 @@
"tone": "^14.8.49",
"unique-names-generator": "^4.7.1",
"vite-plugin-markdown": "^2.1.0",
"zifferjs": "^0.0.12",
"zifferjs": "^0.0.13",
"zzfx": "^1.2.0"
}
}

View File

@ -236,7 +236,7 @@ export class UserAPI {
}
};
public midi = (value: number | object = 60): NoteEvent => {
public midi = (value: number|object = 60): NoteEvent => {
/**
* Sends a MIDI note to the current MIDI output.
*
@ -255,7 +255,6 @@ export class UserAPI {
*/
this.MidiConnection.sendSysExMessage(data);
};
sy = this.sysex;
public pitch_bend = (value: number, channel: number): void => {
/**
@ -278,7 +277,6 @@ export class UserAPI {
*/
this.MidiConnection.sendProgramChange(program, channel);
};
pc = this.program_change;
public midi_clock = (): void => {
/**
@ -300,7 +298,6 @@ export class UserAPI {
*/
this.MidiConnection.sendMidiControlChange(control, value, channel);
};
cc = this.control_change;
public midi_panic = (): void => {
/**
@ -325,9 +322,9 @@ export class UserAPI {
player = new Player(input, options, this.app);
this.app.api.patternCache.set(key, player);
}
if ((player && player.ziffers.index === -1) || player.played) {
player.callTime = this.epulse();
player.played = false;
if ((player && player.notStarted()) || player.played) {
player.callTime = this.epulse();
player.played = false;
}
return player;
};
@ -491,12 +488,6 @@ export class UserAPI {
return current_chunk % 2 === 0;
};
public babou = (chunk: number): boolean => {
const time_pos = this.epulse();
const chunkSize = Math.floor(chunk * this.ppqn());
return time_pos % chunkSize === 0;
};
public divbar = (chunk: number): boolean => {
const time_pos = this.bar() - 1;
const current_chunk = Math.floor(time_pos / chunk);
@ -875,8 +866,10 @@ export class UserAPI {
};
onbar = (n: number, ...bar: number[]): boolean => {
let bar_modulo = (this.bar() % n) + 1;
return bar.some((b) => b == bar_modulo);
// n is acting as a modulo on the bar number
const bar_list = [...Array(n).keys()].map((i) => i + 1);
console.log(bar.some((b) => bar_list.includes(b % n)));
return bar.some((b) => bar_list.includes(b % n));
};
onbeat = (...beat: number[]): boolean => {
@ -1041,7 +1034,7 @@ export class UserAPI {
*/
return this._euclidean_cycle(pulses, length, rotate)[iterator % length];
};
eu = this.euclid;
ec = this.euclid;
_euclidean_cycle(
pulses: number,
@ -1241,7 +1234,7 @@ export class UserAPI {
// Trivial functions
// =============================================================
sound = (sound: string | object) => {
sound = (sound: string|object) => {
return new SoundEvent(sound, this.app);
};

View File

@ -60,7 +60,7 @@ export class Clock {
get ticks_before_new_bar(): number {
/**
* This function returns the number of ticks sepaating the current moment
* This function returns the number of ticks separating the current moment
* from the beginning of the next bar.
*
* @returns number of ticks until next bar

View File

@ -10,6 +10,7 @@ export class Player extends Event {
input: string;
ziffers: Ziffers;
callTime: number = 0;
startBeat: number = 0;
played: boolean = false;
current!: Pitch|Chord|ZRest;
retro: boolean = false;
@ -21,6 +22,10 @@ export class Player extends Event {
this.ziffers = new Ziffers(input, options);
}
notStarted(): boolean {
return this.ziffers.notStarted();
}
next = (): Pitch|Chord|ZRest => {
this.current = this.ziffers.next() as Pitch|Chord|ZRest;
this.played = true;
@ -32,10 +37,15 @@ export class Player extends Event {
}
areWeThereYet = (): boolean => {
const howAboutNow = (this.ziffers.notStarted() ||
this.pulseToSecond(this.app.api.epulse()) >
this.pulseToSecond(this.callTime) +
this.current.duration * this.pulseToSecond(this.app.api.ppqn() * 4))
const howAboutNow = (
(this.notStarted()) ||
(
this.current &&
this.pulseToSecond(this.app.api.epulse()+1) >=
this.pulseToSecond(this.callTime) +
(this.current.duration*4) * this.pulseToSecond(this.app.api.ppqn())
)
);
if(howAboutNow) {
this.tick = 0;
} else {

View File

@ -1446,10 +1446,10 @@ yaml@^2.1.1:
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b"
integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==
zifferjs@^0.0.12:
version "0.0.12"
resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.12.tgz#af03ac66902a4467c9b37430eda710d97f30aad0"
integrity sha512-WoTiBXcmLDt6dPK6hy2bpuVXuY8pKewwv9zSM57t55Zel0dvqhm0Pi4t07V12tdByUb1IyHIxxDRvwC4RJ7q4Q==
zifferjs@^0.0.13:
version "0.0.13"
resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.13.tgz#af155633357c95da6a4e5aaa84f23013b5574236"
integrity sha512-eNOQOn+NM4L3v2FqQEf0RSiJOKiZMaotGLGj1VBCPHi5WhHp3N61R7k9ZrnQKhPnfSI80NBoplhQ1Q1sdEjFlQ==
zzfx@^1.2.0:
version "1.2.0"