Created
August 18, 2022 13:51
-
-
Save erodactyl/f9dd157f846c2375cc952ed27bcfdd2c to your computer and use it in GitHub Desktop.
Sonic Pi in Typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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