Construct a :class:`Tone` from a MIDI note, which must be an integer
        in the range 0 to 127. For reference, A4 (`concert A`_ typically used
        for tuning) is MIDI note #69.

        .. _concert A: https://en.wikipedia.org/wiki/Concert_pitch
508720
def from_midi(cls, midi_note):
        
        midi = int(midi_note)
        if 0 <= midi_note < 128:
            A4_midi = 69
            A4_freq = 440
            return cls.from_frequency(A4_freq * 2 ** ((midi - A4_midi) / 12))
        raise ValueError('invalid MIDI note: %r' % midi)
293431
function() {
    var octave = this.octave();
    var name = this.name();
    name = octave < 3 ? name.toUpperCase() : name.toLowerCase();
    var padchar = octave < 3 ? ',' : '\'';
    var padcount = octave < 2 ? 2 - octave : octave - 3;

    return pad(name + this.accidental(), padchar, padcount);
  }
944420
def qualified_note_rate(pianoroll, threshold=2):
    """"""
    _validate_pianoroll(pianoroll)
    if np.issubdtype(pianoroll.dtype, np.bool_):
        pianoroll = pianoroll.astype(np.uint8)
    padded = np.pad(pianoroll, ((1, 1), (0, 0)), 'constant')
    diff = np.diff(padded, axis=0).reshape(-1)
    onsets = (diff > 0).nonzero()[0]
    offsets = (diff < 0).nonzero()[0]
    n_qualified_notes = np.count_nonzero(offsets - onsets >= threshold)
    return n_qualified_notes / len(onsets)
1111762
public Note calculateSecondNote(Note n1, KeySignature key) {
		if (n1.isRest()) {
			try {
				return (Note) n1.clone();
			} catch (CloneNotSupportedException never) {
				never.printStackTrace();
			}
		}
		byte[] notes = new byte[] { Note.C, Note.D, Note.E, Note.F, Note.G,
				Note.A, Note.B };
		int height1 = n1.getStrictHeight();
		int index = 0;
		for (int i = 0; i < notes.length; i++) {
			if (notes[i] == height1) {
				index = i;
				break;
			}
		}
		int steps = getLabel();
		int octaveTransp = n1.getOctaveTransposition();
		while (steps > 0) {
			int oldIndex = index;
			index = (7 + index + m_direction) % OCTAVE;
			if ((oldIndex == 6) && (index == 0)) {
				//upward one octave
				octaveTransp += 1;
			} else if ((oldIndex == 0) && (index == 6)) {
				//downward one octave
				octaveTransp -= 1;
			}
			steps--;
		}
		Note n2;
		try {
			n2 = (Note) n1.clone();
		} catch (CloneNotSupportedException never) {
			never.printStackTrace();
			n2 = null;
		}
		n2.setHeight(notes[index]);
		n2.setOctaveTransposition((byte) octaveTransp);
		n2.setAccidental(Accidental.NATURAL);
		
		//and now compute accidentals!
		int delta = n1.getMidiLikeHeight(key) + getDirection()*getSemitones()
				- n2.getMidiLikeHeight(key);
		if (delta != 0) {
			n2 = Note.transpose(n2, /*factor*Math.abs*/(delta));
			Accidental[] acc = calculateSecondNoteAccidental(n1, key);
			n2 = Note.createEnharmonic(n2, acc);
		}
		if (key != null) {
			if (n2.getAccidental().equals(key.getAccidentalFor(n2.getStrictHeight())))
				n2.setAccidental(Accidental.NONE);
		}
		return n2;
	}
332975
def transpose(self, interval, up=True):
        
        (old, o_octave) = (self.name, self.octave)
        self.name = intervals.from_shorthand(self.name, interval, up)
        if up:
            if self < Note(old, o_octave):
                self.octave += 1
        else:
            if self > Note(old, o_octave):
                self.octave -= 1
540426
def _mpfr_get_str2(base, ndigits, op, rounding_mode):
    
    digits, exp = mpfr.mpfr_get_str(base, ndigits, op, rounding_mode)
    negative = digits.startswith('-')
    if negative:
        digits = digits[1:]
    return negative, digits, exp
43134
function minor_sixth(note) {
	var arr = minor_triad(note);
	arr.push(intervals.major_sixth(note));
	return arr;
}
1108467
def get_range(self):
        """"""
        (min, max) = (100000, -1)
        for cont in self.bar:
            for note in cont[2]:
                if int(note) < int(min):
                    min = note
                elif int(note) > int(max):
                    max = note
        return (min, max)
1319789
def _validate_pianoroll(pianoroll):
    """"""
    if not isinstance(pianoroll, np.ndarray):
        raise TypeError("`pianoroll` must be of np.ndarray type.")
    if not (np.issubdtype(pianoroll.dtype, np.bool_)
            or np.issubdtype(pianoroll.dtype, np.number)):
        raise TypeError("The data type of `pianoroll` must be np.bool_ or a "
                        "subdtype of  np.number.")
    if pianoroll.ndim != 2:
        raise ValueError("`pianoroll` must have exactly two dimensions.")
    if pianoroll.shape[1] != 128:
        raise ValueError("The length of the second axis of `pianoroll` must be "
                         "128.")
132924
def add_note(self, note, octave=None, dynamics={}):
        
        if type(note) == str:
            if octave is not None:
                note = Note(note, octave, dynamics)
            elif len(self.notes) == 0:
                note = Note(note, 4, dynamics)
            else:
                if Note(note, self.notes[-1].octave) < self.notes[-1]:
                    note = Note(note, self.notes[-1].octave + 1, dynamics)
                else:
                    note = Note(note, self.notes[-1].octave, dynamics)
        if not hasattr(note, 'name'):
            raise UnexpectedObjectError("Object '%s' was not expected. "
                    "Expecting a mingus.containers.Note object." % note)
        if note not in self.notes:
            self.notes.append(note)
            self.notes.sort()
        return self.notes
943890
function (scales, chord) {
  // Exclude scales with a particular interval
  var exclude = function (int) {
    scales = _.filter(scales, function (scale) {
      return !scale.hasInterval(int);
    });
  };

  // Add a scale at a particular index
  var include = function (index, scaleId) {
    scales.splice(index, 0, scale.create(chord.root, scaleId));
  };

  if (_.includes(['m', 'm6', 'm7', 'm9', 'm11', 'm13'], chord.formattedSymbol)) {
    exclude('M3');
  }
  if (_.includes(['7', '9', '11', '13', 'm7', 'm9', 'm11', 'm13'], chord.formattedSymbol)) {
    exclude('M7');
  }
  if (_.includes(['M7', 'M9', 'M11', 'M13'], chord.formattedSymbol)) {
    exclude('m7');
  }
  if (chord.formattedSymbol[0] === '6' || chord.formattedSymbol.slice(0, 2) === 'M6') {
    exclude('m7');
  }

  if (_.includes(['7', '7#9', '7+9', '7#11', '7+11'], chord.formattedSymbol)) {
    include(2, 'blues');
  }

  return scales;
}
1058697
def transpose_note(note, transpose, scale="C"):
    
    val = note_to_val(note)
    val += transpose
    return val_to_note(val, scale)
1366496
def from_shorthand(self, shorthand):
        
        name = ''
        octave = 0
        for x in shorthand:
            if x in ['a', 'b', 'c', 'd', 'e', 'f', 'g']:
                name = str.upper(x)
                octave = 3
            elif x in ['A', 'B', 'C', 'D', 'E', 'F', 'G']:
                name = x
                octave = 2
            elif x in ['#', 'b']:
                name += x
            elif x == ',':
                octave -= 1
            elif x == "'":
                octave += 1
        return self.set_note(name, octave, {})
567233
def midi2str(midi_number, sharp=True):
  
  if isinf(midi_number) or isnan(midi_number):
    return "?"
  num = midi_number - (MIDI_A4 - 4 * 12 - 9)
  note = (num + .5) % 12 - .5
  rnote = int(round(note))
  error = note - rnote
  octave = str(int(round((num - note) / 12.)))
  if sharp:
    names = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
  else:
    names = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"]
  names = names[rnote] + octave
  if abs(error) < 1e-4:
    return names
  else:
    err_sig = "+" if error > 0 else "-"
    err_str = err_sig + str(round(100 * abs(error), 2)) + "%"
    return names + err_str
179661
def note=(note)

      if !note.nil? && note.to_s.length > 60
        fail ArgumentError, "invalid value for 'note', the character length must be smaller than or equal to 60."
      end

      @note = note
    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)
919094
public function alphaToNum($a)
  {
    $l = strlen($a);
    $n = 0;
    for ($i = 0; $i < $l; $i++) {
      $n = $n*26 + ord($a[$i]) - 0x60;
    }
    return $n-1;
  }