Skip to content

Commit

Permalink
plays an mp3 instead
Browse files Browse the repository at this point in the history
  • Loading branch information
voitto committed Feb 22, 2016
1 parent cb89e7d commit d491937
Show file tree
Hide file tree
Showing 18 changed files with 15 additions and 4,189 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ notation for real musicians
here's an inventory of "stuff we need to find first":

- [x] find out "music note fonts" Finale uses and get ahold of a .ttf or .otf file of one of them (I like the Jazz font)~~
- [ ] an open source alternative to garritan instruments for playback. MIDIjs seems to have a bunch of options (http://galacticmilk.com/midi-js/) - abc.js looks interesting (https://github.com/paulrosen/abcjs) - blog post on midi/browser problems (http://abcnotation.com/blog/2013/04/10/the-problem-with-midi/)
- [ ] an open source alternative to garritan instruments for playback. MIDIjs seems to have a bunch of options (http://galacticmilk.com/midi-js/) -
- [ ] setup Gulp to compile JSX files with gulp-nodemon and gulp-react
Binary file added app/demo.mp3
Binary file not shown.
6 changes: 1 addition & 5 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<script src='http://cwilso.github.io/WebMIDIAPIShim/lib/WebMIDIAPI.js'></script>
<!-- MIDIFile: Repos folder must be in the same parent folder than the MIDIPlayer one -->
<script src="./js/MIDIFile.js" type="text/javascript"></script>
<!-- MIDIPlayer -->
<script src="./js/MIDIPlayer.js" type="text/javascript"></script>
<script src="./js/howler.min.js" type="text/javascript"></script>
</head>
<body>
<main></main> <!-- <main> MUST be the firstElementChild! -->
Expand Down
74 changes: 3 additions & 71 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,75 +7,7 @@ const render = ReactDOM.render

render(React.createElement('div', {}, 'this is just a <div> tag rendered in React. you can open command line with ALT+COMMAND+I!'), document.body.firstElementChild)

var midiAccess;
var midiPlayer;
var outputs;
// Requesting Midi Access
navigator.requestMIDIAccess().then(function onsuccesscallback(access) {
outputs = access.outputs;
var iter = outputs.values();
var output;
while(output = iter.next()) {
if(output.done) {
break;
}
var opt = document.createElement('option');
opt.value = output.value.id;
opt.text = output.value.name;
document.getElementById('inputportselector').add(opt);
}
},function onerrorcallback(err) {
console.log('uh-oh! Something went wrong! Error code: ' + err.code);
});
var sound = new Howl({
urls: ['./demo.mp3']
}).play();

// File handlers
function readFile(input) {
var reader = new FileReader();
reader.readAsArrayBuffer(input.files[0]);
reader.onloadend = function(event) {
playFile(event.target.result);
}
}
function downloadFile(input) {
if(!input.value)
return;
var oReq = new XMLHttpRequest();
oReq.open('GET', 'http://github.com/nfroidure/MIDIFile/master/sounds/' + input.value, true);
oReq.responseType = 'arraybuffer';
oReq.onload = function(oEvent) {
playFile(oReq.response);
};
oReq.send(null);
}

// Player
function playFile(buffer) {
var outputKeys = [];
// testing output
if(outputs) {
// Stopping previous play if exists
if(midiPlayer) {
midiPlayer.stop();
}

// Creating player
midiPlayer = new MIDIPlayer({output: outputs.get(
document.getElementById('inputportselector').value
)});

// creating the MidiFile instance from a buffer (view MIDIFile README)
midiFile = new MIDIFile(buffer);
midiPlayer.load(midiFile);

// Playing
midiPlayer.play(function() {
console.log('Play ended.');
});
console.log('Playing.');

} else {
console.log('No access to MIDI output.');
}
}

playFile('./demo.mid');
Loading

5 comments on commit d491937

@ColemanGariety
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since mp3s don't store the actual notes themselves, we'd have to auto-generate mp3s on the fly when people make any change to their feldman document, right?

@ColemanGariety
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, did you get a chance to click the demo link?

@ColemanGariety
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the other demo which does exactly what we want: https://ryoyakawai.github.io/smfplayer/

I think what we ought to do is roll back to your last commit with midifile and midiplayer included, then use this piece as a "synth": http://www.g200kg.com/en/docs/webmidilink/

There's also this one: https://github.com/danigb/soundfont-player

But I think what you had before was perfect, it was just missing a the "virtual synthesizer." We shouldn't be connecting to the OS X MIDI thing in "Audio MIDI Setup.app" and instead find a WebAudio "soundfont" player. That's the way midi.js does it!

@ColemanGariety
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I learned a lot from this GitHub issue on the HTML5 WebMIDI API: WebAudio/web-midi-api#45

@ColemanGariety
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this guy's keeps commenting the threads (to a relatively unresponsive bunch of people whom he calls "powers-the-be") and he's actually solved the whole issue of WebMIDI -> WebAudio here, I think: http://james-ingram-act-two.de/open-source/WebMIDISynthHost/host.html

Please sign in to comment.