# NOTE this is hot garbage ripped from a Jupyter notebook. .. you'll have to work it a bit to make it work.
# Also need a midi player, and to make a .dot file or modify to construct it here.
# (noted below how i played the midi)
def midi_graph_shared(MyMIDI, g, start=None, max_t=1000, duration=1, volume=100, track=0, channel=0):
cur = random.choice(list(g.iternodes())) if start is None is None else start
cnts = dict()
opts = list(g.iterneighbors(cur)) # NOTE: assuming its constant.
for t in range(max_t):
cnt = cnts.get(cur, 0)
cnts[cur] = cnt + 1
cur = opts[(cnt - 1)%len(opts)]
next_opts = list(g.iterneighbors(cur))
n_overlap = len(set(next_opts).intersection(opts))
MyMIDI.addNote(track, channel, 52 + len(opts) + 8*n_overlap, t, duration, volume)
opts = next_opts
from midiutil import MIDIFile
MyMIDI = MIDIFile(1)
MyMIDI.addTempo(0, 0, 240)
g = pygraphviz.AGraph(filename="third.dot")
with open("graph_third.mid", "wb") as output_file:
def basic_draw(g): # Jupyter will draw those from this package.
dg = graphviz.Graph()
for e in g.iteredges():
# Played the midi with:
# Ran fluidsynth
# `fluidsynth -is -a pulseaudio -m alsa_seq -r 48000 "$SOME_SOUNDFONT.sf"`
# `/usr/share/soundfonts/FluidR3_GM.sf2` was on my disc, not ideal.
# Look for ports with `aplaymidi -l`
# `aplaymidi --port $PORT $FILE.mid`