Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <SCRIPT SRC='midi.js'></SCRIPT>
- This is a very simple example to play music from your keyboard.
- <br>
- Press Q to play C, W for D, E for E, etc.
- <SCRIPT>
- function play_note(note_name) {
- var noteEvents = [];
- [note_name].forEach(function(note) {
- Array.prototype.push.apply(noteEvents, MidiEvent.createNote(note));
- });
- var track = new MidiTrack({ events: noteEvents });
- var song = MidiWriter({ tracks: [track] });
- //alert(song.b64);
- song.play();
- }
- function manejador(elEvento) {
- var evento = elEvento || window.event;
- if (evento.keyCode==81)
- {
- //Q
- play_note("C5");
- }
- if (evento.keyCode==87)
- {
- //W
- play_note("D5");
- }
- if (evento.keyCode==69)
- {
- //E
- play_note("E5");
- }
- if (evento.keyCode==82)
- {
- //R
- play_note("F5");
- }
- if (evento.keyCode==84)
- {
- //T
- play_note("G5");
- }
- if (evento.keyCode==89)
- {
- //Y
- play_note("A5");
- }
- if (evento.keyCode==85)
- {
- //U
- play_note("B5");
- }
- }
- document.onkeydown = manejador;
- </SCRIPT>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement