This commit is contained in:
2023-08-21 19:45:06 +03:00
9 changed files with 595 additions and 417 deletions

View File

@ -1,11 +1,15 @@
const key_shortcut = (shortcut: string): string => {
return `<kbd class="px-2 py-1.5 text-sm font-semibold text-gray-800 bg-gray-100 border border-gray-200 rounded-lg dark:bg-gray-600 dark:text-gray-100 dark:border-gray-500">${shortcut}</kbd>`;
return `<kbd class="lg:px-2 lg:py-1.5 px-1 py-1 lg:text-sm text-xs font-semibold text-gray-800 bg-gray-100 border border-gray-200 rounded-lg dark:bg-gray-600 dark:text-gray-100 dark:border-gray-500">${shortcut}</kbd>`;
};
const injectAvailableSamples = (): string => {
return "";
};
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 +18,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,51 +30,53 @@ 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:
<pre><code class="language-javascript">
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')
.delay(0.75).delaytime(0.75)
.speed(seqbeat(1,2,3,4)).out()
mod(48) && 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()
}
bpm(80)
mod(0.25) :: sound('sawtooth')
.note(seqbar(
pick(60, 67, 63) - 12, pick(60, 67, 63) - 12,
pick(60, 67, 63) - 12 + 5, pick(60, 67, 63) - 12 + 5,
pick(60, 67, 63) - 12 + 7, pick(60, 67, 63) - 12 + 7) + (sometimes() ? 24 : 12))
.dur(0.1).fmi(8).fmh(4).room(0.9)
.gain(0.75).cutoff(500 + usine(8) * 10000)
.delay(0.5).delaytime(bpm() / 60 / 4 / 3)
.delayfeedback(0.25)
.out()
mod(1) && snd('kick').out()
mod(2) && snd('snare').out()
mod(.5) && snd('hat').out()
</code></pre>
`;
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 +86,45 @@ 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 <icode>bpm(number)</icode> function. You can interact with time using interface buttons, keyboard shortcuts but also by using the <icode>play()</icode>, <icode>pause()</icode> and <icode>stop()</icode> 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 <icode>bpm(number)</icode> 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 <icode>ppqn(number)</icode> function. It means that the lowest possible rhythmic value is 1/48 of a quarter note. That's plenty of time already.
**Note:** the <icode>ppqn(number)</icode> 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:
- <icode>bar(n: number)</icode>: returns the current bar since the origin of time.
- <icode>beat(n: number)</icode>: returns the current beat since the origin of the bar.
- <icode>beat(n: number)</icode>: returns the current beat since the beginning of the bar.
- <icode>ebeat()</icode>: returns the current beat since the origin of time.
- <icode>ebeat()</icode>: returns the current beat since the origin of time (counting from 1).
- <icode>pulse()</icode>: returns the current bar since the origin of the beat.
- <icode>epulse()</icode>: returns the current bar since the origin of time.
- <icode>ppqn()</icode>: returns the current **PPQN** (see above).
## Useful basic functions
- <icode>bpm()</icode>: 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:
- <icode>time()</icode>: 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:
- <icode>beat(...values: number[])</icode>: returns <icode>true</icode> on the given beat. You can add any number of beat values, (_e.g._ <icode>onbeat(1.2,1.5,2.3,2.5)</icode>). The function will return <icode>true</icode> only for a given pulse, which makes this function very useful for drumming.
@ -112,32 +134,52 @@ Some functions are used very often as time primitives. They are used to create m
onbeat(3) && sound('sd').out()
\`\`\`
- <icode>mod(...values: number[])</icode>: returns <icode>true</icode> if the current pulse is a multiple of the given value. You can add any number of values, (_e.g._ <icode>mod(12,36)</icode>).
- <icode>mod(...values: number[])</icode>: returns <icode>true</icode> if the current pulse is a multiple of the given value. You can add any number of values, (_e.g._ <icode>mod(.25,.75)</icode>). Note that <icode>1</icode> will equal to <icode>ppqn()</icode> pulses by default. Thus, <icode>mod(.5)</icode> for a **PPQN** of 48 will be <icode>24</icode> pulses.
\`\`\`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()
\`\`\`
- <icode>onbar(...values: number[])</icode>: returns <icode>true</icode> if the bar is currently equal to any of the specified values.
- <icode>modbar(...values: number[])</icode>: returns <icode>true</icode> if the bar is currently a multiple of any of the specified values.
## Rhythm generators
We included a bunch of popular rhythm generators in Topos such as the euclidian rhythms algorithms or the one to generate rhythms based on a binary sequence. They all work using _iterators_ that you will gradually learn to use for iterating over lists.
- <icode>euclid(iterator: number, pulses: number, length: number, rotate: number): boolean</icode>: generates <icode>true</icode> or <icode>false</icode> values from an euclidian rhythm sequence. This algorithm is very popular in the electronic music making world.
\`\`\`javascript
mod(.5) && euclid($(1), 5, 8) && snd('kick').out()
mod(.5) && euclid($(2), 2, 8) && snd('sd').out()
\`\`\`
- <icode>bin(iterator: number, n: number): boolean</icode>: a binary rhythm generator. It transforms the given number into its binary representation (_e.g_ <icode>34</icode> becomes <icode>100010</icode>). It then returns a boolean value based on the iterator in order to generate a rhythm.
\`\`\`javascript
mod(.5) && euclid($(1), 34) && snd('kick').out()
mod(.5) && euclid($(2), 48) && snd('sd').out()
\`\`\`
## Using time as a conditional
You can use the time functions as conditionals. The following example will play a pattern A for 2 bars and a pattern B for 2 bars:
\`\`\`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()
}
\`\`\`
`;
const midi: string = `
@ -152,10 +194,23 @@ 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).out()
mod(.25) && note(pick(64, 76)).duration(0.05).out()
mod(.75) && note(seqbeat(64, 67, 69)).duration(0.05).out()
sometimes() && mod(.25) && note(seqbeat(64, 67, 69) + 24).duration(0.05).out()
\`\`\`
### Note chaining
The <icode>note(number)</icode> function can be chained to _specify_ a midi note more. For instance, you can add a duration, a velocity, a channel, etc...:
\`\`\`javascript
mod(0.25) && note(60)
.sometimes(n=>n.note(irand(40,60)))
.duration(0.05)
.channel(2)
.port("bespoke")
.out()
\`\`\`
## Control and Program Changes
@ -184,7 +239,7 @@ You can use Topos to play MIDI thanks to the [WebMIDI API](https://developer.moz
- <icode>midi_clock()</icode>: 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 +265,8 @@ I recommended you to run the following scripts in the global script (${key_short
The basic function to play a sound is <icode>sound('sample/synth').out()</icode>. 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 +281,7 @@ If you remove the **mod** instruction, you will end up with a deluge of kick dru
The <icode>.n(number)</icode> 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,8 +290,8 @@ Don't worry about the number. If it gets too big, it will be automatically wrapp
The <icode>sound('sample_name')</icode> 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')
.speed(pick(1,2,3))
mod(0.5) && sound('hh')
.sometimes(s=>s.speed(pick(1,5,10)))
.room(0.5)
.cutoff(usine(2) * 5000)
.out()
@ -279,6 +334,15 @@ No sound will play until you add <icode>.out()</icode> at the end of the chain.
| <icode>out()</icode> | Returns an object processed by the <icode>superdough</icode> function, using the current values in the <icode>values</icode> object and the <icode>pulse_duration</icode> from the <icode>app.clock</icode>. |
`;
const samples: string = `
# Audio Samples
## Available audio samples
${injectAvailableSamples()}
`;
const about: string = `
# About Topos
@ -318,10 +382,113 @@ 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 <icode>console.log('hello, world')</icode> 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. <icode>&&</icode> can also be written <icode>::</icode> or <icode>-></icode> 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.
- <icode>variable(a: number | string, b?: any)</icode>: 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.
- <icode>delete_variable(name: string)</icode>: deletes a global variable from storage.
- <icode>clear_variables()</icode>: 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 <icode>i</icode> 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.
- <icode>counter(name: number | string, limit?: number, step?: number)</icode>: reads the value of the counter <icode>name</icode>. You can also call this function using the dollar symbol: <icode>$</icode>.
- <icode>limit?</icode>: counter upper limit before wrapping up.
- <icode>step?</icode>: incrementor. If step is <icode>2</icode>, the iterator will go: <icode>0, 2, 4, 6</icode>, etc...
- <icode>drunk(n?: number)</icode>: 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.
- <icode>drunk_max(max: number)</icode>: sets the maximum value.
- <icode>drunk_min(min: number)</icode>: sets the minimum value.
- <icode>drunk_wrap(wrap: boolean)</icode>: 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!
- <icode>script(...number: number[])</icode>: call one or more scripts (_e.g. <icode>script(1,2,3,4)</icode>). Once called, scripts will be evaluated once. There are nine local scripts by default. You cannot call the global script nor the initialisation script.
- <icode>clear_script(number)</icode>: deletes the given script.
- <icode>copy_script(from: number, to: number)</icode>: 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:
- <icode>mouseX()</icode>: the horizontal position of the mouse on the screen (as a floating point number).
- <icode>mouseY()</icode>: the vertical position of the mouse on the screen (as a floating point number).
## 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.
- <icode>sine(freq: number = 1, offset: number= 0): number</icode>: returns a sinusoïdal oscillation between <icode>-1</icode> and <icode>1</icode>.
- <icode>usine(freq: number = 1, offset: number= 0): number</icode>: returns a sinusoïdal oscillation between <icode>0</icode> and <icode>1</icode>. The <icode>u</icode> stands for _unipolar_.
\`\`\`javascript
mod(.25) && snd('cp').speed(1 + usine(0.25) * 2).out()
\`\`\`
- <icode>triangle(freq: number = 1, offset: number= 0): number</icode>: returns a triangle oscillation between <icode>-1</icode> and <icode>1</icode>.
- <icode>utriangle(freq: number = 1, offset: number= 0): number</icode>: returns a triangle oscillation between <icode>0</icode> and <icode>1</icode>. The <icode>u</icode> stands for _unipolar_.
\`\`\`javascript
mod(.25) && snd('cp').speed(1 + utriangle(0.25) * 2).out()
\`\`\`
- <icode>saw(freq: number = 1, offset: number= 0): number</icode>: returns a sawtooth-like oscillation between <icode>-1</icode> and <icode>1</icode>.
- <icode>usaw(freq: number = 1, offset: number= 0): number</icode>: returns a sawtooth-like oscillation between <icode>0</icode> and <icode>1</icode>. The <icode>u</icode> stands for _unipolar_.
\`\`\`javascript
mod(.25) && snd('cp').speed(1 + usaw(0.25) * 2).out()
\`\`\`
- <icode>square(freq: number = 1, offset: number= 0, duty: number = .5): number</icode>: returns a square wave oscillation between <icode>-1</icode> and <icode>1</icode>. You can also control the duty cycle using the <icode>duty</icode> parameter.
- <icode>usquare(freq: number = 1, offset: number= 0, duty: number = .5): number</icode>: returns a square wave oscillation between <icode>0</icode> and <icode>1</icode>. The <icode>u</icode> stands for _unipolar_. You can also control the duty cycle using the <icode>duty</icode> parameter.
\`\`\`javascript
mod(.25) && snd('cp').speed(1 + usquare(0.25, 0, 0.25) * 2).out()
\`\`\`
- <icode>noise()</icode>: returns a random value between -1 and 1.
\`\`\`javascript
mod(.25) && snd('cp').speed(1 + noise() * 2).out()
\`\`\`
## Probabilities
There are some simple functions to play with probabilities.
- <icode>prob(p: number)</icode>: return <icode>true</icode> _p_% of time, <icode>false</icode> in other cases.
- <icode>toss()</icode>: throwing a coin. Head (<icode>true</icode>) or tails (<icode>false</icode>).
## Math functions
- <icode>max(...values: number[]): number</icode>: returns the maximum value of a list of numbers.
- <icode>min(...values: number[]): number</icode>: returns the minimum value of a list of numbers.
- <icode>mean(...values: number[]): number</icode>: returns the arithmetic mean of a list of numbers.
- <icode>limit(value: number, min: number, max: number): number</icode>: Limits a value between a minimum and a maximum.
## Delay functions
- <icode>delay(ms: number, func: Function): void</icode>: Delays the execution of a function by a given number of milliseconds.
- <icode>delayr(ms: number, nb: number, func: Function): void</icode>: Delays the execution of a function by a given number of milliseconds, repeated a given number of times.
`;
const reference: string = `
@ -371,6 +538,7 @@ export const documentation = {
code: code,
time: time,
sound: sound,
samples: samples,
midi: midi,
functions: functions,
reference: reference,