Audio samples are now played as one shots in the documentation
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { seededRandom } from "zifferjs";
|
||||
import { MidiConnection } from "./IO/MidiConnection";
|
||||
import { tryEvaluate } from "./Evaluator";
|
||||
import { tryEvaluate, evaluateOnce } from "./Evaluator";
|
||||
import { DrunkWalk } from "./Utils/Drunk";
|
||||
import { scale } from "./Scales";
|
||||
import { Editor } from "./main";
|
||||
@ -80,6 +80,13 @@ export class UserAPI {
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
_playDocExampleOnce = (code?: string) => {
|
||||
this.play();
|
||||
console.log("Executing documentation example: " + this.app.selectedExample);
|
||||
evaluateOnce(this.app, code as string);
|
||||
};
|
||||
|
||||
_all_samples = (): object => {
|
||||
return soundMap.get();
|
||||
};
|
||||
|
||||
@ -22,14 +22,14 @@ const samples_to_markdown = (application: Editor) => {
|
||||
|
||||
// Adding new examples for each sample folder!
|
||||
const codeId = `sampleExample${i}`;
|
||||
application.api.codeExamples[codeId] = `mod(.5) :: sound("${keys[i]}").n(irand(1,100)).end(1).out()`;
|
||||
application.api.codeExamples[codeId] = `sound("${keys[i]}").n(irand(1, 5)).end(1).out()`;
|
||||
// @ts-ignore
|
||||
const howMany = samples[keys[i]].data.samples.length;
|
||||
|
||||
markdownList += `
|
||||
<button
|
||||
class="hover:bg-neutral-500 inline px-4 py-2 bg-neutral-700 text-orange-300 text-xl"
|
||||
onclick="app.api._playDocExample(app.api.codeExamples['${codeId}'])"
|
||||
onclick="app.api._playDocExampleOnce(app.api.codeExamples['${codeId}'])"
|
||||
>
|
||||
${keys[i]}
|
||||
<b class="text-white">(${howMany})</b>
|
||||
|
||||
@ -95,3 +95,17 @@ export const evaluate = async (
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const evaluateOnce = async (
|
||||
application: Editor,
|
||||
code: string
|
||||
): Promise<void> => {
|
||||
/**
|
||||
* Evaluates the code once without any caching or error-handling mechanisms besides the tryCatchWrapper.
|
||||
*
|
||||
* @param application - The application object that contains the Editor API.
|
||||
* @param code - The code to be evaluated.
|
||||
* @returns A promise that resolves when the code has been evaluated.
|
||||
*/
|
||||
await tryCatchWrapper(application, code);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user