Create a Mehegan symbol given a key and a chord
484566
function (key, ch) {
  key = note.create(key || 'C');
  ch = chord.create(ch);

  return new Mehegan(getNumeral(key, ch.root), getQuality(ch));
}
957446
function buildMidiNumberAttributes(midiNumber) {
  const pitchIndex = (midiNumber - MIDI_NUMBER_C0) % NOTES_IN_OCTAVE;
  const octave = Math.floor((midiNumber - MIDI_NUMBER_C0) / NOTES_IN_OCTAVE);
  const pitchName = SORTED_PITCHES[pitchIndex];
  return {
    note: `${pitchName}${octave}`,
    pitchName,
    octave,
    midiNumber,
    isAccidental: ACCIDENTAL_PITCHES.includes(pitchName),
  };
}
157776
def _chorder(self):
        """"""
        if (self.interleave and
            len([ c for c in self.children if ":" not in c.name ]) > 1):
            return "<interleave>%s</interleave>"
        return "%s"
1293860
function(opacity) {
        return function(g, i) {
          gEnter.selectAll(".chord")
              .filter(function(d) {
                return d.source.index != i && d.target.index != i;
              })
            .transition()
              .style("opacity", opacity);
          var groups = [];
          gEnter.selectAll(".chord")
              .filter(function(d) {
                if (d.source.index == i) {
                  groups.push(d.target.index);
                }
                if (d.target.index == i) {
                  groups.push(d.source.index);
                }
              });
          groups.push(i);
          var length = groups.length;
          gEnter.selectAll('.group')
              .filter(function(d) {
                for (var i = 0; i < length; i++) {
                  if(groups[i] == d.index) return false;
                }
                return true;
              })
              .transition()
                .style("opacity", opacity);
        };
      }
439282
def key_to_metric(self, key):
        """"""
        return ''.join(l if l in string.letters else '_' for l in key)
621446
def determine_polychords(chord, shorthand=False):
    
    polychords = []
    function_list = [determine_triad, determine_seventh,
                     determine_extended_chord5, determine_extended_chord6,
                     determine_extended_chord7]

    # Range tracking.
    if len(chord) <= 3:
        return []
    elif len(chord) > 14:
        return []
    elif len(chord) - 3 <= 5:
        function_nr = range(0, len(chord) - 3)
    else:
        function_nr = range(0, 5)
    for f in function_nr:
        for f2 in function_nr:
            # The clever part: Try the function_list[f] on the len(chord) - (3 +
            # f) last notes of the chord. Then try the function_list[f2] on the
            # f2 + 3 first notes of the chord. Thus, trying all possible
            # combinations.
            for chord1 in function_list[f](chord[len(chord) - (3 + f):], True,
                    True, True):
                for chord2 in function_list[f2](chord[:f2 + 3], True, True,
                        True):
                    polychords.append('%s|%s' % (chord1, chord2))
    if shorthand:
        for p in polychords:
            p = p + ' polychord'
    return polychords
684952
Rule Chord() {
		return Sequence(
				FirstOfS(ChordChordOptionalBass(),
						ChordOptionalChordWithBass()),
/*			OptionalS(String("(")),
			OptionalS(BaseNote()),
			OptionalS(ChordAccidental()),
			OptionalS(ChordType()),
			OptionalS(Sequence(
					suppr("/"),
					BaseNote(),
					OptionalS(ChordAccidental())).label("ChordBass")),
			OptionalS(String(")")),*/
			ZeroOrMore(NonQuote()).suppressNode()
		).label(Chord);
	}
1073845
def make_commkey(key, session_id, ticks=50):
    
    key = int(key)
    session_id = int(session_id)
    k = 0
    for i in range(32):
        if (key & (1 << i)):
            k = (k << 1 | 1)
        else:
            k = k << 1
    k += session_id

    k = pack(b'I', k)
    k = unpack(b'BBBB', k)
    k = pack(
        b'BBBB',
        k[0] ^ ord('Z'),
        k[1] ^ ord('K'),
        k[2] ^ ord('S'),
        k[3] ^ ord('O'))
    k = unpack(b'HH', k)
    k = pack(b'HH', k[1], k[0])

    B = 0xff & ticks
    k = unpack(b'BBBB', k)
    k = pack(
        b'BBBB',
        k[0] ^ B,
        k[1] ^ B,
        B,
        k[3] ^ B)
    return k
1123364
private static int parseIntKey(CharSequence key) {
        int numSpaces = 0;
        StringBuilder digits = new StringBuilder();

        // build a string from the numerical characters
        for (int i=0; i<key.length(); i++) {
            char c = key.charAt(i);
            if (' ' == c) {
                numSpaces++;
            } else if (Character.isDigit(c)) {
                digits.append(c);
            }
        }

        String s = digits.toString();
        // This may be greater than the max value for signed integers
        long n = Long.parseLong(s);

        // result is the numerical value divided by the number of spaces
        return (int) (n / numSpaces);
    }
217866
public String getText(boolean unicode) {
		if (!isChord())
			return m_chordName;
		else {
			StringBuilder ret = new StringBuilder();
			if (isOptional())
				ret.append("(");
			ret.append(note2string(getNote(), unicode));
			ret.append(getQuality());
			if (hasBass()) {
				ret.append("/");
				ret.append(note2string(getBass(), unicode));
			}
			if (isOptional())
				ret.append(")");
			return ret.toString();
		}
	}
451098
def symbolize_keys(hash)
      Hash[hash.map{|(k,v)| [k.to_sym,v]}]
    end
704187
function (chords, settings) {
  var chordEvents = makeChordEvents(chords, settings);

  // Set all channels
  var setPatches = _.reduce(_.range(0xf), function (buffer, channel) {
    return Buffer.concat([buffer, makePatchEvent(channel, settings.chordPatch)]);
  }, new Buffer(0));

  var length = setPatches.length + chordEvents.length + trackFooter.length;

  return Buffer.concat([trackHeader, padNumber(length, 4), setPatches, chordEvents, trackFooter]);
}
801849
function (str) {
  var matches = str.match(/([b#]?)([iIvV]+)([mMxoøs]?)/);
  var alteration;
  var numeral;
  var quality;

  if (!matches) {
    throw new Error('Invalid Mehegan symbol');
  }

  alteration = matches[1];
  numeral = matches[2].toUpperCase();
  quality = matches[3];

  if (!quality) quality = inferQuality(numeral);

  return new Mehegan(alteration + numeral, quality);
}
866117
def __setkey(key):
    
    global C, D, KS, E

    shifts = (1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1)

    # First, generate C and D by permuting the key. The lower order bit of each
    # 8-bit char is not used, so C and D are only 28 bits apiece.
    for i in range(28):
        C[i] = key[PC1_C[i] - 1]
        D[i] = key[PC1_D[i] - 1]

    for i in range(16):
        # rotate
        for k in range(shifts[i]):
            temp = C[0]

            for j in range(27):
                C[j] = C[j + 1]

            C[27] = temp
            temp = D[0]
            for j in range(27):
                D[j] = D[j + 1]

            D[27] = temp

        # get Ki. Note C and D are concatenated
        for j in range(24):
            KS[i][j] = C[PC2_C[j] - 1]
            KS[i][j + 24] = D[PC2_D[j] - 28 - 1]

    # load E with the initial E bit selections
    for i in range(48):
        E[i] = e2[i]
555967
def get_notes(key='C'):
    
    if _key_cache.has_key(key):
        return _key_cache[key]
    if not is_valid_key(key):
        raise NoteFormatError("unrecognized format for key '%s'" % key)
    result = []

    # Calculate notes
    altered_notes = map(operator.itemgetter(0),
            get_key_signature_accidentals(key))

    if get_key_signature(key) < 0:
        symbol = 'b'
    elif get_key_signature(key) > 0:
        symbol = '#'

    raw_tonic_index = base_scale.index(key.upper()[0])

    for note in islice(cycle(base_scale), raw_tonic_index, raw_tonic_index+7):
        if note in altered_notes:
            result.append('%s%s' % (note, symbol))
        else:
            result.append(note)
    
    # Save result to cache
    _key_cache[key] = result
    return result
123862
function toMusicXML() {
        $out = '';
        foreach ($this->chords as $chord) {
            $out .= $chord->toMusicXML();
        }

        return $out;
    }
692267
function signStr(str, key) {
  var hmac = crypto.createHmac('sha1', key);
  hmac.update(str);
  return hmac.digest('base64').replace(/\+/g, '-').replace(/\//g, '_');
}