Trim the trailing silence of the pianoroll.
549532
def trim_trailing_silence(self):
        """"""
        length = self.get_active_length()
        self.pianoroll = self.pianoroll[:length]
1348504
function () {
    // Remove events listners
    this.rl.removeListener('SIGINT', this.forceClose)
    this.rl.removeListener('line', this.onLine)
    this.rl.input.removeListener('keypress', this.onKeypress)
    process.removeListener('exit', this.forceClose)
    
    // Restore prompt functionnalities
    this.rl.output.unmute()
    this.rl.output.write("\x1B[?25h") // show cursor

    // Close the readline
    this.rl.output.end()
    this.rl.pause()
    this.rl.close()
    this.rl = null
  }
1120776
def get_max_length(self):
        
        max_length = 0
        for track in self.tracks:
            if max_length < track.pianoroll.shape[0]:
                max_length = track.pianoroll.shape[0]
        return max_length
1261682
private void doClose()
	{
		// set visible, if system tray active and frame is iconified
		if (useSystemTray && (getExtendedState()&ICONIFIED)!=0) setVisible(true);
		
		doStopPlaying();
		getSeekBarPanel().pauseThread();
		getVULMeterPanel().pauseThread();
		getVURMeterPanel().pauseThread();
		getSALMeterPanel().pauseThread();
		getSARMeterPanel().pauseThread();
		getLEDScrollPanel().pauseThread();
		writePropertyFile();
		if (audioProcessor!=null) audioProcessor.removeListener(this);
		
		MultimediaContainerManager.removeMultimediaContainerEventListener(this);

		useSystemTray = false; setSystemTray();

		for (Window win : windows)
		{
			win.setVisible(false);
			win.dispose();
		}
		setVisible(false);
		dispose();
		
		System.exit(0); // this should not be needed! 
	}
952794
function(obj, num, chordPos) {
        if (currSlur[chordPos] === undefined) {
          // There isn't an exact match for note position, but we'll take any other open slur.
          for (x = 0; x < currSlur.length; x++) {
            if (currSlur[x] !== undefined) {
              chordPos = x;
              break;
            }
          }
          if (currSlur[chordPos] === undefined) {
            var offNum = chordPos*100+1;
            Common.each(obj.endSlur, function(x) { if (offNum === x) --offNum; });
            currSlur[chordPos] = [offNum];
          }
        }
        var slurNum;
        for (var i = 0; i < num; i++) {
          slurNum = currSlur[chordPos].pop();
          obj.endSlur.push(slurNum);
//					lyr.syllable += '<' + slurNum;	// TODO-PER: debugging
        }
        if (currSlur[chordPos].length === 0)
          delete currSlur[chordPos];
        return slurNum;
      }
391576
def silence(temporary_level = Logger::ERROR)
      if silencer
        begin
          old_local_level            = local_level
          self.local_level           = temporary_level

          yield self
        ensure
          self.local_level = old_local_level
        end
      else
        yield self
      end
    end
1241872
def drum_in_pattern_rate(pianoroll, beat_resolution, tolerance=0.1):
    """"""
    if beat_resolution not in (4, 6, 8, 9, 12, 16, 18, 24):
        raise ValueError("Unsupported beat resolution. Only 4, 6, 8 ,9, 12, "
                         "16, 18, 42 are supported.")
    _validate_pianoroll(pianoroll)

    def _drum_pattern_mask(res, tol):
        """Return a drum pattern mask with the given tolerance."""
        if res == 24:
            drum_pattern_mask = np.tile([1., tol, 0., 0., 0., tol], 4)
        elif res == 12:
            drum_pattern_mask = np.tile([1., tol, tol], 4)
        elif res == 6:
            drum_pattern_mask = np.tile([1., tol, tol], 2)
        elif res == 18:
            drum_pattern_mask = np.tile([1., tol, 0., 0., 0., tol], 3)
        elif res == 9:
            drum_pattern_mask = np.tile([1., tol, tol], 3)
        elif res == 16:
            drum_pattern_mask = np.tile([1., tol, 0., tol], 4)
        elif res == 8:
            drum_pattern_mask = np.tile([1., tol], 4)
        elif res == 4:
            drum_pattern_mask = np.tile([1., tol], 2)
        return drum_pattern_mask

    drum_pattern_mask = _drum_pattern_mask(beat_resolution, tolerance)
    n_in_pattern = np.sum(drum_pattern_mask * np.count_nonzero(pianoroll, 1))
    return n_in_pattern / np.count_nonzero(pianoroll)
940104
def trim(self):
        """"""
        for key, value in list(iteritems(self.counters)):
            if value.empty():
                del self.counters[key]
952675
def polyphonic_rate(pianoroll, threshold=2):
    """"""
    _validate_pianoroll(pianoroll)
    n_poly = np.count_nonzero(np.count_nonzero(pianoroll, 1) > threshold)
    return n_poly / len(pianoroll)
1294881
function(silent) {
        var min     = this.minSlider.getValue(),
            max     = this.maxSlider.getValue(),
            changed = false,
            mint,maxt,dim,minConstraint,maxConstraint,thumbInnerWidth;

        if (min != this.minVal || max != this.maxVal) {
            changed = true;

            mint = this.minSlider.thumb;
            maxt = this.maxSlider.thumb;
            dim  = this.isHoriz ? 'x' : 'y';

            thumbInnerWidth = this.minSlider.thumbCenterPoint[dim] +
                              this.maxSlider.thumbCenterPoint[dim];

            // Establish barriers within the respective other thumb's edge, less
            // the minRange.  Limit to the Slider's range in the case of
            // negative minRanges.
            minConstraint = Math.max(max-thumbInnerWidth-this.minRange,0);
            maxConstraint = Math.min(-min-thumbInnerWidth-this.minRange,0);

            if (this.isHoriz) {
                minConstraint = Math.min(minConstraint,maxt.rightConstraint);

                mint.setXConstraint(mint.leftConstraint,minConstraint, mint.tickSize);

                maxt.setXConstraint(maxConstraint,maxt.rightConstraint, maxt.tickSize);
            } else {
                minConstraint = Math.min(minConstraint,maxt.bottomConstraint);
                mint.setYConstraint(mint.leftConstraint,minConstraint, mint.tickSize);

                maxt.setYConstraint(maxConstraint,maxt.bottomConstraint, maxt.tickSize);
            }
        }

        this.minVal = min;
        this.maxVal = max;

        if (changed && !silent) {
            this.fireEvent("change", this);
        }
    }
1123256
def empty_beat_rate(pianoroll, beat_resolution):
    """"""
    _validate_pianoroll(pianoroll)
    reshaped = pianoroll.reshape(-1, beat_resolution * pianoroll.shape[1])
    n_empty_beats = np.count_nonzero(reshaped.any(1))
    return n_empty_beats / len(reshaped)
578340
function() {
      var self = this;
      var limit = self._pool;
      var cnt = 0;
      var i = 0;

      // If there are less sounds than the max pool size, we are done.
      if (self._sounds.length < limit) {
        return;
      }

      // Count the number of inactive sounds.
      for (i=0; i<self._sounds.length; i++) {
        if (self._sounds[i]._ended) {
          cnt++;
        }
      }

      // Remove excess inactive sounds, going in reverse order.
      for (i=self._sounds.length - 1; i>=0; i--) {
        if (cnt <= limit) {
          return;
        }

        if (self._sounds[i]._ended) {
          // Disconnect the audio source when using Web Audio.
          if (self._webAudio && self._sounds[i]._node) {
            self._sounds[i]._node.disconnect(0);
          }

          // Remove sounds until we have the pool size.
          self._sounds.splice(i, 1);
          cnt--;
        }
      }
    }
1163117
public String trimTrailing(String str) {
        if (str == null) {
            return null;
        }

        int length = str.length();
        for (int i=length-1; i>=0; i--) {
            if (str.charAt(i) > ' ') {
                return str.substring(0, i + 1);
            }
        }

        return "";
    }
275740
def get_active_pitch_range(self):
        
        if self.pianoroll.shape[1] < 1:
            raise ValueError("Cannot compute the active pitch range for an "
                             "empty pianoroll")
        lowest = 0
        highest = 127
        while lowest < highest:
            if np.any(self.pianoroll[:, lowest]):
                break
            lowest += 1
        if lowest == highest:
            raise ValueError("Cannot compute the active pitch range for an "
                             "empty pianoroll")
        while not np.any(self.pianoroll[:, highest]):
            highest -= 1

        return lowest, highest
71485
def _to_chroma(pianoroll):
    """"""
    _validate_pianoroll(pianoroll)
    reshaped = pianoroll[:, :120].reshape(-1, 12, 10)
    reshaped[..., :8] += pianoroll[:, 120:].reshape(-1, 1, 8)
    return np.sum(reshaped, 1)
803836
function cleanup () {
    if (!ctrl.hidden) {
      $mdUtil.enableScrolling();
    }

    angular.element($window).off('resize', debouncedOnResize);

    if (elements){
      var items = ['ul', 'scroller', 'scrollContainer', 'input'];
      angular.forEach(items, function(key){
        elements.$[key].remove();
      });
    }
  }
954356
def tonal_distance(pianoroll_1, pianoroll_2, beat_resolution, r1=1.0, r2=1.0,
                   r3=0.5):
    
    _validate_pianoroll(pianoroll_1)
    _validate_pianoroll(pianoroll_2)
    assert len(pianoroll_1) == len(pianoroll_2), (
        "Input pianorolls must have the same length.")

    def _tonal_matrix(r1, r2, r3):
        """Return a tonal matrix for computing the tonal distance."""
        tonal_matrix = np.empty((6, 12))
        tonal_matrix[0] = r1 * np.sin(np.arange(12) * (7. / 6.) * np.pi)
        tonal_matrix[1] = r1 * np.cos(np.arange(12) * (7. / 6.) * np.pi)
        tonal_matrix[2] = r2 * np.sin(np.arange(12) * (3. / 2.) * np.pi)
        tonal_matrix[3] = r2 * np.cos(np.arange(12) * (3. / 2.) * np.pi)
        tonal_matrix[4] = r3 * np.sin(np.arange(12) * (2. / 3.) * np.pi)
        tonal_matrix[5] = r3 * np.cos(np.arange(12) * (2. / 3.) * np.pi)
        return tonal_matrix

    def _to_tonal_space(pianoroll, tonal_matrix):
        """Return the tensor in tonal space where chroma features are normalized
        per beat."""
        beat_chroma = _to_chroma(pianoroll).reshape(-1, beat_resolution, 12)
        beat_chroma = beat_chroma / np.sum(beat_chroma, 2, keepdims=True)
        return np.matmul(tonal_matrix, beat_chroma.T).T

    tonal_matrix = _tonal_matrix(r1, r2, r3)
    mapped_1 = _to_tonal_space(pianoroll_1, tonal_matrix)
    mapped_2 = _to_tonal_space(pianoroll_2, tonal_matrix)
    return np.linalg.norm(mapped_1 - mapped_2)