예제 #1
0
 def test_reduce_accidentals(self):
     known = {
             'C': 'C',
             'F#': 'F#',
             'Bb': 'Bb',
             'G##': 'A',
             'Abb': 'G',
             'B##': 'C#',
             'C####': 'E'
             }
     for k in known.keys():
         self.assertEqual(known[k], notes.reduce_accidentals(k),
                 'The reduced note of %s is not %s, expecting %s' % (k,
                     notes.reduce_accidentals(k), known[k]))
예제 #2
0
 def test_reduce_accidentals(self):
     known = {
         'C': 'C',
         'F#': 'F#',
         'Bb': 'Bb',
         'G##': 'A',
         'Abb': 'G',
         'B##': 'C#',
         'C####': 'E'
     }
     for k in known.keys():
         self.assertEqual(
             known[k], notes.reduce_accidentals(k),
             'The reduced note of %s is not %s, expecting %s' %
             (k, notes.reduce_accidentals(k), known[k]))
예제 #3
0
    def test_get_scale_patterns(self):

        from sidewinder.melodies.patterns import get_scale_patterns as g
        from sidewinder.utilities import cycle_of_fifths
        from mingus.core.notes import reduce_accidentals

        asc = [1, 3, 5, 7, 4, 11, 8]
        target = ['C', 'E', 'G', 'B', 'F#', 'F#', 'C']
        result = g('lydian', p=asc, keys=cycle_of_fifths('C'))['C']

        conds = [result[0][i].name == target[i] for i, _ in enumerate(target)]

        target = ['D', 'F', 'G#', 'C', 'F#', 'F#', 'D']
        result = g('altered', p=asc, keys=['D'])['D']
        #print([reduce_accidentals(result[0][i].name) for i,_ in enumerate(target)])

        conds += [
            reduce_accidentals(result[0][i].name) == target[i]
            for i, _ in enumerate(target)
        ]
        conds += [result[0][4].octave == result[0][5].octave - 1]

        for cond in conds:
            #   print(cond)
            assert cond
예제 #4
0
 def test_reduce_accidentals(self):
     known = {
         "C": "C",
         "F#": "F#",
         "Bb": "Bb",
         "G##": "A",
         "Abb": "G",
         "B##": "C#",
         "C####": "E",
     }
     for k in known:
         self.assertEqual(
             known[k],
             notes.reduce_accidentals(k),
             "The reduced note of %s is not %s, expecting %s" %
             (k, notes.reduce_accidentals(k), known[k]),
         )
예제 #5
0
    def ascending(self):
        notes = [self.tonic]
        current_note = self.tonic
        for ival in BLUES_INTERVALS:
            new_note = reduce_accidentals(ival(current_note))
            notes.append(new_note)
            current_note = new_note

        return notes
예제 #6
0
    def ascending(self):
        notes = [self.tonic]
        current_note = self.tonic
        for ival in BLUES_INTERVALS:
            new_note = reduce_accidentals(ival(current_note))
            notes.append(new_note)
            current_note = new_note

        return notes
예제 #7
0
 def descending(self):
     notes = [self.tonic]
     for note in reversed(get_notes(self.key)):
         if intervals.determine(note, notes[-1]) == ('major second'):
             notes.append(reduce_accidentals(diminish(notes[-1])))
             notes.append(note)
         else:
             notes.append(note)
     notes.pop()
     return notes * self.octaves + [notes[0]]
예제 #8
0
 def descending(self):
     notes = [self.tonic]
     for note in reversed(get_notes(self.key)):
         if intervals.determine(note, notes[-1]) == ('major second'):
             notes.append(reduce_accidentals(diminish(notes[-1])))
             notes.append(note)
         else:
             notes.append(note)
     notes.pop()
     return notes * self.octaves + [notes[0]]
예제 #9
0
    def loop(self):
        buffer = self._stream.read(self._bufferSize)

        self.pitchTracker.Q.put(buffer)

        pitch = int(round(self.pitchTracker.pitch))

        if self.key != "":
            key = self.key[0]
            majorMinor = self.key[-5:]

            # Generate scale from key
            if majorMinor == "major":
                scale = scales.get_notes(key)
            else:
                scale = scales.get_notes(notes.reduce_accidentals(key + "###"))
                scale[4] = notes.reduce_accidentals(scale[4] + "#")

            note = notes.reduce_accidentals(notes.int_to_note(pitch % 12))
            if not note in scale:
                minDiff = 1000
                dPitch = 0
                for n in scale:
                    diff = abs(notes.note_to_int(n) - notes.note_to_int(note))
                    if diff < minDiff:
                        minDiff = diff
                        dPitch = notes.note_to_int(n) - notes.note_to_int(note)
                pitch += dPitch
            print(pitch)

            if pitch > 10:
                self._noAudio = 0
                self._maxLive.send_message("/pitch", pitch)
                self._maxLive.send_message("/key", notes.note_to_int(key))
            else:
                self._noAudio += 1
                print("*** No Audio! " + str(self._noAudio))
                if self._noAudio > 100:
                    self.done.set()
                    self.terminate()

        time.sleep(0.00001)
예제 #10
0
 def note_validity_chk_redundancy_remover(self, note):
     '''
     Objective: Check if note is valid or not; if so remove any redundancy from the note
     '''
     if M_notes.is_valid_note(note):
         note1 = M_notes.reduce_accidentals(
             M_notes.remove_redundant_accidentals(note))
         if self.__original_notation_intact(note) not in note1:
             return (note, True)
         else:
             return (note1, True)
     return (note, False)
예제 #11
0
def make_ascending(chord, octave=4):
    reduced_chord = [notes.reduce_accidentals(n) for n in chord]

    new_chord = [_add_octave_to_name(reduced_chord[0], octave)]
    for i in range(1, len(chord)):
        if reduced_chord[i - 1] == 'C' and reduced_chord[i] != 'C':
            pass
        elif intervals.measure(chord[i - 1], chord[i]) == intervals.measure(
                chord[i - 1], 'C') + intervals.measure('C', chord[i]):
            octave += 1
        new_chord.append(_add_octave_to_name(reduced_chord[i], octave))

    return _rewrite_names(new_chord, chord)
예제 #12
0
def transpose_to_relative_minor(track, original_key, harmonic):
    transposed_track = copy.deepcopy(track)
    if original_key in keys.major_keys:
        old_scale = keys.get_notes(original_key)
        new_key = keys.relative_minor(original_key)
        new_scale = keys.get_notes(new_key)

        if harmonic:
            new_scale[6] = notes.augment(new_scale[6])
            new_scale[6] = notes.reduce_accidentals(new_scale[6])

        input_notes = transposed_track.get_notes()
        for bar in input_notes:

            #Check if the nc contained in the bar/"note" is a pause, then do nothing
            nc = bar[-1]
            if nc is None:
                continue

            #Otherwise
            else:
                #For every actual note in the note containers (important if there is a chord)
                for note in nc:
                    #old_note = copy.deepcopy(note)
                    if note.name in old_scale:
                        index = old_scale.index(note.name)
                        note.name = new_scale[index]

                    else:
                        note.transpose("b3")
                        note.name = notes.reduce_accidentals(note.name)

                    # Fix octaves
                    if note.name[0] == 'A' or note.name[0] == 'B':
                        note.octave_down()

    else:
        print("input key is not major key")
    return transposed_track
예제 #13
0
    def ascending(self):
        tonic = self.tonic
        notes = []
        for i in range(self.octaves * 2):
            notes += [
                reduce_accidentals(note)
                for note in list(Lydian(tonic).ascending()[:4])
            ]  # 4 creates overlap on the fifth
            tonic = intervals.perfect_fifth(tonic)

        if self.octaves == 1:
            return notes
        else:
            return notes[:1 - self.octaves]
예제 #14
0
    def descending(self):
        tonic = self.tonic
        notes = []
        for i in range(self.octaves * 3):
            notes += [
                reduce_accidentals(note)
                for note in list(Lydian(tonic).descending()[:3])
            ]  # 3 = 7 - 4
            tonic = intervals.perfect_fifth(tonic)

        if self.octaves == 1:
            return notes[:-1]
        else:
            return notes[:-1 - self.octaves]
예제 #15
0
    def descending(self):
        tonic = self.tonic
        notes = []
        for i in range(self.octaves * 2):
            notes += [
                reduce_accidentals(note)
                for note in list(Mixolydian(tonic).descending()[:4])
            ]
            tonic = intervals.perfect_fourth(tonic)

        if self.octaves == 1:
            return notes
        else:
            return notes[:-self.octaves]
    def loop(self):
        if self.beatTracker and self.pitchTracker and self.keyDetector:
            if self.keyDetector.key != "" and self.beatTracker.bpm > 0:
                # Grab current data
                pitches = self.pitchTracker.pitches[:]
                beats = self.beatTracker.beatTimes[:]
                bpm = self.beatTracker.bpm
                spb = self.beatTracker.spb
                key = self.keyDetector.key[0]
                majorMinor = self.keyDetector.key[-5:]

                # Generate scale from key
                if majorMinor == "major":
                    scale = scales.get_notes(key)
                else:
                    scale = scales.get_notes(
                        notes.reduce_accidentals(key + "###"))
                    scale[4] = notes.reduce_accidentals(scale[4] + "#")

                # Divide pitch data into packets with the help of beat data
                packets = []
                packet = []
                beat = 0
                for pitchData in pitches:
                    if pitchData[2] < beats[beat]:
                        packet.append(pitchData)
                    else:
                        if len(packet) > 0:
                            packets.append(packet)
                        packet = [pitchData]
                        if beat < len(beats) - 1:
                            beat += 1

                # Turn each packet into consistent notes
                f = open("testdata.py", 'w')
                f.write(repr(packets))
                f.close()
예제 #17
0
def cycle_of_fifths(start='C', repeats=0):
    preferred_accidentals = {'C#': 'Db', 'G#': 'Ab', 'D#': 'Eb', 'A#': 'Bb'}
    out = []
    repeat_counter = 0
    next_note = start
    while repeat_counter <= repeats:
        out.append(next_note)
        next_note = notes.reduce_accidentals(
            intervals.perfect_fifth(next_note))
        if str(next_note) == start:
            repeat_counter += 1
    return [
        preferred_accidentals[note]
        if note in preferred_accidentals.keys() else note for note in out
    ]
예제 #18
0
    def ascending(self, l=None):
        tonic = self.tonic
        if l is None:
            l = self.octaves * 3
        for i in range(l):
            notes += [
                reduce_accidentals(note)
                for note in list(Mixolydian(tonic).ascending()[:3])
            ]
            tonic = intervals.perfect_fourth(tonic)

        if self.octaves == 1:
            return notes[:-1]
        else:
            return notes[:-self.octaves]
예제 #19
0
def _rewrite_name(note_with_octave, note_name):
    current_note, octave = note_with_octave.split('-')
    octave = int(octave)

    assert current_note == notes.reduce_accidentals(
        current_note), 'current_note: ' + current_note
    assert notes.is_enharmonic(current_note, note_name)

    ## assuming sharps, flats, double sharps, and double flats are the only accidentals
    ## <note_name> could have, then these are the only edges cases of interest:
    if current_note[0] == 'B' and note_name[0] == 'C':
        return _add_octave_to_name(note_name, octave + 1)
    elif current_note[0] == 'C' and note_name[0] == 'B':
        return _add_octave_to_name(note_name, octave - 1)
    else:
        return _add_octave_to_name(note_name, octave)
예제 #20
0
            determine_key_and_function(chord)

    elif args.action == 'tritone_substitution':
        for chord in args.chords:
            new_chord, new_notes = tritone_substitution(chord)
            print("The tritone substitution of {} is {} ({})".format(chord, new_chord, ', '.join(new_notes)))

    elif args.action == 'reharmonize_v_to_ii_v':
        for chord in args.chords:
            ii_chord_type_short, chord = reharmonize_v_to_ii_v(chord)
            print("II-V ({}, {})".format(ii_chord_type_short, chord))

    elif args.action == 'ii_v_tritone_substitution':
        for chord in args.chords:
            chord_notes = chords.from_shorthand(chord)
            new_note = reduce_accidentals(tritone(chord_notes[0]))
            new_chord = new_note + '7'

            ii_chord_type_short, chord = reharmonize_v_to_ii_v(new_chord)
            print("{} {}".format(ii_chord_type_short, new_chord))

    elif args.action == 'chord_modes':
        chords = [chords.determine_seventh(mode_func(args.key), shorthand=True)[0]
                  for mode_func in MODE_CHORD_FUNCTIONS]
        print(', '.join(chords))

    elif args.action == '12_bar_blues':
        for four_bars in twelve_bar_blues(args.key):
            print('\t'.join(four_bars))

    elif args.action == 'blues_scale':
예제 #21
0
def tritone_substitution(chord):
    chord_notes = chords.from_shorthand(chord)
    new_note = reduce_accidentals(tritone(chord_notes[0]))
    new_chord = new_note + '7'
    new_notes = chords.from_shorthand(new_chord)
    return new_chord, new_notes
예제 #22
0
def blues_scale(key):
    yield key
    for interval_fn in BLUES_INTERVAL:
        yield reduce_accidentals(interval_fn(key))
예제 #23
0
def scratch():
    import mingus.core.notes as notes
    print notes.reduce_accidentals('B#')  ## output is 'C'

    print notes.remove_redundant_accidentals('C###############')
    print notes.diminish('C##############')
예제 #24
0
 def reduce_accidentals(self):
     """Call notes.reduce_accidentals on this note's name"""
     self.name = notes.reduce_accidentals(self.name)
예제 #25
0
    def generate(self,
                 length,
                 ascending=True,
                 start_degree=1,
                 undulating=False,
                 starting_octave=4):
        """

        Generate given number of notes from the scale, either continuously rising or falling or as
        an undulating wave (i.e., up an octave, then down, then up again, etc.)

        >>> list(Blues('F').generate(length=9))
        ['F', 'Ab', 'Bb', 'B', 'C', 'Eb', 'F', 'Ab', 'Bb']

        >>> list(Blues('F').generate(length=7, undulating=True))
        ['F', 'Ab', 'Bb', 'B', 'C', 'Eb', 'F']

        >>> [repr(note) for note in Blues('F').generate(length=13, undulating=True, starting_octave=1)]
        ["'F-1'", "'Ab-1'", "'Bb-1'", "'B-1'", "'C-1'", "'Eb-1'", "'F-2'", "'Eb-1'", "'C-1'", "'B-1'", "'Bb-1'", "'Ab-1'", "'F-1'"]
        """
        wave = (self.ascending()[:-1] +
                self.descending()[:-1]) if ascending else (
                    self.descending()[:-1] + self.ascending()[:-1])
        incline = (self.ascending() if ascending else self.descending())[:-1]
        alternating_octaves = cycle(
            [starting_octave, starting_octave +
             1]) if starting_octave is not None else None

        # I just want simple monotonic octaves
        seen_notes = {}

        # create offsets from C to our start point so that our notes have offsets of: start(0),... C(+1), C#(+1), D(+1),... (i.e. C crosses into next octave)
        enharmonic_chromatics = [
            'C', 'B#', 'C#', 'Db', 'D', 'D#', 'Eb', 'E', 'Fb', 'E#', 'F', 'F#',
            'Gb', 'G', 'G#', 'Ab', 'A', 'A#', 'Bb', 'B', 'Cb'
        ]
        # account for the fact that Cb-4 is a half step below C-4 even though it sounds the same as B-3; similarly for B# http://openmusictheory.com/pitches.html
        seen_notes['Cb'] = 0
        seen_notes['B#'] = 0
        for n in enharmonic_chromatics[:enharmonic_chromatics.index(
                reduce_accidentals(list(wave if undulating else incline)[0]))]:
            seen_notes[n] = 1
        seen_notes['Cb'] += 1
        seen_notes['B#'] -= 1

        def times_seen_previously(x, counter_dict={}):
            try:
                counter_dict[x] += 1
                return counter_dict[x] - 1
            except KeyError:
                counter_dict[x] = 1
                return 0

        for key in cycle(wave if undulating else incline):
            #octave = starting_octave if (key !=  self.tonic or starting_octave is None) else next(alternating_octaves)
            octave = starting_octave + times_seen_previously(
                key, seen_notes) * (
                    -1 + 2 * ascending) if starting_octave is not None else 0
            yield TemporalNote(
                key, octave=octave) if starting_octave is not None else key
            length -= 1
            if length == 0:
                break
예제 #26
0
def blues_scale(key):
    yield key
    for interval_fn in BLUES_INTERVAL:
        yield reduce_accidentals(interval_fn(key))
예제 #27
0
def tritone_substitution(chord):
    chord_notes = chords.from_shorthand(chord)
    new_note = reduce_accidentals(tritone(chord_notes[0]))
    new_chord = new_note + '7'
    new_notes = chords.from_shorthand(new_chord)
    return new_chord, new_notes
예제 #28
0
    elif args.action == 'tritone_substitution':
        for chord in args.chords:
            new_chord, new_notes = tritone_substitution(chord)
            print("The tritone substitution of {} is {} ({})".format(
                chord, new_chord, ', '.join(new_notes)))

    elif args.action == 'reharmonize_v_to_ii_v':
        for chord in args.chords:
            ii_chord_type_short, chord = reharmonize_v_to_ii_v(chord)
            print("II-V ({}, {})".format(ii_chord_type_short, chord))

    elif args.action == 'ii_v_tritone_substitution':
        for chord in args.chords:
            chord_notes = chords.from_shorthand(chord)
            new_note = reduce_accidentals(tritone(chord_notes[0]))
            new_chord = new_note + '7'

            ii_chord_type_short, chord = reharmonize_v_to_ii_v(new_chord)
            print("{} {}".format(ii_chord_type_short, new_chord))

    elif args.action == 'chord_modes':
        chords = [
            chords.determine_seventh(mode_func(args.key), shorthand=True)[0]
            for mode_func in MODE_CHORD_FUNCTIONS
        ]
        print(', '.join(chords))

    elif args.action == '12_bar_blues':
        for four_bars in twelve_bar_blues(args.key):
            print('\t'.join(four_bars))