Advertisement
Guest User

octave stuff

a guest
Apr 4th, 2020
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     var gAutoSustain = false;
  3.     var gSustain = true;
  4.  
  5.     var gHeldNotes = {};
  6.     var gSustainedNotes = {};
  7.  
  8.     var rollTemp = false;
  9.     var delPlay = false;
  10.  
  11.     var octTemp = 1;
  12.  
  13.     $("body").append('<div id="octave-btn" class="ugly-button" style="bottom: 22px; right: 640px; position: fixed; z-index: 500;">Octave Level</div>');
  14.     $("#octave-btn").on("click", function(evt) {
  15.         var isNumber = Number.isInteger || function(number) {
  16.             return !isNaN(parseFloat(n)) && isFinite(n)
  17.         }
  18.         var result = prompt("Enter Octave Level (MAX 5)");
  19.         if (result > 6 || result < 1) {
  20.             prompt("That number is too high, or too low!");
  21.             octTemp = 1;
  22.         } else {
  23.             octTemp = result;
  24.         }
  25.  
  26.     });
  27.  
  28.  
  29.  
  30.     function release(id) {
  31.         if (gHeldNotes[id]) {
  32.             gHeldNotes[id] = false;
  33.             if ((gAutoSustain || gSustain) && !enableSynth) {
  34.                 gSustainedNotes[id] = true;
  35.             } else {
  36.                 if (gNoteQuota.spend(1)) {
  37.                     gPiano.stop(id, gClient.getOwnParticipant(), 0);
  38.                     gClient.stopNote(id);
  39.                     gSustainedNotes[id] = false;
  40.                 }
  41.             }
  42.         }
  43.     }
  44.  
  45.     function pressSustain() {
  46.         gSustain = true;
  47.     }
  48.  
  49.     function releaseSustain() {
  50.         gSustain = false;
  51.         if (!gAutoSustain) {
  52.             for (var id in gSustainedNotes) {
  53.                 if (gSustainedNotes.hasOwnProperty(id) && gSustainedNotes[id] && !gHeldNotes[id]) {
  54.                     gSustainedNotes[id] = false;
  55.                     if (gNoteQuota.spend(1)) {
  56.                         gPiano.stop(id, gClient.getOwnParticipant(), 0);
  57.                         gClient.stopNote(id);
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.     }
  63.  
  64.  
  65.     function press(id, vol) {
  66.         //used to have an if gClient.preventsPlaying()
  67.         if (delPlay) {
  68.             setTimeout(function() {
  69.                 gPiano.play(id, vol !== undefined ? vol : DEFAULT_VELOCITY, gClient.getOwnParticipant(), 0);
  70.                 gClient.startNote(id + oct, vol);
  71.             }, delTime);
  72.         }
  73.  
  74.         gHeldNotes[id] = true;
  75.         gSustainedNotes[id] = true;
  76.         var octave = parseInt(id.replace(/[^\d.]/, '').replace('s', ''));
  77.         var note = id.replace(/[0-9]/g, '').replace("-", "");
  78.  
  79.         function pressDown(pressed, oct) {
  80.             gPiano.play(pressed + oct, vol !== undefined ? vol : DEFAULT_VELOCITY, gClient.getOwnParticipant(), 0);
  81.             gClient.startNote(pressed + oct, vol);
  82.  
  83.  
  84.         }
  85.         if (!rollTemp && octTemp == 1) {
  86.             pressDown(note, octave);
  87.         }
  88.         if (!rollTemp && octTemp == 2) {
  89.             pressDown(note, octave);
  90.             pressDown(note, (octave - 1));
  91.         }
  92.         if (!rollTemp && octTemp == 3) {
  93.             pressDown(note, octave);
  94.             pressDown(note, (octave - 1));
  95.             pressDown(note, (octave + 1));
  96.         }
  97.         if (!rollTemp && octTemp == 4) {
  98.             pressDown(note, octave);
  99.             pressDown(note, (octave - 1));
  100.             pressDown(note, (octave + 1));
  101.             pressDown(note, (octave - 2));
  102.         }
  103.         if (!rollTemp && octTemp == 5) {
  104.             pressDown(note, octave);
  105.             pressDown(note, (octave - 1));
  106.             pressDown(note, (octave + 1));
  107.             pressDown(note, (octave - 2));
  108.             pressDown(note, (octave + 2));
  109.         }
  110.         if (rollTemp && octTemp == 1) {
  111.             pressDown(note, octave);
  112.         }
  113.         if (rollTemp && octTemp == 2) {
  114.             setTimeout(function() {
  115.                 pressDown(note, octave);
  116.             }, 50);
  117.             pressDown(note, (octave - 1));
  118.         }
  119.         if (rollTemp && octTemp == 3) {
  120.             setTimeout(function() {
  121.                 pressDown(note, octave);
  122.             }, 50);
  123.             pressDown(note, (octave - 1));
  124.             setTimeout(function() {
  125.                 pressDown(note, (octave + 1));
  126.             }, 100);
  127.         }
  128.         if (rollTemp && octTemp == 4) {
  129.             setTimeout(function() {
  130.                 pressDown(note, octave);
  131.             }, 100);
  132.             setTimeout(function() {
  133.                 pressDown(note, (octave - 1));
  134.             }, 50);
  135.             setTimeout(function() {
  136.                 pressDown(note, (octave + 1));
  137.             }, 150);
  138.             pressDown(note, (octave - 2));
  139.         }
  140.         if (rollTemp && octTemp == 5) {
  141.             setTimeout(function() {
  142.                 pressDown(note, octave);
  143.             }, 100);
  144.             setTimeout(function() {
  145.                 pressDown(note, (octave - 1));
  146.             }, 50);
  147.             setTimeout(function() {
  148.                 pressDown(note, (octave + 1));
  149.             }, 150);
  150.             pressDown(note, (octave - 2));
  151.             setTimeout(function() {
  152.                 pressDown(note, (octave + 2));
  153.             }, 200);
  154.         }
  155.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement