fixing some bugs

This commit is contained in:
2023-07-28 11:40:17 +02:00
parent 4aa85765b4
commit 0cb5ed8d27
8 changed files with 66 additions and 34 deletions

View File

@ -19,6 +19,7 @@
"codemirror": "^6.0.1",
"postcss": "^8.4.27",
"tailwindcss": "^3.3.3",
"tone": "^14.8.49",
"zzfx": "^1.2.0"
}
}

View File

@ -1,6 +1,8 @@
import { Editor } from "./main";
import { tryEvaluate } from "./Evaluator";
// @ts-ignore
import { ZZFX, zzfx } from "zzfx";
// import * as Tone from 'tone';
export class UserAPI {
@ -17,7 +19,7 @@ export class UserAPI {
this.globalGain.connect(this.app.audioContext.destination)
}
private registerNode<T>(node: T): T{
private registerNode<T extends AudioNode>(node: T): T{
this.audioNodes.push(node)
return node
}
@ -33,7 +35,7 @@ export class UserAPI {
}
get(name: string) { return this.variables[name] }
pick<T>(array: T[]): T { return array[Math.floor(Math.random() * array.length)] }
pick<T>(...array: T[]): T { return array[Math.floor(Math.random() * array.length)] }
almostNever() { return Math.random() > 0.9 }
sometimes() { return Math.random() > 0.5 }
@ -57,12 +59,15 @@ export class UserAPI {
zzfx(...thing);
}
on(beat: number = 1, pulse: number = 1): boolean {
return this.app.clock.time_position.beat === beat && this.app.clock.time_position.pulse === pulse
beat(...beat: number[]): boolean {
return (
beat.includes(this.app.clock.time_position.beat)
&& this.app.clock.time_position.pulse == 1
)
}
pulse(pulse: number) {
return this.app.clock.time_position.pulse === pulse
pulse(...pulse: number[]) {
return pulse.includes(this.app.clock.time_position.pulse) && this.app.clock.time_position.pulse == 1
}
modPulse(pulse: number) {

View File

@ -34,6 +34,10 @@ export class Clock {
})
}
get pulses_per_beat(): number {
return this.ppqn / this.time_signature[1];
}
start(): void {
// Check if the clock is already running
if (this.transportNode?.state === 'running') {

View File

@ -1,11 +0,0 @@
class Ligne {
public start: number
public end: number
constructor(start: number, end: number)) {
this.start = start
this.end = end
}
}

View File

@ -15,8 +15,8 @@ export class TransportNode extends AudioWorkletNode {
handleMessage = (message) => {
if (message.data === "bang") {
let info = this.convertTimeToBarsBeats(this.context.currentTime);
this.$clock.innerHTML = `${info.bar} / ${info.beat} / ${info.ppqn}`
this.app.clock.time_position = { bar: info.bar, beat: info.beat, pulse: info.ppqn }
// this.$clock.innerHTML = `${info.bar} / ${info.beat} / ${info.ppqn}`
tryEvaluate( this.app, this.app.global_buffer );
}
};

View File

@ -4,7 +4,7 @@ class TransportProcessor extends AudioWorkletProcessor {
super(options);
this.port.addEventListener("message", this.handleMessage);
this.port.start();
this.interval = 0.001;
this.interval = 0.0001;
this.origin = currentTime;
this.next = this.origin + this.interval;
}

View File

@ -74,13 +74,13 @@ export class Editor {
this.selected_universe = "Default";
this.universe_viewer.innerHTML = `Topos: ${this.selected_universe}`
this.universes = {...this.settings.universes, ...template_universes}
this.universes = {...template_universes, ...this.settings.universes}
// ================================================================================
// Audio context and clock
// ================================================================================
this.audioContext = new AudioContext({ sampleRate: 44100, latencyHint: 0.000001});
this.audioContext = new AudioContext({ latencyHint: "playback" });
this.clock = new Clock(this, this.audioContext);
// ================================================================================
@ -98,6 +98,7 @@ export class Editor {
rangeHighlighting(),
javascript(),
EditorView.updateListener.of((v:ViewUpdate) => {
v
// This is the event listener for the editor
}),
...this.userPlugins
@ -142,7 +143,7 @@ export class Editor {
// Ctrl + Enter or Return: Evaluate the hovered code block
if ((event.key === 'Enter' || event.key === 'Return') && event.ctrlKey) {
event.preventDefault();
const code = this.getCodeBlock();
// const code = this.getCodeBlock();
this.currentFile.candidate = this.view.state.doc.toString()
tryEvaluate(this, this.currentFile)
}
@ -151,7 +152,7 @@ export class Editor {
if ((event.key === 'Enter' && event.shiftKey) || (event.key === 'e' && event.ctrlKey)) {
event.preventDefault(); // Prevents the addition of a new line
this.currentFile.candidate = this.view.state.doc.toString()
const code = this.getSelectedLines();
// const code = this.getSelectedLines();
}
// This is the modal to switch between universes
@ -374,16 +375,6 @@ export class Editor {
loadUniverse(universeName: string) {
this.currentFile.candidate = this.view.state.doc.toString()
let editor = this;
function whichBuffer(editor: Editor): File {
switch (editor.editor_mode) {
case 'global': return editor.global_buffer
case 'local': return editor.universes[
editor.selected_universe].locals[editor.local_index]
case 'init': return editor.init_buffer
}
}
let selectedUniverse = universeName.trim()
if (this.universes[selectedUniverse] === undefined) {

View File

@ -7,6 +7,13 @@
resolved "https://registry.yarnpkg.com/@alloc/quick-lru/-/quick-lru-5.2.0.tgz#7bf68b20c0a350f936915fcae06f58e32007ce30"
integrity sha512-UrcABB+4bUrFABwbluTIBErXwvbsU/V7TZWfmbgJfbkwiBuziS9gxdODUyuiecfdGQ85jglMW6juS3+z5TsKLw==
"@babel/runtime@^7.22.6":
version "7.22.6"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.22.6.tgz#57d64b9ae3cff1d67eb067ae117dac087f5bd438"
integrity sha512-wDb5pWm4WDdF6LFUde3Jl8WzPA+3ZbxYqkC6xAXuD3irdEHN1k0NfTRrJD8ZD378SJ61miMLCqIOXYhd8x+AJQ==
dependencies:
regenerator-runtime "^0.13.11"
"@codemirror/autocomplete@^6.0.0":
version "6.9.0"
resolved "https://registry.yarnpkg.com/@codemirror/autocomplete/-/autocomplete-6.9.0.tgz#1a1e63122288b8f8e1e9d7aff2eb39a83e04d8a9"
@ -302,6 +309,14 @@ arg@^5.0.2:
resolved "https://registry.yarnpkg.com/arg/-/arg-5.0.2.tgz#c81433cc427c92c4dcf4865142dbca6f15acd59c"
integrity sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==
automation-events@^6.0.8:
version "6.0.8"
resolved "https://registry.yarnpkg.com/automation-events/-/automation-events-6.0.8.tgz#52929699924cd791eaefc51916ffc033c4d0f42f"
integrity sha512-OXI9rEbA0LwWr+Tmvka4EHtVHBIVw8KD2NM7fIGjd4dyGnuiM3ULZL+Jlo4aKXZDY98raT4R4rEDOHAbz8Jm9A==
dependencies:
"@babel/runtime" "^7.22.6"
tslib "^2.6.1"
autoprefixer@^10.4.14:
version "10.4.14"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.4.14.tgz#e28d49902f8e759dd25b153264e862df2705f79d"
@ -760,6 +775,11 @@ readdirp@~3.6.0:
dependencies:
picomatch "^2.2.1"
regenerator-runtime@^0.13.11:
version "0.13.11"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz#f6dca3e7ceec20590d07ada785636a90cdca17f9"
integrity sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==
resolve@^1.1.7, resolve@^1.22.2:
version "1.22.2"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.2.tgz#0ed0943d4e301867955766c9f3e1ae6d01c6845f"
@ -793,6 +813,15 @@ source-map-js@^1.0.2:
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"
integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==
standardized-audio-context@^25.3.29:
version "25.3.55"
resolved "https://registry.yarnpkg.com/standardized-audio-context/-/standardized-audio-context-25.3.55.tgz#4d87ea6052de80ecf5abf56eb71ecd71f7e52e4e"
integrity sha512-ym9g7FZ5S1FykbQ1///ktTJgk+zTtGF1hGR/BFRQjRkN6G2Xy9GbL5kOcM7DlzflV2yJtqVwfU2gL042b1oHwg==
dependencies:
"@babel/runtime" "^7.22.6"
automation-events "^6.0.8"
tslib "^2.6.1"
style-mod@^4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/style-mod/-/style-mod-4.0.3.tgz#136c4abc905f82a866a18b39df4dc08ec762b1ad"
@ -865,11 +894,24 @@ to-regex-range@^5.0.1:
dependencies:
is-number "^7.0.0"
tone@^14.8.49:
version "14.8.49"
resolved "https://registry.yarnpkg.com/tone/-/tone-14.8.49.tgz#f3dd9052ee94e4b7b80b38f4c47a23a9a55e9241"
integrity sha512-L5YLleEFvkuBYQ83eEL0Fg5DSQS7B28v32sYejnnl8b9yXSytM1X/jNJM1DrB525JGwFb5Pmq5OYZPD9oYQbCQ==
dependencies:
standardized-audio-context "^25.3.29"
tslib "^2.3.1"
ts-interface-checker@^0.1.9:
version "0.1.13"
resolved "https://registry.yarnpkg.com/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz#784fd3d679722bc103b1b4b8030bcddb5db2a699"
integrity sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==
tslib@^2.3.1, tslib@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.1.tgz#fd8c9a0ff42590b25703c0acb3de3d3f4ede0410"
integrity sha512-t0hLfiEKfMUoqhG+U1oid7Pva4bbDPHYfJNiB7BiIjRkj1pyC++4N3huJfqY6aRH6VTB0rvtzQwjM4K6qpfOig==
typescript@^5.0.2:
version "5.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"