import { type Editor } from "../main"; import { makeExampleFactory } from "../Documentation"; export const functions = (application: Editor): string => { const makeExample = makeExampleFactory(application); return ` # Functions ## Scripts You can control scripts programatically. This is the core concept of Topos after all! - script(...number: number[]): call one or more scripts (_e.g. script(1,2,3,4)). Once called, scripts will be evaluated once. There are nine local scripts by default. You cannot call the global script nor the initialisation script. - clear_script(number): deletes the given script. - copy_script(from: number, to: number): copies a local script denoted by its number to another local script. **This is a destructive operation!** ${makeExample( "Calling a script! The most important feature!", ` beat(1) :: script(1) `, true, )} ${makeExample( "Calling mutliple scripts at the same time.", ` beat(1) :: script(1, 3, 5) `, false, )} ## Math functions - max(...values: number[]): number: returns the maximum value of a list of numbers. - min(...values: number[]): number: returns the minimum value of a list of numbers. - mean(...values: number[]): number: returns the arithmetic mean of a list of numbers. - limit(value: number, min: number, max: number): number: Limits a value between a minimum and a maximum. ## Delay functions - delay(ms: number, func: Function): void: Delays the execution of a function by a given number of milliseconds. ${makeExample( "Phased woodblocks", ` // Some very low-budget version of phase music beat(.5) :: delay(usine(.125) * 80, () => sound('east').out()) beat(.5) :: delay(50, () => sound('east').out()) `, true, )} - delayr(ms: number, nb: number, func: Function): void: Delays the execution of a function by a given number of milliseconds, repeated a given number of times. ${makeExample( "Another woodblock texture", ` beat(1) :: delayr(50, 4, () => sound('east').speed([0.5,.25].beat()).out()) flip(2) :: beat(2) :: delayr(150, 4, () => sound('east').speed([0.5,.25].beat() * 4).out()) `, true, )}; `; };