Merge branch 'main' of https://github.com/Bubobubobubobubo/Topos
This commit is contained in:
58
src/API.ts
58
src/API.ts
@ -75,19 +75,50 @@ export class UserAPI {
|
|||||||
};
|
};
|
||||||
|
|
||||||
_playDocExample = (code?: string) => {
|
_playDocExample = (code?: string) => {
|
||||||
this.play();
|
/**
|
||||||
console.log("Executing documentation example: " + this.app.selectedExample);
|
* Play an example from the documentation. The example is going
|
||||||
this.app.universes[this.app.selected_universe as string].global.candidate =
|
* to be stored in the example buffer belonging to the universe.
|
||||||
code ? code : (this.app.selectedExample as string);
|
* This buffer is going to be cleaned everytime the user press
|
||||||
tryEvaluate(
|
* pause or leaves the documentation window.
|
||||||
this.app,
|
*
|
||||||
this.app.universes[this.app.selected_universe as string].global
|
* @param code - The code example to play (identifier)
|
||||||
);
|
*/
|
||||||
|
|
||||||
|
let current_universe = this.app.universes[this.app.selected_universe];
|
||||||
|
this.app.exampleIsPlaying = true;
|
||||||
|
if (!current_universe.example) {
|
||||||
|
current_universe.example = {
|
||||||
|
candidate: "",
|
||||||
|
committed: "",
|
||||||
|
evaluations: 0,
|
||||||
|
};
|
||||||
|
current_universe.example.candidate! = code
|
||||||
|
? code
|
||||||
|
: (this.app.selectedExample as string);
|
||||||
|
} else {
|
||||||
|
current_universe.example.candidate! = code
|
||||||
|
? code
|
||||||
|
: (this.app.selectedExample as string);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
_stopDocExample = () => {
|
||||||
|
let current_universe = this.app.universes[this.app.selected_universe];
|
||||||
|
if (current_universe?.example !== undefined) {
|
||||||
|
this.app.exampleIsPlaying = false;
|
||||||
|
current_universe.example.candidate! = "";
|
||||||
|
current_universe.example.committed! = "";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_playDocExampleOnce = (code?: string) => {
|
_playDocExampleOnce = (code?: string) => {
|
||||||
|
let current_universe = this.app.universes[this.app.selected_universe];
|
||||||
|
if (current_universe?.example !== undefined) {
|
||||||
|
current_universe.example.candidate! = "";
|
||||||
|
current_universe.example.committed! = "";
|
||||||
|
}
|
||||||
this.play();
|
this.play();
|
||||||
console.log("Executing documentation example: " + this.app.selectedExample);
|
this.app.exampleIsPlaying = true;
|
||||||
evaluateOnce(this.app, code as string);
|
evaluateOnce(this.app, code as string);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -406,7 +437,7 @@ export class UserAPI {
|
|||||||
|
|
||||||
player.updateLastCallTime();
|
player.updateLastCallTime();
|
||||||
|
|
||||||
if(id !== "") {
|
if (id !== "") {
|
||||||
// Sync named patterns to z0 by default
|
// Sync named patterns to z0 by default
|
||||||
player.sync("z0");
|
player.sync("z0");
|
||||||
}
|
}
|
||||||
@ -1050,7 +1081,7 @@ export class UserAPI {
|
|||||||
return final_pulses.some((p) => p == true);
|
return final_pulses.some((p) => p == true);
|
||||||
};
|
};
|
||||||
|
|
||||||
oneuclid = (pulses: number, length: number, rotate: number=0): boolean => {
|
oneuclid = (pulses: number, length: number, rotate: number = 0): boolean => {
|
||||||
/**
|
/**
|
||||||
* Returns true if the current beat is in the given euclid sequence.
|
* Returns true if the current beat is in the given euclid sequence.
|
||||||
* @param pulses - The number of pulses in the cycle
|
* @param pulses - The number of pulses in the cycle
|
||||||
@ -1059,7 +1090,10 @@ export class UserAPI {
|
|||||||
* @returns True if the current beat is in the given euclid sequence
|
* @returns True if the current beat is in the given euclid sequence
|
||||||
*/
|
*/
|
||||||
const cycle = this._euclidean_cycle(pulses, length, rotate);
|
const cycle = this._euclidean_cycle(pulses, length, rotate);
|
||||||
const beats = cycle.reduce((acc:number[], x:boolean, i:number) => { if(x) acc.push(i+1); return acc; }, []);
|
const beats = cycle.reduce((acc: number[], x: boolean, i: number) => {
|
||||||
|
if (x) acc.push(i + 1);
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
return this.oncount(beats, length);
|
return this.oncount(beats, length);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,7 @@ export interface Universe {
|
|||||||
locals: { [key: number]: File };
|
locals: { [key: number]: File };
|
||||||
init: File;
|
init: File;
|
||||||
notes: File;
|
notes: File;
|
||||||
|
example?: File;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface File {
|
export interface File {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ export const makeExampleFactory = (application: Editor): Function => {
|
|||||||
<details ${open ? "open" : ""}>
|
<details ${open ? "open" : ""}>
|
||||||
<summary >${description}
|
<summary >${description}
|
||||||
<button class="py-1 align-top text-base rounded-lg pl-2 pr-2 hover:bg-green-700 bg-green-600 inline-block" onclick="app.api._playDocExample(app.api.codeExamples['${codeId}'])">▶️ Play</button>
|
<button class="py-1 align-top text-base rounded-lg pl-2 pr-2 hover:bg-green-700 bg-green-600 inline-block" onclick="app.api._playDocExample(app.api.codeExamples['${codeId}'])">▶️ Play</button>
|
||||||
<button class="py-1 text-base rounded-lg pl-2 pr-2 hover:bg-neutral-600 bg-neutral-500 inline-block pl-2" onclick="stop()">⏸️ Pause</button>
|
<button class="py-1 text-base rounded-lg pl-2 pr-2 hover:bg-neutral-600 bg-neutral-500 inline-block pl-2" onclick="app.api._stopDocExample()">⏸️ Pause</button>
|
||||||
<button class="py-1 text-base rounded-lg pl-2 pr-2 hover:bg-neutral-900 bg-neutral-800 inline-block " onclick="navigator.clipboard.writeText(app.api.codeExamples['${codeId}'])">📎 Copy</button>
|
<button class="py-1 text-base rounded-lg pl-2 pr-2 hover:bg-neutral-900 bg-neutral-800 inline-block " onclick="navigator.clipboard.writeText(app.api.codeExamples['${codeId}'])">📎 Copy</button>
|
||||||
</summary>
|
</summary>
|
||||||
\`\`\`javascript
|
\`\`\`javascript
|
||||||
|
|||||||
@ -21,7 +21,11 @@ export class TransportNode extends AudioWorkletNode {
|
|||||||
const futureTimeStamp = this.app.clock.convertTicksToTimeposition(this.app.clock.tick);
|
const futureTimeStamp = this.app.clock.convertTicksToTimeposition(this.app.clock.tick);
|
||||||
|
|
||||||
this.app.clock.time_position = futureTimeStamp;
|
this.app.clock.time_position = futureTimeStamp;
|
||||||
tryEvaluate(this.app, this.app.global_buffer);
|
if (this.app.exampleIsPlaying) {
|
||||||
|
tryEvaluate(this.app, this.app.example_buffer);
|
||||||
|
} else {
|
||||||
|
tryEvaluate(this.app, this.app.global_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -73,6 +73,7 @@ export class Editor {
|
|||||||
chosenLanguage: Compartment;
|
chosenLanguage: Compartment;
|
||||||
currentDocumentationPane: string = "introduction";
|
currentDocumentationPane: string = "introduction";
|
||||||
exampleCounter: number = 0;
|
exampleCounter: number = 0;
|
||||||
|
exampleIsPlaying: boolean = false;
|
||||||
|
|
||||||
settings = new AppSettings();
|
settings = new AppSettings();
|
||||||
editorExtensions: Extension[] = [];
|
editorExtensions: Extension[] = [];
|
||||||
@ -680,6 +681,10 @@ export class Editor {
|
|||||||
return this.universes[this.selected_universe.toString()].notes;
|
return this.universes[this.selected_universe.toString()].notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get example_buffer() {
|
||||||
|
return this.universes[this.selected_universe.toString()].example;
|
||||||
|
}
|
||||||
|
|
||||||
get global_buffer() {
|
get global_buffer() {
|
||||||
return this.universes[this.selected_universe.toString()].global;
|
return this.universes[this.selected_universe.toString()].global;
|
||||||
}
|
}
|
||||||
@ -746,10 +751,10 @@ export class Editor {
|
|||||||
if (document.getElementById("app")?.classList.contains("hidden")) {
|
if (document.getElementById("app")?.classList.contains("hidden")) {
|
||||||
document.getElementById("app")?.classList.remove("hidden");
|
document.getElementById("app")?.classList.remove("hidden");
|
||||||
document.getElementById("documentation")?.classList.add("hidden");
|
document.getElementById("documentation")?.classList.add("hidden");
|
||||||
|
this.exampleIsPlaying = false;
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("app")?.classList.add("hidden");
|
document.getElementById("app")?.classList.add("hidden");
|
||||||
document.getElementById("documentation")?.classList.remove("hidden");
|
document.getElementById("documentation")?.classList.remove("hidden");
|
||||||
|
|
||||||
// Load and convert Markdown content from the documentation file
|
// Load and convert Markdown content from the documentation file
|
||||||
this.updateDocumentationContent();
|
this.updateDocumentationContent();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user