Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var gAutoSustain = false;
- var gSustain = true;
- var gHeldNotes = {};
- var gSustainedNotes = {};
- var rollTemp = false;
- var delPlay = false;
- var octTemp = 1;
- $("body").append('<div id="octave-btn" class="ugly-button" style="bottom: 22px; right: 640px; position: fixed; z-index: 500;">Octave Level</div>');
- $("#octave-btn").on("click", function(evt) {
- var isNumber = Number.isInteger || function(number) {
- return !isNaN(parseFloat(n)) && isFinite(n)
- }
- var result = prompt("Enter Octave Level (MAX 5)");
- if (result > 6 || result < 1) {
- prompt("That number is too high, or too low!");
- octTemp = 1;
- } else {
- octTemp = result;
- }
- });
- function release(id) {
- if (gHeldNotes[id]) {
- gHeldNotes[id] = false;
- if ((gAutoSustain || gSustain) && !enableSynth) {
- gSustainedNotes[id] = true;
- } else {
- if (gNoteQuota.spend(1)) {
- gPiano.stop(id, gClient.getOwnParticipant(), 0);
- gClient.stopNote(id);
- gSustainedNotes[id] = false;
- }
- }
- }
- }
- function pressSustain() {
- gSustain = true;
- }
- function releaseSustain() {
- gSustain = false;
- if (!gAutoSustain) {
- for (var id in gSustainedNotes) {
- if (gSustainedNotes.hasOwnProperty(id) && gSustainedNotes[id] && !gHeldNotes[id]) {
- gSustainedNotes[id] = false;
- if (gNoteQuota.spend(1)) {
- gPiano.stop(id, gClient.getOwnParticipant(), 0);
- gClient.stopNote(id);
- }
- }
- }
- }
- }
- function press(id, vol) {
- //used to have an if gClient.preventsPlaying()
- if (delPlay) {
- setTimeout(function() {
- gPiano.play(id, vol !== undefined ? vol : DEFAULT_VELOCITY, gClient.getOwnParticipant(), 0);
- gClient.startNote(id + oct, vol);
- }, delTime);
- }
- gHeldNotes[id] = true;
- gSustainedNotes[id] = true;
- var octave = parseInt(id.replace(/[^\d.]/, '').replace('s', ''));
- var note = id.replace(/[0-9]/g, '').replace("-", "");
- function pressDown(pressed, oct) {
- gPiano.play(pressed + oct, vol !== undefined ? vol : DEFAULT_VELOCITY, gClient.getOwnParticipant(), 0);
- gClient.startNote(pressed + oct, vol);
- }
- if (!rollTemp && octTemp == 1) {
- pressDown(note, octave);
- }
- if (!rollTemp && octTemp == 2) {
- pressDown(note, octave);
- pressDown(note, (octave - 1));
- }
- if (!rollTemp && octTemp == 3) {
- pressDown(note, octave);
- pressDown(note, (octave - 1));
- pressDown(note, (octave + 1));
- }
- if (!rollTemp && octTemp == 4) {
- pressDown(note, octave);
- pressDown(note, (octave - 1));
- pressDown(note, (octave + 1));
- pressDown(note, (octave - 2));
- }
- if (!rollTemp && octTemp == 5) {
- pressDown(note, octave);
- pressDown(note, (octave - 1));
- pressDown(note, (octave + 1));
- pressDown(note, (octave - 2));
- pressDown(note, (octave + 2));
- }
- if (rollTemp && octTemp == 1) {
- pressDown(note, octave);
- }
- if (rollTemp && octTemp == 2) {
- setTimeout(function() {
- pressDown(note, octave);
- }, 50);
- pressDown(note, (octave - 1));
- }
- if (rollTemp && octTemp == 3) {
- setTimeout(function() {
- pressDown(note, octave);
- }, 50);
- pressDown(note, (octave - 1));
- setTimeout(function() {
- pressDown(note, (octave + 1));
- }, 100);
- }
- if (rollTemp && octTemp == 4) {
- setTimeout(function() {
- pressDown(note, octave);
- }, 100);
- setTimeout(function() {
- pressDown(note, (octave - 1));
- }, 50);
- setTimeout(function() {
- pressDown(note, (octave + 1));
- }, 150);
- pressDown(note, (octave - 2));
- }
- if (rollTemp && octTemp == 5) {
- setTimeout(function() {
- pressDown(note, octave);
- }, 100);
- setTimeout(function() {
- pressDown(note, (octave - 1));
- }, 50);
- setTimeout(function() {
- pressDown(note, (octave + 1));
- }, 150);
- pressDown(note, (octave - 2));
- setTimeout(function() {
- pressDown(note, (octave + 2));
- }, 200);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement