From 1b2390a919ecc90697080240726f5d63a4f7b856 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sat, 19 Aug 2023 23:08:20 +0200 Subject: [PATCH 01/23] normalising all mod values --- src/API.ts | 109 ++++++++--------------------------------------------- 1 file changed, 16 insertions(+), 93 deletions(-) diff --git a/src/API.ts b/src/API.ts index 645a1d1..2c10158 100644 --- a/src/API.ts +++ b/src/API.ts @@ -191,7 +191,10 @@ export class UserAPI { */ const channel = options.channel ? options.channel : 0; const velocity = options.velocity ? options.velocity : 100; - const duration = options.duration ? options.duration : 0.5; + const duration = options.duration + ? options.duration * + Math.floor(this.app.clock.pulse_duration * this.ppqn()) + : this.app.clock.pulse_duration * this.ppqn(); this.MidiConnection.sendMidiNote(note, channel, velocity, duration); }; @@ -465,7 +468,9 @@ export class UserAPI { public slice = (chunk: number): boolean => { const time_pos = this.epulse(); - const current_chunk = Math.floor(time_pos / chunk); + const current_chunk = Math.floor( + time_pos / Math.floor(chunk * this.ppqn()) + ); return current_chunk % 2 === 0; }; @@ -479,98 +484,12 @@ export class UserAPI { const chunk_size = args[0]; // Get the first argument (chunk size) const elements = args.slice(1); // Get the rest of the arguments as an array const timepos = this.epulse(); - const slice_count = Math.floor(timepos / chunk_size); + const slice_count = Math.floor( + timepos / Math.floor(chunk_size * this.ppqn()) + ); return elements[slice_count % elements.length]; }; - public seqmod = (...input: any[]) => { - if (cache.has(this._sequence_key_generator(input))) { - let sequence = cache.get( - this._sequence_key_generator(input) - ) as Pattern; - - sequence.options.currentIteration++; - - if (sequence.options.currentIteration === sequence.options.nextTarget) { - sequence.options.index++; - sequence.options.nextTarget = - input[sequence.options.index % input.length]; - sequence.options.currentIteration = 0; - } - - cache.set(this._sequence_key_generator(input), { - pattern: input as any[], - options: sequence.options, - }); - - return sequence.options.currentIteration === 0; - } else { - let pattern_options = { - index: -1, - nextTarget: this.app.clock.ticks_before_new_bar, - currentIteration: 0, - }; - if (typeof input[input.length - 1] === "object") { - pattern_options = { - ...input.pop(), - ...(pattern_options as object), - }; - } - - // pattern_options.currentIteration++; - // TEST - pattern_options.nextTarget = this.app.clock.ticks_before_new_bar; - - if (pattern_options.currentIteration === pattern_options.nextTarget) { - pattern_options.index++; - pattern_options.nextTarget = - input[pattern_options.index % input.length]; - pattern_options.currentIteration = 0; - } - - cache.set(this._sequence_key_generator(input), { - pattern: input as any[], - options: pattern_options, - }); - - return pattern_options.currentIteration === 0; - } - }; - - public seq = (...input: any[]) => { - /** - * Returns a value in a sequence stored using an LRU Cache. - * The sequence is stored in the cache with an hash identifier - * made from a base64 encoding of the pattern. The pattern itself - * is composed of the pattern itself (a list of arbitrary typed - * values) and a set of options (an object) detailing how the pattern - * should be iterated on. - * - * @param input - The input to generate a key for - * Note that the last element of the input can be an object - * containing options for the sequence function. - * @returns A value in a sequence stored using an LRU Cache - */ - if (cache.has(this._sequence_key_generator(input))) { - let sequence = cache.get( - this._sequence_key_generator(input) - ) as Pattern; - sequence.options.index += 1; - cache.set(this._sequence_key_generator(input), sequence); - return sequence.pattern[sequence.options.index % sequence.pattern.length]; - } else { - let pattern_options = { index: 0 }; - if (typeof input[input.length - 1] === "object") { - pattern_options = { ...input.pop(), ...(pattern_options as object) }; - } - cache.set(this._sequence_key_generator(input), { - pattern: input as any[], - options: pattern_options, - }); - return cache.get(this._sequence_key_generator(input)); - } - }; - pick = (...array: T[]): T => { /** * Returns a random element from an array. @@ -996,12 +915,16 @@ export class UserAPI { }; public mod = (...n: number[]): boolean => { - const results: boolean[] = n.map((value) => this.epulse() % value === 0); + const results: boolean[] = n.map( + (value) => this.epulse() % Math.floor(value * ppqn()) === 0 + ); return results.some((value) => value === true); }; public modbar = (...n: number[]): boolean => { - const results: boolean[] = n.map((value) => this.bar() % value === 0); + const results: boolean[] = n.map( + (value) => this.bar() % Math.floor(value * ppqn()) === 0 + ); return results.some((value) => value === true); }; From fffefff02c70c8a8f621832616d9ca07290b0c52 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sat, 19 Aug 2023 23:10:27 +0200 Subject: [PATCH 02/23] updating documentation with new mod values --- src/Documentation.ts | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/Documentation.ts b/src/Documentation.ts index 40ac497..11ae01b 100644 --- a/src/Documentation.ts +++ b/src/Documentation.ts @@ -26,16 +26,16 @@ Press ${key_shortcut(

 if (bar() % 4 > 2 ) {
-    often() && mod(48) && sound('808bd').out()
-    mod(24) && euclid($('a'), 3, 8) && sound('808sd').out()
-    mod(seqbeat(24,12)) && euclid($('a'), 7, 8) && sound('hh')
+    often() && mod(.5) && sound('808bd').out()
+    mod(.5) && euclid($('a'), 3, 8) && sound('808sd').out()
+    mod(seqbeat(.5,.25)) && euclid($('a'), 7, 8) && sound('hh')
       .delay(0.75).delaytime(0.75)
       .speed(seqbeat(1,2,3,4)).out()
-    mod(48) && sound('bd').n(6).out()
+    mod(.5) && sound('bd').n(6).out()
 } else {
-      mod(24) && sound('hh').n(seqbeat(1,2,3,4)).end(.01).out()
-      mod(48) && sound('kick').out()
-      mod(24) && euclid($('ba'), 5, 8) && sound('cp').out()
+      mod(.5) && sound('hh').n(seqbeat(1,2,3,4)).end(.01).out()
+      mod(1) && sound('kick').out()
+      mod(.5) && euclid($('ba'), 5, 8) && sound('cp').out()
 }
 
`; @@ -112,12 +112,12 @@ Some functions are used very often as time primitives. They are used to create m onbeat(3) && sound('sd').out() \`\`\` -- mod(...values: number[]): returns true if the current pulse is a multiple of the given value. You can add any number of values, (_e.g._ mod(12,36)). +- mod(...values: number[]): returns true if the current pulse is a multiple of the given value. You can add any number of values, (_e.g._ mod(.25,.75)). \`\`\`javascript - mod(48) && sound('bd').out() - mod(pick(12,24)) && sound('hh').out() - mod(24) && sound('jvbass').out() + mod(1) && sound('bd').out() + mod(pick(.25,.5)) && sound('hh').out() + mod(.5) && sound('jvbass').out() \`\`\` - onbar(...values: number[]): returns true if the bar is currently equal to any of the specified values. @@ -129,13 +129,13 @@ You can use the time functions as conditionals. The following example will play \`\`\`javascript if((bar() % 4) > 1) { - mod(48) && sound('kick').out() - rarely() && mod(24) && sound('sd').out() - mod(24) && sound('jvbass').freq(500).out() + mod(1) && sound('kick').out() + rarely() && mod(.5) && sound('sd').out() + mod(.5) && sound('jvbass').freq(500).out() } else { - mod(24) && sound('hh').out() - mod(36) && sound('cp').out() - mod(24) && sound('jvbass').freq(250).out() + mod(.5) && sound('hh').out() + mod(.75) && sound('cp').out() + mod(.5) && sound('jvbass').freq(250).out() } \`\`\` `; @@ -152,10 +152,10 @@ You can use Topos to play MIDI thanks to the [WebMIDI API](https://developer.moz \`\`\`javascript bpm(80) // Setting a default BPM - mod(24) && note(36 + seqbeat(0,12), {duration: 0.02}) - mod(12) && note(pick(64, 76), {duration: 0.05}) - mod(36) && note(seqbeat(64, 67, 69), {duration: 0.05}) - sometimes() && mod(12) && note(seqbeat(64, 67, 69) + 24, {duration: 0.5}) + mod(.5) && note(36 + seqbeat(0,12), {duration: 0.02}) + mod(.25) && note(pick(64, 76), {duration: 0.05}) + mod(.75) && note(seqbeat(64, 67, 69), {duration: 0.05}) + sometimes() && mod(.25) && note(seqbeat(64, 67, 69) + 24, {duration: 0.5}) \`\`\` ## Control and Program Changes @@ -184,7 +184,7 @@ You can use Topos to play MIDI thanks to the [WebMIDI API](https://developer.moz - midi_clock(): send a MIDI Clock message. This function is used to synchronize Topos with other MIDI devices or DAWs. \`\`\`javascript - mod(12) && midi_clock() // Sending clock to MIDI device from the global buffer + mod(.25) && midi_clock() // Sending clock to MIDI device from the global buffer \`\`\` ## MIDI Output Selection @@ -210,8 +210,8 @@ I recommended you to run the following scripts in the global script (${key_short The basic function to play a sound is sound('sample/synth').out(). If the given sound exists in the database, it will be automatically queried and will start playing once loaded. To play a very basic beat, evaluate the following script: \`\`\`javascript -mod(48) && sound('bd').out() -mod(24) && sound('hh').out() +mod(1) && sound('bd').out() +mod(0.5) && sound('hh').out() \`\`\` In plain english, this translates to: @@ -226,7 +226,7 @@ If you remove the **mod** instruction, you will end up with a deluge of kick dru The .n(number) method can be used to pick a sample from the currently selected sample folder. For instance, the following script will play a random sample from the _kick_ folder: \`\`\`javascript -mod(48) && sound('kick').n(pick(1,2,3,4,5,6,7,8)).out() +mod(1) && sound('kick').n(pick(1,2,3,4,5,6,7,8)).out() \`\`\` Don't worry about the number. If it gets too big, it will be automatically wrapped to the number of samples in the folder. @@ -235,7 +235,7 @@ Don't worry about the number. If it gets too big, it will be automatically wrapp The sound('sample_name') function can be chained to _specify_ a sound more. For instance, you can add a filter and some effects to your high-hat: \`\`\`javascript -mod(24) && sound('hh') +mod(0.5) && sound('hh') .speed(pick(1,2,3)) .room(0.5) .cutoff(usine(2) * 5000) From 63958a572d1ee3e1d75044c7e4ef8721d4ea3524 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sat, 19 Aug 2023 23:12:37 +0200 Subject: [PATCH 03/23] Fixing the build --- src/API.ts | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/src/API.ts b/src/API.ts index 2c10158..1f3a9df 100644 --- a/src/API.ts +++ b/src/API.ts @@ -2,7 +2,6 @@ import { Pitch, Chord, Rest, Event, cachedPattern } from "zifferjs"; import { MidiConnection } from "./IO/MidiConnection"; import { tryEvaluate } from "./Evaluator"; import { DrunkWalk } from "./Utils/Drunk"; -import { LRUCache } from "lru-cache"; import { scale } from "./Scales"; import { Editor } from "./main"; import { Sound } from "./Sound"; @@ -13,22 +12,12 @@ import { // @ts-ignore } from "superdough"; -// This is an LRU cache used for storing persistent patterns -const cache = new LRUCache({ max: 1000, ttl: 1000 * 60 * 5 }); - interface ControlChange { channel: number; control: number; value: number; } -interface Pattern { - pattern: any[]; - options: { - [key: string]: T; - }; -} - /** * This is an override of the basic "includes" method. */ @@ -455,17 +444,6 @@ export class UserAPI { // Sequencer related functions // ============================================================= - private _sequence_key_generator(pattern: any[]) { - /** - * Generates a key for the sequence function. - * - * @param input - The input to generate a key for - * @returns A key for the sequence function - */ - // Make the pattern base64 - return btoa(JSON.stringify(pattern)); - } - public slice = (chunk: number): boolean => { const time_pos = this.epulse(); const current_chunk = Math.floor( @@ -916,28 +894,18 @@ export class UserAPI { public mod = (...n: number[]): boolean => { const results: boolean[] = n.map( - (value) => this.epulse() % Math.floor(value * ppqn()) === 0 + (value) => this.epulse() % Math.floor(value * this.ppqn()) === 0 ); return results.some((value) => value === true); }; public modbar = (...n: number[]): boolean => { const results: boolean[] = n.map( - (value) => this.bar() % Math.floor(value * ppqn()) === 0 + (value) => this.bar() % Math.floor(value * this.ppqn()) === 0 ); return results.some((value) => value === true); }; - // mod = (...pulse: number[]): boolean => { - // /** - // * Returns true if the current pulse is a modulo of any of the given pulses. - // * - // * @param pulse - The pulse to check for - // * @returns True if the current pulse is a modulo of any of the given pulses - // */ - // return pulse.some((p) => this.app.clock.time_position.pulse % p === 0); - // }; - // ============================================================= // Rythmic generators // ============================================================= From c8090b4137b2fd0bb9c76099a9d944efccd3597f Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sat, 19 Aug 2023 23:38:31 +0200 Subject: [PATCH 04/23] weird string replacement experiments --- src/API.ts | 53 ++++++++++++++++++++++++++---------------------- src/Evaluator.ts | 18 ++++++++++++---- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/src/API.ts b/src/API.ts index 1f3a9df..b628bea 100644 --- a/src/API.ts +++ b/src/API.ts @@ -55,7 +55,7 @@ export class UserAPI { */ private variables: { [key: string]: any } = {}; - private iterators: { [key: string]: any } = {}; + private counters: { [key: string]: any } = {}; private _drunk: DrunkWalk = new DrunkWalk(-100, 100, false); MidiConnection: MidiConnection = new MidiConnection(); @@ -298,56 +298,60 @@ export class UserAPI { }; // ============================================================= - // Iterator related functions + // Counter related functions // ============================================================= - public iterator = (name: string, limit?: number, step?: number): number => { + public counter = ( + name: string | number, + limit?: number, + step?: number + ): number => { /** - * Returns the current value of an iterator, and increments it by the step value. + * Returns the current value of a counter, and increments it by the step value. * - * @param name - The name of the iterator - * @param limit - The upper limit of the iterator - * @param step - The step value of the iterator - * @returns The current value of the iterator + * @param name - The name of the counter + * @param limit - The upper limit of the counter + * @param step - The step value of the counter + * @returns The current value of the counter */ - if (!(name in this.iterators)) { - // Create new iterator with default step of 1 - this.iterators[name] = { + if (!(name in this.counters)) { + // Create new counter with default step of 1 + this.counters[name] = { value: 0, step: step ?? 1, limit, }; } else { // Check if limit has changed - if (this.iterators[name].limit !== limit) { + if (this.counters[name].limit !== limit) { // Reset value to 0 and update limit - this.iterators[name].value = 0; - this.iterators[name].limit = limit; + this.counters[name].value = 0; + this.counters[name].limit = limit; } // Check if step has changed - if (this.iterators[name].step !== step) { + if (this.counters[name].step !== step) { // Update step - this.iterators[name].step = step ?? this.iterators[name].step; + this.counters[name].step = step ?? this.counters[name].step; } // Increment existing iterator by step value - this.iterators[name].value += this.iterators[name].step; + this.counters[name].value += this.counters[name].step; // Check for limit overshoot if ( - this.iterators[name].limit !== undefined && - this.iterators[name].value > this.iterators[name].limit + this.counters[name].limit !== undefined && + this.counters[name].value > this.counters[name].limit ) { - this.iterators[name].value = 0; + this.counters[name].value = 0; } } // Return current iterator value - return this.iterators[name].value; + return this.counters[name].value; }; - $ = this.iterator; + $ = this.counter; // ============================================================= // Drunk mechanism @@ -910,7 +914,7 @@ export class UserAPI { // Rythmic generators // ============================================================= - euclid = ( + public euclid = ( iterator: number, pulses: number, length: number, @@ -927,6 +931,7 @@ export class UserAPI { */ return this._euclidean_cycle(pulses, length, rotate)[iterator % length]; }; + ec = this.euclid; _euclidean_cycle( pulses: number, @@ -1119,7 +1124,7 @@ export class UserAPI { sound = (sound: string) => { return new Sound(sound, this.app); }; - + snd = this.sound; samples = samples; log = console.log; diff --git a/src/Evaluator.ts b/src/Evaluator.ts index ff21cf1..e9d832e 100644 --- a/src/Evaluator.ts +++ b/src/Evaluator.ts @@ -6,6 +6,10 @@ const delay = (ms: number) => setTimeout(() => reject(new Error("Operation took too long")), ms) ); +const codeReplace = (code: string): string => { + let new_code = code.replace(/->/g, "&&").replace(/::/g, "&&"); + return new_code; +}; const tryCatchWrapper = ( application: Editor, @@ -13,7 +17,9 @@ const tryCatchWrapper = ( ): Promise => { return new Promise((resolve, _) => { try { - Function(`"use strict";try{${code}} catch (e) {console.log(e)};`).call(application.api); + Function( + `"use strict";try{${codeReplace(code)}} catch (e) {console.log(e)};` + ).call(application.api); resolve(true); } catch (error) { console.log(error); @@ -31,7 +37,7 @@ const addFunctionToCache = (code: string, fn: Function) => { cache.delete(cache.keys().next().value); } cache.set(code, fn); -} +}; export const tryEvaluate = async ( application: Editor, @@ -41,7 +47,7 @@ export const tryEvaluate = async ( try { code.evaluations!++; const candidateCode = code.candidate; - + if (cache.has(candidateCode)) { // If the code is already in cache, use it cache.get(candidateCode)!.call(application.api); @@ -54,7 +60,11 @@ export const tryEvaluate = async ( ]); if (isCodeValid) { code.committed = code.candidate; - const newFunction = new Function(`"use strict";try{${wrappedCode}} catch (e) {console.log(e)};`); + const newFunction = new Function( + `"use strict";try{${codeReplace( + wrappedCode + )}} catch (e) {console.log(e)};` + ); addFunctionToCache(candidateCode, newFunction); } else { await evaluate(application, code, timeout); From a0dfd126abc8ff1bafb8346f54b23bb7e7ebb708 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sun, 20 Aug 2023 00:50:07 +0200 Subject: [PATCH 05/23] adding more documentation --- src/API.ts | 30 +++++++------ src/Documentation.ts | 104 ++++++++++++++++++++++++++++++++++--------- src/main.ts | 4 +- 3 files changed, 103 insertions(+), 35 deletions(-) diff --git a/src/API.ts b/src/API.ts index b628bea..7888485 100644 --- a/src/API.ts +++ b/src/API.ts @@ -76,6 +76,23 @@ export class UserAPI { return this.app.audioContext.currentTime; }; + public play = (): void => { + this.app.setButtonHighlighting("play", true); + this.app.clock.start(); + }; + + public pause = (): void => { + this.app.setButtonHighlighting("pause", true); + this.app.clock.pause(); + }; + + public stop = (): void => { + this.app.setButtonHighlighting("stop", true); + this.app.clock.stop(); + }; + silence = this.stop; + hush = this.stop; + // ============================================================= // Mouse functions // ============================================================= @@ -801,19 +818,6 @@ export class UserAPI { return final_pulses.some((p) => p == true); }; - stop = (): void => { - /** - * Stops the clock. - * - * @see silence - * @see hush - */ - this.app.clock.pause(); - this.app.setButtonHighlighting("pause", true); - }; - silence = this.stop; - hush = this.stop; - prob = (p: number): boolean => { /** * Returns true p% of the time. diff --git a/src/Documentation.ts b/src/Documentation.ts index 11ae01b..25a3d4b 100644 --- a/src/Documentation.ts +++ b/src/Documentation.ts @@ -5,7 +5,7 @@ const key_shortcut = (shortcut: string): string => { const introduction: string = ` # Welcome -Welcome to the Topos documentation. This documentation companion is made to help you understand the software and the ideas behind Topos. You can summon it anytime by pressing ${key_shortcut( +Welcome to the Topos documentation. These pages are made to help you understand the software and the ideas behind Topos. You can jump here anytime by pressing ${key_shortcut( "Ctrl + D" )}. Press again to make the documentation disappear. @@ -14,7 +14,11 @@ Welcome to the Topos documentation. This documentation companion is made to help Topos is an _algorithmic_ sequencer. Topos uses small algorithms to represent musical sequences and processes. These can be written in just a few lines of code. Topos is made to be _live-coded_. The _live coder_ strives for the constant interaction with algorithms and sound during a musical performance. Topos is aiming to be a digital playground for live algorithmic music. -Topos is deeply inspired by the [Monome Teletype](https://monome.org/). The Teletype is an open source hardware module for Eurorack synthesizers. While the Teletype was initially born as an hardware module, Topos is a web-browser based software sequencer from the same family! It is a sequencer, a scriptable interface, a companion for algorithmic music-making. Topos wishes to fullfill the same goal than the Teletype, keeping the same spirit alive on the web. It is free, open-source, and made to be shared and used by everyone. +Topos is deeply inspired by the [Monome Teletype](https://monome.org/). The Teletype is/was an open source hardware module for Eurorack synthesizers. While the Teletype was initially born as an hardware module, Topos aims to be a web-browser based software sequencer from the same family! It is a sequencer, a scriptable interface, a companion for algorithmic music-making. Topos wishes to fullfill the same goal than the Teletype, keeping the same spirit alive on the web. It is free, open-source, and made to be shared and used by everyone. + +## How to read this documentation + +These pages have been conceived to introduce the core concepts first before diving to the more arcane bits. You can read them in order if you just found out about this software! Later on, this documentation will only help you to refresh your memory about some function, etc... ## Example @@ -22,7 +26,7 @@ Press ${key_shortcut( "Ctrl + G" )} to switch to the global file. This is where everything starts! Evaluate the following script there by pasting and pressing ${key_shortcut( "Ctrl + Enter" -)}: +)}. You are now making music:

 if (bar() % 4 > 2 ) {
@@ -43,30 +47,30 @@ if (bar() % 4 > 2 ) {
 const software_interface: string = `
 # Interface
 
-The Topos interface is molded around the core concepts at play: _scripts_ and _universes_. By mastering them, you will be able to compose complex algorithmic musical compositions.
+The Topos interface is molded around the core concepts of the software: _scripts_ and _universes_. By mastering the interface, you will already understand quite a lot about Topos and how to play music with it.
 
 ## Scripts
 
-Topos works by linking together several scripts into what is called a _universe_:
+Every Topos session is composed of several scripts. A set of scripts is called a _universe_. Every script is written using the JavaScript programming language and describes a musical or algorithmic process that takes place over time.
 
 - the global script (${key_shortcut(
   "Ctrl + G"
-)}): Evaluated for every clock pulse.
+)}): **Evaluated for every clock pulse**. The central piece, acting as the conductor for all the other scripts. You can also jam directly from the global script to test your ideas before pushing them to a separate script.
 - the local scripts (${key_shortcut(
   "Ctrl + L"
-)}): Evaluated _on demand_. Local scripts are storing musical parts, logic or whatever you need!
+)}): **Evaluated on demand**. Local scripts are used to store anything too complex to sit in the global script. It can be a musical process, a whole section of your composition, a complex controller that you've built for your hardware, etc...
 - the init script (${key_shortcut(
   "Ctrl + I"
-)}): Evaluated on program load. Used to set up the software (_bpm_, etc...).
+)}): **Evaluated on program load**. Used to set up the software the session to the desired state before playing (_bpm_, etc...).
 - the note file (${key_shortcut(
   "Ctrl + N"
-)}): Not evaluated. Used to store thoughts and ideas about the music you are making.
+)}): **Not evaluated**. Used to store your thoughts or commentaries about the session you are currently playing. It is nothing more than a scratchpad really!
 
 ## Universes
 
 A set of files is called a _universe_. Topos can store several universes and switch immediately from one to another. You can switch between universes by pressing ${key_shortcut(
   "Ctrl + B"
-)}. You can also create a new universe by entering a name that has never been used before. _Universes_ are only known by their names.
+)}. You can also create a new universe by entering a name that has never been used before. _Universes_ are only referenced by their names. Once a universe is loaded, it is not possible to call any data/code from any other universe.
 
 Switching between universes will not stop the transport nor reset the clock. You are switching the context but time keeps flowing. This can be useful to prepare immediate transitions between songs and parts. Think of universes as an algorithmic set of music. All scripts in a given universe are aware about how many times they have been runned already. You can reset that value programatically.
 
@@ -76,33 +80,46 @@ You can clear the current universe by pressing the flame button on the top right
 const time: string = `
 # Time
 
-Time in Topos is handled by a _transport_ system. It allows you to **play**, **pause** and **reset** time. Time is quite simple to understand:
+Time in Topos can be **paused** and/or **resetted**. Musical time is flowing at a given **BPM** (_beats per minute_) like a regular drum machine. There are three core values that you will often interact with in one form or another:
 
 - **bars**: how many bars have elapsed since the origin of time.
 - **beats**: how many beats have elapsed since the beginning of the bar.
 - **pulse**: how many pulses have elapsed since the last beat.
 
-The **pulse** is also known as the [PPQN](https://en.wikipedia.org/wiki/Pulses_per_quarter_note). By default, Topos is using a pulses per quarter note of 48. It means that the lowest possible rhythmic value is 1/48 of a quarter note. That's plenty of time already. Music is sequenced by playing around with these core time values.
+To change the tempo, use the bpm(number) function. You can interact with time using interface buttons, keyboard shortcuts but also by using the play(), pause() and stop() functions. You will soon learn how to manipulate time to your liking for backtracking, jumping forward, etc... The traditional timeline model has little value when you can script everything.
 
-**Note:** you will also learn how to manipulate time to backtrack, jump forward, etc... Your traditional timeline based playback will progressively get more spicy.
+**Note:** the bpm(number) function can serve both for getting and setting the **BPM** value.
 
-## Programming with time
+## Pulses
+
+To make a beat, you need a certain number of time grains or **pulses**. The **pulse** is also known as the [PPQN](https://en.wikipedia.org/wiki/Pulses_per_quarter_note). By default, Topos is using a _pulses per quarter note_ of 48. You can change it by using the ppqn(number) function. It means that the lowest possible rhythmic value is 1/48 of a quarter note. That's plenty of time already.
+
+**Note:** the ppqn(number) function can serve both for getting and setting the **PPQN** value.
+
+
+## Time Primitives
 
 Every script can access the current time by using the following functions:
 
 - bar(n: number): returns the current bar since the origin of time.
 
-- beat(n: number): returns the current beat since the origin of the bar.
+- beat(n: number): returns the current beat since the beginning of the bar.
 
-- ebeat(): returns the current beat since the origin of time.
+- ebeat(): returns the current beat since the origin of time (counting from 1).
 
 - pulse(): returns the current bar since the origin of the beat.
 
-- epulse(): returns the current bar since the origin of time.
+- ppqn(): returns the current **PPQN** (see above).
 
-## Useful basic functions
+- bpm(): returns the current **BPM** (see above).
 
-Some functions are used very often as time primitives. They are used to create more complex rhythms and patterns:
+- time(): returns the current wall clock time, the real time of the system.
+
+These values are **extremely useful** to craft more complex syntax or to write musical scores. However, Topos is also offering more high-level sequencing functions to make it easier to play music.
+
+## Useful Basic Functions
+
+Some functions can be leveraged to play rhythms without thinking too much about the clock. Learn them well:
 
 - beat(...values: number[]): returns true on the given beat. You can add any number of beat values, (_e.g._ onbeat(1.2,1.5,2.3,2.5)). The function will return true only for a given pulse, which makes this function very useful for drumming.
 
@@ -112,7 +129,7 @@ Some functions are used very often as time primitives. They are used to create m
     onbeat(3) && sound('sd').out()
 \`\`\`
 
-- mod(...values: number[]): returns true if the current pulse is a multiple of the given value. You can add any number of values, (_e.g._ mod(.25,.75)).
+- mod(...values: number[]): returns true if the current pulse is a multiple of the given value. You can add any number of values, (_e.g._ mod(.25,.75)). Note that 1 will equal to ppqn() pulses by default. Thus, mod(.5) for a **PPQN** of 48 will be 24 pulses.
 
 \`\`\`javascript
     mod(1) && sound('bd').out()
@@ -138,6 +155,7 @@ You can use the time functions as conditionals. The following example will play
       mod(.5) && sound('jvbass').freq(250).out()
     }
 \`\`\`
+
 `;
 
 const midi: string = `
@@ -318,10 +336,56 @@ The code you enter in any of the scripts is evaluated in strict mode. This tells
 - **about errors and printing:** your code will crash! Don't worry, it will hopefully try to crash in the most gracious way possible. To check if your code is erroring, you will have to open the dev console with ${key_shortcut(
   "Ctrl + Shift + I"
 )}. You cannot directly use console.log('hello, world') in the interface. You will have to open the console as well to see your messages being printed there!
+- **about new syntax:** sometimes, we have taken liberties with the JavaScript syntax in order to make it easier/faster to write on stage. && can also be written :: or -> because it is faster to type or better for the eyes!
+
+## About crashes and bugs
+
+Things will crash, that's also part of the show. You will learn progressively to avoid mistakes and to write safer code. Do not hesitate to kill the page or to stop the transport if you feel overwhelmed by an algorithm blowing up. There are no safeties in place to save you. This is to ensure that you have all the available possible room to write bespoke code and experiment with your ideas through code.
 `;
 
 const functions: string = `
 # Functions
+
+## Global Shared Variables
+
+By default, each script is independant from each other. Scripts live in their own bubble and you cannot get or set variables affecting a script from any other script. **However**, everybody knows that global variables are cool and should be used everywhere. This is an incredibely powerful tool to use for radically altering a composition in a few lines of code.
+
+- variable(a: number | string, b?: any): if only one argument is provided, the value of the variable will be returned through its name, denoted by the first argument. If a second argument is used, it will be saved as a global variable under the name of the first argument.
+	- delete_variable(name: string): deletes a global variable from storage.
+	- clear_variables(): clear **ALL** variables. **This is a destructive operation**!
+
+## 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.
+
+- counter(name: number | string, limit?: number, step?: number): reads the value of the counter name. You can also call this function using the dollar symbol: $.
+	- limit?: counter upper limit before wrapping up.
+	- step?: incrementor. If step is 2, the iterator will go: 0, 2, 4, 6, etc...
+
+- drunk(n?: number): returns the value of the internal drunk walk counter. This iterator will sometimes go up, sometimes go down. It comes with companion functions that you can use to finetune its behavior.
+	- drunk_max(max: number): sets the maximum value.
+	- 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.
+
+
+
+## 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!**
+
+## Mouse
+
+You can get the current position of the mouse on the screen by using the following functions:
+
+- 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).
+
+
 `;
 
 const reference: string = `
diff --git a/src/main.ts b/src/main.ts
index 515c4b8..59c533f 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -28,8 +28,8 @@ import showdown from "showdown";
 showdown.setFlavor("github");
 import showdownHighlight from "showdown-highlight";
 const classMap = {
-  h1: "text-4xl text-white ml-4 mx-4 my-4 mb-8",
-  h2: "text-3xl text-white mx-4 my-4 mt-12 mb-6",
+  h1: "text-white text-4xl ml-4 mx-4 my-4 mb-8 bg-neutral-900 rounded-lg py-2 px-2",
+  h2: "text-white text-3xl mx-4 my-4 mt-12 mb-6 bg-neutral-900 rounded-lg py-2 px-2",
   ul: "text-underline",
   li: "ml-12 list-disc text-2xl text-white mx-4 my-4 leading-normal",
   p: "text-2xl text-white mx-4 my-4 leading-normal",

From b9cf517a7fe344f7a7ff861b775fb41e53044852 Mon Sep 17 00:00:00 2001
From: Raphael Forment 
Date: Sun, 20 Aug 2023 12:49:10 +0200
Subject: [PATCH 06/23] cosmetic changes

---
 index.html | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/index.html b/index.html
index 470591e..b01c0b5 100644
--- a/index.html
+++ b/index.html
@@ -41,28 +41,28 @@
           Topos
 
         
-