You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
compact_sets_sandbox/compact_sets_extended_simpl...

2251 lines
428 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 104,
"id": "806f6f69-1e0b-4d34-aac9-695c8531cdb1",
"metadata": {},
"outputs": [],
"source": [
"from itertools import chain, combinations, permutations, product, pairwise\n",
"from math import prod, log\n",
"from copy import deepcopy\n",
"import networkx as nx\n",
"from fractions import Fraction\n",
"import json\n",
"from operator import add\n",
"\n",
"def hs_array_to_fr(hs_array):\n",
" return prod([pow(dims[d], hs_array[d]) for d in range(len(dims))])\n",
"\n",
"def hs_array_to_cents(hs_array):\n",
" return (1200 * log(hs_array_to_fr(hs_array), 2))\n",
"\n",
"def expand_pitch(hs_array):\n",
" expanded_pitch = list(hs_array)\n",
" frequency_ratio = hs_array_to_fr(hs_array)\n",
" if frequency_ratio < 1:\n",
" while frequency_ratio < 1:\n",
" frequency_ratio *= 2\n",
" expanded_pitch[0] += 1\n",
" elif frequency_ratio >= 2:\n",
" while frequency_ratio >= 2:\n",
" frequency_ratio *= 1/2\n",
" expanded_pitch[0] += -1\n",
" return tuple(expanded_pitch)\n",
"\n",
"def expand_chord(chord):\n",
" return tuple(expand_pitch(p) for p in chord)\n",
"\n",
"def collapse_pitch(hs_array):\n",
" collapsed_pitch = list(hs_array)\n",
" collapsed_pitch[0] = 0\n",
" return tuple(collapsed_pitch)\n",
"\n",
"def collapse_chord(chord):\n",
" return tuple(collapse_pitch(p) for p in chord)\n",
"\n",
"def transpose_pitch(pitch, trans):\n",
" return tuple(map(add, pitch, trans))\n",
"\n",
"def transpose_chord(chord, trans):\n",
" return tuple(transpose_pitch(p, trans) for p in chord)\n",
"\n",
"def cent_difference(hs_array1, hs_array2):\n",
" return hs_array_to_cents(hs_array2) - hs_array_to_cents(hs_array1)\n",
"\n",
"def pitch_difference(hs_array1, hs_array2):\n",
" return transpose_pitch(hs_array1, [p * -1 for p in hs_array2])\n",
"\n",
"# this is modified for different chord sizes like original version\n",
"def grow_chords(chord, root, min_chord_size, max_chord_size):\n",
" #this could use the tranpose_pitch function\n",
" branches = [branch for alt in [-1, 1] for d in range(1, len(root)) if (branch:=(*(r:=root)[:d], r[d] + alt, *r[(d + 1):])) not in chord]\n",
" subsets = chain.from_iterable(combinations(branches, r) for r in range(1, max_chord_size - len(chord) + 1))\n",
" for subset in subsets:\n",
" extended_chord = chord + subset\n",
" if(len(extended_chord) < max_chord_size):\n",
" for branch in subset:\n",
" yield from grow_chords(extended_chord, branch, min_chord_size, max_chord_size)\n",
" if(len(extended_chord) >= min_chord_size):\n",
" yield tuple(sorted(extended_chord, key=hs_array_to_fr))\n",
"\n",
"def chords(chord, root, min_chord_size, max_chord_size):\n",
" # this will filter out the 4x dups of paths that are loops, there might be a faster way to test this\n",
" return set(grow_chords(chord, root, min_chord_size, max_chord_size))\n",
"\n",
"# this is very slow, I have an idea in mind that my be faster by simply growing the chords to max_chord_size + max_sim_diff\n",
"# technically at that point you have generated both chords and can get the second chord from the first\n",
"def edges(chords, min_symdiff, max_symdiff, max_chord_size): \n",
"\n",
" def reverse_movements(movements):\n",
" return {value['destination']:{'destination':key, 'cent_difference':value['cent_difference'] * -1} for key, value in movements.items()}\n",
"\n",
" def is_directly_tunable(intersection, diff):\n",
" # this only works for now when intersection if one element - need to fix that\n",
" return max([sum(abs(p) for p in collapse_pitch(pitch_difference(d, list(intersection)[0]))) for d in diff]) == 1\n",
"\n",
" for combination in combinations(chords, 2):\n",
" [expanded_base, expanded_comp] = [expand_chord(chord) for chord in combination]\n",
" edges = []\n",
" transpositions = set(pitch_difference(pair[0], pair[1]) for pair in set(product(expanded_base, expanded_comp)))\n",
" for trans in transpositions:\n",
" expanded_comp_transposed = transpose_chord(expanded_comp, trans)\n",
" intersection = set(expanded_base) & set(expanded_comp_transposed)\n",
" symdiff_len = sum([len(chord) - len(intersection) for chord in [expanded_base, expanded_comp_transposed]])\n",
" if (min_symdiff <= symdiff_len <= max_symdiff):\n",
" rev_trans = tuple(t * -1 for t in trans)\n",
" [diff1, diff2] = [list(set(chord) - intersection) for chord in [expanded_base, expanded_comp_transposed]]\n",
" base_map = {val: {'destination':transpose_pitch(val, rev_trans), 'cent_difference': 0} for val in intersection}\n",
" base_map_rev = reverse_movements(base_map)\n",
" maps = []\n",
" diff1 += [None] * (max_chord_size - len(diff1) - len(intersection))\n",
" perms = [list(perm) + [None] * (max_chord_size - len(perm) - len(intersection)) for perm in set(permutations(diff2))]\n",
" for p in perms:\n",
" appended_map = {\n",
" diff1[index]:\n",
" {\n",
" 'destination': transpose_pitch(val, rev_trans) if val != None else None, \n",
" 'cent_difference': cent_difference(diff1[index], val) if None not in [diff1[index], val] else None\n",
" } for index, val in enumerate(p)}\n",
" yield (tuple(expanded_base), tuple(expanded_comp), {\n",
" 'transposition': trans,\n",
" 'symmetric_difference': symdiff_len, \n",
" 'is_directly_tunable': is_directly_tunable(intersection, diff2),\n",
" 'movements': base_map | appended_map\n",
" },)\n",
" yield (tuple(expanded_comp), tuple(expanded_base), {\n",
" 'transposition': rev_trans,\n",
" 'symmetric_difference': symdiff_len, \n",
" 'is_directly_tunable': is_directly_tunable(intersection, diff1),\n",
" 'movements': base_map_rev | reverse_movements(appended_map)\n",
" },)\n",
"\n",
"def graph_from_edges(edges):\n",
" g = nx.MultiDiGraph()\n",
" g.add_edges_from(edges)\n",
" return g\n",
"\n",
"def generate_graph(chord_set, min_symdiff, max_symdiff, max_chord_size):\n",
" #chord_set = chords(pitch_set, min_chord_size, max_chord_size)\n",
" edge_set = edges(chord_set, min_symdiff, max_symdiff, max_chord_size)\n",
" res_graph = graph_from_edges(edge_set)\n",
" return res_graph\n",
"\n",
"def display_graph(graph):\n",
" show_graph = nx.Graph(graph)\n",
" pos = nx.draw_spring(show_graph, node_size=5, width=0.1)\n",
" plt.figure(1, figsize=(12,12)) \n",
" nx.draw(show_graph, pos, node_size=5, width=0.1)\n",
" plt.show()\n",
" #plt.savefig('compact_sets.png', dpi=150)\n",
"\n",
"def path_to_chords(path, start_root):\n",
" current_root = start_root\n",
" start_chord = tuple(sorted(path[0][0], key=hs_array_to_fr))\n",
" chords = ((start_chord, start_chord,),)\n",
" for edge in path:\n",
" trans = edge[2]['transposition']\n",
" movements = edge[2]['movements']\n",
" current_root = transpose_pitch(current_root, trans)\n",
" current_ref_chord = chords[-1][0]\n",
" next_ref_chord = tuple(movements[pitch]['destination'] for pitch in current_ref_chord)\n",
" next_transposed_chord = tuple(transpose_pitch(pitch, current_root) for pitch in next_ref_chord)\n",
" chords += ((next_ref_chord, next_transposed_chord,),)\n",
" return tuple(chord[1] for chord in chords)\n",
"\n",
"def write_chord_sequence(path):\n",
" file = open(\"seq.txt\", \"w+\")\n",
" content = json.dumps(path)\n",
" content = content.replace(\"[[[\", \"[\\n\\t[[\")\n",
" content = content.replace(\", [[\", \",\\n\\t[[\")\n",
" content = content.replace(\"]]]\", \"]]\\n]\")\n",
" file.write(content)\n",
" file.close()"
]
},
{
"cell_type": "code",
"execution_count": 683,
"id": "aea5215c-8551-4685-b761-11c2dc74cf22",
"metadata": {},
"outputs": [],
"source": [
"from random import choice, choices\n",
"\n",
"# This is for the static version\n",
"def stochastic_hamiltonian(graph):\n",
" \n",
" def movement_size_weights(edges):\n",
" \n",
" def max_cent_diff(edge):\n",
" res = max([abs(v) for val in edge[2]['movements'].values() if (v:=val['cent_difference']) is not None])\n",
" return res\n",
" \n",
" def min_cent_diff(edge):\n",
" res = [abs(v) for val in edge[2]['movements'].values() if (v:=val['cent_difference']) is not None]\n",
" res.remove(0)\n",
" return min(res)\n",
" \n",
" for e in edges:\n",
" yield 1000 if ((max_cent_diff(e) < 200) and (min_cent_diff(e)) > 50) else 1\n",
"\n",
" def hamiltonian_weights(edges):\n",
" for e in edges:\n",
" yield 10 if e[1] not in [path_edge[0] for path_edge in path] else 1 / graph.nodes[e[1]]['count']\n",
" \n",
" def contrary_motion_weights(edges):\n",
"\n",
" def is_contrary(edge):\n",
" cent_diffs = [v for val in edge[2]['movements'].values() if (v:=val['cent_difference']) is not None]\n",
" cent_diffs.sort()\n",
" return (cent_diffs[0] < 0) and (cent_diffs[1] == 0) and (cent_diffs[2] > 0)\n",
"\n",
" for e in edges:\n",
" yield 10 if is_contrary(e) else 1\n",
" \n",
" def is_directly_tunable_weights(edges):\n",
" for e in edges:\n",
" yield 10 if e[2]['is_directly_tunable'] else 0\n",
"\n",
" def voice_crossing_weights(edges):\n",
" \n",
" def has_voice_crossing(edge):\n",
" source = list(edge[0])\n",
" ordered_source = sorted(source, key=hs_array_to_fr) \n",
" source_order = [ordered_source.index(p) for p in source]\n",
" destination = [transpose_pitch(edge[2]['movements'][p]['destination'], edge[2]['transposition']) for p in source]\n",
" ordered_destination = sorted(destination, key=hs_array_to_fr)\n",
" destination_order = [ordered_destination.index(p) for p in destination]\n",
" return source_order != destination_order\n",
"\n",
" for e in edges:\n",
" yield 10 if not has_voice_crossing(e) else 0\n",
"\n",
" def is_bass_rooted(chord):\n",
" return max([sum(abs(p) for p in collapse_pitch(pitch_difference(chord[0], p))) for p in chord[1:]]) == 1\n",
" \n",
" check_graph = graph.copy()\n",
" next_node = choice([node for node in graph.nodes() if is_bass_rooted(node)])\n",
" check_graph.remove_node(next_node)\n",
" for node in graph.nodes(data=True):\n",
" node[1]['count'] = 1\n",
" path = []\n",
" while (nx.number_of_nodes(check_graph) > 0) and (len(path) < 5000):\n",
" out_edges = list(graph.out_edges(next_node, data=True))\n",
" #print([l for l in zip(movement_size_weights(out_edges), hamiltonian_weights(out_edges))])\n",
" factors = [\n",
" movement_size_weights(out_edges), \n",
" hamiltonian_weights(out_edges), \n",
" contrary_motion_weights(out_edges), \n",
" is_directly_tunable_weights(out_edges),\n",
" voice_crossing_weights(out_edges)\n",
" ]\n",
" weights = [prod(a) for a in zip(*factors)]\n",
" edge = choices(out_edges, weights=weights)[0]\n",
" #edge = random.choice(out_edges)\n",
" next_node = edge[1]\n",
" node[1]['count'] += 1\n",
" path.append(edge)\n",
" if next_node in check_graph.nodes:\n",
" check_graph.remove_node(next_node)\n",
" return path"
]
},
{
"cell_type": "code",
"execution_count": 684,
"id": "4e3ef738-7f64-47c3-9129-0450fd031375",
"metadata": {},
"outputs": [],
"source": [
"dims = (2, 3, 5, 7, 11)\n",
"root = (0, 0, 0, 0, 0)\n",
"chord = (root,)\n",
"chord_set = chords(chord, root, 3, 3)\n",
"graph = generate_graph(chord_set, 4, 4, 3)"
]
},
{
"cell_type": "code",
"execution_count": 685,
"id": "6e0de0e5-7973-4a15-ae90-5bbb4a1ef49d",
"metadata": {},
"outputs": [],
"source": [
"path = stochastic_hamiltonian(graph)\n",
"#for edge in path:\n",
"# print(edge)\n",
"write_chord_sequence(path_to_chords(path, root))"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "7f2d356f-6377-46cf-bbb1-32111be90f4f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The line_profiler extension is already loaded. To reload it, use:\n",
" %reload_ext line_profiler\n"
]
}
],
"source": [
"%load_ext line_profiler"
]
},
{
"cell_type": "code",
"execution_count": 134,
"id": "7f141bf5-fdcb-4c01-a10b-3e86d3d1a7b4",
"metadata": {},
"outputs": [],
"source": [
"chord_set = chords(chord, root, 3, 3)"
]
},
{
"cell_type": "code",
"execution_count": 136,
"id": "88850b8c-a743-44d0-b863-7cd9066690d9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timer unit: 1e-09 s\n",
"\n",
"Total time: 0.112228 s\n",
"File: /tmp/ipykernel_515812/2679284550.py\n",
"Function: edge_data at line 74\n",
"\n",
"Line # Hits Time Per Hit % Time Line Contents\n",
"==============================================================\n",
" 74 def edge_data(chords, min_symdiff, max_symdiff, max_chord_size):\n",
" 75 990 29603044.0 29902.1 26.4 [expanded_base, expanded_comp] = [expand_chord(chord) for chord in chords]\n",
" 76 990 229527.0 231.8 0.2 edges = []\n",
" 77 990 23648371.0 23887.2 21.1 transpositions = set(pitch_difference(pair[0], pair[1]) for pair in set(product(expanded_base, expanded_comp)))\n",
" 78 9193 2315267.0 251.9 2.1 for trans in transpositions:\n",
" 79 8203 33386775.0 4070.1 29.7 expanded_comp_transposed = transpose_chord(expanded_comp, trans)\n",
" 80 8203 8393773.0 1023.3 7.5 intersection = set(expanded_base) & set(expanded_comp_transposed)\n",
" 81 8203 11812057.0 1440.0 10.5 symdiff_len = sum([len(chord) - len(intersection) for chord in [expanded_base, expanded_comp_transposed]])\n",
" 82 8203 2530596.0 308.5 2.3 if (min_symdiff <= symdiff_len <= max_symdiff):\n",
" 83 rev_trans = tuple(t * -1 for t in trans)\n",
" 84 [diff1, diff2] = [list(set(chord) - intersection) for chord in [expanded_base, expanded_comp_transposed]]\n",
" 85 base_map = {val: {'destination':transpose_pitch(val, rev_trans), 'cent_difference': 0} for val in intersection}\n",
" 86 base_map_rev = reverse_movements(base_map)\n",
" 87 tunability = is_directly_tunable(intersection, diff2)\n",
" 88 maps = []\n",
" 89 diff1 += [None] * (max_chord_size - len(diff1) - len(intersection))\n",
" 90 perms = [list(perm) + [None] * (max_chord_size - len(perm) - len(intersection)) for perm in set(permutations(diff2))]\n",
" 91 for p in perms:\n",
" 92 appended_map = {\n",
" 93 diff1[index]:\n",
" 94 {\n",
" 95 'destination': transpose_pitch(val, rev_trans) if val != None else None, \n",
" 96 'cent_difference': cent_difference(diff1[index], val) if None not in [diff1[index], val] else None\n",
" 97 } for index, val in enumerate(p)}\n",
" 98 edges.append((tuple(expanded_base), tuple(expanded_comp), {\n",
" 99 'transposition': trans,\n",
" 100 'symmetric_difference': symdiff_len, \n",
" 101 'is_directly_tunable': tunability,\n",
" 102 'movements': base_map | appended_map\n",
" 103 }))\n",
" 104 edges.append((tuple(expanded_comp), tuple(expanded_base), {\n",
" 105 'transposition': rev_trans,\n",
" 106 'symmetric_difference': symdiff_len, \n",
" 107 'is_directly_tunable': tunability,\n",
" 108 'movements': base_map_rev | reverse_movements(appended_map)\n",
" 109 }))\n",
" 110 990 308812.0 311.9 0.3 return edges if edges != [] else None"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"lprun -f edge_data edges(chord_set, 3, 3, 4)"
]
},
{
"cell_type": "code",
"execution_count": 688,
"id": "6e4ecb10-344b-4721-b2f4-68de91d712db",
"metadata": {},
"outputs": [],
"source": [
"from random import choice, choices\n",
"\n",
"# This is for the rising version / yitgadal\n",
"def stochastic_hamiltonian(graph):\n",
" \n",
" def movement_size_weights(edges):\n",
" \n",
" def max_cent_diff(edge):\n",
" res = max([v for val in edge[2]['movements'].values() if (v:=val['cent_difference']) is not None])\n",
" return res\n",
" \n",
" def min_cent_diff(edge):\n",
" res = [v for val in edge[2]['movements'].values() if (v:=val['cent_difference']) is not None]\n",
" res.remove(0)\n",
" return min(res)\n",
" \n",
" for e in edges:\n",
" yield 1000 if ((max_cent_diff(e) < 175) and (min_cent_diff(e)) >= 0) else 1\n",
"\n",
" def hamiltonian_weights(edges):\n",
" for e in edges:\n",
" yield 10 if e[1] not in [path_edge[0] for path_edge in path] else 1 / graph.nodes[e[1]]['count']\n",
" \n",
" def contrary_motion_weights(edges):\n",
"\n",
" def is_contrary(edge):\n",
" cent_diffs = [v for val in edge[2]['movements'].values() if (v:=val['cent_difference']) is not None]\n",
" cent_diffs.sort()\n",
" return (cent_diffs[0] < 0) and (cent_diffs[1] == 0) and (cent_diffs[2] > 0)\n",
"\n",
" for e in edges:\n",
" yield 2 if is_contrary(e) else 1\n",
" \n",
" def is_directly_tunable_weights(edges):\n",
" for e in edges:\n",
" yield 10 if e[2]['is_directly_tunable'] else 0\n",
"\n",
" def transposition_weight(edges):\n",
" for e in edges:\n",
" yield 1000 if 0 <= hs_array_to_cents(e[2]['transposition']) < 100 else 0\n",
"\n",
" def is_sustained_voice(edges, voice):\n",
" \n",
" def is_sustained(edge):\n",
" source = list(edge[0])\n",
" ordered_source = sorted(source, key=hs_array_to_fr) \n",
" destination = [transpose_pitch(edge[2]['movements'][p]['destination'], edge[2]['transposition']) for p in source]\n",
" ordered_destination = sorted(destination, key=hs_array_to_fr)\n",
" return ordered_source[voice] == ordered_destination[voice]\n",
"\n",
" for e in edges:\n",
" yield 10 if is_sustained(e) else 0\n",
"\n",
" def voice_crossing_weights(edges):\n",
" \n",
" def has_voice_crossing(edge):\n",
" source = list(edge[0])\n",
" ordered_source = sorted(source, key=hs_array_to_fr) \n",
" source_order = [ordered_source.index(p) for p in source]\n",
" destination = [transpose_pitch(edge[2]['movements'][p]['destination'], edge[2]['transposition']) for p in source]\n",
" ordered_destination = sorted(destination, key=hs_array_to_fr)\n",
" destination_order = [ordered_destination.index(p) for p in destination]\n",
" return source_order != destination_order\n",
"\n",
" for e in edges:\n",
" yield 10 if not has_voice_crossing(e) else 0\n",
"\n",
" def is_bass_rooted(chord):\n",
" return max([sum(abs(p) for p in collapse_pitch(pitch_difference(chord[0], p))) for p in chord[1:]]) == 1\n",
" \n",
" check_graph = graph.copy()\n",
" #next_node = choice([node for node in graph.nodes() if is_bass_rooted(node)])\n",
" next_node = choice(list(graph.nodes()))\n",
" print(next_node)\n",
" check_graph.remove_node(next_node)\n",
" for node in graph.nodes(data=True):\n",
" node[1]['count'] = 1\n",
" path = []\n",
" while (nx.number_of_nodes(check_graph) > 0) and (len(path) < 500):\n",
" out_edges = list(graph.out_edges(next_node, data=True))\n",
" #print([l for l in zip(movement_size_weights(out_edges), hamiltonian_weights(out_edges))])\n",
" factors = [\n",
" movement_size_weights(out_edges), \n",
" hamiltonian_weights(out_edges), \n",
" #contrary_motion_weights(out_edges), \n",
" #is_directly_tunable_weights(out_edges),\n",
" voice_crossing_weights(out_edges),\n",
" #transposition_weight(out_edges)\n",
" #is_sustained_voice(out_edges, 0)\n",
" ]\n",
" weights = [prod(a) for a in zip(*factors)]\n",
" #print(weights)\n",
" edge = choices(out_edges, weights=weights)[0]\n",
" #print(edge)\n",
" #edge = random.choice(out_edges)\n",
" next_node = edge[1]\n",
" node[1]['count'] += 1\n",
" path.append(edge)\n",
" if next_node in check_graph.nodes:\n",
" check_graph.remove_node(next_node)\n",
" print(len(check_graph.nodes()))\n",
" return path"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "a76dc0f3-02e2-4739-9014-b53d3a590e3d",
"metadata": {},
"outputs": [],
"source": [
"dims = (2, 3, 5, 7, 11)\n",
"root = (0, 0, 0, 0, 0)\n",
"chord = (root,)\n",
"chord_set = chords(chord, root, 3, 3)\n",
"graph = generate_graph(chord_set, 2, 2, 3)"
]
},
{
"cell_type": "code",
"execution_count": 690,
"id": "7b76d848-fe53-4b60-b414-46cfe570f78b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"((3, 0, 0, -1, 0), (0, 0, 0, 0, 0), (-2, 0, 0, 1, 0))\n",
"0\n"
]
},
{
"data": {
"text/plain": [
"163"
]
},
"execution_count": 690,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"path = stochastic_hamiltonian(graph)\n",
"#for edge in path:\n",
"# print(edge)\n",
"write_chord_sequence(path_to_chords(path, root))\n",
"len(path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "91fd1700-6f41-4a4c-98cb-8355075d44d2",
"metadata": {},
"outputs": [],
"source": [
"#ffmpeg -i video.mkv -acodec pcm_s16le -ar 16000 -ac 2 bereshit_chant.wav\n",
"#sox bereshit_chant.wav bereshit_chant_snippet.wav trim 4 60"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "51be5ff2-2b7f-4350-878f-09e79d4bff1f",
"metadata": {},
"outputs": [],
"source": [
"import crepe\n",
"from scipy.io import wavfile"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "9b8e1e21-c5f5-4d77-8d1c-094b073b8322",
"metadata": {},
"outputs": [],
"source": [
"sr, audio = wavfile.read('/home/mwinter/Downloads/bereshit_chant_snippet.wav')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "01f8f969-fc3c-46a2-acfd-b1f956e438bc",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-05-22 19:43:58.758829: I external/local_tsl/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.\n",
"2024-05-22 19:43:58.911551: I external/local_tsl/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.\n",
"2024-05-22 19:43:59.465441: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
"To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
"2024-05-22 19:44:00.873378: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1m76/76\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m23s\u001b[0m 301ms/step\n"
]
}
],
"source": [
"time, frequency, confidence, activation = crepe.predict(audio, sr, step_size = 25)\n",
"#time, frequency, confidence = [list(time), list(frequency), list(confidence)]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a89c32ee-6413-400a-b3c9-a875f2768954",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy80BEi2AAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOx9d5wlRbX/t/ummdm8ywbCknNOiigKPFFUxBxBEVSe+sDE+71nRH2KoL4nZsX4TOAzKwqigIKKIElyzizL5jS7M3Pv7e76/dFdVaeqTnW4M7OzuPd8PrB37u1Q3V1ddep7vud7AiGEQN/61re+9a1vfevbFFk41Q3oW9/61re+9a1vW7f1nZG+9a1vfetb3/o2pdZ3RvrWt771rW9969uUWt8Z6Vvf+ta3vvWtb1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8djjz4K7LknsOOOwP33T955JtPoe97pmOPreFFL31ho81S2FLNRz/HaRC2cb755Yo4zAbZFZtNMmRU94I0b0/TIovg9Z1UdHc4ZKXOMvNUAdUaKVg0jI+lkXpRO3AsyMpmrl4kegMoiI1/7GvB//2duSydIGiIrca540yb3WvJUbik/pt02BzzZr4sEoSbCWbX3m6zVqX0e6ZA/8ECaRSWvhWagTQSv5LLLUrn/k08e/7Hy7E9/St+tBx6YmD49FWJgNhJC/x5vv/CNhU8FZOSaa9JEh83Jc3rkkXTusu/JFuSw9Z0RatQZ4TrKmWc
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[(1.05, 51.0, 0.0),\n",
" (0.3, 53.0, 200.0),\n",
" (0.125, 51.0, -200.0),\n",
" (1.375, 51.0, 0.0),\n",
" (0.4, 49.0, -200.0),\n",
" (0.625, 48.0, -100.0),\n",
" (0.375, 48.0, 0.0),\n",
" (0.5, 49.0, 100.0),\n",
" (0.125, 49.0, 0.0),\n",
" (0.875, 51.0, 200.0),\n",
" (0.75, 51.0, 0.0),\n",
" (0.025, 49.0, -200.0),\n",
" (0.25, 48.0, -100.0),\n",
" (0.75, 48.0, 0.0),\n",
" (0.5, 51.0, 300.0),\n",
" (0.0, 51.0, 0.0),\n",
" (0.475, 53.0, 200.0),\n",
" (1.125, 51.0, -200.0),\n",
" (0.75, 51.0, 0.0),\n",
" (0.25, 48.0, -300.0),\n",
" (1.125, 48.0, 0.0),\n",
" (0.25, 53.0, 500.0),\n",
" (0.5, 53.0, 0.0),\n",
" (0.875, 49.0, -400.0),\n",
" (0.625, 49.0, 0.0),\n",
" (0.125, 52.0, 300.0),\n",
" (0.1, 53.0, 100.0),\n",
" (0.425, 52.0, -100.0),\n",
" (0.475, 51.0, -100.0),\n",
" (0.1, 52.0, 100.0),\n",
" (0.175, 51.0, -100.0),\n",
" (0.5, 49.0, -200.0),\n",
" (0.0, 49.0, 0.0),\n",
" (0.375, 46.0, -300.0),\n",
" (1.0, 46.0, 0.0),\n",
" (1.25, 51.0, 500.0),\n",
" (0.0, 51.0, 0.0),\n",
" (0.05, 56.0, 500.0),\n",
" (0.125, 57.0, 100.0),\n",
" (0.5, 57.0, 0.0),\n",
" (0.25, 53.0, -400.0),\n",
" (0.625, 53.0, 0.0),\n",
" (0.075, 54.0, 100.0),\n",
" (0.375, 53.0, -100.0),\n",
" (0.025, 56.0, 300.0),\n",
" (0.375, 57.0, 100.0),\n",
" (0.125, 57.0, 0.0),\n",
" (0.875, 51.0, -600.0),\n",
" (0.5, 51.0, 0.0),\n",
" (0.125, 52.0, 100.0),\n",
" (0.375, 52.0, 0.0),\n",
" (0.125, 53.0, 100.0),\n",
" (0.375, 53.0, 0.0),\n",
" (1.0, 51.0, -200.0),\n",
" (1.125, 51.0, 0.0),\n",
" (0.75, 48.0, -300.0),\n",
" (0.375, 48.0, 0.0),\n",
" (0.75, 51.0, 300.0),\n",
" (0.5, 51.0, 0.0),\n",
" (0.45, 53.0, 200.0),\n",
" (0.125, 52.0, -100.0),\n",
" (0.45, 51.0, -100.0),\n",
" (0.025, 56.0, 500.0),\n",
" (0.2, 57.0, 100.0),\n",
" (0.875, 56.0, -100.0),\n",
" (0.0, 56.0, 0.0),\n",
" (0.25, 57.0, 100.0),\n",
" (0.25, 57.0, 0.0),\n",
" (0.3, 53.0, -400.0),\n",
" (1.375, 51.0, -200.0),\n",
" (0.125, 51.0, 0.0),\n",
" (0.125, 52.0, 100.0),\n",
" (0.625, 51.0, -100.0),\n",
" (0.125, 51.0, 0.0),\n",
" (0.425, 52.0, 100.0),\n",
" (1.75, 51.0, -100.0),\n",
" (0.25, 51.0, 0.0),\n",
" (0.625, 48.0, -300.0),\n",
" (0.625, 48.0, 0.0),\n",
" (0.5, 53.0, 500.0),\n",
" (0.125, 53.0, 0.0),\n",
" (0.75, 49.0, -400.0),\n",
" (0.875, 49.0, 0.0),\n",
" (0.5, 51.0, 200.0),\n",
" (0.375, 51.0, 0.0),\n",
" (0.375, 48.0, -300.0),\n",
" (0.625, 48.0, 0.0),\n",
" (0.075, 51.0, 300.0),\n",
" (0.15, 52.0, 100.0),\n",
" (0.5, 51.0, -100.0),\n",
" (0.0, 51.0, 0.0),\n",
" (0.2, 53.0, 200.0),\n",
" (1.125, 52.0, -100.0),\n",
" (0.0, 52.0, 0.0),\n",
" (0.05, 50.0, -200.0),\n",
" (0.625, 49.0, -100.0),\n",
" (0.375, 49.0, 0.0),\n",
" (0.125, 52.0, 300.0),\n",
" (1.5, 52.0, 0.0),\n",
" (0.375, 51.0, -100.0),\n",
" (0.5, 51.0, 0.0),\n",
" (0.45, 53.0, 200.0),\n",
" (1.0, 49.0, -400.0),\n",
" (0.5, 49.0, 0.0),\n",
" (0.125, 56.0, 700.0),\n",
" (0.375, 56.0, 0.0),\n",
" (0.075, 55.0, -100.0),\n",
" (0.3, 54.0, -100.0),\n",
" (0.2, 53.0, -100.0),\n",
" (0.35, 51.0, -200.0),\n",
" (0.25, 53.0, 200.0),\n",
" (0.75, 51.0, -200.0),\n",
" (1.25, 51.0, 0.0),\n",
" (0.45, 49.0, -200.0),\n",
" (0.3, 48.0, -100.0),\n",
" (0.2, 49.0, 100.0),\n",
" (1.0, 51.0, 200.0),\n",
" (1.25, 51.0, 0.0),\n",
" (0.3, 53.0, 200.0),\n",
" (0.05, 52.0, -100.0)]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAh8AAAGdCAYAAACyzRGfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy80BEi2AAAACXBIWXMAAA9hAAAPYQGoP6dpAACsbUlEQVR4nO2dd5xcVfn/P+fOzM723fTegJBKQmghdAkiRURAwQiCCAiIVEHAFvgqBisqXRTBn4WmVAHpASSEEFoCJKSRXkjbvrMzc8/v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pZVjI4A0vDUfacHnY5+tQFUkho97gE4APelKFb71azr8LcTTUURsJIru6nao+96PC1f1w8gI+csQ+fHG+7p5pX4T0LAJSNYC2ydDbR2DlkQLCR8hE0j4OP74483P06ZNw8yZMzFmzBg89NBDmDRpEgDgwgsvxLnnngsAmDFjBl588UXce++9mDdvnu0xr7/+elx11VXm99bWVowaVYEzP6LXUT3mGbw9Zhzwg8vwqxkL8H0AchCoPWJGzgVfPwd1B1+EmSOW4q3QWlr+KGBQAdw54xu46KnlLlsuAgB0/ec84IvaEq6SIEIEx3gNp4y9Hf+4fisSkUYc9LXfaj5HlWr+LCJ5eYI2Nzdj7733xsqVKzFs2DAAwOTJk6VtJk2ahHXr1jkeIx6Po7GxUfpHEOWMlM5b2RvAFYDiP+LCclfgYEoMUGLCygI0sBdiaJO43+soXjOCyIFY1Br+qqqiUJS49oUzpNMk0IZNXsJHe3s7Vq1ahWHDhmHs2LEYPnw4li+XZy2ffPIJxowZk1cjCaIcYeCAHslljpk+wj7TovA
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import librosa \n",
"import numpy as np\n",
"from scipy.signal import savgol_filter\n",
"import matplotlib.pyplot as plt\n",
"from random import randint\n",
"\n",
"def filter_data(time, frequency, confidence):\n",
" data = tuple(data for data in zip(list(time), list(frequency), list(confidence)) if data[2] > 0.1)\n",
" dev = 0\n",
" dur = 0\n",
" for (p1, p2) in pairwise(data):\n",
" t_diff = (p2[0] - p1[0])\n",
" dur = round(dur + (p2[0] - p1[0]), 2)\n",
" if(True):\n",
" freq1, conf1 = p1[1:3]\n",
" midi1 = librosa.hz_to_midi(freq1)\n",
" r_midi1 = np.around(midi1)\n",
" freq2, conf2 = p2[1:3]\n",
" midi2 = librosa.hz_to_midi(freq2)\n",
" r_midi2 = np.around(midi2)\n",
" #if(r_midi2 != r_midi1):\n",
" if(True):\n",
" yield(dur, freq1, conf1, midi1, r_midi1, dev * 100)\n",
" dev = r_midi2 - r_midi1\n",
" dur = 0\n",
" \n",
"def filter_data(time, frequency, confidence):\n",
" data = tuple(data for data in zip(list(time), list(frequency), list(confidence)) if data[2] > 0.9)\n",
" #durs = tuple(round(y[0]-x[0], 2) for (x, y) in pairwise(data)) + ((1,))\n",
" #data = tuple((d,) + data[i][1:] for i, d in enumerate(durs) if d > 0.01)\n",
" #print(data)\n",
" m, rm = [librosa.hz_to_midi(data[0][1]), np.around(librosa.hz_to_midi(data[0][1]))]\n",
" yield(data[0] + (m, rm, 0,))\n",
" for i, [t, f, c] in enumerate(data):\n",
" nm, nrm = [librosa.hz_to_midi(f), np.around(librosa.hz_to_midi(f))]\n",
" if((0 < i < len(data) - 1) and (nrm != rm)):\n",
" m, rm, d = [nm, nrm, nrm - rm]\n",
" yield(t, f, c, m, rm, d * 100)\n",
" \n",
"t_min = 50\n",
"t_max = 600\n",
"f_time, f_frequency, f_confidence = [time[t_min:], frequency[t_min:], confidence[t_min:]]\n",
"s_confidence = savgol_filter(f_confidence, 30, 4)\n",
"plt.plot(f_time, f_confidence)\n",
"plt.plot(f_time, s_confidence, color='red')\n",
"plt.show()\n",
"\n",
"def filter_midi(f_time, f_frequency, s_confidence):\n",
" last_confident_value = 51\n",
" for t, f, c in zip(f_time, f_frequency, s_confidence):\n",
" if c > 0.9:\n",
" last_confident_value = librosa.hz_to_midi(f)\n",
" yield last_confident_value\n",
" \n",
"#m_time, midi = zip(*[[t, librosa.hz_to_midi(f)] for t, f, c in zip(f_time, f_frequency, s_confidence) if c > 0.0])\n",
"#nr_midi = np.interp(f_time, m_time, midi)\n",
"#r_midi = np.interp(f_time, m_time, np.around(midi))\n",
"#midi\n",
"\n",
"midi = list(filter_midi(f_time, f_frequency, s_confidence))\n",
"\n",
"def snap_midi(midi):\n",
" r_midi = np.around(midi)\n",
" s_midi = np.around(savgol_filter(midi, 30, 5))\n",
" last_val = s_midi[0]\n",
" for i, (r1, r2) in enumerate(pairwise(r_midi)):\n",
" if r1 != r2:\n",
" last_val = s_midi[i+5]\n",
" yield last_val\n",
" yield last_val\n",
"\n",
"def filter_midi(midi):\n",
" last_val = midi[0]\n",
" dur = 1\n",
" dev = 0.0\n",
" first_flag = True\n",
" for i, (m1, m2) in enumerate(pairwise(midi)):\n",
" if m1 != m2:\n",
" #yield (dur / 40, last_val, dev * 100)\n",
" if first_flag or dur < 20:\n",
" yield (dur / 40, last_val, dev * 100)\n",
" first_flag = False\n",
" else:\n",
" size = int(dur / 5)\n",
" sep = randint(1, size)\n",
" yield (5 / 40.0 * sep, last_val, dev * 100)\n",
" yield (5 / 40.0 * (size - sep), last_val, 0.0)\n",
" last_val = m2\n",
" dur = 1\n",
" dev = m2 - m1\n",
" else:\n",
" dur += 1\n",
" \n",
" \n",
"\n",
"plt.plot(f_time, midi)\n",
"plt.plot(f_time, savgol_filter(midi, 30, 5), color='yellow')\n",
"plt.plot(f_time, np.around(savgol_filter(midi, 30, 5)), color='red')\n",
"plt.plot(f_time, np.around(midi), color='green')\n",
"plt.plot(f_time, list(snap_midi(midi)), color='blue')\n",
"#plt.show()\n",
"\n",
"target_melody_data = list(filter_midi(list(snap_midi(midi))))\n",
"target_melody_data\n",
"\n",
"#target_melody_data = list(filter_data(time, frequency, confidence))\n",
"#target_melody_data\n",
"#durs = tuple(round(y[0]-x[0], 2) for (x, y) in pairwise(target_melody_data)) + ((1,))\n",
"#print(durs)\n",
"#target_melody_data = tuple((d,) + target_melody_data[i][1:] for i, d in enumerate(durs) if d > 0.1)\n",
"#list(target_melody_data)"
]
},
{
"cell_type": "code",
"execution_count": 118,
"id": "b0d17cc2-a181-4212-aba5-72b90cab2a84",
"metadata": {},
"outputs": [],
"source": [
"from random import choice, choices\n",
"\n",
"# This is for the beginning / breysheet\n",
"def stochastic_hamiltonian(graph):\n",
"\n",
" #try making this omit the moving voice\n",
" def movement_size_weights(edges):\n",
" \n",
" def max_cent_diff(edge):\n",
" res = max([abs(v) for val in edge[2]['movements'].values() if (v:=val['cent_difference']) is not None])\n",
" return res\n",
" \n",
" def min_cent_diff(edge):\n",
" res = [abs(v) for val in edge[2]['movements'].values() if (v:=val['cent_difference']) is not None]\n",
" res.remove(0)\n",
" return min(res)\n",
" \n",
" for e in edges:\n",
" yield 4 if ((max_cent_diff(e) < 300) and (min_cent_diff(e)) >= 0) else 1\n",
"\n",
" def hamiltonian_weights(edges):\n",
" for e in edges:\n",
" yield 10 if e[1] not in [path_edge[0] for path_edge in path] else 1 / graph.nodes[e[1]]['count']\n",
" \n",
" def contrary_motion_weights(edges):\n",
"\n",
" def is_contrary(edge):\n",
" cent_diffs = [v for val in edge[2]['movements'].values() if (v:=val['cent_difference']) is not None]\n",
" cent_diffs.sort()\n",
" return (cent_diffs[0] < 0) and (cent_diffs[1] == 0) and (cent_diffs[2] > 0)\n",
"\n",
" for e in edges:\n",
" yield 2 if is_contrary(e) else 1\n",
" \n",
" def is_directly_tunable_weights(edges):\n",
" for e in edges:\n",
" yield 10 if e[2]['is_directly_tunable'] else 1\n",
"\n",
" def symdiff_weights(edges):\n",
" for e in edges:\n",
" yield 1000 if e[2]['symmetric_difference'] == 2 else 1\n",
"\n",
" def transposition_weight(edges):\n",
" for e in edges:\n",
" yield 100 if 0 <= hs_array_to_cents(e[2]['transposition']) < 100 else 1\n",
"\n",
" def is_sustained_voice(edges, voice):\n",
" \n",
" def is_sustained(edge):\n",
" source = list(edge[0])\n",
" ordered_source = sorted(source, key=hs_array_to_fr) \n",
" destination = [transpose_pitch(edge[2]['movements'][p]['destination'], edge[2]['transposition']) for p in source]\n",
" ordered_destination = sorted(destination, key=hs_array_to_fr)\n",
" return ordered_source[voice] == ordered_destination[voice]\n",
"\n",
" for e in edges:\n",
" yield 10 if is_sustained(e) else 1\n",
"\n",
" def voice_crossing_weights(edges):\n",
" \n",
" def has_voice_crossing(edge):\n",
" source = list(edge[0])\n",
" ordered_source = sorted(source, key=hs_array_to_fr) \n",
" source_order = [ordered_source.index(p) for p in source]\n",
" destination = [transpose_pitch(edge[2]['movements'][p]['destination'], edge[2]['transposition']) for p in source]\n",
" ordered_destination = sorted(destination, key=hs_array_to_fr)\n",
" destination_order = [ordered_destination.index(p) for p in destination]\n",
" return source_order != destination_order\n",
"\n",
" for e in edges:\n",
" yield 10 if not has_voice_crossing(e) else 0\n",
"\n",
" def is_bass_rooted(chord):\n",
" return max([sum(abs(p) for p in collapse_pitch(pitch_difference(chord[0], p))) for p in chord[1:]]) == 1\n",
"\n",
" def target_melody_weights(edges, target, c_devs, voice):\n",
"\n",
" def target_weight(edge, target, c_devs, voice):\n",
" candidate_diffs = []\n",
" for idx, dev in enumerate(c_devs):\n",
" if(idx == 2):\n",
" source = list(edge[0])\n",
" ordered_source = sorted(source, key=hs_array_to_fr) \n",
" candidate_diff = edge[2]['movements'][ordered_source[idx]]['cent_difference']\n",
" candidate_diffs += [abs(dev + candidate_diff - target)]\n",
" #return 1/pow(1.1, min(candidate_diffs))\n",
" return 10 if min(candidate_diffs) < 40 else 1/pow(1.1, min(candidate_diffs))\n",
" \n",
" for e in edges:\n",
" yield target_weight(e, target, c_devs, voice)\n",
" \n",
" check_graph = graph.copy()\n",
" next_node = choice(list(graph.nodes()))\n",
" check_graph.remove_node(next_node)\n",
" for node in graph.nodes(data=True):\n",
" node[1]['count'] = 1\n",
" path = []\n",
" s_next_node = sorted(next_node, key=hs_array_to_fr)\n",
" c_devs = (cent_difference(s_next_node[2], s_next_node[0]), cent_difference(s_next_node[2], s_next_node[1]), 0,)\n",
" #c_devs = (0, cent_difference(s_next_node[0], s_next_node[1]), cent_difference(s_next_node[0], s_next_node[2]),)\n",
" print(c_devs)\n",
" while (nx.number_of_nodes(check_graph) > 0) and (len(path) < len(target_melody_data)-1):\n",
" out_edges = list(graph.out_edges(next_node, data=True))\n",
" factors = [\n",
" movement_size_weights(out_edges), \n",
" #hamiltonian_weights(out_edges), \n",
" #contrary_motion_weights(out_edges), \n",
" #is_directly_tunable_weights(out_edges),\n",
" voice_crossing_weights(out_edges),\n",
" #transposition_weight(out_edges),\n",
" #is_sustained_voice(out_edges, 0),\n",
" target_melody_weights(out_edges, target_melody_data[len(path)+1][-1], c_devs, 2),\n",
" #symdiff_weights(out_edges)\n",
" ]\n",
" weights = [prod(a) for a in zip(*factors)]\n",
" edge = choices(out_edges, weights=weights)[0]\n",
" next_node = edge[1]\n",
" node[1]['count'] += 1\n",
" path.append(edge)\n",
" s_chord = tuple(sorted(edge[0], key=hs_array_to_fr))\n",
" c_devs = tuple(c_devs[pdx] + edge[2]['movements'][pitch]['cent_difference'] - target_melody_data[len(path)][-1] for pdx, pitch in enumerate(s_chord))\n",
" print(s_chord)\n",
" print(c_devs)\n",
" print(target_melody_data[len(path)][-1])\n",
" if next_node in check_graph.nodes:\n",
" check_graph.remove_node(next_node)\n",
" return path"
]
},
{
"cell_type": "code",
"execution_count": 105,
"id": "a8592bc9-7e9e-4b6a-9eaa-4c4e3b69ce91",
"metadata": {},
"outputs": [],
"source": [
"dims = (2, 3, 5, 7, 11, 13)\n",
"root = (0, 0, 0, 0, 0, 0)\n",
"chord = (root,)\n",
"chord_set = chords(chord, root, 3, 3)\n",
"graph = generate_graph(chord_set, 2, 2, 3)"
]
},
{
"cell_type": "code",
"execution_count": 143,
"id": "fb2ad9ad-7a8c-4f84-ab0c-9c1f1ecdb8a8",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy80BEi2AAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOx9d5wlRbX/t/ummdm8ywbCknNOiigKPFFUxBxBEVSe+sDE+71nRH2KoL4nZsX4TOAzKwqigIKKIElyzizL5jS7M3Pv7e76/dFdVaeqTnW4M7OzuPd8PrB37u1Q3V1ddep7vud7AiGEQN/61re+9a1vfevbFFk41Q3oW9/61re+9a1vW7f1nZG+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mNp29G3LMRq6KJqgb7wReM5zgB12mNw2TZZVudapNopeUkSnb1u3feUrwK23Al/+8lS3pG8VrbIzsmnTJhx00EH4yle+Umr7hx9+GCeccAKOPfZY3HLLLXjPe96Dt771rfj9739fubGTbv/sBMXJsm99C/jGN6a6FZNjNF26aIK+5Zb03yR5avYl2uYt3RmhjhNFdPq2ddvKlVPdgr71aJWdkRe+8IU455xz8PKXv7zU9hdccAF22WUXfPazn8U+++yDM888E6961avwuc99rnJjJ92eihPIVNuGDak2xdvelpIe/9mMTnpFYZpp0/j9ylq7DTzzmen9rGoPPADstVe6MvTZqlXAF78ILFvG//5UckZo+/rv7VPDkgR44xuBj3988s7xz55+/09sk84Zufbaa3HccccZ3x1//PG49tprvfu0221s2LDB+G+z2JZKXL3xRuCSS6a6FbytXas/bymx+04HeOyxiTkWdSqqiMr14oz87nfAtdemSFNV++Y3gfvuA84807/N5z4HvPvdwAtewP/+VHJGen0ufZs6u/JK4Ic/BD760ck7B3VGtrTx/KqrgJNPBh5/fKpbskXapDsjy5Ytw8KFC43vFi5ciA0bNmCUZioQO++88zBr1iz13+LFiye7maltaZ1X2tOeBrz4xcCDD051S1xbvVp/rhK7P/XUdFKcjFXtCScAO+0E3HTT+I9FJ7oiB4P2n16cEXovx8bS451xBvCpTxXv63mXDJNcrVtv5X9/qjojWxIycvvtwPHHA9dfP9Ut2TLswx9OEwKEAB55RH8/WWMtdUa2pD4sBHDsscBFFwE/+tFUt2aLtC0ym+YDH/gA1q9fr/57fHN5kuMd1MpMCFXszjuBn/1M//3EE+M/5ve/nyq2TpRRNKQsMpIkwPe+B/z+96mM/UTbFVek/37ve+M/1uZERppN/Xn9+vTefPWrwAc+MDETbhG34qnkjND2bUnIyPHHA3/4A/Dc5051S7YM++Qn0zHntts2D0GaOiNbUso37aMPPTR17diCbdKdkUWLFmG5VdNj+fLlmDlzJgYHB9l9Wq0WZs6cafy3WayIE5BnF1wADA0Bv/jFxLVn//1NhcmBgfEdT4h0lfKxjwF33D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zsd0+GTheSKnJEqAm9TbfZE4+MeXXGFzl44++yJOfcTTwDbblt8P8djjz4K7LknsOOOwP33T955JtPoe97pmOPreFFL31ho81S2FLNRz/HaRC2cb755Yo4zAbZFZtNMmRU94I0b0/TIovg9Z1UdHc4ZKXOMvNUAdUaKVg0jI+lkXpRO3AsyMpmrl4kegMoiI1/7GvB//2duSydIGiIrca540yb3WvJUbik/pt02BzzZr4sEoSbCWbX3m6zVqX0e6ZA/8ECaRSWvhWagTQSv5LLLUrn/k08e/7Hy7E9/St+tBx6YmD49FWJgNhJC/x5vv/CNhU8FZOSaa9JEh83Jc3rkkXTusu/JFuSw9Z0RatQZ4TrKmWc
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[(0.25, 51.0, 0.0),\n",
" (0.25, 53.0, 200.0),\n",
" (0.0, 53.0, 0.0),\n",
" (0.25, 51.0, -200.0),\n",
" (1.25, 51.0, 0.0),\n",
" (0.25, 49.0, -200.0),\n",
" (0.0, 49.0, 0.0),\n",
" (0.75, 48.0, -100.0),\n",
" (0.25, 48.0, 0.0),\n",
" (0.5, 49.0, 100.0),\n",
" (0.0, 49.0, 0.0),\n",
" (0.25, 51.0, 200.0),\n",
" (1.25, 51.0, 0.0),\n",
" (0.25, 49.0, -200.0),\n",
" (0.5, 48.0, -100.0),\n",
" (0.5, 48.0, 0.0),\n",
" (0.5, 51.0, 300.0),\n",
" (0.0, 51.0, 0.0),\n",
" (0.25, 53.0, 200.0),\n",
" (0.0, 53.0, 0.0),\n",
" (0.75, 51.0, -200.0),\n",
" (1.0, 51.0, 0.0),\n",
" (1.0, 48.0, -300.0),\n",
" (0.25, 48.0, 0.0),\n",
" (0.5, 53.0, 500.0),\n",
" (0.25, 53.0, 0.0),\n",
" (1.5, 49.0, -400.0),\n",
" (0.0, 49.0, 0.0),\n",
" (0.25, 52.0, 300.0),\n",
" (0.25, 53.0, 100.0),\n",
" (0.25, 52.0, -100.0),\n",
" (0.0, 52.0, 0.0),\n",
" (0.25, 51.0, -100.0),\n",
" (0.0, 51.0, 0.0),\n",
" (0.25, 52.0, 100.0),\n",
" (0.25, 51.0, -100.0),\n",
" (0.5, 49.0, -200.0),\n",
" (0.0, 49.0, 0.0),\n",
" (0.25, 46.0, -300.0),\n",
" (1.0, 46.0, 0.0),\n",
" (0.25, 51.0, 500.0),\n",
" (1.0, 51.0, 0.0),\n",
" (0.25, 56.0, 500.0),\n",
" (0.5, 57.0, 100.0),\n",
" (0.0, 57.0, 0.0),\n",
" (0.75, 53.0, -400.0),\n",
" (0.0, 53.0, 0.0),\n",
" (0.25, 54.0, 100.0),\n",
" (0.25, 53.0, -100.0),\n",
" (0.0, 53.0, 0.0),\n",
" (0.25, 56.0, 300.0),\n",
" (0.5, 57.0, 100.0),\n",
" (0.0, 57.0, 0.0),\n",
" (0.75, 51.0, -600.0),\n",
" (0.5, 51.0, 0.0),\n",
" (0.5, 52.0, 100.0),\n",
" (0.0, 52.0, 0.0),\n",
" (0.25, 53.0, 100.0),\n",
" (0.25, 53.0, 0.0),\n",
" (1.5, 51.0, -200.0),\n",
" (0.5, 51.0, 0.0),\n",
" (0.25, 48.0, -300.0),\n",
" (0.75, 48.0, 0.0),\n",
" (1.25, 51.0, 300.0),\n",
" (0.0, 51.0, 0.0),\n",
" (0.25, 53.0, 200.0),\n",
" (0.0, 53.0, 0.0),\n",
" (0.25, 52.0, -100.0),\n",
" (0.25, 51.0, -100.0),\n",
" (0.0, 51.0, 0.0),\n",
" (0.25, 56.0, 500.0),\n",
" (0.25, 57.0, 100.0),\n",
" (0.75, 56.0, -100.0),\n",
" (0.0, 56.0, 0.0),\n",
" (0.5, 57.0, 100.0),\n",
" (0.0, 57.0, 0.0),\n",
" (0.25, 53.0, -400.0),\n",
" (0.0, 53.0, 0.0),\n",
" (1.0, 51.0, -200.0),\n",
" (0.5, 51.0, 0.0),\n",
" (0.25, 52.0, 100.0),\n",
" (0.25, 51.0, -100.0),\n",
" (0.5, 51.0, 0.0),\n",
" (0.25, 52.0, 100.0),\n",
" (0.0, 52.0, 0.0),\n",
" (1.75, 51.0, -100.0),\n",
" (0.25, 51.0, 0.0),\n",
" (0.75, 48.0, -300.0),\n",
" (0.5, 48.0, 0.0),\n",
" (0.5, 53.0, 500.0),\n",
" (0.0, 53.0, 0.0),\n",
" (0.75, 49.0, -400.0),\n",
" (0.75, 49.0, 0.0),\n",
" (0.25, 51.0, 200.0),\n",
" (0.5, 51.0, 0.0),\n",
" (0.5, 48.0, -300.0),\n",
" (0.5, 48.0, 0.0),\n",
" (0.25, 51.0, 300.0),\n",
" (0.25, 52.0, 100.0),\n",
" (0.25, 51.0, -100.0),\n",
" (0.25, 51.0, 0.0),\n",
" (0.25, 53.0, 200.0),\n",
" (1.0, 52.0, -100.0),\n",
" (0.0, 52.0, 0.0),\n",
" (0.25, 50.0, -200.0),\n",
" (0.5, 49.0, -100.0),\n",
" (0.5, 49.0, 0.0),\n",
" (1.0, 52.0, 300.0),\n",
" (0.5, 52.0, 0.0),\n",
" (0.5, 51.0, -100.0),\n",
" (0.25, 51.0, 0.0),\n",
" (0.25, 53.0, 200.0),\n",
" (0.0, 53.0, 0.0),\n",
" (0.5, 49.0, -400.0),\n",
" (1.0, 49.0, 0.0),\n",
" (0.5, 56.0, 700.0),\n",
" (0.0, 56.0, 0.0),\n",
" (0.25, 55.0, -100.0),\n",
" (0.25, 54.0, -100.0),\n",
" (0.0, 54.0, 0.0),\n",
" (0.25, 53.0, -100.0),\n",
" (0.25, 51.0, -200.0),\n",
" (0.0, 51.0, 0.0),\n",
" (0.25, 53.0, 200.0),\n",
" (0.0, 53.0, 0.0),\n",
" (1.75, 51.0, -200.0),\n",
" (0.25, 51.0, 0.0),\n",
" (0.25, 49.0, -200.0),\n",
" (0.0, 49.0, 0.0),\n",
" (0.25, 48.0, -100.0),\n",
" (0.0, 48.0, 0.0),\n",
" (0.25, 49.0, 100.0),\n",
" (1.0, 51.0, 200.0),\n",
" (1.25, 51.0, 0.0),\n",
" (0.25, 53.0, 200.0),\n",
" (0.0, 53.0, 0.0),\n",
" (0.25, 52.0, -100.0)]"
]
},
"execution_count": 143,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAh8AAAGdCAYAAACyzRGfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy80BEi2AAAACXBIWXMAAA9hAAAPYQGoP6dpAACsbUlEQVR4nO2dd5xcVfn/P+fOzM723fTegJBKQmghdAkiRURAwQiCCAiIVEHAFvgqBisqXRTBn4WmVAHpASSEEFoCJKSRXkjbvrMzc8/vj9vOmbl1Zu7M7M7zfr2Snbn1zC3nPOepjHPOQRAEQRAEUSSUUjeAIAiCIIjKgoQPgiAIgiCKCgkfBEEQBEEUFRI+CIIgCIIoKiR8EARBEARRVEj4IAiCIAiiqJDwQRAEQRBEUSHhgyAIgiCIohItdQMyUVUVmzZtQkNDAxhjpW4OQRAEQRA+4Jyjra0Nw4cPh6K46zbKTvjYtGkTRo0aVepmEARBEASRA+vXr8fIkSNdtyk74aOhoQGA1vjGxsYSt4YgCIIgCD+0trZi1KhR5jjuRtkJH4appbGxkYQPgiAIguhl+HGZIIdTgiAIgiCKCgkfBEEQBEEUFRI+CIIgCIIoKiR8EARBEARRVEj4IAiCIAiiqJDwQRAEQRBEUSHhgyAIgiCIokLCB0EQBEEQRYWED4IgCIIgigoJHwRBEARBFBUSPgiCIAiCKCokfBAEQRAEUVTKrrAcQfQGLv/DM1j+SAQTO2uBeBWQTCF2wHScf3kdJkzw3v/GOz7Cw39fhmmdcQzuVIB+/dD/c9NwxfW1qMR6io/OX4GbfrECys7t+N5Rn+KMeT8GhOJUqRTwjcvfwDuLV6G6PQGluhqIV+OQr9Ti9itPKGHLiV6NquJ/v70C17U9inOOuAznz76m1C2qGBjnnJe6ESKtra1oampCS0s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TrcPNLuxHf/A9zUdeaUcaGAORQW06htkQOJJMc/2/ZZICNNpf9+x6OERN3lLBVlUNg4WPFihUYPnw4qqurMWvWLMybNw+jR4/Gtm3bsHDhQpx55pk45JBDsGrVKkycOBE33XQTDjvsMMfjJRIJJBIJ83tra2tuv4QgisSny+q1D2oEcz+nL/wQwMNAR3IdgBGu+6eNRCG6luSEswA8DuBdYEP7QgCjnHbtu4imk/Zh+PmT84AnbbZTNOEuKlisSPQgcuFrl3+Ef//jYWnZIwCU4W9i3gVdqInVlKZhFUIg4WPmzJm47777MGHCBGzevBk33ngjDj/8cCxduhSrV68GoPmF/PrXv8a+++6Lv/71r5g9ezaWLl2K8ePH2x5z3rx5uPHGG/P/JQRRJEwfg+7+2H8TgDiwpZVjI4A0vDUfacHnY5+tQFUkho97gE4APelKFb71azr8LcTTUURsJIru6nao+96PC1f1w8gI+csQ+fHG+7p5pX4T0LAJSNYC2ydDbR2DlkQLCR8hE0j4OP74483P06ZNw8yZMzFmzBg89NBDmDRpEgDgwgsvxLnnngsAmDFjBl588UXce++9mDdvnu0xr7/+elx11VXm99bWVowaVYEzP6LXUT3mGbw9Zhzwg8vwqxkL8H0AchCoPWJGzgVfPwd1B1+EmSOW4q3QWlr+KGBQAdw54xu46KnlLlsuAgB0/ec84IvaEq6SIEIEx3gNp4y9Hf+4fisSkUYc9LXfaj5HlWr+LCJ5eYI2Nzdj7733xsqVKzFs2DAAwOTJk6VtJk2ahHXr1jkeIx6Po7GxUfpHEOWMlM5b2RvAFYDiP+LCclfgYEoMUGLCygI0sBdiaJO43+soXjOCyIFY1Br+qqqiUJS49oUzpNMk0IZNXsJHe3s7Vq1ahWHDhmHs2LEYPnw4li+XZy2ffPIJxowZk1cjCaIcYeCAHslljpk+wj7TovA
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import librosa \n",
"import numpy as np\n",
"from scipy.signal import savgol_filter\n",
"import matplotlib.pyplot as plt\n",
"from random import randint\n",
"\n",
"def filter_data(time, frequency, confidence):\n",
" data = tuple(data for data in zip(list(time), list(frequency), list(confidence)) if data[2] > 0.1)\n",
" dev = 0\n",
" dur = 0\n",
" for (p1, p2) in pairwise(data):\n",
" t_diff = (p2[0] - p1[0])\n",
" dur = round(dur + (p2[0] - p1[0]), 2)\n",
" if(True):\n",
" freq1, conf1 = p1[1:3]\n",
" midi1 = librosa.hz_to_midi(freq1)\n",
" r_midi1 = np.around(midi1)\n",
" freq2, conf2 = p2[1:3]\n",
" midi2 = librosa.hz_to_midi(freq2)\n",
" r_midi2 = np.around(midi2)\n",
" #if(r_midi2 != r_midi1):\n",
" if(True):\n",
" yield(dur, freq1, conf1, midi1, r_midi1, dev * 100)\n",
" dev = r_midi2 - r_midi1\n",
" dur = 0\n",
" \n",
"def filter_data(time, frequency, confidence):\n",
" data = tuple(data for data in zip(list(time), list(frequency), list(confidence)) if data[2] > 0.9)\n",
" #durs = tuple(round(y[0]-x[0], 2) for (x, y) in pairwise(data)) + ((1,))\n",
" #data = tuple((d,) + data[i][1:] for i, d in enumerate(durs) if d > 0.01)\n",
" #print(data)\n",
" m, rm = [librosa.hz_to_midi(data[0][1]), np.around(librosa.hz_to_midi(data[0][1]))]\n",
" yield(data[0] + (m, rm, 0,))\n",
" for i, [t, f, c] in enumerate(data):\n",
" nm, nrm = [librosa.hz_to_midi(f), np.around(librosa.hz_to_midi(f))]\n",
" if((0 < i < len(data) - 1) and (nrm != rm)):\n",
" m, rm, d = [nm, nrm, nrm - rm]\n",
" yield(t, f, c, m, rm, d * 100)\n",
" \n",
"t_min = 50\n",
"t_max = 600\n",
"f_time, f_frequency, f_confidence = [time[t_min:], frequency[t_min:], confidence[t_min:]]\n",
"s_confidence = savgol_filter(f_confidence, 30, 4)\n",
"plt.plot(f_time, f_confidence)\n",
"plt.plot(f_time, s_confidence, color='red')\n",
"plt.show()\n",
"\n",
"def filter_midi(f_time, f_frequency, s_confidence):\n",
" last_confident_value = 51\n",
" for t, f, c in zip(f_time, f_frequency, s_confidence):\n",
" if c > 0.9:\n",
" last_confident_value = librosa.hz_to_midi(f)\n",
" yield last_confident_value\n",
" \n",
"#m_time, midi = zip(*[[t, librosa.hz_to_midi(f)] for t, f, c in zip(f_time, f_frequency, s_confidence) if c > 0.0])\n",
"#nr_midi = np.interp(f_time, m_time, midi)\n",
"#r_midi = np.interp(f_time, m_time, np.around(midi))\n",
"#midi\n",
"\n",
"midi = list(filter_midi(f_time, f_frequency, s_confidence))\n",
"\n",
"def snap_midi(midi):\n",
" r_midi = np.around(midi)\n",
" s_midi = np.around(savgol_filter(midi, 30, 5))\n",
" last_val = s_midi[0]\n",
" for i, (r1, r2) in enumerate(pairwise(r_midi)):\n",
" if r1 != r2:\n",
" last_val = s_midi[i+5]\n",
" yield last_val\n",
" yield last_val\n",
"\n",
"def filter_midi(midi):\n",
" last_val = midi[0]\n",
" dur = 1\n",
" dev = 0.0\n",
" first_flag = True\n",
" for i, (m1, m2) in enumerate(pairwise(midi)):\n",
" if m1 != m2:\n",
" #yield (dur / 40, last_val, dev * 100)\n",
" if first_flag or dur < 10:\n",
" yield (10 / 40.0, last_val, dev * 100)\n",
" first_flag = False\n",
" else:\n",
" size = int(dur / 10)\n",
" \n",
" sep = randint(1, size)\n",
" yield (10 / 40.0 * sep, last_val, dev * 100)\n",
" yield (10 / 40.0 * (size - sep), last_val, 0.0)\n",
"\n",
" #yield (10 / 40.0, last_val, dev * 100)\n",
" #for i in range(size):\n",
" # yield (10 / 40.0, last_val, 0.0)\n",
" \n",
" last_val = m2\n",
" dur = 1\n",
" dev = m2 - m1\n",
" else:\n",
" dur += 1\n",
" \n",
" \n",
"\n",
"plt.plot(f_time, midi)\n",
"plt.plot(f_time, savgol_filter(midi, 30, 5), color='yellow')\n",
"plt.plot(f_time, np.around(savgol_filter(midi, 30, 5)), color='red')\n",
"plt.plot(f_time, np.around(midi), color='green')\n",
"plt.plot(f_time, list(snap_midi(midi)), color='blue')\n",
"#plt.show()\n",
"\n",
"target_melody_data = list(filter_midi(list(snap_midi(midi))))\n",
"target_melody_data\n",
"\n",
"#target_melody_data = list(filter_data(time, frequency, confidence))\n",
"#target_melody_data\n",
"#durs = tuple(round(y[0]-x[0], 2) for (x, y) in pairwise(target_melody_data)) + ((1,))\n",
"#print(durs)\n",
"#target_melody_data = tuple((d,) + target_melody_data[i][1:] for i, d in enumerate(durs) if d > 0.1)\n",
"#list(target_melody_data)"
]
},
{
"cell_type": "code",
"execution_count": 115,
"id": "be01e4ae-e629-42ff-9d95-f77d510c13bf",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(-551.3179423647567, -165.0042284999219, 0)\n",
"((0, 0, 0, 0, 0, 0), (-2, 0, 1, 0, 0, 0), (-3, 0, 0, 0, 1, 0))\n",
"(-751.3179423647567, -365.0042284999219, 21.309485364912916)\n",
"200.0\n",
"((0, 0, 0, 0, 0, 0), (-2, 0, 1, 0, 0, 0), (-4, 0, 2, 0, 0, 0))\n",
"(-724.4765667306114, -365.0042284999219, 21.309485364912916)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (2, 0, 1, 0, 0, -1))\n",
"(-524.4765667306114, -165.0042284999219, 26.841375634145265)\n",
"-200.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (-3, 0, 0, 0, 1, 0))\n",
"(-524.4765667306114, -204.33271789672978, 26.841375634145265)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-6, 0, 0, 1, 1, 0), (-3, 0, 0, 0, 1, 0))\n",
"(-475.11362523124217, -4.3327178967297755, 226.84137563414527)\n",
"-200.0\n",
"((0, 0, 0, 0, 0, 0), (-4, 1, 0, 1, 0, 0), (-1, 1, 0, 0, 0, 0))\n",
"(-421.8406820010981, -4.3327178967297755, 226.84137563414527)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (1, 0, 0, 1, -1, 0), (4, 0, 0, 0, -1, 0))\n",
"(-135.50681142760473, 95.66728210327022, 326.84137563414527)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, 0, -1, 0, 0), (6, 0, 0, -2, 0, 0))\n",
"(-135.50681142760473, 95.66728210327022, 223.9655268030848)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, 0, -1, 0, 0), (4, 0, 0, 0, 0, -1))\n",
"(-235.50681142760473, -107.20856672779013, 123.9655268030848)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (1, 0, 0, 1, 0, -1), (4, 0, 0, 0, 0, -1))\n",
"(-920.8948528629555, -107.20856672779013, 123.9655268030848)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, -1, 0, 0, 0), (6, 0, -1, -1, 0, 0))\n",
"(-574.0794723315278, -307.2085667277901, -76.0344731969152)\n",
"200.0\n",
"((0, 0, 0, 0, 0, 0), (-1, -1, 0, 1, 0, 0), (2, -1, 0, 0, 0, 0))\n",
"(-889.7207593320804, -307.2085667277901, -76.0344731969152)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (0, 0, -1, 1, 0, 0), (3, 0, -1, 0, 0, 0))\n",
"(-947.7362284971007, -107.20856672779013, 123.9655268030848)\n",
"-200.0\n",
"((0, 0, 0, 0, 0, 0), (-3, 0, 0, 0, 0, 1), (0, 0, 0, -1, 0, 1))\n",
"(-847.7362284971007, -7.208566727790128, 121.0896779720241)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (-3, 0, 0, 0, 0, 1), (-2, 0, 0, 1, 0, 0))\n",
"(-847.7362284971007, -110.08441555885082, 121.0896779720241)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-5, 0, 0, 2, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-1019.4379837972862, -410.0844155588508, -178.9103220279759)\n",
"300.0\n",
"((0, 0, 0, 0, 0, 0), (-6, 0, 0, 1, 0, 1), (-3, 0, 0, 0, 0, 1))\n",
"(-1019.4379837972862, -410.0844155588508, -50.612077328161604)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-6, 0, 0, 1, 0, 1), (-2, 0, 0, 1, 0, 0))\n",
"(-1219.437983797286, -1091.1397390974719, -250.6120773281616)\n",
"200.0\n",
"((0, 0, 0, 0, 0, 0), (1, 0, 0, 1, 0, -1), (-2, 0, 0, 1, 0, 0))\n",
"(-1219.437983797286, -570.7559261620431, -250.6120773281616)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-1019.437983797286, -370.7559261620431, 15.557787702791757)\n",
"-200.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (2, 0, 1, 0, -1, 0))\n",
"(-730.2282643927321, -370.7559261620431, 15.557787702791757)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (2, 0, 1, 0, 0, -1))\n",
"(-430.22826439273206, -70.75592616204312, -43.9145505278978)\n",
"-300.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (-2, 0, 1, 0, 0, 0))\n",
"(-884.4422122972078, -70.75592616204312, -43.9145505278978)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, -1, 0, 0, 0), (-3, 0, 0, 0, 0, 1))\n",
"(-1384.4422122972078, -570.7559261620431, -211.28358793135357)\n",
"500.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, -1, 0, 0, 0), (7, 0, -1, 0, 0, -1))\n",
"(-1051.8112497006637, -570.7559261620431, -211.28358793135357)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-7, 0, 0, 0, 0, 2), (-3, 0, 0, 0, 0, 1))\n",
"(-651.8112497006637, -42.45768146222866, 188.71641206864643)\n",
"-400.0\n",
"((0, 0, 0, 0, 0, 0), (-6, 0, 0, 1, 0, 1), (-3, 0, 0, 0, 0, 1))\n",
"(-170.7559261620425, -42.45768146222866, 188.71641206864643)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (1, 0, 0, 1, 0, -1), (4, 0, 0, 0, 0, -1))\n",
"(-728.7713953270627, -342.45768146222866, -111.28358793135357)\n",
"300.0\n",
"((0, 0, 0, 0, 0, 0), (-2, 0, 1, 0, 0, 0), (1, 0, 1, -1, 0, 0))\n",
"(-828.7713953270627, -442.45768146222866, -15.085109191897857)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (-2, 0, 1, 0, 0, 0), (3, 0, -1, 0, 0, 0))\n",
"(-728.7713953270627, -342.45768146222866, -26.81639446167577)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (-2, 0, 1, 0, 0, 0), (-1, 1, 0, 0, 0, 0))\n",
"(-728.7713953270627, -524.8613935962886, -26.81639446167577)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-3, 2, 0, 0, 0, 0), (-1, 1, 0, 0, 0, 0))\n",
"(-1073.5434512315312, -424.8613935962886, 73.18360553832423)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (6, -1, 0, 0, -1, 0))\n",
"(-1073.5434512315312, -424.8613935962886, -38.54767973145334)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (2, 0, 1, 0, -1, 0))\n",
"(-1173.5434512315312, -524.8613935962886, -26.81639446167577)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (6, -1, 0, 0, -1, 0))\n",
"(-1073.5434512315312, -424.8613935962886, -38.54767973145334)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (2, 0, 1, 0, -1, 0))\n",
"(-873.5434512315312, -224.86139359628862, -33.015789462220994)\n",
"-200.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (-3, 0, 0, 0, 0, 1))\n",
"(-873.5434512315312, -514.0711130008425, -33.015789462220994)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (-3, 0, 0, 0, 0, 1))\n",
"(-573.5434512315312, -214.0711130008425, -22.225508866774874)\n",
"-300.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (-3, 0, 0, 0, 1, 0))\n",
"(-573.5434512315312, -408.53922273161, -22.225508866774874)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-1, 0, -1, 0, 1, 0), (-3, 0, 0, 0, 1, 0))\n",
"(-1073.5434512315312, -908.5392227316099, -259.85716509636626)\n",
"500.0\n",
"((0, 0, 0, 0, 0, 0), (-1, 0, -1, 0, 1, 0), (3, 0, -1, 0, 0, 0))\n",
"(-1073.5434512315312, -714.0711130008424, -259.85716509636626)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (3, 0, -1, 0, 0, 0))\n",
"(-1573.5434512315312, -1214.0711130008424, -400.38482686567676)\n",
"500.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (7, 0, -1, 0, 0, -1))\n",
"(-1545.2452065317168, -1314.0711130008424, -500.38482686567676)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, 0, -1, 0, 0), (6, 0, -1, -1, 0, 0))\n",
"(-1545.2452065317168, -1314.0711130008424, -473.5434512315314)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, 0, -1, 0, 0), (0, 0, 0, -1, 0, 1))\n",
"(-1145.2452065317168, -914.0711130008424, -100.38482686567676)\n",
"-400.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, 0, -1, 0, 0), (6, 0, -1, -1, 0, 0))\n",
"(-1145.2452065317168, -914.0711130008424, -73.54345123153138)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, 0, -1, 0, 0), (0, 0, 0, -1, 0, 1))\n",
"(-1142.3693577006563, -1014.0711130008424, -173.54345123153138)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (1, 0, 0, 1, 0, -1), (-2, 0, 0, 1, 0, 0))\n",
"(-1042.3693577006563, -393.68730006541364, -73.54345123153138)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-1042.3693577006563, -393.68730006541364, -7.373586200578018)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (2, 0, 1, 0, -1, 0))\n",
"(-1342.3693577006563, -693.6873000654136, -195.64230093080045)\n",
"300.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (6, -1, 0, 0, -1, 0))\n",
"(-1136.1699627001112, -793.6873000654136, -295.64230093080045)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (-5, 1, 0, 0, 0, 1), (-3, 0, 0, 0, 0, 1))\n",
"(-1291.7322992000259, -793.6873000654136, -295.64230093080045)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (2, -1, 0, 0, 0, 0), (4, -2, 0, 0, 0, 0))\n",
"(-691.7322992000259, -193.68730006541364, 10.22270166536191)\n",
"-600.0\n",
"((0, 0, 0, 0, 0, 0), (2, -1, 0, 0, 0, 0), (-1, 1, 0, 0, 0, 0))\n",
"(-691.7322992000259, -376.0910121994732, 10.22270166536191)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (1, 1, -1, 0, 0, 0), (-1, 1, 0, 0, 0, 0))\n",
"(-791.7322992000259, -476.0910121994732, 21.953986935139824)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (1, 1, -1, 0, 0, 0), (3, 0, -1, 0, 0, 0))\n",
"(-974.1360113340859, -476.0910121994732, 21.953986935139824)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (2, -1, 0, 0, 0, 0), (4, -2, 0, 0, 0, 0))\n",
"(-1074.1360113340859, -576.0910121994732, -24.77306983471601)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (2, -1, 0, 0, 0, 0), (-1, -1, 0, 0, 1, 0))\n",
"(-935.5633504301628, -576.0910121994732, -24.77306983471601)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (1, 0, 0, 0, 1, -1))\n",
"(-735.5633504301628, -376.0910121994732, -16.61867396878347)\n",
"-200.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (8, 0, 0, 0, 0, -2))\n",
"(-402.93238783361875, -376.0910121994732, -16.61867396878347)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-6, 0, 1, 0, 0, 1), (-2, 0, 1, 0, 0, 0))\n",
"(-889.7772983346388, -76.0910121994732, 283.38132603121653)\n",
"-300.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, -1, 0, 0, 0), (7, 0, -1, 0, 0, -1))\n",
"(-889.7772983346388, -76.0910121994732, -49.249636565327705)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, -1, 0, 0, 0), (-3, 0, 0, 0, 0, 1))\n",
"(-1189.7772983346388, -376.0910121994732, -16.61867396878347)\n",
"300.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, -1, 0, 0, 0), (7, 0, -1, 0, 0, -1))\n",
"(-1078.046013064861, -376.0910121994732, -16.61867396878347)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-1, 1, 0, 0, 0, 0), (3, 1, 0, 0, 0, -1))\n",
"(-1278.046013064861, -576.0910121994732, -189.77729833463832)\n",
"200.0\n",
"((0, 0, 0, 0, 0, 0), (-1, 1, 0, 0, 0, 0), (-3, 1, 1, 0, 0, 0))\n",
"(-1003.4635844698039, -576.0910121994732, -189.77729833463832)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (5, 0, -2, 0, 0, 0), (3, 0, -1, 0, 0, 0))\n",
"(-707.2651057303485, -476.0910121994732, -89.77729833463832)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, 0, -1, 0, 0), (1, 0, 1, -1, 0, 0))\n",
"(-607.2651057303485, -220.95139186551336, 10.222701665361683)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (-2, 0, 1, 0, 0, 0), (1, 0, 1, -1, 0, 0))\n",
"(-638.4593559698822, -220.95139186551336, 10.222701665361683)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (1, 0, 0, 1, -1, 0), (4, 0, 0, 0, -1, 0))\n",
"(-1138.4593559698822, -720.9513918655134, -169.6334495007568)\n",
"500.0\n",
"((0, 0, 0, 0, 0, 0), (1, 0, 0, 1, -1, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-1238.4593559698822, -740.4143568352691, -269.6334495007568)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (2, -1, 0, 0, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-1138.4593559698822, -640.4143568352691, 8.267700799974136)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (2, -1, 0, 0, 0, 0), (6, -1, 0, 0, -1, 0))\n",
"(-832.2599609693369, -640.4143568352691, 8.267700799974136)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-7, 0, 0, 0, 1, 1), (-3, 0, 0, 0, 0, 1))\n",
"(-1238.4593559698822, -740.4143568352691, -91.73229920002586)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (2, -1, 0, 0, 0, 0), (6, -1, 0, 0, -1, 0))\n",
"(-793.6873000654139, -740.4143568352691, -91.73229920002586)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-5, 1, 0, 0, 1, 0), (-1, 1, 0, 0, 0, 0))\n",
"(-393.68730006541387, -340.41435683526913, 157.63064229934344)\n",
"-400.0\n",
"((0, 0, 0, 0, 0, 0), (-5, 1, 0, 0, 1, 0), (-3, 0, 0, 0, 1, 0))\n",
"(-891.7322992000263, -340.41435683526913, 157.63064229934344)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-3, 0, 0, 0, 1, 0), (-1, -1, 0, 0, 1, 0))\n",
"(-691.7322992000263, -140.41435683526913, 10.22270166536157)\n",
"-200.0\n",
"((0, 0, 0, 0, 0, 0), (-3, 0, 0, 0, 1, 0), (-1, 1, 0, 0, 0, 0))\n",
"(-691.7322992000263, -220.95139186551347, 10.22270166536157)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-4, 1, 0, 1, 0, 0), (-1, 1, 0, 0, 0, 0))\n",
"(-930.3049601039494, -320.9513918655135, -89.77729833463843)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (-6, 0, 0, 1, 0, 1), (-3, 0, 0, 0, 0, 1))\n",
"(-452.12548539638885, -220.95139186551347, 10.22270166536157)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (3, 0, 0, -1, 0, 0), (6, 0, 0, -2, 0, 0))\n",
"(-541.0952406993954, -220.95139186551347, 10.22270166536157)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-6, 0, 0, 1, 1, 0), (-3, 0, 0, 0, 1, 0))\n",
"(-1022.9063927309014, -320.9513918655135, -89.77729833463843)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (-1, 1, 0, 0, 0, 0), (2, 1, 0, -1, 0, 0))\n",
"(-1022.9063927309014, -320.9513918655135, 38.520946365176314)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-1, 1, 0, 0, 0, 0), (3, 1, 0, 0, 0, -1))\n",
"(-922.9063927309014, -220.95139186551347, 10.22270166536157)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (-1, 1, 0, 0, 0, 0), (2, 1, 0, -1, 0, 0))\n",
"(-541.0952406993954, -220.95139186551347, 10.22270166536157)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-6, 0, 0, 1, 1, 0), (-3, 0, 0, 0, 1, 0))\n",
"(-658.6032048037637, 79.04860813448653, 310.22270166536157)\n",
"-300.0\n",
"((0, 0, 0, 0, 0, 0), (-5, 0, 0, 2, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-76.09101219947331, 79.04860813448653, 310.22270166536157)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-5, 0, 1, 1, 0, 0), (-2, 0, 1, 0, 0, 0))\n",
"(-1030.304960103949, -420.9513918655135, -189.77729833463843)\n",
"500.0\n",
"((0, 0, 0, 0, 0, 0), (-6, 0, 0, 1, 0, 1), (-3, 0, 0, 0, 0, 1))\n",
"(-1030.304960103949, -420.9513918655135, -61.47905363482414)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-6, 0, 0, 1, 0, 1), (-2, 0, 0, 1, 0, 0))\n",
"(-630.304960103949, -20.95139186551347, 210.22270166536157)\n",
"-400.0\n",
"((0, 0, 0, 0, 0, 0), (-6, 0, 0, 1, 0, 1), (-3, 0, 0, 0, 0, 1))\n",
"(-861.479053634824, -20.95139186551347, 210.22270166536157)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-3, 0, 0, 0, 0, 1), (0, 0, 0, -1, 0, 1))\n",
"(-487.8222974692509, -220.95139186551347, 10.22270166536157)\n",
"200.0\n",
"((0, 0, 0, 0, 0, 0), (-1, -1, 0, 1, 0, 0), (2, -1, 0, 0, 0, 0))\n",
"(-958.6032048037633, -220.95139186551347, 10.22270166536157)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-5, 0, 0, 2, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-658.6032048037633, -76.09101219947314, 310.22270166536157)\n",
"-300.0\n",
"((0, 0, 0, 0, 0, 0), (0, 0, -1, 1, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-658.6032048037633, -76.09101219947314, 155.083081331402)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (0, 0, -1, 1, 0, 0), (3, 0, -1, 0, 0, 0))\n",
"(-958.6032048037633, -376.09101219947314, 10.22270166536157)\n",
"300.0\n",
"((0, 0, 0, 0, 0, 0), (0, 0, -1, 1, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-1058.6032048037632, -356.64820393837596, -89.77729833463843)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (-1, 1, 0, 0, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-958.6032048037632, -541.0952406993952, 10.22270166536157)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (1, 0, 0, 1, -1, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-958.6032048037632, -830.3049601039487, 10.22270166536157)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (1, 0, 0, 1, 0, -1), (-2, 0, 0, 1, 0, 0))\n",
"(-1158.6032048037632, -509.92114716851995, -189.77729833463843)\n",
"200.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-1058.6032048037632, -409.92114716851995, -23.60743330368507)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (2, 0, 1, 0, -1, 0))\n",
"(-574.9253756684418, -409.92114716851995, -23.60743330368507)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-1, 0, -1, 0, 1, 0), (-3, 0, 0, 0, 1, 0))\n",
"(-792.43333977281, -209.92114716851995, 176.39256669631493)\n",
"-200.0\n",
"((0, 0, 0, 0, 0, 0), (0, 0, -1, 1, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-692.43333977281, -109.92114716851995, 121.25294636235537)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (0, 0, -1, 1, 0, 0), (3, 0, -1, 0, 0, 0))\n",
"(-376.79205277225725, -109.92114716851995, 121.25294636235537)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-1, -1, 0, 1, 0, 0), (2, -1, 0, 0, 0, 0))\n",
"(-676.7920527722572, -317.31971454156775, -178.74705363764463)\n",
"300.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (2, -1, 0, 0, 0, 0))\n",
"(-676.7920527722572, -317.31971454156775, 25.162948093130353)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (-1, 1, 0, 0, 0, 0))\n",
"(-576.7920527722572, -217.31971454156775, -25.474110407500348)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (-3, 0, 0, 0, 1, 0))\n",
"(-576.7920527722572, -217.31971454156775, 13.85437898930752)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (7, 0, 0, -1, 0, -1))\n",
"(-776.7920527722572, -417.31971454156775, -31.006000676732697)\n",
"200.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (2, 0, 1, 0, 0, -1))\n",
"(-844.6922868118982, -417.31971454156775, -31.006000676732697)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (5, 0, -2, 0, 0, 0), (3, 0, -1, 0, 0, 0))\n",
"(-515.3647136761801, -17.31971454156775, 368.9939993232673)\n",
"-400.0\n",
"((0, 0, 0, 0, 0, 0), (2, -1, 0, 0, 0, 0), (0, -1, 1, 0, 0, 0))\n",
"(-515.3647136761801, -17.31971454156775, 35.9532286885767)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (2, -1, 0, 0, 0, 0), (-3, 0, 0, 0, 1, 0))\n",
"(-1215.3647136761801, -717.3197145415677, -68.6376569063242)\n",
"700.0\n",
"((0, 0, 0, 0, 0, 0), (2, -1, 0, 0, 0, 0), (6, -1, 0, 0, -1, 0))\n",
"(-1076.7920527722572, -717.3197145415677, -68.6376569063242)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (8, 0, 0, 0, -1, -1))\n",
"(-976.7920527722572, -328.1099951370138, 31.362343093675804)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (8, 0, 0, 0, -1, -1))\n",
"(-876.7920527722572, -228.1099951370138, 3.064098393861059)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (7, 0, 0, -1, -1, 0))\n",
"(-965.7618080752637, -228.1099951370138, 3.064098393861059)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-5, 0, 0, 2, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-710.622187741304, -128.1099951370138, 103.06409839386106)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (0, 0, -1, 1, 0, 0), (3, 0, -1, 0, 0, 0))\n",
"(-194.98090074075122, 71.89000486298619, 303.06409839386106)\n",
"-200.0\n",
"((0, 0, 0, 0, 0, 0), (-1, -1, 0, 1, 0, 0), (2, -1, 0, 0, 0, 0))\n",
"(-768.6376569063243, 71.89000486298619, 303.06409839386106)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-3, 0, 0, 0, 0, 1), (0, 0, 0, -1, 0, 1))\n",
"(-968.6376569063243, -128.1099951370138, 0.1882495628003653)\n",
"200.0\n",
"((0, 0, 0, 0, 0, 0), (-3, 0, 0, 0, 0, 1), (-2, 0, 0, 1, 0, 0))\n",
"(-968.6376569063243, -609.1653186756349, 0.1882495628003653)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (-2, 0, 0, 1, 0, 0))\n",
"(-768.6376569063243, -409.1653186756349, -22.851604810800154)\n",
"-200.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (2, 0, 1, 0, 0, -1))\n",
"(-960.4832610403917, -409.1653186756349, -22.851604810800154)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-3, 0, 0, 0, 1, 0), (-5, 0, 1, 0, 1, 0))\n",
"(-760.4832610403917, -209.16531867563492, 22.00877485523995)\n",
"-200.0\n",
"((0, 0, 0, 0, 0, 0), (-3, 0, 0, 0, 1, 0), (0, 0, 0, -1, 1, 0))\n",
"(-337.4635633754494, -209.16531867563492, 22.00877485523995)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (1, 0, 0, 1, 0, -1), (4, 0, 0, 0, 0, -1))\n",
"(-579.9462260101475, -109.16531867563492, 122.00877485523995)\n",
"-100.0\n",
"((0, 0, 0, 0, 0, 0), (-4, 1, 0, 1, 0, 0), (-1, 1, 0, 0, 0, 0))\n",
"(-468.63765690632454, -109.16531867563492, 122.00877485523995)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, 0, -1), (7, 0, 0, -1, 0, -1))\n",
"(-857.8473763108782, -209.16531867563492, 22.00877485523995)\n",
"100.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (7, 0, 0, -1, -1, 0))\n",
"(-1057.8473763108782, -409.1653186756349, -22.85160481080004)\n",
"200.0\n",
"((0, 0, 0, 0, 0, 0), (4, 0, 0, 0, -1, 0), (2, 0, 1, 0, -1, 0))\n",
"(-960.4832610403915, -409.1653186756349, -22.85160481080004)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (-3, 0, 0, 0, 1, 0), (-5, 0, 1, 0, 1, 0))\n",
"(-1160.4832610403914, -609.1653186756349, -57.84737631087819)\n",
"200.0\n",
"((0, 0, 0, 0, 0, 0), (-3, 0, 0, 0, 1, 0), (-6, 0, 0, 0, 2, 0))\n",
"(-1026.673282780003, -609.1653186756349, -57.84737631087819)\n",
"0.0\n",
"((0, 0, 0, 0, 0, 0), (1, 0, 0, 1, -1, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-895.4790325404695, -509.1653186756349, 42.15262368912181)\n",
"-100.0\n"
]
}
],
"source": [
"path = stochastic_hamiltonian(graph)\n",
"#durs = tuple(round(y[0]-x[0], 2) for (x, y) in pairwise(target_melody_data)) + ((1,))\n",
"durs = tuple(d[0] for d in target_melody_data)\n",
"path_to_chords(path, root)\n",
"write_chord_sequence(list(zip(durs, path_to_chords(path, root))))"
]
},
{
"cell_type": "code",
"execution_count": 158,
"id": "57c834bf-fee7-4ef4-b648-2173099fbb56",
"metadata": {},
"outputs": [],
"source": [
"from random import choice, choices\n",
"\n",
"def next_edges(source): \n",
"\n",
" def transpose_to_nearest(hs_array1, hs_array2):\n",
" expanded_pitch = hs_array2\n",
" frequency_ratio = hs_array_to_fr(list(hs_array2)) / hs_array_to_fr(list(hs_array1))\n",
" if frequency_ratio < 1:\n",
" while frequency_ratio < 1:\n",
" frequency_ratio *= 2\n",
" expanded_pitch[0] += 1\n",
" elif frequency_ratio >= 2:\n",
" while frequency_ratio >= 2:\n",
" frequency_ratio *= 1/2\n",
" expanded_pitch[0] += -1\n",
" return tuple(expanded_pitch)\n",
" \n",
" def gen_candidates(chord):\n",
" for sdx, s_pitch in enumerate(chord):\n",
" for cdx, c_pitch in enumerate(chord):\n",
" if sdx != cdx: \n",
" for ddx, dim in enumerate(c_pitch[1:]):\n",
" for alt in [-1, 1]:\n",
" new_pitch = list(c_pitch)\n",
" new_pitch[ddx+1] += alt\n",
" new_pitch_up = transpose_to_nearest(s_pitch, new_pitch)\n",
" new_pitch_down = list(new_pitch_up)\n",
" new_pitch_down[0] += -1\n",
" new_chord = list(chord)\n",
" new_chord[sdx] = tuple(new_pitch_up)\n",
" yield tuple(new_chord)\n",
" new_chord[sdx] = tuple(new_pitch_down)\n",
" yield tuple(new_chord)\n",
"\n",
" for candidate in gen_candidates(source):\n",
"\n",
" movements = {\n",
" pitch:\n",
" {\n",
" 'destination': candidate[index], \n",
" 'cent_difference': cent_difference(pitch, candidate[index])\n",
" } for index, pitch in enumerate(source)}\n",
" \n",
" yield (tuple(source), tuple(candidate), {'transposition': root, 'movements': movements},)\n",
"\n",
"\n",
"# This is for the beginning / breysheet - redone to calculate next chord as a function and not from the graph\n",
"def stochastic_hamiltonian(graph):\n",
"\n",
" #try making this omit the moving voice\n",
" def movement_size_weights(edges):\n",
" \n",
" def max_cent_diff(edge):\n",
" res = max([abs(v) for val in edge[2]['movements'].values() if (v:=val['cent_difference']) is not None])\n",
" return res\n",
" \n",
" def min_cent_diff(edge):\n",
" res = [abs(v) for val in edge[2]['movements'].values() if (v:=val['cent_difference']) is not None]\n",
" res.remove(0)\n",
" return min(res)\n",
" \n",
" for e in edges:\n",
" yield 7 if ((max_cent_diff(e) < 100) and (min_cent_diff(e)) >= 0) else 1\n",
"\n",
" def hamiltonian_weights(edges):\n",
" for e in edges:\n",
" yield 10 if e[1] not in [path_edge[0] for path_edge in path] else 1 / graph.nodes[e[1]]['count']\n",
" \n",
" def contrary_motion_weights(edges):\n",
"\n",
" def is_contrary(edge):\n",
" cent_diffs = [v for val in edge[2]['movements'].values() if (v:=val['cent_difference']) is not None]\n",
" cent_diffs.sort()\n",
" return (cent_diffs[0] < 0) and (cent_diffs[1] == 0) and (cent_diffs[2] > 0)\n",
"\n",
" for e in edges:\n",
" yield 2 if is_contrary(e) else 1\n",
" \n",
" def is_directly_tunable_weights(edges):\n",
" for e in edges:\n",
" yield 10 if e[2]['is_directly_tunable'] else 1\n",
"\n",
" def symdiff_weights(edges):\n",
" for e in edges:\n",
" yield 1000 if e[2]['symmetric_difference'] == 2 else 1\n",
"\n",
" def transposition_weight(edges):\n",
" for e in edges:\n",
" yield 100 if 0 <= hs_array_to_cents(e[2]['transposition']) < 100 else 1\n",
"\n",
" def in_range(edges):\n",
" for e in edges:\n",
" yield 5 if hs_array_to_fr(e[0][0]) >= 0 else 0\n",
"\n",
" def is_sustained_voice(edges, voice):\n",
" \n",
" def is_sustained(edge):\n",
" source = list(edge[0])\n",
" ordered_source = sorted(source, key=hs_array_to_fr) \n",
" destination = [transpose_pitch(edge[2]['movements'][p]['destination'], edge[2]['transposition']) for p in source]\n",
" ordered_destination = sorted(destination, key=hs_array_to_fr)\n",
" return ordered_source[voice] == ordered_destination[voice]\n",
"\n",
" for e in edges:\n",
" yield 10 if is_sustained(e) else 1\n",
"\n",
" def voice_crossing_weights(edges):\n",
" \n",
" def has_voice_crossing(edge):\n",
" source = list(edge[0])\n",
" ordered_source = sorted(source, key=hs_array_to_fr) \n",
" source_order = [ordered_source.index(p) for p in source]\n",
" destination = [transpose_pitch(edge[2]['movements'][p]['destination'], edge[2]['transposition']) for p in source]\n",
" ordered_destination = sorted(destination, key=hs_array_to_fr)\n",
" destination_order = [ordered_destination.index(p) for p in destination]\n",
" return source_order != destination_order\n",
"\n",
" for e in edges:\n",
" yield 10 if not has_voice_crossing(e) else 0\n",
"\n",
" def is_bass_rooted(chord):\n",
" return max([sum(abs(p) for p in collapse_pitch(pitch_difference(chord[0], p))) for p in chord[1:]]) == 1\n",
"\n",
" def target_melody_weights(edges, target, c_devs, voice):\n",
"\n",
" def target_weight(edge, target, c_devs, voice):\n",
" candidate_diffs = []\n",
" for idx, dev in enumerate(c_devs):\n",
" if(idx == 2):\n",
" source = list(edge[0])\n",
" ordered_source = sorted(source, key=hs_array_to_fr) \n",
" candidate_diff = edge[2]['movements'][ordered_source[idx]]['cent_difference']\n",
" candidate_diffs += [abs(dev + candidate_diff - target)]\n",
" #return 1/pow(1.1, min(candidate_diffs))\n",
" return 10 if min(candidate_diffs) < 40 else 1/pow(1.1, min(candidate_diffs))\n",
" \n",
" for e in edges:\n",
" yield target_weight(e, target, c_devs, voice)\n",
" \n",
" check_graph = graph.copy()\n",
" next_node = choice(list(graph.nodes()))\n",
" check_graph.remove_node(next_node)\n",
" for node in graph.nodes(data=True):\n",
" node[1]['count'] = 1\n",
" path = []\n",
" s_next_node = sorted(next_node, key=hs_array_to_fr)\n",
" c_devs = (cent_difference(s_next_node[2], s_next_node[0]), cent_difference(s_next_node[2], s_next_node[1]), 0,)\n",
" #c_devs = (0, cent_difference(s_next_node[0], s_next_node[1]), cent_difference(s_next_node[0], s_next_node[2]),)\n",
" print(c_devs)\n",
" while (nx.number_of_nodes(check_graph) > 0) and (len(path) < len(target_melody_data)-1):\n",
" #out_edges = list(graph.out_edges(next_node, data=True))\n",
" out_edges = list(next_edges(next_node))\n",
" factors = [\n",
" movement_size_weights(out_edges), \n",
" #hamiltonian_weights(out_edges), \n",
" #contrary_motion_weights(out_edges), \n",
" #is_directly_tunable_weights(out_edges),\n",
" voice_crossing_weights(out_edges),\n",
" #transposition_weight(out_edges),\n",
" #is_sustained_voice(out_edges, 0),\n",
" target_melody_weights(out_edges, target_melody_data[len(path)+1][-1], c_devs, 2),\n",
" #symdiff_weights(out_edges),\n",
" in_range(out_edges)\n",
" ]\n",
" weights = [prod(a) for a in zip(*factors)]\n",
" edge = choices(out_edges, weights=weights)[0]\n",
" next_node = edge[1]\n",
" node[1]['count'] += 1\n",
" path.append(edge)\n",
" s_chord = tuple(sorted(edge[0], key=hs_array_to_fr))\n",
" c_devs = tuple(c_devs[pdx] + edge[2]['movements'][pitch]['cent_difference'] - target_melody_data[len(path)][-1] for pdx, pitch in enumerate(s_chord))\n",
" print(s_chord)\n",
" print(c_devs)\n",
" #print(target_melody_data[len(path)][-1])\n",
" if next_node in check_graph.nodes:\n",
" check_graph.remove_node(next_node)\n",
" return path"
]
},
{
"cell_type": "code",
"execution_count": 159,
"id": "8912c650-a43d-4539-ae24-b5acf9bc543d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(-968.8259064691249, -813.6862861351651, 0)\n",
"((0, 0, 0, 0, 0, 0), (-5, 0, 1, 1, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-1168.825906469125, -1013.6862861351651, -44.86037966604022)\n",
"((0, 0, 0, 0, 0, 0), (-5, 0, 1, 1, 0, 0), (-7, 0, 1, 2, 0, 0))\n",
"(-1168.825906469125, -276.0344731969153, -44.86037966604022)\n",
"((0, 0, 0, 0, 0, 0), (-10, 0, 1, 3, 0, 0), (-7, 0, 1, 2, 0, 0))\n",
"(-968.8259064691249, -76.03447319691531, 0.0)\n",
"((0, 0, 0, 0, 0, 0), (-10, 0, 1, 3, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-1901.9550008653875, -76.03447319691531, 0.0)\n",
"((-2, -1, 0, 1, 0, 0), (-10, 0, 1, 3, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-1701.9550008653875, 123.96552680308469, 146.7270567698556)\n",
"((-2, -1, 0, 1, 0, 0), (-10, 0, 1, 3, 0, 0), (3, -1, 0, 1, -1, 0))\n",
"(-2612.745281460834, 123.96552680308469, 146.7270567698556)\n",
"((-3, -1, 0, 1, -1, 1), (-10, 0, 1, 3, 0, 0), (3, -1, 0, 1, -1, 0))\n",
"(-1655.2279440955317, 223.96552680308469, 246.7270567698556)\n",
"((3, -2, 0, 1, -1, 0), (-10, 0, 1, 3, 0, 0), (3, -1, 0, 1, -1, 0))\n",
"(-2512.745281460834, 223.96552680308469, 246.7270567698556)\n",
"((-3, -1, 0, 1, -1, 1), (-10, 0, 1, 3, 0, 0), (3, -1, 0, 1, -1, 0))\n",
"(-1777.989474062303, 123.96552680308469, 146.7270567698556)\n",
"((-10, -1, 1, 3, 0, 0), (-10, 0, 1, 3, 0, 0), (3, -1, 0, 1, -1, 0))\n",
"(-1777.989474062303, -501.95500086538755, 146.7270567698556)\n",
"((-10, -1, 1, 3, 0, 0), (-1, -1, 0, 1, 0, 0), (3, -1, 0, 1, -1, 0))\n",
"(-1977.989474062303, -701.9550008653875, 0.0)\n",
"((-10, -1, 1, 3, 0, 0), (-1, -1, 0, 1, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-2040.5276617693105, -701.9550008653875, 0.0)\n",
"((0, 0, 0, 1, 0, -1), (-1, -1, 0, 1, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-1840.5276617693105, -501.95500086538755, -3.9100017307749795)\n",
"((0, 0, 0, 1, 0, -1), (-1, -1, 0, 1, 0, 0), (1, -2, 0, 1, 0, 0))\n",
"(-1740.5276617693105, -401.95500086538755, 10.790280595446234)\n",
"((0, 0, 0, 1, 0, -1), (-1, -1, 0, 1, 0, 0), (-2, 0, 0, 1, 1, -1))\n",
"(-1740.5276617693105, -401.95500086538755, 10.790280595446234)\n",
"((0, 0, 0, 1, 0, -1), (-1, -1, 0, 1, 0, 0), (-2, 0, 0, 1, 1, -1))\n",
"(-2040.5276617693105, -701.9550008653875, -26.84137563414515)\n",
"((0, 0, 0, 1, 0, -1), (-1, -1, 0, 1, 0, 0), (4, 0, -1, 1, 0, -1))\n",
"(-2040.5276617693105, -701.9550008653875, 0.0)\n",
"((0, 0, 0, 1, 0, -1), (-1, -1, 0, 1, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-2240.5276617693107, -901.9550008653875, -61.42733909607705)\n",
"((0, 0, 0, 1, 0, -1), (-1, -1, 0, 1, 0, 0), (-4, -1, 0, 1, 0, 1))\n",
"(-2803.9100017307755, -901.9550008653875, -61.42733909607705)\n",
"((-1, -2, 0, 1, 0, 0), (-1, -1, 0, 1, 0, 0), (-4, -1, 0, 1, 0, 1))\n",
"(-2603.9100017307755, -701.9550008653875, 0.0)\n",
"((-1, -2, 0, 1, 0, 0), (-1, -1, 0, 1, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-2603.9100017307755, -701.9550008653875, 0.0)\n",
"((-1, -2, 0, 1, 0, 0), (-1, -1, 0, 1, 0, 0), (-2, 0, 0, 1, 0, 0))\n",
"(-2303.9100017307755, -401.95500086538755, -15.641287000552666)\n",
"((-1, -2, 0, 1, 0, 0), (-1, -1, 0, 1, 0, 0), (-3, -1, 1, 1, 0, 0))\n",
"(-1370.780907334513, -401.95500086538755, -15.641287000552666)\n",
"((1, -1, 0, 0, 0, 0), (-1, -1, 0, 1, 0, 0), (-3, -1, 1, 1, 0, 0))\n",
"(-1870.780907334513, -901.9550008653875, -22.098849699269067)\n",
"((1, -1, 0, 0, 0, 0), (-1, -1, 0, 1, 0, 0), (6, -1, 0, 0, -1, 0))\n",
"(-1870.780907334513, -901.9550008653875, -22.098849699269067)\n",
"((1, -1, 0, 0, 0, 0), (-1, -1, 0, 1, 0, 0), (6, -1, 0, 0, -1, 0))\n",
"(-1470.780907334513, -501.95500086538755, -39.60681380363735)\n",
"((1, -1, 0, 0, 0, 0), (-1, -1, 0, 1, 0, 0), (5, -1, 0, -1, 0, 0))\n",
"(-1470.780907334513, -919.4629649697556, -39.60681380363735)\n",
"((1, -1, 0, 0, 0, 0), (-2, -1, 0, 0, 1, 0), (5, -1, 0, -1, 0, 0))\n",
"(-1770.780907334513, -1219.4629649697556, -19.462964969755603)\n",
"((1, -1, 0, 0, 0, 0), (-2, -1, 0, 0, 1, 0), (-1, -1, 0, 0, 1, 0))\n",
"(-1870.780907334513, -1319.4629649697556, 31.174093530875098)\n",
"((1, -1, 0, 0, 0, 0), (-2, -1, 0, 0, 1, 0), (1, 0, 0, 0, 0, 0))\n",
"(-1770.780907334513, -1219.4629649697556, -19.462964969755603)\n",
"((1, -1, 0, 0, 0, 0), (-2, -1, 0, 0, 1, 0), (-1, -1, 0, 0, 1, 0))\n",
"(-1717.5079641043687, -1219.4629649697556, -19.462964969755603)\n",
"((-4, 0, 0, 0, 1, 0), (-2, -1, 0, 0, 1, 0), (-1, -1, 0, 0, 1, 0))\n",
"(-1617.5079641043687, -1119.4629649697556, -31.19425023953329)\n",
"((-4, 0, 0, 0, 1, 0), (-2, -1, 0, 0, 1, 0), (-5, 0, 1, 0, 1, 0))\n",
"(-1462.368343770409, -1119.4629649697556, -31.19425023953329)\n",
"((-9, 0, 1, 1, 1, 0), (-2, -1, 0, 0, 1, 0), (-5, 0, 1, 0, 1, 0))\n",
"(-1562.368343770409, -1219.4629649697556, 23.94537009442638)\n",
"((-9, 0, 1, 1, 1, 0), (-2, -1, 0, 0, 1, 0), (-10, 0, 2, 1, 1, 0))\n",
"(-1462.368343770409, -1119.4629649697556, -31.19425023953329)\n",
"((-9, 0, 1, 1, 1, 0), (-2, -1, 0, 0, 1, 0), (-5, 0, 1, 0, 1, 0))\n",
"(-1262.368343770409, -919.4629649697556, 49.362941499369185)\n",
"((-9, 0, 1, 1, 1, 0), (-2, -1, 0, 0, 1, 0), (-4, -1, 0, 1, 1, 0))\n",
"(-1262.368343770409, -919.4629649697556, 49.362941499369185)\n",
"((-9, 0, 1, 1, 1, 0), (-2, -1, 0, 0, 1, 0), (-4, -1, 0, 1, 1, 0))\n",
"(-962.368343770409, -619.4629649697556, 29.21909266548755)\n",
"((-9, 0, 1, 1, 1, 0), (-2, -1, 0, 0, 1, 0), (2, -1, 0, 0, 0, 0))\n",
"(-962.368343770409, -260.41334290502095, 29.21909266548755)\n",
"((-9, 0, 1, 1, 1, 0), (-10, 1, 1, 1, 1, 0), (2, -1, 0, 0, 0, 0))\n",
"(-1462.368343770409, -760.413342905021, -31.19425023953329)\n",
"((-9, 0, 1, 1, 1, 0), (-10, 1, 1, 1, 1, 0), (-5, 0, 1, 0, 1, 0))\n",
"(-1258.458342039634, -760.413342905021, -31.19425023953329)\n",
"((-12, 2, 1, 1, 1, 0), (-10, 1, 1, 1, 1, 0), (-5, 0, 1, 0, 1, 0))\n",
"(-1758.458342039634, -1260.413342905021, -7.1403996748767895)\n",
"((-12, 2, 1, 1, 1, 0), (-10, 1, 1, 1, 1, 0), (-14, 2, 1, 1, 2, 0))\n",
"(-1858.458342039634, -1360.413342905021, -9.77628440439048)\n",
"((-12, 2, 1, 1, 1, 0), (-10, 1, 1, 1, 1, 0), (-7, 2, 1, 1, 0, 0))\n",
"(-1858.458342039634, -1761.094226769147, -9.77628440439048)\n",
"((-12, 2, 1, 1, 1, 0), (-5, 2, 1, 1, -1, 0), (-7, 2, 1, 1, 0, 0))\n",
"(-1458.458342039634, -1361.094226769147, -27.284248508758537)\n",
"((-12, 2, 1, 1, 1, 0), (-5, 2, 1, 1, -1, 0), (-8, 2, 1, 0, 1, 0))\n",
"(-1458.458342039634, -1072.144628174799, -27.284248508758537)\n",
"((-12, 2, 1, 1, 1, 0), (-14, 2, 2, 1, 1, 0), (-8, 2, 1, 0, 1, 0))\n",
"(-1558.458342039634, -1172.144628174799, 1.0139961910560942)\n",
"((-12, 2, 1, 1, 1, 0), (-14, 2, 2, 1, 1, 0), (-7, 2, 1, 1, 1, -1))\n",
"(-1458.458342039634, -1072.144628174799, -27.284248508758537)\n",
"((-12, 2, 1, 1, 1, 0), (-14, 2, 2, 1, 1, 0), (-8, 2, 1, 0, 1, 0))\n",
"(-2040.970534643924, -1072.144628174799, -27.284248508758537)\n",
"((-12, 2, 2, 0, 1, 0), (-14, 2, 2, 1, 1, 0), (-8, 2, 1, 0, 1, 0))\n",
"(-2340.970534643924, -1372.144628174799, 59.02946535607657)\n",
"((-12, 2, 2, 0, 1, 0), (-14, 2, 2, 1, 1, 0), (-10, 2, 2, 0, 1, 0))\n",
"(-2440.970534643924, -854.6568207790891, -40.97053464392343)\n",
"((-12, 2, 2, 0, 1, 0), (-13, 2, 3, 0, 1, 0), (-10, 2, 2, 0, 1, 0))\n",
"(-2440.970534643924, -854.6568207790891, -14.129159009778277)\n",
"((-12, 2, 2, 0, 1, 0), (-13, 2, 3, 0, 1, 0), (-16, 2, 3, 0, 1, 1))\n",
"(-1840.970534643924, -254.65682077908912, -23.48272724821402)\n",
"((-12, 2, 2, 0, 1, 0), (-13, 2, 3, 0, 1, 0), (-10, 2, 3, -1, 1, 0))\n",
"(-1840.970534643924, -254.65682077908912, -23.48272724821402)\n",
"((-12, 2, 2, 0, 1, 0), (-13, 2, 3, 0, 1, 0), (-10, 2, 3, -1, 1, 0))\n",
"(-1940.970534643924, -354.6568207790891, -39.01553377853611)\n",
"((-12, 2, 2, 0, 1, 0), (-13, 2, 3, 0, 1, 0), (-12, 3, 2, 0, 1, 0))\n",
"(-1323.4827272482144, -354.6568207790891, -39.01553377853611)\n",
"((-11, 2, 3, -1, 1, 0), (-13, 2, 3, 0, 1, 0), (-12, 3, 2, 0, 1, 0))\n",
"(-1423.4827272482144, -454.6568207790891, 7.691366282661193)\n",
"((-11, 2, 3, -1, 1, 0), (-13, 2, 3, 0, 1, 0), (-7, 2, 3, -2, 1, 0))\n",
"(-1423.4827272482144, -961.1345401864637, 7.691366282661193)\n",
"((-11, 2, 3, -1, 1, 0), (-5, 2, 3, -3, 1, 0), (-7, 2, 3, -2, 1, 0))\n",
"(-1223.4827272482144, -761.1345401864637, -59.17953932107628)\n",
"((-11, 2, 3, -1, 1, 0), (-5, 2, 3, -3, 1, 0), (-6, 3, 3, -3, 1, 0))\n",
"(-1223.4827272482144, -707.8615969563199, -59.17953932107628)\n",
"((-11, 2, 3, -1, 1, 0), (-10, 3, 3, -3, 2, 0), (-6, 3, 3, -3, 1, 0))\n",
"(-923.4827272482144, -407.8615969563199, -21.547883091484664)\n",
"((-11, 2, 3, -1, 1, 0), (-10, 3, 3, -3, 2, 0), (-12, 3, 4, -3, 2, 0))\n",
"(-923.4827272482144, -252.7219766223601, -21.547883091484664)\n",
"((-11, 2, 3, -1, 1, 0), (-15, 3, 4, -2, 2, 0), (-12, 3, 4, -3, 2, 0))\n",
"(-1223.4827272482144, -552.7219766223601, -1.4040342576033709)\n",
"((-11, 2, 3, -1, 1, 0), (-15, 3, 4, -2, 2, 0), (-18, 3, 4, -2, 3, 0))\n",
"(-1223.4827272482144, -552.7219766223601, -1.4040342576033709)\n",
"((-11, 2, 3, -1, 1, 0), (-15, 3, 4, -2, 2, 0), (-18, 3, 4, -2, 3, 0))\n",
"(-1423.4827272482144, -752.7219766223601, 7.691366282661193)\n",
"((-11, 2, 3, -1, 1, 0), (-15, 3, 4, -2, 2, 0), (-7, 2, 3, -2, 1, 0))\n",
"(-1423.4827272482144, -694.2636345827268, 7.691366282661193)\n",
"((-11, 2, 3, -1, 1, 0), (-6, 1, 3, -2, 1, 0), (-7, 2, 3, -2, 1, 0))\n",
"(-1323.4827272482144, -594.2636345827268, -96.21863544811367)\n",
"((-11, 2, 3, -1, 1, 0), (-6, 1, 3, -2, 1, 0), (-4, 0, 3, -2, 1, 0))\n",
"(-1223.4827272482144, -494.2636345827268, 3.781364551886327)\n",
"((-11, 2, 3, -1, 1, 0), (-6, 1, 3, -2, 1, 0), (-4, 0, 3, -2, 1, 0))\n",
"(-1223.4827272482144, -521.5277263828268, 3.781364551886327)\n",
"((-11, 2, 3, -1, 1, 0), (-12, 3, 3, -1, 1, 0), (-4, 0, 3, -2, 1, 0))\n",
"(-1723.4827272482144, -1021.5277263828268, -25.43772811360145)\n",
"((-11, 2, 3, -1, 1, 0), (-12, 3, 3, -1, 1, 0), (-8, 1, 3, -1, 1, 0))\n",
"(-1823.4827272482144, -1121.5277263828268, 25.19933038702925)\n",
"((-11, 2, 3, -1, 1, 0), (-12, 3, 3, -1, 1, 0), (-6, 2, 3, -1, 0, 0))\n",
"(-1723.4827272482144, -1021.5277263828268, 27.835215116542713)\n",
"((-11, 2, 3, -1, 1, 0), (-12, 3, 3, -1, 1, 0), (-13, 2, 3, -1, 2, 0))\n",
"(-1670.2097840180702, -1021.5277263828268, 27.835215116542713)\n",
"((-16, 3, 3, -1, 2, 0), (-12, 3, 3, -1, 1, 0), (-13, 2, 3, -1, 2, 0))\n",
"(-1770.2097840180702, -1121.5277263828268, -18.891841653313122)\n",
"((-16, 3, 3, -1, 2, 0), (-12, 3, 3, -1, 1, 0), (-18, 3, 3, -1, 3, 0))\n",
"(-1770.2097840180702, -250.06593518418833, -18.891841653313122)\n",
"((-16, 3, 3, -1, 2, 0), (-21, 3, 3, 0, 3, 0), (-18, 3, 3, -1, 3, 0))\n",
"(-1370.2097840180702, 149.93406481581167, 189.26255421261976)\n",
"((-16, 3, 3, -1, 2, 0), (-21, 3, 3, 0, 3, 0), (-11, 3, 3, -1, 2, -1))\n",
"(-1370.2097840180702, 60.964309512805016, 189.26255421261976)\n",
"((-16, 3, 3, -1, 2, 0), (-12, 3, 3, -2, 2, 0), (-11, 3, 3, -1, 2, -1))\n",
"(-1651.2651075566914, 260.964309512805, 389.26255421261976)\n",
"((-9, 3, 3, -1, 2, -2), (-12, 3, 3, -2, 2, 0), (-11, 3, 3, -1, 2, -1))\n",
"(-1651.2651075566914, 260.964309512805, 362.4211785784737)\n",
"((-9, 3, 3, -1, 2, -2), (-12, 3, 3, -2, 2, 0), (-5, 3, 2, -1, 2, -2))\n",
"(-2523.8925352863607, 160.96430951280502, 262.4211785784737)\n",
"((-5, 3, 1, -1, 2, -2), (-12, 3, 3, -2, 2, 0), (-5, 3, 2, -1, 2, -2))\n",
"(-3006.404727890651, 260.964309512805, 362.4211785784737)\n",
"((-5, 3, 2, -2, 2, -2), (-12, 3, 3, -2, 2, 0), (-5, 3, 2, -1, 2, -2))\n",
"(-2423.8925352863607, 260.964309512805, 362.4211785784737)\n",
"((-5, 3, 1, -1, 2, -2), (-12, 3, 3, -2, 2, 0), (-5, 3, 2, -1, 2, -2))\n",
"(-2523.8925352863607, 160.96430951280502, 235.579802944329)\n",
"((-5, 3, 1, -1, 2, -2), (-12, 3, 3, -2, 2, 0), (1, 3, 1, -1, 2, -3))\n",
"(-2598.5080287178844, 160.96430951280502, 235.579802944329)\n",
"((-18, 3, 3, -2, 2, 1), (-12, 3, 3, -2, 2, 0), (1, 3, 1, -1, 2, -3))\n",
"(-2498.5080287178844, 260.964309512805, 287.80568514695074)\n",
"((-18, 3, 3, -2, 2, 1), (-12, 3, 3, -2, 2, 0), (-18, 3, 4, -2, 2, 1))\n",
"(-1779.5633522565056, 260.964309512805, 287.80568514695074)\n",
"((-10, 3, 3, -2, 2, -1), (-12, 3, 3, -2, 2, 0), (-18, 3, 4, -2, 2, 1))\n",
"(-1479.5633522565056, 560.964309512805, 587.8056851469507)\n",
"((-10, 3, 3, -2, 2, -1), (-12, 3, 3, -2, 2, 0), (-18, 3, 4, -2, 2, 1))\n",
"(-1479.5633522565056, 534.1229338786599, 587.8056851469507)\n",
"((-10, 3, 3, -2, 2, -1), (-6, 3, 2, -2, 2, -1), (-18, 3, 4, -2, 2, 1))\n",
"(-1979.5633522565056, 34.122933878659865, 60.96430951280536)\n",
"((-10, 3, 3, -2, 2, -1), (-6, 3, 2, -2, 2, -1), (-12, 3, 3, -2, 2, 0))\n",
"(-1952.7219766223602, 34.122933878659865, 60.96430951280536)\n",
"((-16, 3, 4, -2, 2, 0), (-6, 3, 2, -2, 2, -1), (-12, 3, 3, -2, 2, 0))\n",
"(-1098.5080287178844, 434.12293387865986, 460.96430951280536)\n",
"((-17, 3, 3, -2, 2, 1), (-6, 3, 2, -2, 2, -1), (-12, 3, 3, -2, 2, 0))\n",
"(-534.7029725904652, 434.12293387865986, 460.96430951280536)\n",
"((-4, 3, 2, -3, 2, -1), (-6, 3, 2, -2, 2, -1), (-12, 3, 3, -2, 2, 0))\n",
"(-734.7029725904652, -183.38503022570842, 260.96430951280536)\n",
"((-4, 3, 2, -3, 2, -1), (-7, 3, 2, -3, 3, -1), (-12, 3, 3, -2, 2, 0))\n",
"(-734.7029725904652, -183.38503022570842, -32.74797172507738)\n",
"((-4, 3, 2, -3, 2, -1), (-7, 3, 2, -3, 3, -1), (-5, 4, 2, -3, 2, -1))\n",
"(-434.70297259046515, 116.61496977429158, 213.97908504477857)\n",
"((-4, 3, 2, -3, 2, -1), (-7, 3, 2, -3, 3, -1), (0, 3, 2, -3, 1, -1))\n",
"(-434.70297259046515, 63.342026544147416, 213.97908504477857)\n",
"((-4, 3, 2, -3, 2, -1), (-2, 2, 2, -3, 2, -1), (0, 3, 2, -3, 1, -1))\n",
"(-734.7029725904652, -236.65797345585258, -5.483879924977373)\n",
"((-4, 3, 2, -3, 2, -1), (-2, 2, 2, -3, 2, -1), (1, 2, 2, -4, 2, -1))\n",
"(-834.7029725904652, -336.6579734558526, 22.81436477483703)\n",
"((-4, 3, 2, -3, 2, -1), (-2, 2, 2, -3, 2, -1), (2, 2, 2, -3, 2, -2))\n",
"(-734.7029725904652, -236.65797345585258, -32.74797172507738)\n",
"((-4, 3, 2, -3, 2, -1), (-2, 2, 2, -3, 2, -1), (-5, 4, 2, -3, 2, -1))\n",
"(-734.7029725904652, -263.92206525595327, -32.74797172507738)\n",
"((-4, 3, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-5, 4, 2, -3, 2, -1))\n",
"(-934.7029725904652, -463.92206525595327, 34.122933878660206)\n",
"((-4, 3, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-6, 3, 2, -2, 2, -1))\n",
"(-834.7029725904652, -363.92206525595327, 5.8246891788458015)\n",
"((-4, 3, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-7, 3, 2, -3, 2, 0))\n",
"(-807.8615969563199, -363.92206525595327, 5.8246891788458015)\n",
"((-10, 3, 3, -3, 2, 0), (-8, 4, 2, -2, 2, -1), (-7, 3, 2, -3, 2, 0))\n",
"(-607.8615969563199, -163.92206525595327, 40.82046067892372)\n",
"((-10, 3, 3, -3, 2, 0), (-8, 4, 2, -2, 2, -1), (-6, 3, 3, -3, 1, 0))\n",
"(-507.8615969563199, -63.92206525595327, -9.816597821706978)\n",
"((-10, 3, 3, -3, 2, 0), (-8, 4, 2, -2, 2, -1), (-8, 2, 3, -3, 2, 0))\n",
"(-507.8615969563199, -63.92206525595327, -9.816597821706978)\n",
"((-10, 3, 3, -3, 2, 0), (-8, 4, 2, -2, 2, -1), (-8, 2, 3, -3, 2, 0))\n",
"(-807.8615969563199, -363.92206525595327, 5.8246891788458015)\n",
"((-10, 3, 3, -3, 2, 0), (-8, 4, 2, -2, 2, -1), (-7, 3, 2, -3, 2, 0))\n",
"(-807.8615969563199, -363.92206525595327, 5.8246891788458015)\n",
"((-10, 3, 3, -3, 2, 0), (-8, 4, 2, -2, 2, -1), (-7, 3, 2, -3, 2, 0))\n",
"(-707.8615969563199, -263.92206525595327, -5.906596090932339)\n",
"((-10, 3, 3, -3, 2, 0), (-8, 4, 2, -2, 2, -1), (-11, 4, 3, -3, 2, 0))\n",
"(-1232.7479717250776, -263.92206525595327, -5.906596090932339)\n",
"((-6, 4, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-11, 4, 3, -3, 2, 0))\n",
"(-1432.7479717250776, -463.92206525595327, 34.122933878660206)\n",
"((-6, 4, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-6, 3, 2, -2, 2, -1))\n",
"(-1432.7479717250776, -463.92206525595327, 34.122933878660206)\n",
"((-6, 4, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-6, 3, 2, -2, 2, -1))\n",
"(-1032.7479717250776, -63.92206525595327, 167.25202827492262)\n",
"((-6, 4, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-5, 4, 2, -3, 2, -1))\n",
"(-1032.7479717250776, -63.92206525595327, 167.25202827492262)\n",
"((-6, 4, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-5, 4, 2, -3, 2, -1))\n",
"(-1732.7479717250776, -763.9220652559533, 18.56997063967924)\n",
"((-6, 4, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-8, 4, 2, -3, 3, -1))\n",
"(-1732.7479717250776, -763.9220652559533, 18.56997063967924)\n",
"((-6, 4, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-8, 4, 2, -3, 3, -1))\n",
"(-1632.7479717250776, -663.9220652559533, -15.24000762070932)\n",
"((-6, 4, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-4, 4, 2, -2, 1, -1))\n",
"(-1532.7479717250776, -563.9220652559533, 26.724366505612124)\n",
"((-6, 4, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-1, 4, 2, -3, 2, -2))\n",
"(-1532.7479717250776, -563.9220652559533, 26.724366505612124)\n",
"((-6, 4, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-1, 4, 2, -3, 2, -2))\n",
"(-1432.7479717250776, -463.92206525595327, 34.122933878660206)\n",
"((-6, 4, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-6, 3, 2, -2, 2, -1))\n",
"(-1232.7479717250776, -263.92206525595327, -32.74797172507738)\n",
"((-6, 4, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-5, 4, 2, -3, 2, -1))\n",
"(-1934.702972590465, -263.92206525595327, -32.74797172507738)\n",
"((-5, 3, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-5, 4, 2, -3, 2, -1))\n",
"(-2134.702972590465, -463.92206525595327, 34.122933878660206)\n",
"((-5, 3, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-6, 3, 2, -2, 2, -1))\n",
"(-2134.702972590465, -463.92206525595327, 34.122933878660206)\n",
"((-5, 3, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-6, 3, 2, -2, 2, -1))\n",
"(-1934.702972590465, -263.92206525595327, -32.74797172507738)\n",
"((-5, 3, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-5, 4, 2, -3, 2, -1))\n",
"(-1934.702972590465, -263.92206525595327, -32.74797172507738)\n",
"((-5, 3, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-5, 4, 2, -3, 2, -1))\n",
"(-1734.702972590465, -63.92206525595327, -36.65797345585224)\n",
"((-5, 3, 2, -3, 2, -1), (-8, 4, 2, -2, 2, -1), (-2, 2, 2, -3, 2, -1))\n",
"(-1005.4838799249776, -63.92206525595327, -36.65797345585224)\n",
"((0, 2, 2, -4, 2, -1), (-8, 4, 2, -2, 2, -1), (-2, 2, 2, -3, 2, -1))\n",
"(-905.4838799249776, 36.07793474404673, 63.34202654414776)\n",
"((0, 2, 2, -4, 2, -1), (-8, 4, 2, -2, 2, -1), (-2, 2, 2, -3, 2, -1))\n",
"(-905.4838799249776, -546.0115416942884, 63.34202654414776)\n",
"((0, 2, 2, -4, 2, -1), (4, 2, 2, -4, 2, -2), (-2, 2, 2, -3, 2, -1))\n",
"(-1005.4838799249776, -646.0115416942884, -36.65797345585224)\n",
"((0, 2, 2, -4, 2, -1), (4, 2, 2, -4, 2, -2), (-2, 2, 2, -3, 2, -1))\n",
"(-1205.4838799249776, -846.0115416942884, -5.483879924977373)\n",
"((0, 2, 2, -4, 2, -1), (4, 2, 2, -4, 2, -2), (1, 2, 2, -4, 2, -1))\n",
"(-1205.4838799249776, -364.95621815566716, -5.483879924977373)\n",
"((0, 2, 2, -4, 2, -1), (-3, 2, 2, -4, 2, 0), (1, 2, 2, -4, 2, -1))\n",
"(-1405.4838799249776, -564.9562181556671, -13.63827579091003)\n",
"((0, 2, 2, -4, 2, -1), (-3, 2, 2, -4, 2, 0), (-6, 2, 2, -4, 3, 0))\n",
"(-1444.8123693217854, -564.9562181556671, -13.63827579091003)\n",
"((-10, 2, 2, -3, 3, 0), (-3, 2, 2, -4, 2, 0), (-6, 2, 2, -4, 3, 0))\n",
"(-1344.8123693217854, -464.9562181556671, 33.08878097894603)\n"
]
}
],
"source": [
"path = stochastic_hamiltonian(graph)\n",
"#durs = tuple(round(y[0]-x[0], 2) for (x, y) in pairwise(target_melody_data)) + ((1,))\n",
"durs = tuple(d[0] for d in target_melody_data)\n",
"path_to_chords(path, root)\n",
"write_chord_sequence(list(zip(durs, path_to_chords(path, root))))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6a13bec1-1a48-4647-821e-f1779976d80f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (compact sets)",
"language": "python",
"name": "compact_sets"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}