fix typing and build errors

This commit is contained in:
2023-11-18 21:18:25 +01:00
parent a21fcd47f2
commit ddc17d28a9
14 changed files with 82 additions and 94 deletions

View File

@ -2094,7 +2094,7 @@ export class UserAPI {
return this.app.clock.nudge;
};
public bpm = (n?: number): number => {
public tempo = (n?: number): number => {
/**
* Sets or returns the current bpm.
*
@ -2107,7 +2107,7 @@ export class UserAPI {
this.app.clock.bpm = n;
return n;
};
tempo = this.bpm;
// tempo = this.bpm;
public bpb = (n?: number): number => {
/**

View File

@ -17,7 +17,6 @@ import { oscilloscope } from "./documentation/more/oscilloscope";
import { synchronisation } from "./documentation/more/synchronisation";
import { about } from "./documentation/more/about";
import { bonus } from "./documentation/more/bonus";
import { samples } from "./documentation/samples";
import { chaining } from "./documentation/chaining";
import { interaction } from "./documentation/interaction";
import { time } from "./documentation/time/time";
@ -32,7 +31,6 @@ import { variables } from "./documentation/variables";
import { probabilities } from "./documentation/probabilities";
import { lfos } from "./documentation/lfos";
import { ziffers } from "./documentation/ziffers";
import { reference } from "./documentation/reference";
import { synths } from "./documentation/synths";
// Setting up the Markdown converter with syntax highlighting
@ -85,7 +83,6 @@ export const documentation_factory = (application: Editor) => {
cyclic: cyclical_time(application),
longform: long_forms(application),
sound: sound(application),
samples: samples(application),
synths: synths(application),
chaining: chaining(application),
patterns: patterns(application),
@ -95,7 +92,6 @@ export const documentation_factory = (application: Editor) => {
variables: variables(application),
probabilities: probabilities(application),
functions: functions(application),
reference: reference(),
shortcuts: shortcuts(application),
amplitude: amplitude(application),
reverb_delay: reverb(application),

View File

@ -9,7 +9,9 @@ export type ElementMap = {
| HTMLInputElement
| HTMLSelectElement
| HTMLCanvasElement
| HTMLFormElement;
| HTMLFormElement
| HTMLInputElement
;
};
export const singleElements = {

View File

@ -263,7 +263,7 @@ export const initializeSelectedUniverse = (app: Editor): void => {
app.universes[app.selected_universe] = structuredClone(template_universe);
}
}
app.interface.universe_viewer.placeholder! = `${app.selected_universe}`;
(app.interface.universe_viewer as HTMLInputElement).placeholder! = `${app.selected_universe}`;
};
export const emptyUrl = () => {
@ -334,7 +334,7 @@ export const loadUniverse = (
// Updating references to the currently selected universe
app.settings.selected_universe = selectedUniverse;
app.selected_universe = selectedUniverse;
app.interface.universe_viewer.placeholder! = `${selectedUniverse}`;
(app.interface.universe_viewer as HTMLInputElement).placeholder! = `${selectedUniverse}`;
// Updating the editor View to reflect the selected universe
app.updateEditorView();
// Evaluating the initialisation script for the selected universe

View File

@ -64,7 +64,7 @@ export class MidiConnection {
constructor(api: UserAPI, settings: AppSettings) {
this.api = api;
this.settings = settings;
this.lastBPM = api.bpm();
this.lastBPM = api.tempo();
this.roundedBPM = this.lastBPM;
this.initializeMidiAccess();
}
@ -519,7 +519,7 @@ export class MidiConnection {
const estimatedBPM = this.estimatedBPM();
if (estimatedBPM !== this.roundedBPM) {
console.log("Estimated BPM: ", estimatedBPM);
this.api.bpm(estimatedBPM);
this.api.tempo(estimatedBPM);
this.roundedBPM = estimatedBPM;
}
}

View File

@ -116,22 +116,20 @@ export const installInterfaceLogic = (app: Editor) => {
}
});
app.interface.universe_viewer.addEventListener("keydown", (event: KeyboardEvent) => {
app.interface.universe_viewer.addEventListener("keydown", (event: any) => {
if (event.key === "Enter") {
let content = app.interface.universe_viewer.value.trim();
console.log("boum")
let content = (app.interface.universe_viewer as HTMLInputElement).value.trim();
if (content.length > 2 && content.length < 40) {
if (content !== app.selected_universe) {
Object.defineProperty(app.universes, content,
// @ts-ignore
Object.getOwnPropertyDescriptor(app.universes, app.selected_universe));
delete app.universes[app.selected_universe];
}
app.selected_universe = content;
loadUniverse(app, app.selected_universe);
app.interface.universe_viewer.placeholder = content;
app.interface.universe_viewer.value = '';
(app.interface.universe_viewer as HTMLInputElement).placeholder = content;
(app.interface.universe_viewer as HTMLInputElement).value = '';
}
}
});

View File

@ -22,6 +22,8 @@ The sampler is a rather complex beast. There is a lot you can do by manipulating
| <ic>cut</ic> | | Set with <ic>0</ic> or <ic>1</ic>. Will cut the sample as soon as another sample is played on the same bus |
| <ic>clip</ic> | | Multiply the duration of the sample with the given number |
| <ic>pan</ic> | | Stereo position of the audio playback (<ic>0</ic> = left, <ic>1</ic> = right)|
| <ic>vib</ic> | | vibrato speed (in hertz)|
| <ic>vibmod</ic> | | vibrato depth (from <ic>0</ic> to <ic>n</ic>)|
Let's apply some of these methods naïvely. We will then break everything using simpler examples.
@ -127,4 +129,16 @@ beat(0.125)::sound('notes')
+ [-12,12].beat()).out()
`, true)}
## Adding vibrato to samples
You can add vibrato to any sample using <ic>vib</ic> and <ic>vibmod</ic>:
${makeExample("Adding vibrato to a sample", `
beat(1)::sound('fhang').vib([1, 2, 4].bar()).vibmod([0.5, 2].beat()).out()
`, true)}
`}

View File

@ -555,19 +555,12 @@ const completionDatabase: CompletionDatabase = {
"Base function to play audio (samples / synths). Alias for <code>sound<code>.",
example: "sound('bd').out()",
},
bpm: {
name: "bpm",
category: "time",
description: "Get or set the current beats per minute.",
example: "bpm(135) // set the bpm to 135",
},
tempo: {
name: "tempo",
category: "time",
description: "Get or set the current beats per minute.",
example: "tempo(135) // set the bpm to 135",
},
out: {
name: "out",
category: "audio",

View File

@ -140,7 +140,7 @@ flipbar(2)
${makeExample(
"Using onbar for filler drums",
`
bpm(150);
tempo(150);
// Only play on the third and fourth bar of the cycle.
onbar([3,4], 4)::beat(.25)::snd('hh').out();
// Using JavaScript regular control flow

View File

@ -22,22 +22,22 @@ Your web browser is capable of sending and receiving MIDI information through th
${makeExample(
"Listing MIDI outputs",
`
"Listing MIDI outputs",
`
midi_outputs()
`,
true
)}
true
)}
- <ic>midi_output(output_name: string)</ic>: enter your desired output to connect to it.
${makeExample(
"Changing MIDI output",
`
"Changing MIDI output",
`
midi_output("MIDI Rocket-Trumpet")
`,
true
)}
true
)}
That's it! You are now ready to play with MIDI.
@ -48,69 +48,69 @@ The most basic MIDI event is the note. MIDI notes traditionally take three param
- <ic>midi(note: number|object)</ic>: send a MIDI Note. This function is quite bizarre. It can be written and used in many different ways. You can pass form one up to three arguments in different forms.
${makeExample(
"MIDI note using one parameter: note",
`
"MIDI note using one parameter: note",
`
// Configure your MIDI first!
// => midi_output("MIDI Bus 1")
rhythm(.5, 5, 8) :: midi(50).out()
`,
true
)}
true
)}
${makeExample(
"MIDI note using three parameters: note, velocity, channel",
`
"MIDI note using three parameters: note, velocity, channel",
`
// MIDI Note 50, Velocity 50 + LFO, Channel 0
rhythm(.5, 5, 8) :: midi(50, 50 + usine(.5) * 20, 0).out()
`,
false
)}
false
)}
${makeExample(
"MIDI note by passing an object",
`
"MIDI note by passing an object",
`
// MIDI Note 50, Velocity 50 + LFO, Channel 0
rhythm(.5, 5, 8) :: midi({note: 50, velocity: 50 + usine(.5) * 20, channel: 0}).out()
`,
false
)}
false
)}
We can now have some fun and starting playing a small piano piece:
${makeExample(
"Playing some piano",
`
bpm(80) // Setting a default BPM
"Playing some piano",
`
tempo(80) // Setting a default BPM
beat(.5) && midi(36 + [0,12].beat()).sustain(0.02).out()
beat(.25) && midi([64, 76].pick()).sustain(0.05).out()
beat(.75) && midi([64, 67, 69].beat()).sustain(0.05).out()
beat(.25) && midi([64, 67, 69].beat() + 24).sustain(0.05).out()
`,
true
)}
true
)}
## Control and Program Changes
- <ic>control_change({control: number, value: number, channel: number})</ic>: send a MIDI Control Change. This function takes a single object argument to specify the control message (_e.g._ <ic>control_change({control: 1, value: 127, channel: 1})</ic>).
${makeExample(
"Imagine that I am tweaking an hardware synthesizer!",
`
"Imagine that I am tweaking an hardware synthesizer!",
`
control_change({control: [24,25].pick(), value: irand(1,120), channel: 1})
control_change({control: [30,35].pick(), value: irand(1,120) / 2, channel: 1})
`,
true
)}
true
)}
- <ic>program_change(program: number, channel: number)</ic>: send a MIDI Program Change. This function takes two arguments to specify the program and the channel (_e.g._ <ic>program_change(1, 1)</ic>).
${makeExample(
"Crashing old synthesizers: a hobby",
`
"Crashing old synthesizers: a hobby",
`
program_change([1,2,3,4,5,6,7,8].pick(), 1)
`,
true
)}
true
)}
## System Exclusive Messages
@ -119,44 +119,44 @@ program_change([1,2,3,4,5,6,7,8].pick(), 1)
${makeExample(
"Nobody can say that we don't support Sysex messages!",
`
"Nobody can say that we don't support Sysex messages!",
`
sysex(0x90, 0x40, 0x7f)
`,
true
)}
true
)}
## Clock
- <ic>midi_clock()</ic>: send a MIDI Clock message. This function is used to synchronize Topos with other MIDI devices or DAWs.
${makeExample(
"Tic, tac, tic, tac...",
`
"Tic, tac, tic, tac...",
`
beat(.25) && midi_clock() // Sending clock to MIDI device from the global buffer
`,
true
)}
true
)}
## Using midi with ziffers
Ziffers offers some shorthands for defining channels within the patterns. See Ziffers for more information.
${makeExample(
"Using midi with ziffers",
`
"Using midi with ziffers",
`
z1('0 2 e 5 2 q 4 2').midi().port(2).channel(4).out()
`,
true
)}
true
)}
${makeExample(
"Setting the channel within the pattern",
`
"Setting the channel within the pattern",
`
z1('(0 2 e 5 2):0 (4 2):1').midi().out()
`,
true
)}
true
)}
`;
};

View File

@ -113,7 +113,7 @@ ${makeExample(
beat(0.5)::sound('notes').n([1,2].dur(1, 2))
.room(0.5).size(8).delay(0.125).delayt(1/8)
.speed(0.5).ad(0, .125).out()
// Kick (3 beats), Snare (1 beat)
// Kick (3 beats), Snare (1bpm beat)
beat(1)::sound(['kick', 'fsnare'].dur(3, 1))
.n([0,3].dur(3, 1)).out()
`,

View File

@ -1,3 +0,0 @@
export const reference = (): string => {
return ``;
};

View File

@ -1,12 +0,0 @@
import { type Editor } from "../main";
import { makeExampleFactory } from "../Documentation";
export const samples = (application: Editor): string => {
const makeExample = makeExampleFactory(application);
return `
# Audio Samples
Audio samples are dynamically loaded from the web. By default, Topos is providing some samples coming from the classic [Dirt-Samples](https://github.com/tidalcycles/Dirt-Samples) but also from the [Topos-Samples](https://github.com/Bubobubobubobubo/Topos-Samples) repository. You can contribute to the latter if you want to share your samples with the community! For each sample folder, we are indicating how many of them are available in parentheses. The samples starting with <ic>ST</ic> are coming from [a wonderful collection](https://archive.org/details/AmigaSoundtrackerSamplePacksst-xx) of Ultimate Tracker Amiga audio samples released by Karsten Obarski. They are very high-pitched as was usual in the tracker era. Pitch them down using <ic>.speed(0.5)</ic>.
`;
};

View File

@ -78,7 +78,7 @@ You can also add some amount of vibrato to the sound using the <ic>vib</ic> and
${makeExample(
"Different vibrato settings",
`
bpm(140);
tempo(140);
beat(1) :: sound('triangle')
.freq(400).release(0.2)
.vib([1/2, 1, 2, 4].beat())
@ -94,7 +94,7 @@ A certain amount of brown noise can be added by using the <ic>.noise</ic> key:
${makeExample(
"Different vibrato settings",
`
bpm(140);
tempo(140);
beat(1) :: sound('triangle')
.freq(400).release(0.2)
.noise([0.2,0.4,0.5].bar())
@ -609,7 +609,7 @@ ${makeExample(
${makeExample(
"Live coded poetry with array and string chaining",
`
bpm(70)
tempo(70)
const croissant = [
"Volant", "Arc-en-ciel", "Chocolat", "Dansant",