Skip to content

Commit

Permalink
Rewrite part of evaluation logic, run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubobubobubobubo committed Nov 26, 2023
1 parent 22b5245 commit eb8ef87
Show file tree
Hide file tree
Showing 56 changed files with 2,079 additions and 2,610 deletions.
41 changes: 28 additions & 13 deletions src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,28 @@ interface ControlChange {
export async function loadSamples() {
return Promise.all([
initAudioOnFirstClick(),
samples("github:tidalcycles/Dirt-Samples/master", undefined, { tag: "Tidal" }).then(() =>
registerSynthSounds()
),
samples("github:tidalcycles/Dirt-Samples/master", undefined, {
tag: "Tidal",
}).then(() => registerSynthSounds()),
registerZZFXSounds(),
samples(drums, "github:ritchse/tidal-drum-machines/main/machines/", { tag: "Machines" }),
samples("github:Bubobubobubobubo/Dough-Fox/main", undefined, { tag: "FoxDot" }),
samples("github:Bubobubobubobubo/Dough-Samples/main", undefined, { tag: "Pack" }),
samples("github:Bubobubobubobubo/Dough-Amiga/main", undefined, { tag: "Amiga" }),
samples("github:Bubobubobubobubo/Dough-Amen/main", undefined, { tag: "Amen" }),
samples("github:Bubobubobubobubo/Dough-Waveforms/main", undefined, { tag: "Waveforms" }),
samples(drums, "github:ritchse/tidal-drum-machines/main/machines/", {
tag: "Machines",
}),
samples("github:Bubobubobubobubo/Dough-Fox/main", undefined, {
tag: "FoxDot",
}),
samples("github:Bubobubobubobubo/Dough-Samples/main", undefined, {
tag: "Pack",
}),
samples("github:Bubobubobubobubo/Dough-Amiga/main", undefined, {
tag: "Amiga",
}),
samples("github:Bubobubobubobubo/Dough-Amen/main", undefined, {
tag: "Amen",
}),
samples("github:Bubobubobubobubo/Dough-Waveforms/main", undefined, {
tag: "Waveforms",
}),
]);
}

Expand Down Expand Up @@ -1281,7 +1293,7 @@ export class UserAPI {
const results: boolean[] = nArray.map(
(value) =>
(this.app.clock.pulses_since_origin - Math.floor(nudge * this.ppqn())) %
Math.floor(value * this.ppqn()) ===
Math.floor(value * this.ppqn()) ===
0
);
return results.some((value) => value === true);
Expand All @@ -1301,7 +1313,7 @@ export class UserAPI {
const results: boolean[] = nArray.map(
(value) =>
(this.app.clock.pulses_since_origin - nudgeInPulses) %
Math.floor(value * barLength) ===
Math.floor(value * barLength) ===
0
);
return results.some((value) => value === true);
Expand Down Expand Up @@ -1901,10 +1913,13 @@ export class UserAPI {
// =============================================================

register = (name: string, operation: EventOperation<AbstractEvent>): void => {
AbstractEvent.prototype[name] = function(this: AbstractEvent, ...args: any[]) {
AbstractEvent.prototype[name] = function (
this: AbstractEvent,
...args: any[]
) {
return operation(this, ...args);
};
}
};

public shuffle = <T>(array: T[]): T[] => {
/**
Expand Down
30 changes: 16 additions & 14 deletions src/AudioVisualisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const drawCircle = (
x: number,
y: number,
radius: number,
color: string
color: string,
): void => {
// @ts-ignore
const canvas: HTMLCanvasElement = app.interface.feedback;
Expand All @@ -36,7 +36,7 @@ export const drawCircle = (
export const blinkScript = (
app: Editor,
script: "local" | "global" | "init",
no?: number
no?: number,
) => {
if (no !== undefined && no < 1 && no > 9) return;
const blinkDuration =
Expand All @@ -55,7 +55,7 @@ export const blinkScript = (
horizontalOffset + shift,
app.interface.feedback.clientHeight - 15,
8,
"#fdba74"
"#fdba74",
);
};

Expand Down Expand Up @@ -91,7 +91,7 @@ export const blinkScript = (
0,
0,
(app.interface.feedback as HTMLCanvasElement).width,
(app.interface.feedback as HTMLCanvasElement).height
(app.interface.feedback as HTMLCanvasElement).height,
);
}, blinkDuration);
}
Expand Down Expand Up @@ -141,7 +141,7 @@ let lastRenderTime: number = 0;
*/
export const runOscilloscope = (
canvas: HTMLCanvasElement,
app: Editor
app: Editor,
): void => {
let config = app.osc;
let analyzer = getAnalyser(config.fftSize);
Expand All @@ -155,7 +155,7 @@ export const runOscilloscope = (
width: number,
height: number,
offset_height: number,
offset_width: number
offset_width: number,
) {
const maxFPS = 30;
const now = performance.now();
Expand All @@ -169,10 +169,12 @@ export const runOscilloscope = (
canvasCtx.clearRect(0, 0, width, height);

const performanceFactor = 1;
const reducedDataSize = Math.floor(freqDataArray.length * performanceFactor);
const reducedDataSize = Math.floor(
freqDataArray.length * performanceFactor,
);
const numBars = Math.min(
reducedDataSize,
app.osc.orientation === "horizontal" ? width : height
app.osc.orientation === "horizontal" ? width : height,
);
const barWidth =
app.osc.orientation === "horizontal" ? width / numBars : height / numBars;
Expand All @@ -184,30 +186,30 @@ export const runOscilloscope = (

for (let i = 0; i < numBars; i++) {
barHeight = Math.floor(
freqDataArray[Math.floor(i * freqDataArray.length / numBars)] * ((height / 256) * app.osc.size)
freqDataArray[Math.floor((i * freqDataArray.length) / numBars)] *
((height / 256) * app.osc.size),
);

if (app.osc.orientation === "horizontal") {
canvasCtx.fillRect(
x + offset_width,
(height - barHeight) / 2 + offset_height,
barWidth + 1,
barHeight
barHeight,
);
x += barWidth;
} else {
canvasCtx.fillRect(
(width - barHeight) / 2 + offset_width,
y + offset_height,
barHeight,
barWidth + 1
barWidth + 1,
);
y += barWidth;
}
}
}


function draw() {
// Update the canvas position on each cycle
const WIDTH = canvas.width;
Expand All @@ -230,7 +232,7 @@ export const runOscilloscope = (
-OFFSET_WIDTH,
-OFFSET_HEIGHT,
WIDTH + 2 * OFFSET_WIDTH,
HEIGHT + 2 * OFFSET_HEIGHT
HEIGHT + 2 * OFFSET_HEIGHT,
);
return;
}
Expand All @@ -250,7 +252,7 @@ export const runOscilloscope = (
-OFFSET_WIDTH,
-OFFSET_HEIGHT,
WIDTH + 2 * OFFSET_WIDTH,
HEIGHT + 2 * OFFSET_HEIGHT
HEIGHT + 2 * OFFSET_HEIGHT,
);
}
canvasCtx.lineWidth = app.osc.thickness;
Expand Down
5 changes: 4 additions & 1 deletion src/Clock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export class Clock {
lastPlayPressTime: number;
totalPauseTime: number;

constructor(public app: Editor, ctx: AudioContext) {
constructor(
public app: Editor,
ctx: AudioContext,
) {
this.time_position = { bar: 0, beat: 0, pulse: 0 };
this.time_signature = [4, 4];
this.logicalTime = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const makeExampleFactory = (application: Editor): Function => {
const make_example = (
description: string,
code: string,
open: boolean = false
open: boolean = false,
) => {
const codeId = `codeExample${application.exampleCounter++}`;
// Store the code snippet in the data structure
Expand Down Expand Up @@ -143,7 +143,7 @@ export const updateDocumentationContent = (app: Editor, bindings: any) => {
extensions: [showdownHighlight({ auto_detection: true }), ...bindings],
});
const converted_markdown = converter.makeHtml(
app.docs[app.currentDocumentationPane]
app.docs[app.currentDocumentationPane],
);
document.getElementById("documentation-content")!.innerHTML =
converted_markdown;
Expand Down
22 changes: 9 additions & 13 deletions src/DomElements.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { type Editor } from "./main";


export type ElementMap = {
[key: string]:
| HTMLElement
| HTMLButtonElement
| HTMLDivElement
| HTMLInputElement
| HTMLSelectElement
| HTMLCanvasElement
| HTMLFormElement
| HTMLInputElement
;
| HTMLElement
| HTMLButtonElement
| HTMLDivElement
| HTMLInputElement
| HTMLSelectElement
| HTMLCanvasElement
| HTMLFormElement
| HTMLInputElement;
};

export const singleElements = {
Expand Down Expand Up @@ -92,6 +90,4 @@ export const createDocumentationStyle = (app: Editor) => {
tr: "",
box: "border bg-red-500",
};
}


};
20 changes: 11 additions & 9 deletions src/EditorSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
bracketMatching,
} from "@codemirror/language";
import { defaultKeymap, historyKeymap, history } from "@codemirror/commands";
import { searchKeymap, highlightSelectionMatches } from "@codemirror/search"
import { searchKeymap, highlightSelectionMatches } from "@codemirror/search";
import {
autocompletion,
closeBrackets,
Expand All @@ -34,15 +34,15 @@ import { toposTheme } from "./themes/toposTheme";
import { javascript } from "@codemirror/lang-javascript";
import { inlineHoveringTips } from "./documentation/inlineHelp";
import { toposCompletions, soundCompletions } from "./documentation/inlineHelp";
import { javascriptLanguage } from "@codemirror/lang-javascript"
import { javascriptLanguage } from "@codemirror/lang-javascript";

export const jsCompletions = javascriptLanguage.data.of({
autocomplete: toposCompletions
})
autocomplete: toposCompletions,
});

export const toposSoundCompletions = javascriptLanguage.data.of({
autocomplete: soundCompletions
})
autocomplete: soundCompletions,
});

export const editorSetup: Extension = (() => [
highlightActiveLineGutter(),
Expand Down Expand Up @@ -95,7 +95,9 @@ export const installEditor = (app: Editor) => {
app.withLineNumbers.of(lines),
app.fontSize.of(fontModif),
app.hoveringCompartment.of(app.settings.tips ? inlineHoveringTips : []),
app.completionsCompartment.of(app.settings.completions ? [jsCompletions, toposSoundCompletions] : []),
app.completionsCompartment.of(
app.settings.completions ? [jsCompletions, toposSoundCompletions] : [],
),
editorSetup,
toposTheme,
app.chosenLanguage.of(javascript()),
Expand All @@ -114,7 +116,7 @@ export const installEditor = (app: Editor) => {
return true;
},
},
])
]),
),
keymap.of([indentWithTab]),
],
Expand All @@ -139,7 +141,7 @@ export const installEditor = (app: Editor) => {
".cm-gutters": {
fontSize: `${app.settings.font_size}px`,
},
})
}),
),
});
};
Loading

0 comments on commit eb8ef87

Please sign in to comment.