From ddc17d28a9749d74efec7cc01f43443d4b098508 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sat, 18 Nov 2023 21:18:25 +0100 Subject: [PATCH] fix typing and build errors --- src/API.ts | 4 +- src/Documentation.ts | 4 - src/DomElements.ts | 4 +- src/FileManagement.ts | 4 +- src/IO/MidiConnection.ts | 4 +- src/InterfaceLogic.ts | 12 ++- src/documentation/audio_engine/sampler.ts | 14 ++++ src/documentation/inlineHelp.ts | 7 -- src/documentation/long_forms.ts | 2 +- src/documentation/midi.ts | 98 +++++++++++------------ src/documentation/patterns.ts | 2 +- src/documentation/reference.ts | 3 - src/documentation/samples.ts | 12 --- src/documentation/synths.ts | 6 +- 14 files changed, 82 insertions(+), 94 deletions(-) delete mode 100644 src/documentation/reference.ts delete mode 100644 src/documentation/samples.ts diff --git a/src/API.ts b/src/API.ts index 8ea9c85..c3835fe 100644 --- a/src/API.ts +++ b/src/API.ts @@ -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 => { /** diff --git a/src/Documentation.ts b/src/Documentation.ts index 2cc30f0..6b66f90 100644 --- a/src/Documentation.ts +++ b/src/Documentation.ts @@ -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), diff --git a/src/DomElements.ts b/src/DomElements.ts index 3526f1f..9e3409a 100644 --- a/src/DomElements.ts +++ b/src/DomElements.ts @@ -9,7 +9,9 @@ export type ElementMap = { | HTMLInputElement | HTMLSelectElement | HTMLCanvasElement - | HTMLFormElement; + | HTMLFormElement + | HTMLInputElement + ; }; export const singleElements = { diff --git a/src/FileManagement.ts b/src/FileManagement.ts index ec58d8b..561da5e 100644 --- a/src/FileManagement.ts +++ b/src/FileManagement.ts @@ -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 diff --git a/src/IO/MidiConnection.ts b/src/IO/MidiConnection.ts index 2967c38..1cf38b9 100644 --- a/src/IO/MidiConnection.ts +++ b/src/IO/MidiConnection.ts @@ -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; } } diff --git a/src/InterfaceLogic.ts b/src/InterfaceLogic.ts index d89ce1a..04f2837 100644 --- a/src/InterfaceLogic.ts +++ b/src/InterfaceLogic.ts @@ -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 = ''; } } }); diff --git a/src/documentation/audio_engine/sampler.ts b/src/documentation/audio_engine/sampler.ts index ce35223..3e65f30 100644 --- a/src/documentation/audio_engine/sampler.ts +++ b/src/documentation/audio_engine/sampler.ts @@ -22,6 +22,8 @@ The sampler is a rather complex beast. There is a lot you can do by manipulating | cut | | Set with 0 or 1. Will cut the sample as soon as another sample is played on the same bus | | clip | | Multiply the duration of the sample with the given number | | pan | | Stereo position of the audio playback (0 = left, 1 = right)| +| vib | | vibrato speed (in hertz)| +| vibmod | | vibrato depth (from 0 to n)| 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 vib and vibmod: + +${makeExample("Adding vibrato to a sample", ` + +beat(1)::sound('fhang').vib([1, 2, 4].bar()).vibmod([0.5, 2].beat()).out() +`, true)} + + `} + + diff --git a/src/documentation/inlineHelp.ts b/src/documentation/inlineHelp.ts index d5985d7..eb6055b 100644 --- a/src/documentation/inlineHelp.ts +++ b/src/documentation/inlineHelp.ts @@ -555,19 +555,12 @@ const completionDatabase: CompletionDatabase = { "Base function to play audio (samples / synths). Alias for sound.", 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", diff --git a/src/documentation/long_forms.ts b/src/documentation/long_forms.ts index 299f930..f8800c0 100644 --- a/src/documentation/long_forms.ts +++ b/src/documentation/long_forms.ts @@ -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 diff --git a/src/documentation/midi.ts b/src/documentation/midi.ts index 49a74ed..e487f11 100644 --- a/src/documentation/midi.ts +++ b/src/documentation/midi.ts @@ -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 + )} - midi_output(output_name: string): 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 - midi(note: number|object): 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 - control_change({control: number, value: number, channel: number}): send a MIDI Control Change. This function takes a single object argument to specify the control message (_e.g._ control_change({control: 1, value: 127, channel: 1})). ${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 + )} - program_change(program: number, channel: number): send a MIDI Program Change. This function takes two arguments to specify the program and the channel (_e.g._ program_change(1, 1)). ${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 - midi_clock(): 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 + )} `; }; diff --git a/src/documentation/patterns.ts b/src/documentation/patterns.ts index 983e5b8..34262cd 100644 --- a/src/documentation/patterns.ts +++ b/src/documentation/patterns.ts @@ -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() `, diff --git a/src/documentation/reference.ts b/src/documentation/reference.ts deleted file mode 100644 index 8e2611a..0000000 --- a/src/documentation/reference.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const reference = (): string => { - return ``; -}; diff --git a/src/documentation/samples.ts b/src/documentation/samples.ts deleted file mode 100644 index e85d9c5..0000000 --- a/src/documentation/samples.ts +++ /dev/null @@ -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 ST 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 .speed(0.5). - -`; -}; diff --git a/src/documentation/synths.ts b/src/documentation/synths.ts index 6343cb8..d15325f 100644 --- a/src/documentation/synths.ts +++ b/src/documentation/synths.ts @@ -78,7 +78,7 @@ You can also add some amount of vibrato to the sound using the vib 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 .noise 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",