def main(): init() tonic_progressions = [ p for p in rules.all_progressions if p[0] == "I" and p[-1] == "I" ] i = 0 while i < minRepeat or random() > 0.5: progression = choice(tonic_progressions) print " ".join(progression) progression = progression[:-1] chords = progressions.to_chords(progression, key) play_progression(chords) i = i + 1 play_basic_chord(ch.I(key))
def get_chord(prev_chord=None, key='A'): if prev_chord is None: return chords.tonic(key) hfunc = progressions.determine(prev_chord, key, True)[0] if hfunc == 'I': return choice([ chords.ii(key), chords.iii(key), chords.IV(key), chords.IV7(key), chords.V(key), chords.V7(key) ]) elif hfunc == 'ii': return choice([chords.iii(key), chords.V(key)]) elif hfunc == 'iii': return choice( [chords.ii(key), chords.IV(key), chords.IV7(key), chords.vi(key)]) elif hfunc == 'IV': return choice([ chords.I(key), chords.ii(key), chords.iii(key), chords.V(key), chords.V7(key) ]) elif hfunc == 'V': return choice([chords.I(key), chords.vi(key)]) elif hfunc == 'vi': return choice([chords.ii(key), chords.IV(key)]) else: return chords.I(key)
def ending(first_track, second_track, subject, key=r""): if not bool(key): key = 'C' canon_subject = shift(subject, 2) cadence = [chord.I(key), chord.IV(key), chord.V(key), chord.I(key)] notes = [] for note in canon_subject[-1]: if note[-1][0].name not in notes: notes.append(note[-1][0].name) bar = Bar(key=key) # Hitta om det finns ett ackord med de sista noterna i subjektet i, i så fall, komplettera det ackordet if len(notes) <= 2 or len(chord.determine(notes, True)) == 0: chord_notes = [intervals.fourth(notes[0], key)] else: subject_chord = chord.determine(notes, True)[0] chord_notes = chord.from_shorthand(subject_chord) if len(chord_notes) != len(notes): for note in notes: chord_notes.remove(note) else: chord_notes = chord_notes[0] bar.place_notes(chord_notes[random.randint(0, len(chord_notes) - 1)], 2) first_track.add_bar( bar) #Sätt något som passar med andra hälften av subjektet while second_track[ -1].current_beat < 1: #Placing fitting notes in second to last bar #print('test1') duration = 2**random.randint(1, 3) pitch = cadence[0][random.randint(1, len(cadence[0]) - 1)] # If the randomized duration doesn't fit in the bar, make it fit if 1 / duration > 1 - second_track[-1].current_beat: duration = 1 / (1 - second_track[-1].current_beat) # Place the new note in the bar second_track[-1].place_notes(pitch, duration) first_track[-1].place_notes(cadence[0][0], 2) bar = Bar(key=key) bar.place_notes(cadence[1][0], 2) bar.place_notes(cadence[2][0], 2) first_track.add_bar(bar) bar = Bar(key=key) bar.place_notes(cadence[3][0], 1) first_track.add_bar(bar) bar = Bar(key=key) while bar.current_beat < 0.5: #print('test2') # Randomize pitch and duration of each note. duration = 2**random.randint(1, 3) pitch = cadence[1][random.randint(1, len(cadence[1]) - 1)] # 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) while bar.current_beat < 1: #print('test3') duration = 2**random.randint(1, 3) pitch = cadence[2][random.randint(1, len(cadence[2]) - 1)] # 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) second_track.add_bar(bar) bar = Bar(key=key) bar.place_notes(cadence[3][2], 1) second_track.add_bar(bar)
''' Created on Jan 6, 2017 @author: stephenkoh ''' import mingus.core.chords as chords key = input('Please enter a key: ') song = [lambda x: chords.I(x), lambda x: chords.IV(x), lambda x: chords.V(x), lambda x: chords.I(x)] for i in range(len(song)): print(chords.determine(song[i](key), True)[0])