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

@ -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,17 +375,7 @@ 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) {
this.universes[selectedUniverse] = template_universe