Пример #1
0
def determine(notes):
    """Determine the scales containing the notes.

    All major and minor scales are recognized.

    Example:
    >>> determine(['A', 'Bb', 'E', 'F#', 'G'])
    ['G melodic minor', 'G Bachian', 'D harmonic major']
    """
    notes = set(notes)
    res = []

    for key in keys:
        for scale in _Scale.__subclasses__():
            if scale.type == "major":
                if notes <= set(scale(key[0]).ascending()) or notes <= set(
                    scale(key[0]).descending()
                ):
                    res.append(scale(key[0]).name)
            elif scale.type == "minor":
                if notes <= set(scale(get_notes(key[1])[0]).ascending()) or notes <= set(
                    scale(get_notes(key[1])[0]).descending()
                ):
                    res.append(scale(get_notes(key[1])[0]).name)
    return res
Пример #2
0
def get_interval(note, interval, key='C'):
    """Return the note an interval (in half notes) away from the given note.

    This will produce mostly theoretical sound results, but you should use
    the minor and major functions to work around the corner cases.
    """
    intervals = list(
        map(lambda x: (notes.note_to_int(key) + x) % 12, [
            0,
            2,
            4,
            5,
            7,
            9,
            11,
        ]))
    key_notes = keys.get_notes(key)
    for x in key_notes:
        if x[0] == note[0]:
            result = (intervals[key_notes.index(x)] + interval) % 12
    if result in intervals:
        return key_notes[intervals.index(result)] + note[1:]
    else:
        return notes.diminish(key_notes[intervals.index((result + 1) % 12)] +
                              note[1:])
Пример #3
0
def sevenths(key):
    """Return all the sevenths chords in key in a list."""
    if _sevenths_cache.has_key(key):
        return _sevenths_cache[key]
    res = map(lambda x: seventh(x, key), keys.get_notes(key))
    _sevenths_cache[key] = res
    return res
Пример #4
0
 def test_get_notes(self):
     for k in self.scale:
         self.assertEqual(
             self.scale[k],
             keys.get_notes(k),
             "Invalid notes for key %s" % self.scale[k],
         )
Пример #5
0
def determine_scale(notes):
    """ Same as determine, but returns the scale object itself """
    notes = set(notes)
    res = []

    for key in all_keys:
        for scale in _Scale.__subclasses__():
            if scale.type == 'major':
                if (notes <= set(scale(key[0]).ascending()) or
                        notes <= set(scale(key[0]).descending())):
                    res.append(scale(key[0]))
            elif scale.type == 'minor':
                if (notes <= set(scale(get_notes(key[1])[0]).ascending()) or
                        notes <= set(scale(get_notes(key[1])[0]).descending())):
                    res.append(scale(get_notes(key[1])[0]))
    return res
Пример #6
0
def init_random_track(key, is_subject=True):
    notes = keys.get_notes(key)
    bar = Bar(key=key)
    while bar.current_beat < 1:
        # Randomize pitch and duration of each note.
        duration = 2**random.randint(1, 3)
        pitch = notes[random.randint(0, 6)]

        # If it is intened to be a subject, set the first note to the root.
        if bar.current_beat == 0 and is_subject == True:
            pitch = notes[0]

        # If the randomized duration doesn't fit in the bar, make it fit
        if 1 / duration > 1 - bar.current_beat:
            duration = 1 / (1 - bar.current_beat)

        # Place the new note in the bar
        bar.place_notes(pitch, duration)

    # Create a track to contain the randomized bar
    track = Track()
    track + bar

    # Return the track
    return track
Пример #7
0
def sevenths(key):
    """Return all the sevenths chords in key in a list."""
    if key in _sevenths_cache:
        return _sevenths_cache[key]
    res = list(map(lambda x: seventh(x, key), keys.get_notes(key)))
    _sevenths_cache[key] = res
    return res
Пример #8
0
def sevenths(key):
    """Return all the sevenths chords in key in a list."""
    if key in _sevenths_cache:
        return _sevenths_cache[key]
    res = [seventh(x, key) for x in keys.get_notes(key)]
    _sevenths_cache[key] = res
    return res
Пример #9
0
def determine_scale(notes):
    """ Same as determine, but returns the scale object itself """
    notes = set(notes)
    res = []

    for key in all_keys:
        for scale in _Scale.__subclasses__():
            if scale.type == 'major':
                if (notes <= set(scale(key[0]).ascending())
                        or notes <= set(scale(key[0]).descending())):
                    res.append(scale(key[0]))
            elif scale.type == 'minor':
                if (notes <= set(scale(get_notes(key[1])[0]).ascending())
                        or notes <= set(
                            scale(get_notes(key[1])[0]).descending())):
                    res.append(scale(get_notes(key[1])[0]))
    return res
Пример #10
0
 def ascending(self):
     try:
         notes = get_notes(
             self.tonic
         )  # this fails with G# (for ex), see mingus.core.keys.keys (i.e. missing in that list)
     except NoteFormatError:
         notes = Diatonic(self.tonic, (3, 7)).ascending()
     return notes * self.octaves + [notes[0]]
Пример #11
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]]
Пример #12
0
 def ascending(self):
     notes = [self.tonic]
     for note in get_notes(self.key)[1:] + [self.tonic]:
         if intervals.determine(notes[-1], note) == ('major second'):
             notes.append(augment(notes[-1]))
             notes.append(note)
         else:
             notes.append(note)
     notes.pop()
     return notes * self.octaves + [notes[0]]
Пример #13
0
def twelve_bar_blues_chord_progression(key):
    from mingus.core.harmony import MODE_CHORD_FUNCTIONS
    key_notes = get_notes(key)
    aChord = chords.create_dominant_seventh_symbol(key)
    bChord = chords.create_dominant_seventh_symbol(key_notes[3])
    cChord = chords.determine_seventh(MODE_CHORD_FUNCTIONS[1](key), shorthand=True)[0]
    dChord = chords.determine_seventh(MODE_CHORD_FUNCTIONS[4](key), shorthand=True)[0]
    return [aChord, bChord, aChord, aChord,
            bChord, bChord, aChord, aChord,
            cChord, dChord, aChord, aChord]
Пример #14
0
def triads(key):
    """Return all the triads in key.

    Implemented using a cache.
    """
    if key in _triads_cache:
        return _triads_cache[key]
    res = list(map(lambda x: triad(x, key), keys.get_notes(key)))
    _triads_cache[key] = res
    return res
Пример #15
0
def triads(key):
    """Return all the triads in key.

    Implemented using a cache.
    """
    if _triads_cache.has_key(key):
        return _triads_cache[key]
    res = map(lambda x: triad(x, key), keys.get_notes(key))
    _triads_cache[key] = res
    return res
Пример #16
0
 def ascending(self):
     notes = [self.tonic]
     for note in get_notes(self.key)[1:] + [self.tonic]:
         if intervals.determine(notes[-1], note) == ('major second'):
             notes.append(augment(notes[-1]))
             notes.append(note)
         else:
             notes.append(note)
     notes.pop()
     return notes * self.octaves + [notes[0]]
Пример #17
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]]
Пример #18
0
def triads(key):
    """Return all the triads in key.

    Implemented using a cache.
    """
    if key in _triads_cache:
        return _triads_cache[key]
    res = [triad(x, key) for x in keys.get_notes(key)]
    _triads_cache[key] = res
    return res
Пример #19
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
Пример #20
0
def determine(notes):
    """Determine the scales containing the notes.

    All major and minor scales are recognized.

    Example:
    >>> determine(['A', 'Bb', 'E', 'F#', 'G'])
    ['G melodic minor', 'G Bachian', 'D harmonic major']
    """
    notes = set(notes)
    res = []

    for key in keys:
        for scale in _Scale.__subclasses__():
            if scale.type == 'major':
                if (notes <= set(scale(key[0]).ascending()) or
                        notes <= set(scale(key[0]).descending())):
                    res.append(scale(key[0]).name)
            elif scale.type == 'minor':
                if (notes <= set(scale(get_notes(key[1])[0]).ascending()) or
                        notes <= set(scale(get_notes(key[1])[0]).descending())):
                    res.append(scale(get_notes(key[1])[0]).name)
    return res
Пример #21
0
def count_notes_in_scale(track, key):
    total_nr_of_notes = 0
    notes_in_scale = 0
    scale_notes = keys.get_notes(key)
    notes = track.get_notes()
    for note_container in notes:
        if note_container[-1] is None:
            total_nr_of_notes += 1
            continue
        note = note_container[-1][0]
        total_nr_of_notes += 1
        if note.name in scale_notes:
            notes_in_scale += 1

    return notes_in_scale / total_nr_of_notes
Пример #22
0
def interval(key, start_note, interval):
    """Return the note found at the interval starting from start_note in the
    given key.

    Raise a KeyError exception if start_note is not a valid note.

    Example:
    >>> interval('C', 'D', 1)
    'E'
    """
    if not notes.is_valid_note(start_note):
        raise KeyError("The start note '%s' is not a valid note" % start_note)
    notes_in_key = keys.get_notes(key)
    for n in notes_in_key:
        if n[0] == start_note[0]:
            index = notes_in_key.index(n)
    return notes_in_key[(index + interval) % 7]
Пример #23
0
def interval(key, start_note, interval):
    """Return the note found at the interval starting from start_note in the
    given key.

    Raise a KeyError exception if start_note is not a valid note.

    Example:
    >>> interval('C', 'D', 1)
    'E'
    """
    if not notes.is_valid_note(start_note):
        raise KeyError("The start note '%s' is not a valid note" % start_note)
    notes_in_key = keys.get_notes(key)
    for n in notes_in_key:
        if n[0] == start_note[0]:
            index = notes_in_key.index(n)
    return notes_in_key[(index + interval) % 7]
Пример #24
0
def get_interval(note, interval, key='C'):
    """Return the note an interval (in half notes) away from the given note.

    This will produce mostly theoretical sound results, but you should use
    the minor and major functions to work around the corner cases.
    """
    intervals = list(map(lambda x: (notes.note_to_int(key) + x) % 12, [
        0,
        2,
        4,
        5,
        7,
        9,
        11,
        ]))
    key_notes = keys.get_notes(key)
    for x in key_notes:
        if x[0] == note[0]:
            result = (intervals[key_notes.index(x)] + interval) % 12
    if result in intervals:
        return key_notes[intervals.index(result)] + note[1:]
    else:
        return notes.diminish(key_notes[intervals.index((result + 1) % 12)]
                               + note[1:])
Пример #25
0
'''
Created on Jan 6, 2017

@author: stephenkoh
'''

import mingus.core.keys as keys
import mingus.core.notes as notes

while (True):
    key = str(input('Please enter a key: '))
    keyz = keys.get_notes(key)
    #print(keys)
    for i in range(len(keyz)):
        keyz[i] = notes.augment(keyz[i])
    print(keyz)
Пример #26
0
 def get_question(self):
     return SingleNote(random.choice(keys.get_notes('C')))
Пример #27
0
 def __init__(self, key, octaves=1):
     """Create the chromatic scale in the chosen key."""
     self.key = key
     self.tonic = get_notes(key)[0]
     self.octaves = octaves
     self.name = '{0} chromatic'.format(self.tonic)
Пример #28
0
 def test_get_notes(self):
     for k in self.scale.keys():
         self.assertEqual(self.scale[k], keys.get_notes(k),
         'Invalid notes for key %s' % self.scale[k])
Пример #29
0
 def ascending(self):
     notes = get_notes(self.tonic.lower())
     return notes * self.octaves + [notes[0]]
Пример #30
0
 def test_get_notes(self):
     for k in self.scale.keys():
         self.assertEqual(self.scale[k], keys.get_notes(k),
                          'Invalid notes for key %s' % self.scale[k])
Пример #31
0
 def __init__(self, key, octaves=1):
     """Create the chromatic scale in the chosen key."""
     self.key = key
     self.tonic = get_notes(key)[0]
     self.octaves = octaves
     self.name = '{0} chromatic'.format(self.tonic)
Пример #32
0
def write_song(melody):
    unl = keys.get_notes(melody.key)
    note_list = randomList()
    note_list.setDefaultWeight(100)
    note_list.add(unl, recursive=True)
    note_list.add(None, (random.gauss(25, 10)))
    print(note_list.normalisedWeights())
    print(note_list.list)

    wds = randomList()
    td = melody.tempo - 120.0
    #scaling for these is kinda wonky but whatever
    full = 0
    half = 0
    quarter = 0
    eighth = 0
    sixteenth = 0
    if (td < 0):
        #half notes - more often (180) for faster tempos, less often (90) for slower tempos
        half = max(0, random.gauss(120.0 + (td / 2), 60))
        #full notes - 1.25x as often for faster tempos, half as often for slower tempos
        full = max(0, random.gauss((120.0 + (td / 2)) / 2, 60))
        #sixteenth notes - less often (90) for faster tempos, more often (180) for slower tempos
        sixteenth = max(0, random.gauss((120.0 - td), 60))
    else:
        half = max(0, random.gauss(120.0 + (td / 2), 60))
        full = max(0, random.gauss((120.0 + (td / 2)) * 1.25, 60))
        sixteenth = max(0, random.gauss((120.0 - (td / 4)), 60))

    #quarter notes - 120 median always
    quarter = max(0, random.gauss(120, 60))
    #eighth notes - 120 median always
    eighth = max(0, random.gauss(120, 60))

    wds.add(1, full)
    wds.add(2, half)
    wds.add(4, quarter)
    wds.add(8, eighth)
    wds.add(16, sixteenth)

    melody.weights = wds.normalisedWeights()
    sig = random.choice(signatures)
    print(sig)

    t = Track()
    i = 0
    numBars = melody.length

    while (i < numBars):
        b = Bar(melody.key, sig)
        while (b.current_beat != b.length):
            duration = wds.pickWeighted()
            n = note_list.pickWeighted()
            while (n == None
                   and (duration <= 2 or duration > 8 or b.current_beat == 0
                        or melody.raw_song[-1][0] == None)):
                n = note_list.pickWeighted()
            if (b.place_notes(n, duration)):
                melody.raw_song.append((n, duration))
        t.add_bar(b)
        i = i + 1
    return t
Пример #33
0
 def ascending(self):
     notes = get_notes(self.tonic.lower())
     return notes * self.octaves + [notes[0]]
Пример #34
0
                                 settings.large_font[1])
bg = pygame.image.load(settings.bg_image)
screen = pygame.display.set_mode(
    [settings.width + settings.panel_width, settings.height])
pygame.display.set_caption('Airwaves')

radar = (width, height) = (settings.width, settings.height)
radar_rect = pygame.Rect((0, 0) + radar)
radar_surface = pygame.Surface(radar)

dimensions = (width, height) = (settings.panel_width, settings.height)
panel_surface = pygame.Surface(dimensions)

infopanel = panel.infopanel(pygame, font, panel_surface, screen)
infopanel.init_display()
key = keys.get_notes(key=settings.initial_key)
scale = objects.scale(key)
plotter = plotter.plotter(screen, radar_surface, map, scale, infopanel, font,
                          font_large)

# main loop
while running:

    # loop unless quit detected
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # draw background
    radar_surface.blit(bg, settings.home_xy)
    pygame.draw.circle(radar_surface, (settings.green),
Пример #35
0
import mingus.core.notes as notes
import mingus.core.keys as keys
import mingus.core.intervals as intervals

print(notes.is_valid_note('C#'))
print(notes.int_to_note(0))  # [0,..,11]

print(keys.get_notes("C"))

print(intervals.second("E", "C"))
print(intervals.determine("Gbb", "Ab"))
print(intervals.determine("Gbb", "Ab", True))
print(intervals.measure("C", "D"))
print(intervals.measure("D", "C"))