def test_triad(self): self.assertEqual(["C", "E", "G"], chords.triad("C", "C")) self.assertEqual(["C", "Eb", "G"], chords.triad("C", "Eb"))
def generate_triad_container(self, number, key): scale = scales.diatonic(key) pos = number % len(scale) triad = chords.triad(scale[pos], key) return NoteContainer(triad)
def test_triad(self): self.assertEqual(['C', 'E', 'G'], chords.triad('C', 'C')) self.assertEqual(['C', 'Eb', 'G'], chords.triad('C', 'Eb'))
# $ sudo pip install mingus # # Download ChoriumRevA and unpack in this folder: # http://www.hammersound.com/cgi-bin/soundlink.pl?action=view_download_page;ID=733;SoundFont_Location_Selected=Download%20USA;SoundFont_Filename_Selected=ChoriumRevA.rar # (this is a webpage, don't try wget) from random import shuffle from mingus.midi import fluidsynth from mingus.core import chords from mingus.containers import Bar, Track from mingus.containers.Instrument import MidiInstrument fluidsynth.init("ChoriumRevA/ChoriumRevA.SF2", "alsa") tr = lambda note: chords.triad(note, "C") # that's stupid # http://www.youtube.com/watch?v=5pidokakU4I prg = [tr("C"), tr("G"), tr("A"), tr("F")] bars = [] for chord in prg: b = Bar() b.place_notes(chord, 4) bars.append(b) t = Track()
def generate_end_bars(previews_bar, previews_bar_notes, pattern_index, key, mode): # on genere deux mesures de fin # previews_bar = format de la bdd nb_notes = get_nb_notes(previews_bar) first_bar = Bar() last_bar = Bar() last_index = len(previews_bar_notes)-1 last_note = previews_bar_notes[last_index] for i in range(1, nb_notes[0]): time = first_bar.current_beat + 1 list_compatible = get_compatible_notes(pattern_index, previews_bar_notes, key, time) list_length = get_max_length_note(first_bar, nb_notes[0]-i) best_notes = get_best_notes(list_compatible, last_note) chosen_note = best_notes[random.randint(0, len(best_notes)-1)] chosen_length = list_length[random.randint(0, len(list_length)-1)] first_bar.place_notes(chosen_note.name, chosen_length) if first_bar.length - first_bar.current_beat != 0 : print("ajout de silence") space_left = 1.0 / (first_bar.length - first_bar.current_beat) first_bar.place_rest(space_left) for i in range(1, nb_notes[1]): time = last_bar.current_beat + 1 list_compatible = get_compatible_notes(pattern_index, previews_bar_notes, key, time) list_length = get_max_length_note(last_bar, nb_notes[1]-i) best_notes = get_best_notes(list_compatible, last_note) chosen_note = best_notes[random.randint(0, len(best_notes)-1)] chosen_length = list_length[random.randint(0, len(list_length)-1)] #chosen_note.octave chord_possible = [] chord_possible.append(intervals.unison(key, key)) chord_possible.append(intervals.fourth(key, key)) chord_possible.append(intervals.fifth(key, key)) intervals_last = [] for note_possible in chord_possible : test = [] test.append(intervals.measure(note_possible, last_note.name)) test.append(intervals.measure(last_note.name, note_possible)) intervals_last.append(min(test)) for i,j in enumerate(intervals_last) : if j == min(intervals_last) : index = i break chosen_chord = chord_possible[index] if mode == "mixolydien" : chord = chords.triad(chosen_chord, key) chord_list = [] for note in chord : note_m = Note(note, chosen_note.octave) chord_list.append(note_m) last_note = note_m last_bar.place_notes(chord_list, chosen_length) else : chord = chords.triad(chosen_chord, key) chord_list = [] for note in chord : note_m = Note(note, chosen_note.octave) last_note = note_m chord_list.append(note_m) last_bar.place_notes(chord_list, chosen_length) if last_bar.length - last_bar.current_beat != 0 : print("ajout de silence") space_left = 1.0 / (last_bar.length - last_bar.current_beat) last_bar.place_rest(space_left) return [first_bar, last_bar]