gramCanvas.addEventListener('wheel', wheelSpectrogramCanvas);
        spectrogramCanvas.addEventListener('keydown', keydownEitherCanvas);

        scrubberCanvas.addEventListener('keydown', keydownEitherCanvas);
      	scrubberCanvas.addEventListener('mousedown', mousedownScrubberCanvas);
      	//scrubberCanvas.addEventListener('mouseup', mouseupScrubberCanvas);
      	scrubberCanvas.addEventListener('mousemove', mousemoveScrubberCanvas);
      	scrubberCanvas.addEventListener('mouseenter', mouseenterScrubberCanvas);
      	scrubberCanvas.addEventListener('mouseleave', mouseleaveScrubberCanvas);

        //document.addEventListener('keypress',tabPressedGlobal);

        // Vertex shader program for video (if present)
        const media_vsSource = `
          attribute vec4 aVertexPosition;
      		attribute vec2 aTextureCoord;

      		uniform mat4 uModelViewMatrix;
          uniform mat4 uProjectionMatrix;

      		varying highp vec2 vTextureCoord;

          void main(void) {
            gl_Position = uProjectionMatrix * uModelViewMatrix * aVertexPosition;
      			vTextureCoord = aTextureCoord;
          }
        `;

        // Fragment shader program for video (if present)
        const media_fsSource = `
          varying highp vec2 vTextureCoord;
      		uniform sampler2D uCurrFrame;
      		uniform sampler2D uPrevFrame;
          uniform lowp float uOverlayAlpha;
          uniform lowp float uNoizeSeed;

      		lowp float rand(lowp vec2 co) {
            return fract(sin(dot(co.xy,vec2(12.9898,78.233))) * 43758.5453);
          }

      		void main() {
      			highp vec4 currTexelColor = texture2D(uCurrFrame, vTextureCoord);
      			highp vec4 prevTexelColor = texture2D(uPrevFrame, vTextureCoord);

      			if (uOverlayAlpha > 0.5) {
      			  highp float noize = rand(vTextureCoord * uNoizeSeed) * uOverlayAlpha;
              gl_FragColor = vec4(noize,noize,noize,1.0);
      			} else {
      			   gl_FragColor = vec4(
      				  abs(currTexelColor.r - prevTexelColor.r),
      				  abs(currTexelColor.g - prevTexelColor.g),
      				  abs(currTexelColor.b - prevTexelColor.b),
      				  1.0);
      			}
          }
        `;


        // Vertex shader program for spectrogram
        const spectrogram_vsSource = `
          attribute vec4 aVertexPosition;
      		attribute vec2 aTextureCoord;

      		uniform mat4 uModelViewMatrix;
          uniform mat4 uProjectionMatrix;

      		varying highp vec2 vTextureCoord;

          void main(void) {
            gl_Position = uProjectionMatrix * uModelViewMatrix * aVertexPosition;
      			vTextureCoord = aTextureCoord;
          }
        `;

         // Fragment shader program for spectrogram
        const spectrogram_fsSource = `
          varying highp vec2 vTextureCoord;
      		uniform sampler2D uPrevFrame;
      		uniform sampler2D uCurrFrame;
      		uniform sampler2D uNextFrame;
          uniform highp float uPlayhead;
          uniform highp float uGain;
          uniform highp float uContrast;
          uniform highp float uViewportWidth;
          uniform highp float uGamma;
          uniform highp float uVerticalScale;

      		void main() {

            highp vec2 vRelativeTextureCoord; // = vTextureCoord;
            highp float scaledTextureHeight = pow(vTextureCoord.y, uGamma) * uVerticalScale;
            highp vec4 texelColor; // = texture2D(uCurrFrame,vTextureCoord);

            if (scaledTextureHeight > 1.0) {
              texelColor = vec4(0.0, 0.0, 0.0, 1.0);
            } else if (vTextureCoord.x < 0.0)  {
      		    vRelativeTextureCoord = vec2(vTextureCoord.x + 1.0, scaledTextureHeight);
      		    texelColor = texture2D(uPrevFrame, vRelativeTextureCoord);
      		  } else if (vTextureCoord.x > 1.0) {
      		    vRelativeTextureCoord = vec2(vTextureCoord.x - 1.0, scaledTextureHeight);
      		    texelColor = texture2D(uNextFrame, vRelativeTextureCoord);
      		  } else {
      		    vRelativeTextureCoord = vec2(vTextureCoord.x, scaledTextureHeight);
      		    texelColor = texture2D(uCurrFrame, vRelativeTextureCoord);

      		  }

            //if (mod(vTextureCoord.x, 1.0) < 0.01) {
            //  texelColor = vec4(1.0, texelColor.gb, 1.0);
            //}

            highp vec4 vecContrast =  vec4(uContrast,uContrast,uContrast,1.0);
            texelColor = pow(texelColor, vecContrast);
            texelColor = clamp(texelColor * uGain, 0.0, 1.0);

            if (abs(gl_FragCoord.x - uViewportWidth * 0.5) < 10.0) {
              gl_FragColor = vec4(1.0 - texelColor.r, 1.0 - texelColor.g, 1.0 - texelColor.b, 1.0);
            } else {
    			    gl_FragColor = vec4(texelColor.rgb,1.0);
            }

          }
        `;

        // Initialize a shader program; this is where all the lighting
        // for the vertices and so forth is established.
        const media_shaderProgram = initShaderProgram(media_gl, media_vsSource, media_fsSource);
        const spectrogram_shaderProgram = initShaderProgram(spectrogram_gl, spectrogram_vsSource, spectrogram_fsSource);

        // Collect all the info needed to use the shader program.
        // Look up which attribute our shader program is using
        // for aVertexPosition and look up uniform locations.
        const media_programInfo = {
          program: media_shaderProgram,
          attribLocations: {
            vertexPosition: media_gl.getAttribLocation(media_shaderProgram, 'aVertexPosition'),
      			textureCoord: media_gl.getAttribLocation(media_shaderProgram, 'aTextureCoord'),
          },
          uniformLocations: {
            projectionMatrix: media_gl.getUniformLocation(media_shaderProgram, 'uProjectionMatrix'),
            modelViewMatrix: media_gl.getUniformLocation(media_shaderProgram, 'uModelViewMatrix'),
      			currFrame: media_gl.getUniformLocation(media_shaderProgram, 'uCurrFrame'),
      			prevFrame: media_gl.getUniformLocation(media_shaderProgram, 'uPrevFrame'),
      			overlayAlpha: media_gl.getUniformLocation(media_shaderProgram, 'uOverlayAlpha'),
      			noizeSeed: media_gl.getUniformLocation(media_shaderProgram, 'uNoizeSeed'),
          },
        };


      	const spectrogram_programInfo = {
          program: spectrogram_shaderProgram,
          attribLocations: {
            vertexPosition: spectrogram_gl.getAttribLocation(spectrogram_shaderProgram, 'aVertexPosition'),
      			textureCoord: spectrogram_gl.getAttribLocation(spectrogram_shaderProgram, 'aTextureCoord'),
          },
          uniformLocations: {
            projectionMatrix: spectrogram_gl.getUniformLocation(spectrogram_shaderProgram, 'uProjectionMatrix'),
            modelViewMatrix: spectrogram_gl.getUniformLocation(spectrogram_shaderProgram, 'uModelViewMatrix'),
      			prevFrame: spectrogram_gl.getUniformLocation(spectrogram_shaderProgram, 'uPrevFrame'),
      			currFrame: spectrogram_gl.getUniformLocation(spectrogram_shaderProgram, 'uCur