def test_seconds(self): secs_c = {'C': 'D', 'E': 'F', 'D': 'E'} secs_fsharp = {'F#': 'G#', 'A#': 'B', 'E#': 'F#'} list(map(lambda x: self.assertEqual(secs_c[x], intervals.second(x, 'C'), 'Invalid second for %s in key C' % x), list(secs_c.keys()))) list(map(lambda x: self.assertEqual(secs_fsharp[x], intervals.second(x, 'F#' ), 'Invalid second for %s in key F#' % x), list(secs_fsharp.keys())))
def test_seconds(self): secs_c = {"C": "D", "E": "F", "D": "E"} secs_fsharp = {"F#": "G#", "A#": "B", "E#": "F#"} for x in secs_c: self.assertEqual( secs_c[x], intervals.second(x, "C"), "Invalid second for %s in key C" % x, ) for x in secs_fsharp: self.assertEqual( secs_fsharp[x], intervals.second(x, "F#"), "Invalid second for %s in key F#" % x, )
def test_seconds(self): secs_c = { "C": "D", "E": "F", "D": "E" } secs_fsharp = { "F#" : "G#", "A#" : "B", "E#" : "F#" } map(lambda x: self.assertEqual(secs_c[x], intervals.second(x, "C"),\ "Invalid second for %s in key C" % x), secs_c.keys()) map(lambda x: self.assertEqual(secs_fsharp[x],\ intervals.second(x, "F#"),"Invalid second for %s in key F#"\ % x), secs_fsharp.keys())
def playProgression(): progression = ["I", "vi", "ii", "iii7", "I7", "viidom7", "iii7", "V7"] key = "C" chords = progressions.to_chords(progression, key) if not fluidsynth.init(SF2): print "Couldn't load soundfont", SF2 sys.exit(1) while 1: i = 0 for chord in chords: c = NoteContainer(chords[i]) l = Note(c[0].name) p = c[1] l.octave_down() print ch.determine(chords[i])[0] # Play chord and lowered first note fluidsynth.play_NoteContainer(c) fluidsynth.play_Note(l) time.sleep(1.0) # Play highest note in chord fluidsynth.play_Note(c[-1]) # 50% chance on a bass note if random() > 0.5: p = Note(c[1].name) p.octave_down() fluidsynth.play_Note(p) time.sleep(0.50) # 50% chance on a ninth if random() > 0.5: l = Note(intervals.second(c[0].name, key)) l.octave_up() fluidsynth.play_Note(l) time.sleep(0.25) # 50% chance on the second highest note if random() > 0.5: fluidsynth.play_Note(c[-2]) time.sleep(0.25) fluidsynth.stop_NoteContainer(c) fluidsynth.stop_Note(l) fluidsynth.stop_Note(p) i += 1 print "-" * 20
def get_note_pattern(pattern, key): if pattern[0] == 1 : note = intervals.unison(key) elif pattern[0] == 2 : note = intervals.second(key, key) elif pattern[0] == 3 : note = intervals.third(key, key) elif pattern[0] == 4 : note = intervals.fourth(key, key) elif pattern[0] == 5 : note = intervals.fifth(key, key) elif pattern[0] == 6 : note = intervals.sixth(key, key) elif pattern[0] == 7 : note = intervals.seventh(key, key) if pattern[3] == "bemol": note = notes.diminish(note) elif pattern[3] == "diese" : note = notes.augment(note) return note
def play_chord(chord): c = play_basic_chord(chord) # Play highest note in chord fluidsynth.play_Note(c[-1]) # 50% chance on a bass note if random() > 0.5: p = Note(c[1].name) p.octave_down() fluidsynth.play_Note(p) time.sleep(0.50) # 50% chance on a ninth if random() > 0.5: p = Note(intervals.second(c[0].name, key)) p.octave_up() fluidsynth.play_Note(p) time.sleep(0.25) # 50% chance on the second highest note if random() > 0.5: fluidsynth.play_Note(c[-2]) time.sleep(0.25)
if double_time: beats = [random() > 0.5 for x in range((loop % 2 + 1) * 8)] else: beats = [random() > 0.5 for x in range(8)] t = 0 for beat in beats: # Play random note if beat and play_solo and loop > solo_start and loop < solo_end: fluidsynth.stop_Note(n) if t % 2 == 0: n = Note(choice(c).name) elif random() > 0.5: if random() < 0.46: n = Note(intervals.second(choice(c).name, key)) elif random() < 0.46: n = Note(intervals.seventh(choice(c).name, key)) else: n = Note(choice(c).name) if t > 0 and t < len(beats) - 1: if beats[t - 1] and not beats[t + 1]: n = Note(choice(c).name) fluidsynth.play_Note(n, solo_channel, randrange(80, 110)) print n # Repeat chord on half of the bar if play_chords and t != 0 and loop > chord_start and loop\ < chord_end: if swing and random() > 0.95:
fluidsynth.play_Note(l) time.sleep(1.0) # Play highest note in chord fluidsynth.play_Note(c[-1]) # 50% chance on a bass note if random() > 0.5: p = Note(c[1].name) p.octave_down() fluidsynth.play_Note(p) time.sleep(0.50) # 50% chance on a ninth if random() > 0.5: l = Note(intervals.second(c[0].name, key)) l.octave_up() fluidsynth.play_Note(l) time.sleep(0.25) # 50% chance on the second highest note if random() > 0.5: fluidsynth.play_Note(c[-2]) time.sleep(0.25) fluidsynth.stop_NoteContainer(c) fluidsynth.stop_Note(l) fluidsynth.stop_Note(p) i += 1 print "-" * 20
# Play highest note in chord fluidsynth.play_Note(c[-1]) # 50% chance on a bass note if random() > 0.50: p = Note(c[1].name) p.octave_down() fluidsynth.play_Note(p) time.sleep(0.50) # 50% chance on a ninth if random() > 0.50: l = Note(intervals.second(c[0].name, key)) l.octave_up() fluidsynth.play_Note(l) time.sleep(0.25) # 50% chance on the second highest note if random() > 0.50: fluidsynth.play_Note(c[-2]) time.sleep(0.25) fluidsynth.stop_NoteContainer(c) fluidsynth.stop_Note(l) fluidsynth.stop_Note(p) i += 1 print('-' * 20)
def generate_accompaniment(net_output_chords): generated_chords = [] chords = [] for chord in net_output_chords: root, key = (chord.split(":")) print(root, key) if key == 'maj': chords.append(ch.major_triad(root)) if key == 'min': chords.append(ch.minor_triad(root)) print(chords) key = chords[0][0] print('key', key) if not fluidsynth.init(SF2): print("Couldn't load soundfont", SF2) sys.exit(1) print(dir(fluidsynth.midi)) # fluidsynth.midi.start_audio_output() fluidsynth.midi.start_recording() phrase = 0 while phrase == 0: i = 0 for chord in chords: print("chord", chord) c = NoteContainer(chords[i]) generated_chords.append([{'note':cc.name.replace("B#","B").replace("E#","E").replace("##","#"), 'octave':cc.octave} for cc in c]) l = Note(c[0].name) p = c[1] l.octave_down() print(ch.determine(chords[i])[0]) # Play chord and lowered first note # fluidsynth.midi.MidiFileOut.write_NoteContainer("test.mid", c) print("NEW CHORD = ", c) if PLAY_ENABLED: fluidsynth.play_NoteContainer(c) fluidsynth.play_Note(l) time.sleep(1.0) # Play highest note in chord fluidsynth.play_Note(c[-1]) # 50% chance on a bass note if random() > 0.50: p = Note(c[1].name) p.octave_down() fluidsynth.play_Note(p) time.sleep(0.50) # 50% chance on a ninth if random() > 0.50: l = Note(intervals.second(c[0].name, key)) l.octave_up() fluidsynth.play_Note(l) time.sleep(0.25) # 50% chance on the second highest note if random() > 0.50: fluidsynth.play_Note(c[-2]) time.sleep(0.25) fluidsynth.stop_NoteContainer(c) fluidsynth.stop_Note(l) fluidsynth.stop_Note(p) i += 1 print("-" * 20) phrase = 1 return generated_chords
#write a melody leadBar = Bar(key, meter) noteLengths = [2, 4, 8] lastNote = Note() lastNoteLength = 4 while leadBar.is_full() == False: if random() < 0.8: currentBeat = leadBar.current_beat # add a note # if random() < 0.5 and len(leadBar) > 0: # n = Note(intervals.second(lastNote.name, key)) # print("second of last") if random() < 0.5 and currentBeat != 0.0: n = Note(intervals.second(choice(container).name, key)) # print("second") elif random() < 0.5 and currentBeat != 0.0: n = Note(intervals.seventh(choice(container).name, key)) # print("seventh") else: n = Note(choice(container).name) # print("in chord") lastNote = n lastNoteLength = choice(noteLengths) leadBar.place_notes(n, lastNoteLength) else: # add a rest leadBar.place_rest(choice(noteLengths))
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"))