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

View File

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

View File

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

View File

@ -263,7 +263,7 @@ export const initializeSelectedUniverse = (app: Editor): void => {
app.universes[app.selected_universe] = structuredClone(template_universe); 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 = () => { export const emptyUrl = () => {
@ -334,7 +334,7 @@ export const loadUniverse = (
// Updating references to the currently selected universe // Updating references to the currently selected universe
app.settings.selected_universe = selectedUniverse; app.settings.selected_universe = selectedUniverse;
app.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 // Updating the editor View to reflect the selected universe
app.updateEditorView(); app.updateEditorView();
// Evaluating the initialisation script for the selected universe // Evaluating the initialisation script for the selected universe

View File

@ -64,7 +64,7 @@ export class MidiConnection {
constructor(api: UserAPI, settings: AppSettings) { constructor(api: UserAPI, settings: AppSettings) {
this.api = api; this.api = api;
this.settings = settings; this.settings = settings;
this.lastBPM = api.bpm(); this.lastBPM = api.tempo();
this.roundedBPM = this.lastBPM; this.roundedBPM = this.lastBPM;
this.initializeMidiAccess(); this.initializeMidiAccess();
} }
@ -519,7 +519,7 @@ export class MidiConnection {
const estimatedBPM = this.estimatedBPM(); const estimatedBPM = this.estimatedBPM();
if (estimatedBPM !== this.roundedBPM) { if (estimatedBPM !== this.roundedBPM) {
console.log("Estimated BPM: ", estimatedBPM); console.log("Estimated BPM: ", estimatedBPM);
this.api.bpm(estimatedBPM); this.api.tempo(estimatedBPM);
this.roundedBPM = 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") { if (event.key === "Enter") {
let content = app.interface.universe_viewer.value.trim(); let content = (app.interface.universe_viewer as HTMLInputElement).value.trim();
console.log("boum")
if (content.length > 2 && content.length < 40) { if (content.length > 2 && content.length < 40) {
if (content !== app.selected_universe) { if (content !== app.selected_universe) {
Object.defineProperty(app.universes, content, Object.defineProperty(app.universes, content,
// @ts-ignore
Object.getOwnPropertyDescriptor(app.universes, app.selected_universe)); Object.getOwnPropertyDescriptor(app.universes, app.selected_universe));
delete app.universes[app.selected_universe]; delete app.universes[app.selected_universe];
} }
app.selected_universe = content; app.selected_universe = content;
loadUniverse(app, app.selected_universe); loadUniverse(app, app.selected_universe);
app.interface.universe_viewer.placeholder = content; (app.interface.universe_viewer as HTMLInputElement).placeholder = content;
app.interface.universe_viewer.value = ''; (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>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>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>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. 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() + [-12,12].beat()).out()
`, true)} `, 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>.", "Base function to play audio (samples / synths). Alias for <code>sound<code>.",
example: "sound('bd').out()", 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: { tempo: {
name: "tempo", name: "tempo",
category: "time", category: "time",
description: "Get or set the current beats per minute.", description: "Get or set the current beats per minute.",
example: "tempo(135) // set the bpm to 135", example: "tempo(135) // set the bpm to 135",
}, },
out: { out: {
name: "out", name: "out",
category: "audio", category: "audio",

View File

@ -140,7 +140,7 @@ flipbar(2)
${makeExample( ${makeExample(
"Using onbar for filler drums", "Using onbar for filler drums",
` `
bpm(150); tempo(150);
// Only play on the third and fourth bar of the cycle. // Only play on the third and fourth bar of the cycle.
onbar([3,4], 4)::beat(.25)::snd('hh').out(); onbar([3,4], 4)::beat(.25)::snd('hh').out();
// Using JavaScript regular control flow // 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( ${makeExample(
"Listing MIDI outputs", "Listing MIDI outputs",
` `
midi_outputs() midi_outputs()
`, `,
true true
)} )}
- <ic>midi_output(output_name: string)</ic>: enter your desired output to connect to it. - <ic>midi_output(output_name: string)</ic>: enter your desired output to connect to it.
${makeExample( ${makeExample(
"Changing MIDI output", "Changing MIDI output",
` `
midi_output("MIDI Rocket-Trumpet") midi_output("MIDI Rocket-Trumpet")
`, `,
true true
)} )}
That's it! You are now ready to play with MIDI. 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. - <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( ${makeExample(
"MIDI note using one parameter: note", "MIDI note using one parameter: note",
` `
// Configure your MIDI first! // Configure your MIDI first!
// => midi_output("MIDI Bus 1") // => midi_output("MIDI Bus 1")
rhythm(.5, 5, 8) :: midi(50).out() rhythm(.5, 5, 8) :: midi(50).out()
`, `,
true true
)} )}
${makeExample( ${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 // MIDI Note 50, Velocity 50 + LFO, Channel 0
rhythm(.5, 5, 8) :: midi(50, 50 + usine(.5) * 20, 0).out() rhythm(.5, 5, 8) :: midi(50, 50 + usine(.5) * 20, 0).out()
`, `,
false false
)} )}
${makeExample( ${makeExample(
"MIDI note by passing an object", "MIDI note by passing an object",
` `
// MIDI Note 50, Velocity 50 + LFO, Channel 0 // MIDI Note 50, Velocity 50 + LFO, Channel 0
rhythm(.5, 5, 8) :: midi({note: 50, velocity: 50 + usine(.5) * 20, channel: 0}).out() 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: We can now have some fun and starting playing a small piano piece:
${makeExample( ${makeExample(
"Playing some piano", "Playing some piano",
` `
bpm(80) // Setting a default BPM tempo(80) // Setting a default BPM
beat(.5) && midi(36 + [0,12].beat()).sustain(0.02).out() beat(.5) && midi(36 + [0,12].beat()).sustain(0.02).out()
beat(.25) && midi([64, 76].pick()).sustain(0.05).out() beat(.25) && midi([64, 76].pick()).sustain(0.05).out()
beat(.75) && midi([64, 67, 69].beat()).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() beat(.25) && midi([64, 67, 69].beat() + 24).sustain(0.05).out()
`, `,
true true
)} )}
## Control and Program Changes ## 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>). - <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( ${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: [24,25].pick(), value: irand(1,120), channel: 1})
control_change({control: [30,35].pick(), value: irand(1,120) / 2, 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>). - <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( ${makeExample(
"Crashing old synthesizers: a hobby", "Crashing old synthesizers: a hobby",
` `
program_change([1,2,3,4,5,6,7,8].pick(), 1) program_change([1,2,3,4,5,6,7,8].pick(), 1)
`, `,
true true
)} )}
## System Exclusive Messages ## System Exclusive Messages
@ -119,44 +119,44 @@ program_change([1,2,3,4,5,6,7,8].pick(), 1)
${makeExample( ${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) sysex(0x90, 0x40, 0x7f)
`, `,
true true
)} )}
## Clock ## Clock
- <ic>midi_clock()</ic>: send a MIDI Clock message. This function is used to synchronize Topos with other MIDI devices or DAWs. - <ic>midi_clock()</ic>: send a MIDI Clock message. This function is used to synchronize Topos with other MIDI devices or DAWs.
${makeExample( ${makeExample(
"Tic, tac, tic, tac...", "Tic, tac, tic, tac...",
` `
beat(.25) && midi_clock() // Sending clock to MIDI device from the global buffer beat(.25) && midi_clock() // Sending clock to MIDI device from the global buffer
`, `,
true true
)} )}
## Using midi with ziffers ## Using midi with ziffers
Ziffers offers some shorthands for defining channels within the patterns. See Ziffers for more information. Ziffers offers some shorthands for defining channels within the patterns. See Ziffers for more information.
${makeExample( ${makeExample(
"Using midi with ziffers", "Using midi with ziffers",
` `
z1('0 2 e 5 2 q 4 2').midi().port(2).channel(4).out() z1('0 2 e 5 2 q 4 2').midi().port(2).channel(4).out()
`, `,
true true
)} )}
${makeExample( ${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() 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)) beat(0.5)::sound('notes').n([1,2].dur(1, 2))
.room(0.5).size(8).delay(0.125).delayt(1/8) .room(0.5).size(8).delay(0.125).delayt(1/8)
.speed(0.5).ad(0, .125).out() .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)) beat(1)::sound(['kick', 'fsnare'].dur(3, 1))
.n([0,3].dur(3, 1)).out() .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( ${makeExample(
"Different vibrato settings", "Different vibrato settings",
` `
bpm(140); tempo(140);
beat(1) :: sound('triangle') beat(1) :: sound('triangle')
.freq(400).release(0.2) .freq(400).release(0.2)
.vib([1/2, 1, 2, 4].beat()) .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( ${makeExample(
"Different vibrato settings", "Different vibrato settings",
` `
bpm(140); tempo(140);
beat(1) :: sound('triangle') beat(1) :: sound('triangle')
.freq(400).release(0.2) .freq(400).release(0.2)
.noise([0.2,0.4,0.5].bar()) .noise([0.2,0.4,0.5].bar())
@ -609,7 +609,7 @@ ${makeExample(
${makeExample( ${makeExample(
"Live coded poetry with array and string chaining", "Live coded poetry with array and string chaining",
` `
bpm(70) tempo(70)
const croissant = [ const croissant = [
"Volant", "Arc-en-ciel", "Chocolat", "Dansant", "Volant", "Arc-en-ciel", "Chocolat", "Dansant",