Update zifferjs and fix some bugs

This commit is contained in:
2023-08-30 18:19:04 +03:00
parent 93029401a7
commit 43eff8bda2
6 changed files with 47 additions and 33 deletions

View File

@ -39,7 +39,7 @@
"tone": "^14.8.49",
"unique-names-generator": "^4.7.1",
"vite-plugin-markdown": "^2.1.0",
"zifferjs": "link:../zifferjs",
"zifferjs": "^0.0.18",
"zzfx": "^1.2.0"
}
}

View File

@ -905,6 +905,13 @@ export class UserAPI {
return this.app.clock.pulses_since_origin;
};
signature = (): number[] => {
/**
* Returns the current time signature
*/
return this.app.clock.time_signature;
};
// =============================================================
// Time Filters
// =============================================================
@ -966,14 +973,11 @@ export class UserAPI {
*/
let final_pulses: boolean[] = [];
beat.forEach((b) => {
const beat =
b % this.app.clock.time_signature[0] ||
this.app.clock.time_signature[0];
const beat = b % this.signature()[0];
const integral_part = Math.floor(beat);
const decimal_part = (beat - integral_part) * this.app.clock.ppqn + 1;
const decimal_part = (beat - integral_part) * this.ppqn() + 1;
final_pulses.push(
integral_part === this.app.clock.time_position.beat &&
this.app.clock.time_position.pulse === decimal_part
integral_part === this.beat() && this.pulse() === decimal_part
);
});
return final_pulses.some((p) => p == true);

View File

@ -1424,6 +1424,24 @@ z1('q 0 3 {10 14} e 8 4 {5 10 12 14 7 0}').sound('sine')
true
)}
${makeExample(
"Scala scale from variable",
`
const werckmeister = "107.82 203.91 311.72 401.955 503.91 605.865 701.955 809.775 900. 1007.82 1103.91 1200."
z0('s (0,3) ^ 0 3 ^ 0 (3,6) 0 _ (3,5) 0 _ 3 ^ 0 (3,5) ^ 0 6 0 _ 3 0')
.key('C3')
.scale(werckmeister)
.sound('sine')
.fmi(1 + usine(0.5) * irand(1,10))
.cutoff(100 + usine(.5) * 100)
.out()
onbeat(1,1.5,3) :: sound('bd').cutoff(100 + usine(.25) * 1000).out()
`,
true
)}
- Algorithmic operations
${makeExample(

View File

@ -16,7 +16,7 @@ export class TransportNode extends AudioWorkletNode {
if (message.data && message.data.type === "bang") {
this.logicalTime = message.data.logicalTime;
let futureTimeStamp = this.convertTicksToTimeposition(this.app.clock.tick);
const futureTimeStamp = this.convertTicksToTimeposition(this.app.clock.tick);
// console.log("BANG", this.logicalTime, futureTimeStamp);
this.app.clock.time_position = futureTimeStamp;

View File

@ -71,7 +71,7 @@ export class Player extends Event {
};
origin = (): number => {
return this.app.clock.pulses_since_origin;
return this.app.clock.pulses_since_origin+1;
};
pulse = (): number => {
@ -86,6 +86,10 @@ export class Player extends Event {
return this.app.clock.next_beat_in_ticks;
};
nextBeatInTicks = (): number => {
return this.app.clock.next_beat_in_ticks;
};
// Check if it's time to play the event
areWeThereYet = (): boolean => {
// If clock has stopped
@ -100,17 +104,14 @@ export class Player extends Event {
const howAboutNow =
// If pattern is just starting
(this.notStarted() &&
(this.app.clock.time_position.pulse === 1 ||
this.app.clock.pulses_since_origin >=
this.app.clock.next_beat_in_ticks) &&
this.app.clock.pulses_since_origin >= this.waitTime) || // If pattern is already playing
(this.pulse() === 1 || this.origin() >= this.nextBeatInTicks()) &&
this.origin() >= this.waitTime) ||
// If pattern is already playing
(this.current &&
this.pulseToSecond(this.app.clock.pulses_since_origin) >=
this.pulseToSecond(this.origin()) >=
this.pulseToSecond(this.lastCallTime) +
this.current.duration *
4 *
this.pulseToSecond(this.app.api.ppqn()) &&
this.app.clock.pulses_since_origin >= this.waitTime);
this.current.duration * 4 * this.pulseToSecond(this.app.api.ppqn()) &&
this.origin() >= this.waitTime);
// Increment index of how many times call is skipped
this.skipIndex = howAboutNow ? 0 : this.skipIndex + 1;

View File

@ -451,11 +451,6 @@
resolved "https://registry.yarnpkg.com/@types/marked/-/marked-5.0.1.tgz#15acd796d722b91bf00738c8c8539aaf5034f0c6"
integrity sha512-Y3pAUzHKh605fN6fvASsz5FDSWbZcs/65Q6xYRmnIP9ZIYz27T4IOmXfH9gWJV1dpi7f1e7z7nBGUTx/a0ptpA==
"@types/seedrandom@^3.0.5":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@types/seedrandom/-/seedrandom-3.0.5.tgz#31fb257427742a9cc33fcf0c25dacca92e8f45a1"
integrity sha512-kopEpYpFQvQdYsZkZVwht/0THHmTFFYXDaqV/lM45eweJ8kcGVDgZHs0RVTolSq55UPZNmjhKc9r7UvLu/mQQg==
"@types/showdown@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@types/showdown/-/showdown-2.0.1.tgz#24134738ba3107237d6a783e054a54773e739f81"
@ -967,7 +962,7 @@ lodash.merge@^4.6.2:
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
lru-cache@^10.0.0, lru-cache@^10.0.1:
lru-cache@^10.0.1:
version "10.0.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.0.1.tgz#0a3be479df549cca0e5d693ac402ff19537a6b7a"
integrity sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==
@ -1211,11 +1206,6 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"
seedrandom@^3.0.5:
version "3.0.5"
resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-3.0.5.tgz#54edc85c95222525b0c7a6f6b3543d8e0b3aa0a7"
integrity sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==
showdown-highlight@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/showdown-highlight/-/showdown-highlight-3.1.0.tgz#c9ec902c35100e1ac3433761cdb655810120f1e5"
@ -1461,9 +1451,10 @@ yaml@^2.1.1:
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b"
integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==
"zifferjs@link:../zifferjs":
version "0.0.0"
uid ""
zifferjs@^0.0.18:
version "0.0.18"
resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.18.tgz#e8a5cb5cfef77c098899a12450380b04f0100841"
integrity sha512-qixh6tb6wpMx/iFM1uGeDQVi6oaURPwP553Gc75pgZLIvapoXnnJIn23f8fAEgxwTdI+EkqLEZZLa57sDxj0PA==
zzfx@^1.2.0:
version "1.2.0"