Generating documentation using factory

This commit is contained in:
2023-08-25 12:36:37 +02:00
parent 94acee819a
commit 58c0a2cf66
3 changed files with 407 additions and 370 deletions

View File

@ -51,7 +51,7 @@ Array.prototype.in = function <T>(this: T[], value: T): boolean {
return this.includes(value); return this.includes(value);
}; };
async function loadSamples() { export async function loadSamples() {
// const ds = "https://raw.githubusercontent.com/felixroos/dough-samples/main/"; // const ds = "https://raw.githubusercontent.com/felixroos/dough-samples/main/";
return Promise.all([ return Promise.all([
initAudioOnFirstClick(), initAudioOnFirstClick(),
@ -62,8 +62,6 @@ async function loadSamples() {
]); ]);
} }
loadSamples();
export const generateCacheKey = (...args: any[]): string => { export const generateCacheKey = (...args: any[]): string => {
return args.map((arg) => JSON.stringify(arg)).join(","); return args.map((arg) => JSON.stringify(arg)).join(",");
}; };
@ -92,6 +90,10 @@ export class UserAPI {
//this.load = samples("github:tidalcycles/Dirt-Samples/master"); //this.load = samples("github:tidalcycles/Dirt-Samples/master");
} }
_all_samples = (): object => {
return soundMap.get();
};
_reportError = (error: any): void => { _reportError = (error: any): void => {
console.log(error); console.log(error);
clearTimeout(this.errorTimeoutID); clearTimeout(this.errorTimeoutID);
@ -236,7 +238,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. * Sends a MIDI note to the current MIDI output.
* *
@ -323,8 +325,8 @@ export class UserAPI {
this.app.api.patternCache.set(key, player); this.app.api.patternCache.set(key, player);
} }
if ((player && player.notStarted()) || player.played) { if ((player && player.notStarted()) || player.played) {
player.callTime = this.epulse(); player.callTime = this.epulse();
player.played = false; player.played = false;
} }
return player; return player;
}; };
@ -889,7 +891,7 @@ export class UserAPI {
let integral_part = Math.floor(b); let integral_part = Math.floor(b);
let decimal_part = b - integral_part; let decimal_part = b - integral_part;
final_pulses.push( final_pulses.push(
integral_part === this.app.clock.time_position.beat && integral_part === this.app.clock.time_position.beat &&
this.app.clock.time_position.pulse === this.app.clock.time_position.pulse ===
decimal_part * this.app.clock.ppqn decimal_part * this.app.clock.ppqn
); );
@ -1235,7 +1237,7 @@ export class UserAPI {
// Trivial functions // Trivial functions
// ============================================================= // =============================================================
sound = (sound: string|object) => { sound = (sound: string | object) => {
return new SoundEvent(sound, this.app); return new SoundEvent(sound, this.app);
}; };

File diff suppressed because it is too large Load Diff

View File

@ -14,10 +14,10 @@ import { indentWithTab } from "@codemirror/commands";
import { vim } from "@replit/codemirror-vim"; import { vim } from "@replit/codemirror-vim";
import { AppSettings, Universe } from "./AppSettings"; import { AppSettings, Universe } from "./AppSettings";
import { editorSetup } from "./EditorSetup"; import { editorSetup } from "./EditorSetup";
import { documentation } from "./Documentation"; import { documentation_factory } from "./Documentation";
import { EditorView } from "codemirror"; import { EditorView } from "codemirror";
import { Clock } from "./Clock"; import { Clock } from "./Clock";
import { UserAPI } from "./API"; import { loadSamples, UserAPI } from "./API";
import "./style.css"; import "./style.css";
import { import {
Universes, Universes,
@ -27,9 +27,6 @@ import {
} from "./AppSettings"; } from "./AppSettings";
import { tryEvaluate } from "./Evaluator"; import { tryEvaluate } from "./Evaluator";
type Documentation = { [key: string]: string };
const Docs: Documentation = documentation;
// Importing showdown and setting up the markdown converter // Importing showdown and setting up the markdown converter
import showdown from "showdown"; import showdown from "showdown";
showdown.setFlavor("github"); showdown.setFlavor("github");
@ -78,6 +75,7 @@ export class Editor {
userPlugins: Extension[] = []; userPlugins: Extension[] = [];
state: EditorState; state: EditorState;
api: UserAPI; api: UserAPI;
docs: { [key: string]: string } = {};
// Audio stuff // Audio stuff
audioContext: AudioContext; audioContext: AudioContext;
@ -236,6 +234,13 @@ export class Editor {
let dynamicPlugins = new Compartment(); let dynamicPlugins = new Compartment();
// ================================================================================
// Building the documentation
loadSamples().then(() => {
this.docs = documentation_factory(this);
});
// ================================================================================
// ================================================================================ // ================================================================================
// Application event listeners // Application event listeners
// ================================================================================ // ================================================================================
@ -662,10 +667,11 @@ export class Editor {
const converter = new showdown.Converter({ const converter = new showdown.Converter({
emoji: true, emoji: true,
moreStyling: true, moreStyling: true,
backslashEscapesHTMLTags: true,
extensions: [showdownHighlight({ auto_detection: true }), ...bindings], extensions: [showdownHighlight({ auto_detection: true }), ...bindings],
}); });
const converted_markdown = converter.makeHtml( const converted_markdown = converter.makeHtml(
Docs[this.currentDocumentationPane] this.docs[this.currentDocumentationPane]
); );
function wrapCodeWithPre(inputString: string): string { function wrapCodeWithPre(inputString: string): string {
let newString = inputString.replace(/<code>/g, "<pre><code>"); let newString = inputString.replace(/<code>/g, "<pre><code>");