diff --git a/src/Documentation.ts b/src/Documentation.ts index 6dfa87e..fee8a6a 100644 --- a/src/Documentation.ts +++ b/src/Documentation.ts @@ -1217,14 +1217,14 @@ The basic Ziffer notation is entirely written in JavaScript strings (_e.g_ delete_variable(name: string): deletes a global variable from storage. - clear_variables(): clear **ALL** variables. **This is a destructive operation**! +**Note:** since this example is running in the documentation, we cannot take advantage of the multiple scripts paradigm. Try to send a variable from the global file to the local file n°6. + +${makeExample( + "Setting a global variable", +` +v('my_cool_variable', 2) +`, true)} + +${makeExample( + "Getting that variable back and printing!", +` +// Note that we just use one argument +log(v('my_cool_variable')) +`, false)} + + ## Counter and iterators You will often need to use iterators and/or counters to index over data structures (getting a note from a list of notes, etc...). There are functions ready to be used for this. Each script also comes with its own iterator that you can access using the i variable. **Note:** the script iteration count is **not** resetted between sessions. It will continue to increase the more you play, even if you just picked up an old project. @@ -1682,14 +1698,49 @@ You will often need to use iterators and/or counters to index over data structur - drunk_min(min: number): sets the minimum value. - drunk_wrap(wrap: boolean): whether to wrap the drunk walk to 0 once the upper limit is reached or not. +**Note:** Counters also come with a secret syntax. They can be called with the **$** symbol! + +${makeExample( + "Iterating over a list of samples using a counter", +` +rhythm(.25, 6, 8) :: sound('dr').n($(1)).end(.25).out() +`, true)} + +${makeExample( + "Using a more complex counter", +` +// Limit is 20, step is 5 +rhythm(.25, 6, 8) :: sound('dr').n($(1, 20, 5)).end(.25).out() +`, false)} + +${makeExample( + "Calling the drunk mechanism", +` +// Limit is 20, step is 5 +rhythm(.25, 6, 8) :: sound('dr').n(drunk()).end(.25).out() +`, false)} + ## 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!", +` +mod(1) :: script(1) +`, true)} + +${makeExample( + "Calling mutliple scripts at the same time.", +` +mod(1) :: script(1, 3, 5) +`, false)} + + ## Mouse @@ -1698,11 +1749,33 @@ You can get the current position of the mouse on the screen by using the followi - mouseX(): the horizontal position of the mouse on the screen (as a floating point number). - mouseY(): the vertical position of the mouse on the screen (as a floating point number). +${makeExample( + "FM Synthesizer controlled using the mouse", +` +mod(.25) :: sound('sine') + .fmi(mouseX() / 100) + .fmh(mouseY() / 100) + .vel(0.2) + .room(0.9).out() +`, true)} + Current mouse position can also be used to generate notes: - noteX(): returns a MIDI note number (0-127) based on the horizontal position of the mouse on the screen. - noteY(): returns a MIDI note number (0-127) based on the vertical position of the mouse on the screen. + +${makeExample( + "The same synthesizer, with note control!", +` +mod(.25) :: sound('sine') + .fmi(mouseX() / 100) + .note(noteX()) + .fmh(mouseY() / 100) + .vel(0.2) + .room(0.9).out() +`, true)} + ## Low Frequency Oscillators Low Frequency Oscillators (_LFOs_) are an important piece in any digital audio workstation or synthesizer. Topos implements some basic waveforms you can play with to automatically modulate your paremeters. @@ -1749,11 +1822,32 @@ There are some simple functions to play with probabilities. - rand(min: number, max:number): returns a random number between min and max. Shorthand _r()_. - irand(min: number, max:number): returns a random integer between min and max. Shorthands _ir()_ or _rI()_. + +${makeExample( + "Bleep bloop, what were you expecting?", +` +rhythm(0.125, 10, 16) :: sound('sid').n(4).note(50 + irand(50, 62) % 8).out() +`, true)} + + - prob(p: number): return true _p_% of time, false in other cases. - toss(): throwing a coin. Head (true) or tails (false). + + +${makeExample( + "The Teletype experience!", +` +prob(50) :: script(1); +prob(60) :: script(2); +prob(80) :: script(toss() ? script(3) : script(4)) +`, true)} + - seed(val: number|string): sets the seed of the random number generator. You can use a number or a string. The same seed will always return the same sequence of random numbers. - -Chance operators returning a boolean value are also available: + + +## Chance operators + +Chance operators returning a boolean value are also available. They are super important because they also exist for another mechanism called **chaining**. Checkout the **Chaining** page to learn how to use them in different contexts! - odds(n: number, sec?: number): returns true for every n (odds) (eg. 1/4 = 0.25) in given seconds (sec) - almostNever(sec?: number): returns true 0.1% in given seconds (sec) @@ -1774,7 +1868,23 @@ Chance operators returning a boolean value are also available: ## 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 +mod(.5) :: delay(usine(.125) * 80, () => sound('east').out()) +mod(.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", +` +mod(1) :: delayr(50, 4, () => sound('east').speed([0.5,.25].beat()).out()) +div(2) :: mod(2) :: delayr(150, 4, () => sound('east').speed([0.5,.25].beat() * 4).out()) +`, true)}; `; const reference: string = `