import os import random from mido import MidiFile, Message, MidiTrack from music21 import note, stream, interval, meter, chord from ortools.sat.python import cp_model from hexachords import Hexachord from smallmuse.temporals import NoteList, TemporalNote class Movement: def __init__(self, h): self.hexachord = h def generate_movements(self, param): reals = self.hexachord.generate_3_chords_realizations(self.hexachord._base_sequence) mvts_templates = [] for index_of_chord in range(6): chords = [real[index_of_chord] for real in reals] mvts_templates.append(chords) return mvts_templates if __name__ == '__main__': hexa = Hexachord() note_names = ["C3", "Eb3", "E3", "F#3", "G3", "Bb3"] notes = [note.Note(n) for n in note_names] cs1 = hexa.generate_base_sequence(notes, intrvl="P4") print (cs1) move = Movement(hexa) mvmts= move.generate_movements(1) movement = random.choice(mvmts) # make a temporallist nl = NoteList() for i_chord, chord in enumerate(movement): for note in chord: nl.add_note(TemporalNote(note.pitch.midi, i_chord * 4, 4)) nl.join_notes() # nl.show() nl.apply_rules() print('after rules') nl.save_midi('output.mid') nl.show()