Last active
August 13, 2016 02:31
-
-
Save airportyh/183cec734057d2dc8fbb0dd78dc807f7 to your computer and use it in GitHub Desktop.
Plays the Final Fantasy II Theme. Requires https://github.com/gleitz/midi-js-soundfonts to be installed into the same directory.
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
| var playSound = require('play-sound'); | |
| var path = require('path'); | |
| var _ = require('lodash'); | |
| var player = playSound(); | |
| var chords = [ | |
| ['c3', 'd3', 'e3', 'g3'], | |
| ['a2', 'b2', 'c3', 'e3'], | |
| ['c3', 'd3', 'e3', 'g3'], | |
| ['a2', 'b2', 'c3', 'e3'], | |
| ['a2', 'c3', 'f3', 'g3'], | |
| ['b2', 'd3', 'g3', 'a3'], | |
| ['ab2', 'c3', 'eb3', 'g3'], | |
| ['bb2', 'd3', 'f3', 'a3'] | |
| ]; | |
| var notes = _.flatten(chords.map(function(chord) { | |
| var chordDown = [octaveUp(1)(chord[0]), chord[3], chord[2], chord[1]]; | |
| return chord | |
| .concat(chord.map(octaveUp(1))) | |
| .concat(chord.map(octaveUp(2))) | |
| .concat(chord.map(octaveUp(3))) | |
| .concat(chordDown.map(octaveUp(3))) | |
| .concat(chordDown.map(octaveUp(2))) | |
| .concat(chordDown.map(octaveUp(1))) | |
| .concat(chordDown); | |
| })); | |
| notes = notes.concat(notes).concat(notes); | |
| var i = 0; | |
| function nextNote() { | |
| var note = notes[i++]; | |
| if (!note) return; | |
| play(note); | |
| setTimeout(nextNote, 150); | |
| } | |
| nextNote(); | |
| function octaveUp(n) { | |
| return function(note) { | |
| var num = Number(note[note.length - 1]); | |
| return note.substring(0, note.length - 1) + (num + n); | |
| } | |
| } | |
| function play(note) { | |
| player.play(path.resolve('midi-js-soundfonts/FluidR3_GM/celesta-mp3/' + note.toUpperCase() + '.mp3')); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment