Last active
December 23, 2020 22:51
-
-
Save OverlappingElvis/09a6d402c2715c12489be5d3808533c8 to your computer and use it in GitHub Desktop.
midi-to-blobs
This file contains hidden or 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
| const fs = require(`fs`) | |
| const _ = require(`lodash`) | |
| const { Player } = require(`midi-player-js`) | |
| const VOWELS = [`a`, `e`, `i`, `o`, `u`] | |
| const CONSONANTS = [`p`, `g`, `f`, `c`, `qu`, `h`, `j`, `n`, `l`, `m`, `t`, `d`, `ch`, `r`] | |
| const player = new Player() | |
| player.loadFile(`./test.mid`) | |
| const songTime = player.getSongTime() | |
| const allEvents = player.getEvents() | |
| const MAX_TICKS = _.last(_.maxBy(allEvents, (events) => _.last(events).tick)).tick | |
| const parsedEvents = allEvents.map((track) => { | |
| return track.filter(event => event.name === `Note on`).map((event) => { | |
| return { | |
| timeSeconds: (event.tick / MAX_TICKS) * songTime, | |
| midiPitch: event.noteNumber, | |
| librettoChunk: { | |
| vowel: { | |
| name: _.sample(VOWELS), | |
| duration: 0.20000000298023224 | |
| }, | |
| suffix: [ | |
| { | |
| name: _.sample(CONSONANTS), | |
| duration: 0.10000000149011612 | |
| } | |
| ] | |
| } | |
| } | |
| }) | |
| }).filter(track => !_.isEmpty(track)).map((track) => { | |
| return { | |
| notes: track, | |
| startSuffix: [ | |
| { | |
| name: _.sample(CONSONANTS), | |
| duration: 0.10000000149011612 | |
| } | |
| ] | |
| } | |
| }) | |
| const song = { | |
| theme: 1, | |
| parts: parsedEvents | |
| } | |
| fs.writeFile(`test.json`, JSON.stringify(song), () => console.log(`done`)) |
I'm confused, how do you get the blobs to sing with the test.json file?
I'm confused, how do you get the blobs to sing with the
test.jsonfile?
If you set a breakpoint in the blob opera script where sample songs are loaded, you can sideload your custom json (see https://twitter.com/Overlapping/status/1338979945792466944)
This must now be called with a midi file argument: node index.js <song.mid>
Check out https://github.com/OverlappingElvis/blob-opera-midi, now a standalone package
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this might be getting out of hand
