def play_midi_file_from_disk( midi_path="mung2midi/sample/The_Nutcracker_Russion_dance.mid", soundfont='mung2midi/UprightPianoKW-small-SF2-20190703/UprightPianoKW-small-20190703.sf2' ): """Plays (or attempts to play) the given MIDI file. Requires Fluidsynth to be installed on your machine, see https://github.com/FluidSynth/fluidsynth/wiki/Download :param midi_path: Path to a MIDI file on the disc :param soundfont: A *.sf2 soundfont for FluidSynth to load. """ fs = FluidSynth( '/Users/elona/Documents/GitHub/mung/mung2midi/UprightPianoKW-small-SF2-20190703/UprightPianoKW-small-20190703.sf2' ) fs.play_midi(midi_path)
def main(): for mode in [Mode.DORIAN]: for h in range(1): lines = [VocalRange.ALTO, VocalRange.SOPRANO] optimal = None while optimal is None: counterpoint_generator = TwoPartImitativeCounterpointGenerator( randint(14, 16), lines, mode) counterpoint_generator.generate_counterpoint() counterpoint_generator.score_solutions() optimal = counterpoint_generator.get_one_solution() if optimal is not None: counterpoint_generator.print_counterpoint() if optimal is not None: mw = MidiWriter() mw.write_midi_from_counterpoint(optimal, "counterpoint.mid", speed_up=1) fs = FluidSynth( "/Users/alexkelber/Development/FluidR3_GM/FluidR3_GM.sf2") fs.play_midi("counterpoint.mid") tw = TemplateWriter() tw.write_template_from_counterpoint(optimal, lines, "counterpoint.ly")
def main(): # for mode in ModeOption: # start_time = time() # g2p1s = GenerateTwoPartFirstSpecies(8 + math.floor(random() * 5), mode, 5) # g2p1s.generate_2p1s() # print("time to generate counterpoint:", (time() - start_time) * 1000) # mw = MidiWriter() # mw.write_midi_from_counterpoint(g2p1s.get_optimal(), "counterpoint.mid") # fs = FluidSynth("/Users/alexkelber/Development/FluidR3_GM/FluidR3_GM.sf2") # fs.play_midi("counterpoint.mid") # # fs.midi_to_audio("counterpoint.mid", "audio/first-species-" + mode.value["name"] + ".wav") # # for mode in ModeOption: # # orientation = Orientation.BELOW if random() > .5 else Orientation.ABOVE # # g2p2s = GenerateTwoPartSecondSpecies(8 + math.floor(random() * 5), mode, 5, orientation=orientation) # # g2p2s.generate_2p2s() # # optimal = g2p2s.get_optimal() # # if optimal is not None: # # mw = MidiWriter() # # mw.write_midi_from_counterpoint(optimal, "counterpointçc.mid") # # for filename in ["FluidR3_GM/FluidR3_GM.sf2"]: # # print(filename) # # fs = FluidSynth("/Users/alexkelber/Development/" + filename) # # fs.play_midi("counterpoint.mid") # # fs.midi_to_audio("counterpoint.mid", "audio/second-species-" + mode.value["name"] + ".wav") # # for mode in ModeOption: # orientation = Orientation.BELOW if random() > .5 else Orientation.ABOVE # octave = 4 if orientation == Orientation.ABOVE else 5 # g2p3s = GenerateTwoPartThirdSpecies(11, mode, octave, orientation=orientation) # g2p3s.generate_2p3s() # optimal = g2p3s.get_optimal() # while optimal is None: # g2p3s = GenerateTwoPartThirdSpecies(11, mode, octave, orientation=orientation) # g2p3s.generate_2p3s() # optimal = g2p3s.get_optimal() # mw = MidiWriter() # mw.write_midi_from_counterpoint(optimal, "counterpoint.mid") # for filename in ["FluidR3_GM/FluidR3_GM.sf2"]: # print(filename) # fs = FluidSynth("/Users/alexkelber/Development/" + filename) # fs.play_midi("counterpoint.mid") # fs.midi_to_audio("counterpoint.mid", "audio/third-species-" + mode.value["name"] + ".wav") # for mode in ModeOption: # exercises = [] # ornt = Orientation.BELOW if random() < .5 else Orientation.ABOVE # g2p4s = GenerateTwoPartFourthSpecies(11, mode, 5, orientation=ornt) # g2p4s.generate_2p4s() # optimal = g2p4s.get_optimal() # while optimal is None: # g2p4s = GenerateTwoPartFourthSpecies(11, mode, 4) # g2p4s.generate_2p4s() # optimal = g2p4s.get_optimal() # mw = MidiWriter() # mw.write_midi_from_counterpoint(optimal, "counterpoint.mid") # for filename in ["FluidR3_GM/FluidR3_GM.sf2"]: # fs = FluidSynth("/Users/alexkelber/Development/" + filename) # fs.play_midi("counterpoint.mid") # fs.midi_to_audio("counterpoint.mid", "audio/fourth-species-" + mode.value["name"] + ".wav") # for mode in ModeOption: # optimal = None # while optimal is None: # g1p5s = GenerateOnePartFifthSpecies(randint(8, 12), mode, range_option=RangeOption.TENOR) # g1p5s.generate_1p5s() # optimal = g1p5s.get_optimal() # if optimal is not None: # mw = MidiWriter() # mw.write_midi_from_counterpoint(optimal, "counterpoint.mid") # for filename in ["FluidR3_GM/FluidR3_GM.sf2"]: # fs = FluidSynth("/Users/alexkelber/Development/" + filename) # fs.play_midi("counterpoint.mid") # # fs.midi_to_audio("counterpoint.mid", "audio/fifth-species-one-part-" + mode.value["name"] + ".wav") # for mode in ModeOption: # optimal = None # range_option = RangeOption.ALTO if mode in [ModeOption.IONIAN, ModeOption.DORIAN, ModeOption.PHRYGIAN] else RangeOption.SOPRANO # while optimal is None: # g2p5s = GenerateTwoPartFifthSpecies(randint(8, 11), mode, range_option=range_option) # g2p5s.generate_2p5s() # optimal = g2p5s.get_optimal() # if optimal is not None: # mw = MidiWriter() # mw.write_midi_from_counterpoint(optimal, "counterpoint.mid") # for filename in ["FluidR3_GM/FluidR3_GM.sf2"]: # fs = FluidSynth("/Users/alexkelber/Development/" + filename) # fs.play_midi("counterpoint.mid") # fs.midi_to_audio("counterpoint.mid", "audio/fifth-species-" + mode.value["name"] + ".wav") ranges = [RangeOption.SOPRANO, RangeOption.ALTO, RangeOption.TENOR] for i in range(100): for mode in ModeOption: optimal = None count = 0 while optimal is None and count < 1000: count += 1 shuffle(ranges) g2pfc = GenerateTwoPartFreeCounterpoint(ranges[:2], randint(14, 19), mode, with_imitation=True) g2pfc.generate_2pfc() optimal = g2pfc.get_optimal() if optimal is not None: # g2pfc.print_function_log() mw = MidiWriter() mw.write_midi_from_counterpoint(optimal, "counterpoint.mid") for filename in ["FluidR3_GM/FluidR3_GM.sf2"]: fs = FluidSynth("/Users/alexkelber/Development/" + filename) fs.play_midi("counterpoint.mid") fs.midi_to_audio( "counterpoint.mid", "audio/imitative-counterpoint-" + str(i) + "-" + mode.value["name"] + ".wav")