SHARE
TWEET

Untitled

a guest Jul 17th, 2017 39 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <SCRIPT SRC='midi.js'></SCRIPT>
  2. This is a very simple example to play music from your keyboard.
  3. <br>
  4. Press Q to play C, W for D, E for E, etc.
  5. <SCRIPT>
  6. function play_note(note_name) {
  7.   var noteEvents = [];
  8.   [note_name].forEach(function(note) {
  9.       Array.prototype.push.apply(noteEvents, MidiEvent.createNote(note));
  10.   });
  11.   var track = new MidiTrack({ events: noteEvents });
  12.   var song  = MidiWriter({ tracks: [track] });
  13.   //alert(song.b64);
  14.   song.play();
  15. }
  16.  
  17. function manejador(elEvento) {
  18.   var evento = elEvento || window.event;
  19.   if (evento.keyCode==81)
  20.   {
  21.   //Q
  22.   play_note("C5");
  23.   }
  24.   if (evento.keyCode==87)
  25.   {
  26.   //W
  27.   play_note("D5");
  28.   }
  29.   if (evento.keyCode==69)
  30.   {
  31.   //E
  32.   play_note("E5");
  33.   }
  34.   if (evento.keyCode==82)
  35.   {
  36.   //R
  37.   play_note("F5");
  38.   }
  39.   if (evento.keyCode==84)
  40.   {
  41.   //T
  42.   play_note("G5");
  43.   }
  44.   if (evento.keyCode==89)
  45.   {
  46.   //Y
  47.   play_note("A5");
  48.   }
  49.   if (evento.keyCode==85)
  50.   {
  51.   //U
  52.   play_note("B5");
  53.   }
  54. }
  55. document.onkeydown = manejador;
  56. </SCRIPT>
RAW Paste Data
Top