File size: 1,314 Bytes
c2f178d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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()