Skip to content

Instantly share code, notes, and snippets.

@erodactyl
Created August 18, 2022 13:51
Show Gist options
  • Save erodactyl/f9dd157f846c2375cc952ed27bcfdd2c to your computer and use it in GitHub Desktop.
Save erodactyl/f9dd157f846c2375cc952ed27bcfdd2c to your computer and use it in GitHub Desktop.
Sonic Pi in Typescript
import { default as player } from "play-sound";
const play = (name: string) => player().play(`./assets/${name}.wav`);
const sleep = (time: number) => {
return new Promise((res) =>
setTimeout(() => {
res(null);
}, time)
);
};
(async function note() {
while (true) {
play("guitar-note");
await sleep(1000);
}
})();
(async function riff() {
while (true) {
play("guitar-rif");
await sleep(2000);
}
})();
(async function strum() {
while (true) {
play("guitar-strum");
await sleep(3000);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment