Substitute a diminished chord for another diminished chord.

    'dim' and 'dim7' suffixes recognized, and 'VI' if there is no suffix.

    Example:
    >>> substitute_diminished_for_diminished(['VII'], 0)
    ['IIdim', 'bIVdim', 'bbVIdim']
494374
def substitute_diminished_for_diminished(progression, substitute_index,
        ignore_suffix=False):
    
    (roman, acc, suff) = parse_string(progression[substitute_index])
    res = []

    # Diminished progressions
    if suff == 'dim7' or suff == 'dim' or suff == '' and roman in ['VII']\
         or ignore_suffix:
        if suff == '':
            suff = 'dim'

        # Add diminished chord
        last = roman
        for x in range(3):
            next = skip(last, 2)
            acc += interval_diff(last, next, 3)
            res.append(tuple_to_string((next, acc, suff)))
            last = next
    return res
331729
def substitute_variables(command, level, name, value, target=None, **kwargs):
    """"""
    rule = kwargs.get('rule', {})
    rule_value = rule.get('value', '') if rule else ''
    substitutes = {
        '${level}': str(level),
        '${target}': str(target),
        '${name}': '"' + str(name) + '"',
        '${value}': str(value),
        '${limit_value}': str(rule_value),
    }

    result = command
    for pattern, value in substitutes.items():
        result = result.replace(pattern, value)

    return result
1285264
def substitute(dict_, source):
    
    d_esc = (re.escape(k) for k in dict_.keys())
    pattern = re.compile('|'.join(d_esc))
    return pattern.sub(lambda x: dict_[x.group()], source)
825886
def apply_T7(word):
    ''''''
    T7 = ''
    WORD = word.split('.')

    for i, v in enumerate(WORD):

        if contains_VVV(v):

            for I, V in enumerate(v[::-1]):

                if is_vowel(V):
                    WORD[i] = v[:I] + '.' + v[I:]
                    T7 = ' T7'

    word = '.'.join(WORD)

    return word, T7
962505
def note_to_chord(notes):
    
    if not notes:
        raise ValueError("Please specify notes which consist a chord.")
    root = notes[0]
    root_and_positions = []
    for rotated_notes in get_all_rotated_notes(notes):
        rotated_root = rotated_notes[0]
        root_and_positions.append([rotated_root, notes_to_positions(rotated_notes, rotated_notes[0])])
    chords = []
    for temp_root, positions in root_and_positions:
        quality = find_quality(positions)
        if quality is None:
            continue
        if temp_root == root:
            chord = "{}{}".format(root, quality)
        else:
            chord = "{}{}/{}".format(temp_root, quality, root)
        chords.append(Chord(chord))
    return chords
426265
def _join_strings(x):
    """"""
    for i in range(len(x)-1):  # Process successive pairs of elements
        if x[i]['t'] == 'Str' and x[i+1]['t'] == 'Str':
            x[i]['c'] += x[i+1]['c']
            del x[i+1]  # In-place deletion of element from list
            return None  # Forces processing to repeat
    return True
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
99239
def sub_escapes(sval):
    '''
    
    '''
    sval = sval.replace('\\a', '\a')
    sval = sval.replace('\\b', '\x00')
    sval = sval.replace('\\f', '\f')
    sval = sval.replace('\\n', '\n')
    sval = sval.replace('\\r', '\r')
    sval = sval.replace('\\t', '\t')
    sval = sval.replace('\\v', '\v')
    sval = sval.replace('\\\\', '\\')
    return sval
546824
def strseq(prefix: str, first: int, last: int, suffix: str = "") -> List[str]:
    
    return [strnum(prefix, n, suffix) for n in range(first, last + 1)]
1337909
def build_substr_idx(umis, umi_length, min_edit):
    '''
    
    '''
    substr_idx = collections.defaultdict(
        lambda: collections.defaultdict(set))
    slices = get_substr_slices(umi_length, min_edit + 1)
    for idx in slices:
        for u in umis:
            u_sub = u[slice(*idx)]
            substr_idx[idx][u_sub].add(u)
    return substr_idx
1023118
def append_on_chord(self, on_chord, root):
        
        root_val = note_to_val(root)
        on_chord_val = note_to_val(on_chord) - root_val

        list_ = list(self.components)
        for idx, val in enumerate(list_):
            if val % 12 == on_chord_val:
                self.components.remove(val)
                break

        if on_chord_val > root_val:
            on_chord_val -= 12

        if on_chord_val not in self.components:
            self.components.insert(0, on_chord_val)
538731
function interpolation6(prefix, v0, i0, v1, i1, v2, i2, v3, i3, v4, i4, v5, suffix) {
    var different = bindingUpdated4(v0, v1, v2, v3);
    different = bindingUpdated2(v4, v5) || different;
    return different ?
        prefix + stringify$1(v0) + i0 + stringify$1(v1) + i1 + stringify$1(v2) + i2 + stringify$1(v3) + i3 +
            stringify$1(v4) + i4 + stringify$1(v5) + suffix :
        NO_CHANGE;
}
971487
function determine(chord, shorthand, no_inversions, no_polychords) {
	if(shorthand == null) {
		shorthand = false;
	}
	if(no_inversions == null) {
		no_inversions = false;
	}
	if(no_polychords == null) {
		no_polychords = false;
	}
	if(chord == []) {
		return [];
	} else if(chord.length == 1) {
		return chord;
	} else if(chord.length == 2) {
		return [intervals.determine(chord[0], chord[1])];
	} else if(chord.length == 3) {
		return determine_triad(chord, shorthand, no_inversions, no_polychords);
	} else if(chord.length == 4) {
		return determine_seventh(chord, shorthand, no_inversions, no_polychords);
	} else if(chord.length == 5) {
		return determine_extended_chord5(chord, shorthand, no_inversions, no_polychords);
	} else if(chord.length == 6) {
		return determine_extended_chord6(chord, shorthand, no_inversions, no_polychords);
	} else if(chord.length == 7) {
		return determine_extended_chord7(chord, shorthand, no_inversions, no_polychords);
	} else {
		return determine_polychords(chord, shorthand);
	}
}
614436
def apply_T5(word):  # BROKEN
    ''''''
    T5 = ''
    WORD = word.split('.')

    for i, v in enumerate(WORD):
        if contains_VVV(v) and any(i for i in i_DIPHTHONGS if i in v):
            I = v.rfind('i') - 1 or 2
            I = I + 2 if is_consonant(v[I - 1]) else I
            WORD[i] = v[:I] + '.' + v[I:]
            T5 = ' T5'

    word = '.'.join(WORD)

    return word, T5
1182071
def augment_or_diminish_until_the_interval_is_right(note1, note2, interval):
    
    cur = measure(note1, note2)
    while cur != interval:
        if cur > interval:
            note2 = notes.diminish(note2)
        elif cur < interval:
            note2 = notes.augment(note2)
        cur = measure(note1, note2)

    # We are practically done right now, but we need to be able to create the
    # minor seventh of Cb and get Bbb instead of B######### as the result
    val = 0
    for token in note2[1:]:
        if token == '#':
            val += 1
        elif token == 'b':
            val -= 1

    # These are some checks to see if we have generated too much #'s or too much
    # b's. In these cases we need to convert #'s to b's and vice versa.
    if val > 6:
        val = val % 12
        val = -12 + val
    elif val < -6:
        val = val % -12
        val = 12 + val

    # Rebuild the note
    result = note2[0]
    while val > 0:
        result = notes.augment(result)
        val -= 1
    while val < 0:
        result = notes.diminish(result)
        val += 1
    return result
239512
def apply_T7(word):
    ''''''
    WORD = _split_consonants_and_vowels(word)

    for k, v in WORD.iteritems():

        if len(v) == 3 and is_vowel(v[0]):
            WORD[k] = v[:2] + '.' + v[2:]

    word = _compile_dict_into_word(WORD)

    return word
238429
def _is_suffix(self, t):
        """"""
        return t not in NOT_SUFFIX and (t.replace('.', '') in SUFFIXES or t.replace('.', '') in SUFFIXES_LOWER)