{ "cells": [ { "cell_type": "code", "execution_count": 236, "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": 2, "id": "51be5ff2-2b7f-4350-878f-09e79d4bff1f", "metadata": {}, "outputs": [], "source": [ "import crepe\n", "from scipy.io import wavfile" ] }, { "cell_type": "code", "execution_count": 3, "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": 4, "id": "01f8f969-fc3c-46a2-acfd-b1f956e438bc", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2024-05-24 17:13:22.147078: 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-24 17:13:22.471453: 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-24 17:13:23.474683: 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-24 17:13:25.296611: 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[1m36s\u001b[0m 471ms/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": 379, "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 == voice):\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": 374, "id": "a8592bc9-7e9e-4b6a-9eaa-4c4e3b69ce91", "metadata": {}, "outputs": [], "source": [ "dims = (2, 3, 5, 7)\n", "root = (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": 342, "id": "fb2ad9ad-7a8c-4f84-ab0c-9c1f1ecdb8a8", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[(39.0, 44.0, 51.0), (39.0, 44.0, 53.0)]\n", "51.0\n", "2\n", "[(39.0, 44.0, 53.0), (39.0, 44.0, 51.0)]\n", "53.0\n", "2\n", "[(39.0, 44.0, 51.0), (39.0, 46.0, 51.0)]\n", "51.0\n", "2\n", "[(39.0, 46.0, 51.0), (39.0, 44.0, 51.0)]\n", "46.0\n", "1\n", "[(39.0, 44.0, 51.0), (39.0, 44.0, 49.0)]\n", "44.0\n", "1\n", "[(39.0, 44.0, 49.0), (39.0, 44.0, 48.0)]\n", "49.0\n", "2\n", "[(39.0, 44.0, 48.0), (41.0, 44.0, 48.0)]\n", "48.0\n", "2\n", "[(41.0, 44.0, 48.0), (39.0, 44.0, 48.0)]\n", "41.0\n", "0\n", "[(39.0, 44.0, 48.0), (39.0, 44.0, 49.0)]\n", "39.0\n", "0\n", "[(39.0, 44.0, 49.0), (39.0, 42.0, 49.0)]\n", "49.0\n", "2\n", "[(39.0, 42.0, 49.0), (39.0, 42.0, 51.0)]\n", "42.0\n", "1\n", "[(39.0, 42.0, 51.0), (39.0, 41.0, 51.0)]\n", "51.0\n", "2\n", "[(39.0, 41.0, 51.0), (39.0, 41.0, 52.0)]\n", "41.0\n", "1\n", "[(39.0, 41.0, 52.0), (39.0, 41.0, 51.0)]\n", "52.0\n", "2\n", "[(39.0, 41.0, 51.0), (39.0, 42.0, 51.0)]\n", "51.0\n", "2\n", "[(39.0, 42.0, 51.0), (39.0, 42.0, 49.0)]\n", "42.0\n", "1\n", "[(39.0, 42.0, 49.0), (39.0, 42.0, 48.0)]\n", "49.0\n", "2\n", "[(39.0, 42.0, 48.0), (37.0, 42.0, 48.0)]\n", "48.0\n", "2\n", "[(37.0, 42.0, 48.0), (37.0, 44.0, 48.0)]\n", "37.0\n", "0\n", "[(37.0, 44.0, 48.0), (36.0, 44.0, 48.0)]\n", "44.0\n", "1\n", "[(36.0, 44.0, 48.0), (36.0, 44.0, 51.0)]\n", "36.0\n", "0\n", "[(36.0, 44.0, 51.0), (36.0, 45.0, 51.0)]\n", "51.0\n", "2\n", "[(36.0, 45.0, 51.0), (36.0, 44.0, 51.0)]\n", "45.0\n", "1\n", "[(36.0, 44.0, 51.0), (36.0, 44.0, 53.0)]\n", "44.0\n", "1\n", "[(36.0, 44.0, 53.0), (36.0, 44.0, 51.0)]\n", "53.0\n", "2\n", "[(36.0, 44.0, 51.0), (36.0, 42.0, 51.0)]\n", "51.0\n", "2\n", "[(36.0, 42.0, 51.0), (36.0, 41.0, 51.0)]\n", "42.0\n", "1\n", "[(36.0, 41.0, 51.0), (37.0, 41.0, 51.0)]\n", "41.0\n", "1\n", "[(37.0, 41.0, 51.0), (37.0, 41.0, 52.0)]\n", "37.0\n", "0\n", "[(37.0, 41.0, 52.0), (37.0, 41.0, 48.0)]\n", "52.0\n", "2\n", "[(37.0, 41.0, 48.0), (37.0, 44.0, 48.0)]\n", "48.0\n", "2\n", "[(37.0, 44.0, 48.0), (39.0, 44.0, 48.0)]\n", "44.0\n", "1\n", "[(39.0, 44.0, 48.0), (39.0, 46.0, 48.0)]\n", "39.0\n", "0\n", "[(39.0, 46.0, 48.0), (39.0, 46.0, 53.0)]\n", "46.0\n", "1\n", "[(39.0, 46.0, 53.0), (40.0, 46.0, 53.0)]\n", "53.0\n", "2\n", "[(40.0, 46.0, 53.0), (39.0, 46.0, 53.0)]\n", "40.0\n", "0\n", "[(39.0, 46.0, 53.0), (39.0, 44.0, 53.0)]\n", "39.0\n", "0\n", "[(39.0, 44.0, 53.0), (39.0, 44.0, 51.0)]\n", "44.0\n", "1\n", "[(39.0, 44.0, 51.0), (39.0, 44.0, 49.0)]\n", "51.0\n", "2\n", "[(39.0, 44.0, 49.0), (39.0, 45.0, 49.0)]\n", "49.0\n", "2\n", "[(39.0, 45.0, 49.0), (39.0, 45.0, 52.0)]\n", "45.0\n", "1\n", "[(39.0, 45.0, 52.0), (39.0, 45.0, 53.0)]\n", "52.0\n", "2\n", "[(39.0, 45.0, 53.0), (37.0, 45.0, 53.0)]\n", "53.0\n", "2\n", "[(37.0, 45.0, 53.0), (37.0, 45.0, 52.0)]\n", "37.0\n", "0\n", "[(37.0, 45.0, 52.0), (36.0, 45.0, 52.0)]\n", "52.0\n", "2\n", "[(36.0, 45.0, 52.0), (36.0, 41.0, 52.0)]\n", "36.0\n", "0\n", "[(36.0, 41.0, 52.0), (36.0, 41.0, 51.0)]\n", "41.0\n", "1\n", "[(36.0, 41.0, 51.0), (36.0, 41.0, 52.0)]\n", "51.0\n", "2\n", "[(36.0, 41.0, 52.0), (36.0, 41.0, 51.0)]\n", "52.0\n", "2\n", "[(36.0, 41.0, 51.0), (36.0, 41.0, 49.0)]\n", "51.0\n", "2\n", "[(36.0, 41.0, 49.0), (36.0, 41.0, 48.0)]\n", "49.0\n", "2\n", "[(36.0, 41.0, 48.0), (36.0, 41.0, 46.0)]\n", "48.0\n", "2\n", "[(36.0, 41.0, 46.0), (36.0, 46.0, 46.0)]\n", "46.0\n", "2\n", "[(36.0, 46.0, 46.0), (39.0, 46.0, 46.0)]\n", "46.0\n", "1\n", "[(39.0, 46.0, 46.0), (39.0, 44.0, 46.0)]\n", "39.0\n", "0\n", "[(39.0, 44.0, 46.0), (39.0, 42.0, 46.0)]\n", "44.0\n", "1\n", "[(39.0, 42.0, 46.0), (39.0, 42.0, 51.0)]\n", "42.0\n", "1\n", "[(39.0, 42.0, 51.0), (39.0, 42.0, 52.0)]\n", "51.0\n", "2\n", "[(39.0, 42.0, 52.0), (41.0, 42.0, 52.0)]\n", "52.0\n", "2\n", "[(41.0, 42.0, 52.0), (41.0, 42.0, 54.0)]\n", "41.0\n", "0\n", "[(41.0, 42.0, 54.0), (41.0, 42.0, 56.0)]\n", "54.0\n", "2\n", "[(41.0, 42.0, 56.0), (41.0, 42.0, 57.0)]\n", "56.0\n", "2\n", "[(41.0, 42.0, 57.0), (39.0, 42.0, 57.0)]\n", "57.0\n", "2\n", "[(39.0, 42.0, 57.0), (39.0, 42.0, 53.0)]\n", "39.0\n", "0\n", "[(39.0, 42.0, 53.0), (39.0, 45.0, 53.0)]\n", "53.0\n", "2\n", "[(39.0, 45.0, 53.0), (39.0, 46.0, 53.0)]\n", "45.0\n", "1\n", "[(39.0, 46.0, 53.0), (39.0, 45.0, 53.0)]\n", "46.0\n", "1\n", "[(39.0, 45.0, 53.0), (39.0, 44.0, 53.0)]\n", "45.0\n", "1\n", "[(39.0, 44.0, 53.0), (39.0, 44.0, 57.0)]\n", "44.0\n", "1\n", "[(39.0, 44.0, 57.0), (39.0, 44.0, 55.0)]\n", "57.0\n", "2\n", "[(39.0, 44.0, 55.0), (39.0, 44.0, 54.0)]\n", "55.0\n", "2\n", "[(39.0, 44.0, 54.0), (39.0, 45.0, 54.0)]\n", "54.0\n", "2\n", "[(39.0, 45.0, 54.0), (39.0, 45.0, 51.0)]\n", "45.0\n", "1\n", "[(39.0, 45.0, 51.0), (39.0, 44.0, 51.0)]\n", "51.0\n", "2\n", "[(39.0, 44.0, 51.0), (39.0, 42.0, 51.0)]\n", "44.0\n", "1\n", "[(39.0, 42.0, 51.0), (40.0, 42.0, 51.0)]\n", "42.0\n", "1\n", "[(40.0, 42.0, 51.0), (40.0, 41.0, 51.0)]\n", "40.0\n", "0\n", "[(40.0, 41.0, 51.0), (40.0, 39.0, 51.0)]\n", "41.0\n", "1\n", "[(40.0, 39.0, 51.0), (36.0, 39.0, 51.0)]\n", "39.0\n", "1\n", "[(36.0, 39.0, 51.0), (36.0, 39.0, 53.0)]\n", "36.0\n", "0\n", "[(36.0, 39.0, 53.0), (36.0, 39.0, 51.0)]\n", "53.0\n", "2\n", "[(36.0, 39.0, 51.0), (36.0, 44.0, 51.0)]\n", "51.0\n", "2\n", "[(36.0, 44.0, 51.0), (36.0, 45.0, 51.0)]\n", "44.0\n", "1\n", "[(36.0, 45.0, 51.0), (41.0, 45.0, 51.0)]\n", "45.0\n", "1\n", "[(41.0, 45.0, 51.0), (41.0, 47.0, 51.0)]\n", "41.0\n", "0\n", "[(41.0, 47.0, 51.0), (41.0, 47.0, 49.0)]\n", "47.0\n", "1\n", "[(41.0, 47.0, 49.0), (41.0, 49.0, 49.0)]\n", "49.0\n", "2\n", "[(41.0, 49.0, 49.0), (41.0, 50.0, 49.0)]\n", "49.0\n", "1\n", "[(41.0, 50.0, 49.0), (41.0, 50.0, 48.0)]\n", "50.0\n", "1\n", "[(41.0, 50.0, 48.0), (39.0, 50.0, 48.0)]\n", "48.0\n", "2\n", "[(39.0, 50.0, 48.0), (39.0, 46.0, 48.0)]\n", "39.0\n", "0\n", "[(39.0, 46.0, 48.0), (37.0, 46.0, 48.0)]\n", "46.0\n", "1\n", "[(37.0, 46.0, 48.0), (37.0, 46.0, 49.0)]\n", "37.0\n", "0\n", "[(37.0, 46.0, 49.0), (37.0, 46.0, 51.0)]\n", "49.0\n", "2\n", "[(37.0, 46.0, 51.0), (37.0, 46.0, 50.0)]\n", "51.0\n", "2\n", "[(37.0, 46.0, 50.0), (37.0, 50.0, 50.0)]\n", "50.0\n", "2\n", "[(37.0, 50.0, 50.0), (37.0, 50.0, 52.0)]\n", "50.0\n", "1\n", "[(37.0, 50.0, 52.0), (37.0, 50.0, 53.0)]\n", "52.0\n", "2\n", "[(37.0, 50.0, 53.0), (37.0, 48.0, 53.0)]\n", "53.0\n", "2\n", "[(37.0, 48.0, 53.0), (37.0, 47.0, 53.0)]\n", "48.0\n", "1\n", "[(37.0, 47.0, 53.0), (37.0, 44.0, 53.0)]\n", "47.0\n", "1\n", "[(37.0, 44.0, 53.0), (37.0, 44.0, 51.0)]\n", "44.0\n", "1\n", "[(37.0, 44.0, 51.0), (37.0, 44.0, 55.0)]\n", "51.0\n", "2\n", "[(37.0, 44.0, 55.0), (37.0, 44.0, 57.0)]\n", "55.0\n", "2\n", "[(37.0, 44.0, 57.0), (37.0, 44.0, 56.0)]\n", "57.0\n", "2\n", "[(37.0, 44.0, 56.0), (40.0, 44.0, 56.0)]\n", "56.0\n", "2\n", "[(40.0, 44.0, 56.0), (41.0, 44.0, 56.0)]\n", "40.0\n", "0\n", "[(41.0, 44.0, 56.0), (40.0, 44.0, 56.0)]\n", "41.0\n", "0\n", "[(40.0, 44.0, 56.0), (40.0, 44.0, 57.0)]\n", "40.0\n", "0\n", "[(40.0, 44.0, 57.0), (40.0, 44.0, 56.0)]\n", "57.0\n", "2\n", "[(40.0, 44.0, 56.0), (40.0, 44.0, 53.0)]\n", "56.0\n", "2\n", "[(40.0, 44.0, 53.0), (39.0, 44.0, 53.0)]\n", "53.0\n", "2\n", "[(39.0, 44.0, 53.0), (39.0, 44.0, 51.0)]\n", "39.0\n", "0\n", "[(39.0, 44.0, 51.0), (39.0, 46.0, 51.0)]\n", "51.0\n", "2\n", "[(39.0, 46.0, 51.0), (40.0, 46.0, 51.0)]\n", "46.0\n", "1\n", "[(40.0, 46.0, 51.0), (39.0, 46.0, 51.0)]\n", "40.0\n", "0\n", "[(39.0, 46.0, 51.0), (39.0, 44.0, 51.0)]\n", "39.0\n", "0\n", "[(39.0, 44.0, 51.0), (37.0, 44.0, 51.0)]\n", "44.0\n", "1\n", "[(37.0, 44.0, 51.0), (36.0, 44.0, 51.0)]\n", "37.0\n", "0\n", "[(36.0, 44.0, 51.0), (34.0, 44.0, 51.0)]\n", "36.0\n", "0\n", "[(34.0, 44.0, 51.0), (34.0, 44.0, 53.0)]\n", "34.0\n", "0\n", "[(34.0, 44.0, 53.0), (34.0, 44.0, 51.0)]\n", "53.0\n", "2\n", "[(34.0, 44.0, 51.0), (34.0, 42.0, 51.0)]\n", "51.0\n", "2\n", "[(34.0, 42.0, 51.0), (34.0, 41.0, 51.0)]\n", "42.0\n", "1\n", "[(34.0, 41.0, 51.0), (39.0, 41.0, 51.0)]\n", "41.0\n", "1\n", "[(39.0, 41.0, 51.0), (40.0, 41.0, 51.0)]\n", "39.0\n", "0\n", "[(40.0, 41.0, 51.0), (40.0, 41.0, 48.0)]\n", "40.0\n", "0\n", "[(40.0, 41.0, 48.0), (40.0, 42.0, 48.0)]\n", "48.0\n", "2\n", "[(40.0, 42.0, 48.0), (40.0, 42.0, 49.0)]\n", "42.0\n", "1\n", "[(40.0, 42.0, 49.0), (40.0, 44.0, 49.0)]\n", "49.0\n", "2\n", "[(40.0, 44.0, 49.0), (40.0, 44.0, 46.0)]\n", "44.0\n", "1\n", "[(40.0, 44.0, 46.0), (40.0, 44.0, 53.0)]\n", "46.0\n", "2\n", "[(40.0, 44.0, 53.0), (40.0, 44.0, 54.0)]\n", "53.0\n", "2\n", "[(40.0, 44.0, 54.0), (40.0, 44.0, 49.0)]\n", "54.0\n", "2\n", "[(40.0, 44.0, 49.0), (40.0, 43.0, 49.0)]\n", "49.0\n", "2\n", "[(40.0, 43.0, 49.0), (42.0, 45.0, 49.0)]\n", "43.0\n", "1\n", "[(42.0, 45.0, 49.0), (42.0, 46.0, 49.0)]\n", "42.0\n", "0\n", "[(42.0, 46.0, 49.0), (44.0, 46.0, 49.0)]\n", "46.0\n", "1\n", "[(44.0, 46.0, 49.0), (45.0, 46.0, 49.0)]\n", "44.0\n", "0\n", "[(45.0, 46.0, 49.0), (45.0, 44.0, 49.0)]\n", "45.0\n", "0\n", "[(45.0, 44.0, 49.0), (41.0, 44.0, 49.0)]\n", "44.0\n", "1\n", "[(41.0, 44.0, 49.0), (41.0, 48.0, 51.0)]\n", "41.0\n", "0\n", "[(41.0, 48.0, 51.0), (41.0, 50.0, 51.0)]\n", "48.0\n", "1\n", "[(41.0, 50.0, 51.0), (41.0, 49.0, 51.0)]\n", "50.0\n", "1\n", "[(41.0, 49.0, 51.0), (41.0, 49.0, 48.0)]\n", "49.0\n", "1\n", "[(41.0, 49.0, 48.0), (41.0, 50.0, 48.0)]\n", "48.0\n", "2\n", "[(41.0, 50.0, 48.0), (41.0, 50.0, 51.0)]\n", "50.0\n", "1\n", "[(41.0, 50.0, 51.0), (41.0, 50.0, 52.0)]\n", "51.0\n", "2\n", "[(41.0, 50.0, 52.0), (41.0, 49.0, 52.0)]\n", "52.0\n", "2\n", "[(41.0, 49.0, 52.0), (41.0, 49.0, 51.0)]\n", "49.0\n", "1\n", "[(41.0, 49.0, 51.0), (41.0, 46.0, 51.0)]\n", "51.0\n", "2\n", "[(41.0, 46.0, 51.0), (41.0, 46.0, 53.0)]\n", "46.0\n", "1\n", "[(41.0, 46.0, 53.0), (41.0, 44.0, 53.0)]\n", "53.0\n", "2\n", "[(41.0, 44.0, 53.0), (45.0, 44.0, 52.0)]\n", "44.0\n", "1\n", "[(45.0, 44.0, 52.0), (45.0, 44.0, 51.0)]\n", "45.0\n", "0\n", "[(45.0, 44.0, 51.0), (43.0, 44.0, 51.0)]\n", "51.0\n", "2\n", "[(43.0, 44.0, 51.0), (42.0, 44.0, 51.0)]\n", "43.0\n", "0\n", "[(42.0, 44.0, 51.0), (39.0, 44.0, 51.0)]\n", "42.0\n", "0\n", "[(39.0, 44.0, 51.0), (39.0, 44.0, 49.0)]\n", "39.0\n", "0\n", "[(39.0, 44.0, 49.0), (39.0, 44.0, 50.0)]\n", "49.0\n", "2\n", "[(39.0, 44.0, 50.0), (39.0, 44.0, 52.0)]\n", "50.0\n", "2\n", "[(39.0, 44.0, 52.0), (39.0, 44.0, 51.0)]\n", "52.0\n", "2\n", "[(39.0, 44.0, 51.0), (39.0, 46.0, 51.0)]\n", "51.0\n", "2\n", "[(39.0, 46.0, 51.0), (39.0, 44.0, 51.0)]\n", "46.0\n", "1\n", "[(39.0, 44.0, 51.0), (39.0, 44.0, 52.0)]\n", "44.0\n", "1\n", "[(39.0, 44.0, 52.0), (39.0, 44.0, 53.0)]\n", "52.0\n", "2\n", "[(39.0, 44.0, 53.0), (41.0, 44.0, 53.0)]\n", "53.0\n", "2\n", "[(41.0, 44.0, 53.0), (41.0, 44.0, 49.0)]\n", "41.0\n", "0\n", "[(41.0, 44.0, 49.0), (39.0, 44.0, 49.0)]\n", "49.0\n", "2\n", "[(39.0, 44.0, 49.0), (39.0, 41.0, 49.0)]\n", "39.0\n", "0\n", "[(39.0, 41.0, 49.0), (39.0, 41.0, 56.0)]\n", "41.0\n", "1\n", "[(39.0, 41.0, 56.0), (39.0, 42.0, 56.0)]\n", "56.0\n", "2\n", "[(39.0, 42.0, 56.0), (39.0, 42.0, 54.0)]\n", "42.0\n", "1\n", "[(39.0, 42.0, 54.0), (39.0, 42.0, 53.0)]\n", "54.0\n", "2\n", "[(39.0, 42.0, 53.0), (39.0, 39.0, 53.0)]\n", "53.0\n", "2\n", "[(39.0, 39.0, 53.0), (39.0, 39.0, 51.0)]\n", "39.0\n", "1\n", "[(39.0, 39.0, 51.0), (39.0, 46.0, 51.0)]\n", "51.0\n", "2\n", "[(39.0, 46.0, 51.0), (39.0, 47.0, 51.0)]\n", "46.0\n", "1\n", "[(39.0, 47.0, 51.0), (39.0, 47.0, 53.0)]\n", "47.0\n", "1\n", "[(39.0, 47.0, 53.0), (39.0, 47.0, 51.0)]\n", "53.0\n", "2\n", "[(39.0, 47.0, 51.0), (39.0, 42.0, 51.0)]\n", "51.0\n", "2\n", "[(39.0, 42.0, 51.0), (37.0, 42.0, 51.0)]\n", "42.0\n", "1\n", "[(37.0, 42.0, 51.0), (37.0, 42.0, 49.0)]\n", "37.0\n", "0\n", "[(37.0, 42.0, 49.0), (36.0, 42.0, 49.0)]\n", "49.0\n", "2\n", "[(36.0, 42.0, 49.0), (36.0, 42.0, 48.0)]\n", "36.0\n", "0\n", "[(36.0, 42.0, 48.0), (36.0, 44.0, 49.0)]\n", "48.0\n", "2\n", "[(36.0, 44.0, 49.0), (36.0, 44.0, 51.0)]\n", "44.0\n", "1\n", "[(36.0, 44.0, 51.0), (37.0, 44.0, 51.0)]\n", "51.0\n", "2\n", "[(37.0, 44.0, 51.0), (37.0, 41.0, 51.0)]\n", "37.0\n", "0\n", "[(37.0, 41.0, 51.0), (39.0, 41.0, 51.0)]\n", "41.0\n", "1\n", "[(39.0, 41.0, 51.0), (39.0, 41.0, 52.0)]\n", "39.0\n", "0\n", "[(39.0, 41.0, 52.0), (39.0, 44.0, 53.0)]\n", "52.0\n", "2\n", "[(39.0, 44.0, 53.0), (39.0, 45.0, 53.0)]\n", "44.0\n", "1\n", "[(39.0, 45.0, 53.0), (39.0, 45.0, 52.0)]\n", "45.0\n", "1\n", "[(39.0, 45.0, 52.0), (39.0, 45.0, 51.0)]\n", "52.0\n", "2\n", "[(39.0, 45.0, 51.0), (39.0, 44.0, 51.0)]\n", "51.0\n", "2\n", "[(39.0, 44.0, 51.0), (39.0, 44.0, 52.0)]\n", "44.0\n", "1\n", "[(39.0, 44.0, 52.0), (39.0, 46.0, 52.0)]\n", "52.0\n", "2\n", "[(39.0, 46.0, 52.0), (39.0, 45.0, 52.0)]\n", "46.0\n", "1\n", "[(39.0, 45.0, 52.0), (38.0, 45.0, 52.0)]\n", "45.0\n", "1\n", "[(38.0, 45.0, 52.0), (40.0, 45.0, 52.0)]\n", "38.0\n", "0\n", "[(40.0, 45.0, 52.0), (41.0, 45.0, 52.0)]\n", "40.0\n", "0\n", "[(41.0, 45.0, 52.0), (41.0, 44.0, 52.0)]\n", "41.0\n", "0\n", "[(41.0, 44.0, 52.0), (41.0, 42.0, 52.0)]\n", "44.0\n", "1\n", "[(41.0, 42.0, 52.0), (39.0, 42.0, 52.0)]\n", "42.0\n", "1\n", "[(39.0, 42.0, 52.0), (39.0, 43.0, 52.0)]\n", "39.0\n", "0\n", "[(39.0, 43.0, 52.0), (43.0, 43.0, 52.0)]\n", "43.0\n", "1\n", "[(43.0, 43.0, 52.0), (45.0, 43.0, 52.0)]\n", "43.0\n", "0\n", "[(45.0, 43.0, 52.0), (44.0, 43.0, 52.0)]\n", "45.0\n", "0\n", "[(44.0, 43.0, 52.0), (44.0, 45.0, 52.0)]\n", "44.0\n", "0\n", "[(44.0, 45.0, 52.0), (44.0, 44.0, 52.0)]\n", "45.0\n", "1\n", "[(44.0, 44.0, 52.0), (45.0, 44.0, 52.0)]\n", "44.0\n", "1\n", "[(45.0, 44.0, 52.0), (44.0, 44.0, 52.0)]\n", "45.0\n", "0\n", "[(44.0, 44.0, 52.0), (41.0, 44.0, 52.0)]\n", "44.0\n", "0\n", "[(41.0, 44.0, 52.0), (41.0, 45.0, 52.0)]\n", "41.0\n", "0\n" ] }, { "data": { "text/plain": [ "[(1.525, 51.0, 2, 0.0),\n", " (0.425, 53.0, 2, 200.0),\n", " (1.225, 51.0, 2, -200.0),\n", " (0.65, 46.0, 1, -500.0),\n", " (0.375, 44.0, 1, -200.0),\n", " (0.65, 49.0, 2, 500.0),\n", " (0.175, 48.0, 2, -100.0),\n", " (0.925, 41.0, 0, -700.0),\n", " (0.4, 39.0, 0, -200.0),\n", " (0.4, 49.0, 2, 1000.0),\n", " (0.7, 42.0, 1, -700.0),\n", " (0.25, 51.0, 2, 900.0),\n", " (0.625, 41.0, 1, -1000.0),\n", " (0.1, 52.0, 2, 1100.0),\n", " (1.175, 51.0, 2, -100.0),\n", " (0.475, 42.0, 1, -900.0),\n", " (0.1, 49.0, 2, 700.0),\n", " (0.225, 48.0, 2, -100.0),\n", " (0.625, 37.0, 0, -1100.0),\n", " (0.525, 44.0, 1, 700.0),\n", " (0.2, 36.0, 0, -800.0),\n", " (0.625, 51.0, 2, 1500.0),\n", " (0.05, 45.0, 1, -600.0),\n", " (0.175, 44.0, 1, -100.0),\n", " (0.65, 53.0, 2, 900.0),\n", " (1.0, 51.0, 2, -200.0),\n", " (0.075, 42.0, 1, -900.0),\n", " (0.075, 41.0, 1, -100.0),\n", " (1.2, 37.0, 0, -400.0),\n", " (0.525, 52.0, 2, 1500.0),\n", " (0.3, 48.0, 2, -400.0),\n", " (0.075, 44.0, 1, -400.0),\n", " (1.225, 39.0, 0, -500.0),\n", " (0.325, 46.0, 1, 700.0),\n", " (0.3, 53.0, 2, 700.0),\n", " (0.15, 40.0, 0, -1300.0),\n", " (0.075, 39.0, 0, -100.0),\n", " (0.525, 44.0, 1, 500.0),\n", " (0.225, 51.0, 2, 700.0),\n", " (2.275, 49.0, 2, -200.0),\n", " (0.125, 45.0, 1, -400.0),\n", " (0.025, 52.0, 2, 700.0),\n", " (0.225, 53.0, 2, 100.0),\n", " (0.025, 37.0, 0, -1600.0),\n", " (0.125, 52.0, 2, 1500.0),\n", " (0.25, 36.0, 0, -1600.0),\n", " (0.25, 41.0, 1, 500.0),\n", " (0.8, 51.0, 2, 1000.0),\n", " (0.125, 52.0, 2, 100.0),\n", " (0.325, 51.0, 2, -100.0),\n", " (0.275, 49.0, 2, -200.0),\n", " (0.375, 48.0, 2, -100.0),\n", " (0.425, 46.0, 2, -200.0),\n", " (0.125, 46.0, 1, 0.0),\n", " (1.1, 39.0, 0, -700.0),\n", " (0.375, 44.0, 1, 500.0),\n", " (0.05, 42.0, 1, -200.0),\n", " (0.1, 51.0, 2, 900.0),\n", " (0.4, 52.0, 2, 100.0),\n", " (1.15, 41.0, 0, -1100.0),\n", " (0.15, 54.0, 2, 1300.0),\n", " (0.1, 56.0, 2, 200.0),\n", " (0.075, 57.0, 2, 100.0),\n", " (0.75, 39.0, 0, -1800.0),\n", " (0.575, 53.0, 2, 1400.0),\n", " (0.05, 45.0, 1, -800.0),\n", " (0.325, 46.0, 1, 100.0),\n", " (0.9, 45.0, 1, -100.0),\n", " (0.375, 44.0, 1, -100.0),\n", " (0.575, 57.0, 2, 1300.0),\n", " (0.05, 55.0, 2, -200.0),\n", " (0.125, 54.0, 2, -100.0),\n", " (0.075, 45.0, 1, -900.0),\n", " (0.125, 51.0, 2, 600.0),\n", " (0.4, 44.0, 1, -700.0),\n", " (0.275, 42.0, 1, -200.0),\n", " (0.125, 40.0, 0, -200.0),\n", " (0.525, 41.0, 1, 100.0),\n", " (0.65, 39.0, 1, -200.0),\n", " (0.975, 36.0, 0, -300.0),\n", " (0.725, 53.0, 2, 1700.0),\n", " (0.275, 51.0, 2, -200.0),\n", " (0.175, 44.0, 1, -700.0),\n", " (1.65, 45.0, 1, 100.0),\n", " (0.7, 41.0, 0, -400.0),\n", " (0.1, 47.0, 1, 600.0),\n", " (0.05, 49.0, 2, 200.0),\n", " (0.225, 49.0, 1, 0.0),\n", " (0.4, 50.0, 1, 100.0),\n", " (0.375, 48.0, 2, -200.0),\n", " (0.325, 39.0, 0, -900.0),\n", " (0.2, 46.0, 1, 700.0),\n", " (0.225, 37.0, 0, -900.0),\n", " (0.425, 49.0, 2, 1200.0),\n", " (2.05, 51.0, 2, 200.0),\n", " (0.025, 50.0, 2, -100.0),\n", " (0.125, 50.0, 1, 0.0),\n", " (0.075, 52.0, 2, 200.0),\n", " (0.45, 53.0, 2, 100.0),\n", " (0.075, 48.0, 1, -500.0),\n", " (0.225, 47.0, 1, -100.0),\n", " (0.075, 44.0, 1, -300.0),\n", " (0.35, 51.0, 2, 700.0),\n", " (0.15, 55.0, 2, 400.0),\n", " (0.3, 57.0, 2, 200.0),\n", " (0.175, 56.0, 2, -100.0),\n", " (0.1, 40.0, 0, -1600.0),\n", " (0.525, 41.0, 0, 100.0),\n", " (0.55, 40.0, 0, -100.0),\n", " (0.325, 57.0, 2, 1700.0),\n", " (0.375, 56.0, 2, -100.0),\n", " (0.075, 53.0, 2, -300.0),\n", " (0.5, 39.0, 0, -1400.0),\n", " (0.525, 51.0, 2, 1200.0),\n", " (0.7, 46.0, 1, -500.0),\n", " (0.3, 40.0, 0, -600.0),\n", " (0.05, 39.0, 0, -100.0),\n", " (0.55, 44.0, 1, 500.0),\n", " (0.65, 37.0, 0, -700.0),\n", " (0.675, 36.0, 0, -100.0),\n", " (0.25, 34.0, 0, -200.0),\n", " (0.7, 53.0, 2, 1900.0),\n", " (0.85, 51.0, 2, -200.0),\n", " (0.9, 42.0, 1, -900.0),\n", " (1.15, 41.0, 1, -100.0),\n", " (0.25, 39.0, 0, -200.0),\n", " (0.025, 40.0, 0, 100.0),\n", " (0.1, 48.0, 2, 800.0),\n", " (0.475, 42.0, 1, -600.0),\n", " (0.125, 49.0, 2, 700.0),\n", " (1.0, 44.0, 1, -500.0),\n", " (0.35, 46.0, 2, 200.0),\n", " (0.075, 53.0, 2, 700.0),\n", " (0.725, 54.0, 2, 100.0),\n", " (0.3, 49.0, 2, -500.0),\n", " (0.2, 43.0, 1, -600.0),\n", " (0.1, 42.0, 0, -100.0),\n", " (0.25, 46.0, 1, 400.0),\n", " (0.2, 44.0, 0, -200.0),\n", " (0.975, 45.0, 0, 100.0),\n", " (0.55, 44.0, 1, -100.0),\n", " (0.025, 41.0, 0, -300.0),\n", " (0.225, 48.0, 1, 700.0),\n", " (0.425, 50.0, 1, 200.0),\n", " (0.525, 49.0, 1, -100.0),\n", " (1.45, 48.0, 2, -100.0),\n", " (0.025, 50.0, 1, 200.0),\n", " (0.175, 51.0, 2, 100.0),\n", " (0.275, 52.0, 2, 100.0),\n", " (0.025, 49.0, 1, -300.0),\n", " (0.35, 51.0, 2, 200.0),\n", " (0.4, 46.0, 1, -500.0),\n", " (0.4, 53.0, 2, 700.0),\n", " (0.075, 44.0, 1, -900.0),\n", " (0.7, 45.0, 0, 100.0),\n", " (0.35, 51.0, 2, 600.0),\n", " (0.1, 43.0, 0, -800.0),\n", " (0.4, 42.0, 0, -100.0),\n", " (0.175, 39.0, 0, -300.0),\n", " (0.275, 49.0, 2, 1000.0),\n", " (1.425, 50.0, 2, 100.0),\n", " (0.775, 52.0, 2, 200.0),\n", " (0.475, 51.0, 2, -100.0),\n", " (0.85, 46.0, 1, -500.0),\n", " (1.375, 44.0, 1, -200.0),\n", " (0.25, 52.0, 2, 800.0),\n", " (0.55, 53.0, 2, 100.0),\n", " (0.075, 41.0, 0, -1200.0),\n", " (1.425, 49.0, 2, 800.0),\n", " (0.325, 39.0, 0, -1000.0),\n", " (0.525, 41.0, 1, 200.0),\n", " (0.3, 56.0, 2, 1500.0),\n", " (0.825, 42.0, 1, -1400.0),\n", " (0.525, 54.0, 2, 1200.0),\n", " (0.15, 53.0, 2, -100.0),\n", " (0.075, 39.0, 1, -1400.0),\n", " (0.375, 51.0, 2, 1200.0),\n", " (0.125, 46.0, 1, -500.0),\n", " (0.05, 47.0, 1, 100.0),\n", " (0.3, 53.0, 2, 600.0),\n", " (0.675, 51.0, 2, -200.0),\n", " (1.4, 42.0, 1, -900.0),\n", " (0.9, 37.0, 0, -500.0),\n", " (0.475, 49.0, 2, 1200.0),\n", " (0.425, 36.0, 0, -1300.0),\n", " (0.475, 48.0, 2, 1200.0),\n", " (0.275, 44.0, 1, -400.0),\n", " (1.175, 51.0, 2, 700.0),\n", " (0.3, 37.0, 0, -1400.0),\n", " (0.45, 41.0, 1, 400.0),\n", " (1.375, 39.0, 0, -200.0),\n", " (0.225, 52.0, 2, 1300.0),\n", " (0.25, 44.0, 1, -800.0),\n", " (0.1, 45.0, 1, 100.0),\n", " (0.05, 52.0, 2, 700.0),\n", " (0.15, 51.0, 2, -100.0),\n", " (0.6, 44.0, 1, -700.0),\n", " (0.225, 52.0, 2, 800.0),\n", " (0.55, 46.0, 1, -600.0),\n", " (0.45, 45.0, 1, -100.0),\n", " (0.275, 38.0, 0, -700.0),\n", " (0.15, 40.0, 0, 200.0),\n", " (0.05, 41.0, 0, 100.0),\n", " (1.45, 44.0, 1, 300.0),\n", " (0.225, 42.0, 1, -200.0),\n", " (0.225, 39.0, 0, -300.0),\n", " (0.75, 43.0, 1, 400.0),\n", " (0.25, 43.0, 0, 0.0),\n", " (0.55, 45.0, 0, 200.0),\n", " (0.525, 44.0, 0, -100.0),\n", " (0.925, 45.0, 1, 100.0),\n", " (1.4, 44.0, 1, -100.0),\n", " (0.725, 45.0, 0, 100.0),\n", " (0.8, 44.0, 0, -100.0),\n", " (0.775, 41.0, 0, -300.0)]" ] }, "execution_count": 342, "metadata": {}, "output_type": "execute_result" } ], "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 freqs_to_midi(freqs, confs):\n", " last_confident_value = 51\n", " for f, c in zip(freqs, confs):\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", "#data_v2 = tuple(d + (2,) for d in zip(f_time, f_frequency, s_confidence))\n", "#data_v1 = tuple(d + (1,) for d in zip([t + 2 for t in f_time], f_frequency, s_confidence))\n", "#data_v0 = tuple(d + (0,) for d in zip([t + 4 for t in f_time], f_frequency, s_confidence))\n", "\n", "#data = data_v2 + data_v1 + data_v0\n", "#data = sorted(data)\n", "#f_time = tuple(d[0] for d in data)\n", "#ins = tuple(d[-1] for d in data)\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 format_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 / 20)\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", " b_dur = randint(5, 10)\n", " yield (randint(10, 20) / 40.0, last_val, dev * 100)\n", " for i in range(size):\n", " yield (randint(10, 20) / 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", "def filter_midi(midi):\n", " last_val = midi[0][-1]\n", " ins = 2\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", " print([m1, m2])\n", " print(last_val)\n", " print(ins)\n", " yield (dur / 40, last_val, ins, dev * 100)\n", "\n", " #if first_flag or dur < 10:\n", " # yield (10 / 40.0, last_val, ins, dev * 100)\n", " # first_flag = False\n", " #else:\n", " # size = int(dur / 10)\n", "\n", " # b_dur = randint(5, 10)\n", " # yield (randint(5, 10) / 40.0, last_val, ins, dev * 100)\n", " # for i in range(size):\n", " # yield (randint(5, 10) / 40.0, last_val, ins, 0.0)\n", " \n", "\n", " ins = [i for i, m in enumerate(m1) if m1[i] != m2[i]][0]\n", " #ins = 2\n", " dur = 1\n", " dev = m2[ins] - last_val\n", " last_val = m2[ins]\n", " else:\n", " dur += 1\n", "\n", " \n", "midi = list(freqs_to_midi(f_frequency, f_confidence))\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", "midi = tuple(snap_midi(midi))\n", "#midi = zip(\n", "# tuple(midi[0] - 12 for i in range(2 * 40)) + tuple(m - 12 for m in midi for r in range(2)),\n", "# tuple(midi[0] - 7 for i in range(1 * 40)) + tuple(m - 7 for m in midi for r in range(2)) + tuple(midi[-1] - 12 for i in range(5 * 40)),\n", "# tuple(m - 0 for m in midi) + tuple(midi[-1] - 0 for i in range(10 * 40)))\n", "\n", "midi = zip(\n", " tuple(midi[0] - 12 for i in range(2 * 40)) + tuple(chain(*tuple([m - 12 for r in range(randint(2, 4))] for m in midi))),\n", " tuple(midi[0] - 7 for i in range(1 * 40)) + tuple(chain(*tuple([m - 7 for r in range(randint(1, 3))] for m in midi))) + tuple(midi[-1] - 12 for i in range(5 * 40)),\n", " tuple(chain(*tuple([m for r in range(randint(1, 2))] for m in midi))) + tuple(midi[-1] - 0 for i in range(10 * 40)))\n", "\n", "#midi = zip(\n", "# tuple(m - 24 for m in midi) + tuple(midi[-1] - 24 for i in range(5 * 40)),\n", "# tuple(midi[0] - 12 for i in range(3 * 40)) + tuple(m - 12 for m in midi) + tuple(midi[-1] - 12 for i in range(2 * 40)),\n", "# tuple(midi[0] - 0 for i in range(5 * 40)) + tuple(m - 0 for m in midi))\n", "\n", "target_melody_data = list(filter_midi(list(midi)))\n", "target_melody_data\n", "\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": 319, "id": "2b311f14-5061-4f51-9ee7-bd19a1d938fc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1, 1, 2, 2, 2, 2, 3, 3, 3)" ] }, "execution_count": 319, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tuple(chain(*tuple([m for r in range(randint(2, 4))] for m in [1, 2, 3])))" ] }, { "cell_type": "code", "execution_count": 380, "id": "be01e4ae-e629-42ff-9d95-f77d510c13bf", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(-701.9550008653874, -386.31371386483454, 0)\n", "((0, 0, 0, 0), (1, 1, -1, 0), (-1, 1, 0, 0))\n", "(-901.9550008653874, -586.3137138648345, -88.26871473022209)\n", "200.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(-701.9550008653874, -386.31371386483454, 0.0)\n", "-200.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (-1, 1, 0, 0))\n", "(-313.68628613516523, 113.68628613516546, 500.0)\n", "-500.0\n", "((0, 0, 0, 0), (5, 0, -2, 0), (3, 0, -1, 0))\n", "(-184.35871299944722, 313.68628613516546, 700.0)\n", "-200.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (0, -1, 1, 0))\n", "(-684.3587129994472, -186.31371386483454, 17.5962878659401)\n", "500.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (-1, 1, 0, 0))\n", "(-584.3587129994472, -268.7174259988941, 117.5962878659401)\n", "-100.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (-1, 1, 0, 0))\n", "(3.9100017307749795, 431.2825740011059, 817.5962878659401)\n", "-700.0\n", "((0, 0, 0, 0), (5, 0, -2, 0), (3, 0, -1, 0))\n", "(400.10848047023035, 631.2825740011059, 1017.5962878659401)\n", "-200.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (1, 0, 1, -1))\n", "(-796.089998269225, -368.7174259988941, 17.5962878659401)\n", "1000.0\n", "((0, 0, 0, 0), (5, 0, -2, 0), (3, 0, -1, 0))\n", "(-166.762425133507, 331.2825740011059, 717.5962878659401)\n", "-700.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (0, -1, 1, 0))\n", "(-1066.762425133507, -568.7174259988941, -70.6724268642821)\n", "900.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (4, -2, 0, 0))\n", "(-66.7624251335069, 431.2825740011059, 635.1925757318802)\n", "-1000.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (-1, 1, 0, 0))\n", "(-1166.762425133507, -668.7174259988941, -170.6724268642821)\n", "1100.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (4, -2, 0, 0))\n", "(-884.3587129994469, -568.7174259988941, -70.6724268642821)\n", "-100.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(15.64128700055312, 331.2825740011059, 717.59628786594)\n", "-900.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (-1, 1, 0, 0))\n", "(-684.3587129994469, -186.31371386483454, 17.596287865939985)\n", "700.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (-1, 1, 0, 0))\n", "(-584.3587129994469, -113.5778056649346, 117.59628786593998)\n", "-100.0\n", "((0, 0, 0, 0), (-4, 1, 0, 1), (-1, 1, 0, 0))\n", "(284.467193469678, 986.4221943350653, 1217.59628786594)\n", "-1100.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (2, 1, 0, -1))\n", "(-415.532806530322, 286.42219433506534, 398.15347960484314)\n", "700.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (3, 0, -1, 0))\n", "(384.467193469678, 811.8397657400083, 1198.1534796048431)\n", "-800.0\n", "((0, 0, 0, 0), (5, 0, -2, 0), (3, 0, -1, 0))\n", "(-1115.532806530322, -729.2190926654873, -301.84652039515686)\n", "1500.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (3, 0, -1, 0))\n", "(-515.532806530322, -129.21909266548732, -17.48780739570975)\n", "-600.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(-415.532806530322, -303.8015212605444, 82.51219260429025)\n", "-100.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (2, -1, 0, 0))\n", "(-1315.532806530322, -1203.8015212605444, -501.84652039515686)\n", "900.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (3, 0, -1, 0))\n", "(-1115.532806530322, -799.8915195297693, -301.84652039515686)\n", "-200.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(-215.53280653032198, 100.10848047023069, 486.4221943350652)\n", "-900.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (-1, 1, 0, 0))\n", "(-227.26409180009978, 200.1084804702307, 586.4221943350652)\n", "-100.0\n", "((0, 0, 0, 0), (5, 0, -2, 0), (3, 0, -1, 0))\n", "(172.73590819990022, 755.2481008041905, 986.4221943350652)\n", "-400.0\n", "((0, 0, 0, 0), (0, 0, -1, 1), (3, 0, -1, 0))\n", "(-1327.2640918000998, -744.7518991958095, -358.4381853309751)\n", "1500.0\n", "((0, 0, 0, 0), (0, 0, -1, 1), (-2, 0, 0, 1))\n", "(-731.0656130606444, -344.75189919580953, 41.5618146690249)\n", "-400.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-4, 0, 2, 0))\n", "(-331.0656130606444, 55.24810080419047, 166.9793860739677)\n", "-400.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(168.9343869393556, 435.80529254309295, 666.9793860739677)\n", "-500.0\n", "((0, 0, 0, 0), (-1, -1, 0, 1), (2, -1, 0, 0))\n", "(-1077.8809935920724, -264.19470745690705, -33.0206139260323)\n", "700.0\n", "((0, 0, 0, 0), (3, 0, -1, 0), (6, 0, -1, -1))\n", "(-1701.8465203951573, -964.194707456907, -733.0206139260323)\n", "700.0\n", "((0, 0, 0, 0), (-5, 0, 0, 2), (-2, 0, 0, 1))\n", "(-246.70690006119753, 335.80529254309295, 566.9793860739677)\n", "-1300.0\n", "((0, 0, 0, 0), (0, 0, -1, 1), (3, 0, -1, 0))\n", "(-146.70690006119753, 168.9343869393556, 666.9793860739677)\n", "-100.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(-646.7069000611975, -331.0656130606444, 55.24810080418979)\n", "500.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (-1, 1, 0, 0))\n", "(-1346.7069000611975, -1031.0656130606444, -533.0206139260323)\n", "700.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(-1217.3793269254795, -831.0656130606444, -333.0206139260323)\n", "-200.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (0, -1, 1, 0))\n", "(-817.3793269254795, -431.0656130606444, -3.693040790314285)\n", "-400.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (3, 0, -1, 0))\n", "(-1517.3793269254795, -1131.0656130606444, -429.11061219525743)\n", "700.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-3, 1, 1, 0))\n", "(-1617.3793269254795, -915.4243260600917, -529.1106121952574)\n", "100.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (-3, 1, 1, 0))\n", "(-17.379326925479518, 684.5756739399083, 796.3069592096857)\n", "-1600.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (3, 0, -1, 0))\n", "(-1517.3793269254795, -815.4243260600917, -429.11061219525754)\n", "1500.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (-3, 1, 1, 0))\n", "(82.62067307452048, 784.5756739399083, 896.3069592096856)\n", "-1600.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (3, 0, -1, 0))\n", "(-417.3793269254795, 80.66567220913328, 396.3069592096856)\n", "500.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (3, 0, -1, 0))\n", "(-1417.3793269254795, -919.3343277908667, -421.2893286562546)\n", "1000.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (4, -2, 0, 0))\n", "(-1223.244329521642, -1019.3343277908667, -521.2893286562546)\n", "100.0\n", "((0, 0, 0, 0), (-3, 2, 0, 0), (-1, 1, 0, 0))\n", "(-1234.9756147914197, -919.3343277908667, -421.2893286562546)\n", "-100.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(-1034.9756147914197, -803.8015212605446, -221.2893286562546)\n", "-200.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (3, 0, -1, 0))\n", "(-934.9756147914197, -703.8015212605446, -1.846520395157654)\n", "-100.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (2, 1, 0, -1))\n", "(-734.9756147914197, -503.80152126054463, -33.020613926032524)\n", "-200.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (-1, 1, 0, 0))\n", "(-734.9756147914197, -419.3343277908667, -33.020613926032524)\n", "0.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (-1, 1, 0, 0))\n", "(-301.8465203951573, 280.6656722091333, 666.9793860739675)\n", "-700.0\n", "((0, 0, 0, 0), (0, 0, -1, 1), (-2, 0, 0, 1))\n", "(-801.8465203951573, -219.33432779086672, 11.83976574000792)\n", "500.0\n", "((0, 0, 0, 0), (0, 0, -1, 1), (3, 0, -1, 0))\n", "(-517.3793269254793, -19.334327790866723, 211.83976574000792)\n", "-200.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (5, -1, 0, -1))\n", "(-1417.3793269254793, -919.3343277908667, -421.2893286562545)\n", "900.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (4, -2, 0, 0))\n", "(-1490.115235125379, -1019.3343277908667, -521.2893286562545)\n", "100.0\n", "((0, 0, 0, 0), (-4, 1, 0, 1), (-2, 0, 0, 1))\n", "(-390.11523512537906, 80.66567220913328, 311.83976574000803)\n", "-1100.0\n", "((0, 0, 0, 0), (-4, 1, 0, 1), (-1, 1, 0, 0))\n", "(-1690.115235125379, -1219.3343277908666, -721.2893286562545)\n", "1300.0\n", "((0, 0, 0, 0), (-4, 1, 0, 1), (-2, 0, 0, 1))\n", "(-1890.115235125379, -1152.463422187129, -921.2893286562545)\n", "200.0\n", "((0, 0, 0, 0), (-5, 0, 0, 2), (-2, 0, 0, 1))\n", "(-1519.3343277908666, -1252.463422187129, -1021.2893286562545)\n", "100.0\n", "((0, 0, 0, 0), (-1, -1, 0, 1), (2, -1, 0, 0))\n", "(-34.9756147914195, 547.536577812871, 778.7106713437455)\n", "-1800.0\n", "((0, 0, 0, 0), (0, 0, -1, 1), (3, 0, -1, 0))\n", "(-1434.9756147914195, -852.463422187129, -466.14970832229494)\n", "1400.0\n", "((0, 0, 0, 0), (0, 0, -1, 1), (-2, 0, 0, 1))\n", "(-634.9756147914195, -52.46342218712903, 178.7106713437455)\n", "-800.0\n", "((0, 0, 0, 0), (0, 0, -1, 1), (3, 0, -1, 0))\n", "(-538.777136051964, -152.46342218712903, 78.7106713437455)\n", "100.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (1, 0, 1, -1))\n", "(-438.777136051964, -52.46342218712903, 59.26786308264832)\n", "-100.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(-338.777136051964, -71.90623044822655, 159.26786308264832)\n", "-100.0\n", "((0, 0, 0, 0), (-1, -1, 0, 1), (2, -1, 0, 0))\n", "(-1638.7771360519641, -1371.9062304482266, -669.9512295828392)\n", "1300.0\n", "((0, 0, 0, 0), (-1, -1, 0, 1), (-2, 0, 0, 1))\n", "(-1438.7771360519641, -1052.463422187129, -469.95122958283923)\n", "-200.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-2, 0, 0, 1))\n", "(-1338.7771360519641, -952.463422187129, -250.50842132174193)\n", "-100.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-3, 1, 1, 0))\n", "(-438.77713605196413, -52.46342218712903, 59.26786308264832)\n", "-900.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(-1038.7771360519641, -652.463422187129, 49.491578678258065)\n", "600.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-3, 1, 1, 0))\n", "(-338.77713605196413, 47.53657781287097, 159.26786308264832)\n", "-700.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(-138.77713605196413, 92.39695747891113, 359.2678630826483)\n", "-200.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (2, -1, 0, 0))\n", "(61.222863948035865, 292.39695747891113, 447.5365778128707)\n", "-200.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (-2, 0, 1, 0))\n", "(-38.777136051964135, 116.3624842819959, 347.5365778128707)\n", "100.0\n", "((0, 0, 0, 0), (-5, 0, 1, 1), (-2, 0, 1, 0))\n", "(-421.2893286562545, 316.3624842819959, 547.5365778128707)\n", "-200.0\n", "((0, 0, 0, 0), (-5, 0, 0, 2), (-2, 0, 0, 1))\n", "(-121.2893286562545, 461.2228639480362, 847.5365778128707)\n", "-300.0\n", "((0, 0, 0, 0), (0, 0, -1, 1), (-2, 0, 0, 1))\n", "(-1821.2893286562544, -1007.6030425210887, -852.4634221871293)\n", "1700.0\n", "((0, 0, 0, 0), (3, 0, -1, 0), (-2, 0, 0, 1))\n", "(-1621.2893286562544, -807.6030425210887, -576.4289489902139)\n", "-200.0\n", "((0, 0, 0, 0), (3, 0, -1, 0), (6, 0, -1, -1))\n", "(-921.2893286562544, -107.6030425210887, 47.536577812870746)\n", "-700.0\n", "((0, 0, 0, 0), (3, 0, -1, 0), (-2, 0, 0, 1))\n", "(-1021.2893286562544, -207.6030425210887, 23.57105100978606)\n", "100.0\n", "((0, 0, 0, 0), (3, 0, -1, 0), (6, 0, -1, -1))\n", "(-621.2893286562544, 192.3969574789113, 347.53657781287075)\n", "-400.0\n", "((0, 0, 0, 0), (3, 0, -1, 0), (-2, 0, 0, 1))\n", "(-1221.2893286562544, -407.6030425210887, -176.42894899021394)\n", "600.0\n", "((0, 0, 0, 0), (3, 0, -1, 0), (6, 0, -1, -1))\n", "(-1078.3839498556015, -607.6030425210887, -376.42894899021394)\n", "200.0\n", "((0, 0, 0, 0), (-4, 1, 0, 1), (-1, 1, 0, 0))\n", "(-1078.3839498556015, -607.6030425210887, -109.55804338647647)\n", "0.0\n", "((0, 0, 0, 0), (-4, 1, 0, 1), (-2, 0, 0, 1))\n", "(-1178.3839498556015, -440.73213691735117, -209.55804338647647)\n", "100.0\n", "((0, 0, 0, 0), (-5, 0, 0, 2), (-2, 0, 0, 1))\n", "(-627.0458507821862, -240.73213691735117, -9.55804338647647)\n", "-200.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (1, 0, 1, -1))\n", "(272.9541492178138, 659.2678630826488, 770.9991483524263)\n", "-900.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(-427.0458507821862, -160.17494517844875, 70.99914835242635)\n", "700.0\n", "((0, 0, 0, 0), (-1, -1, 0, 1), (2, -1, 0, 0))\n", "(472.9541492178138, 859.2678630826488, 970.9991483524263)\n", "-900.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(-727.0458507821862, -340.7321369173512, -25.09084991679856)\n", "1200.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-1, 1, 0, 0))\n", "(-927.0458507821862, -540.7321369173512, -42.68713778273866)\n", "200.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (0, -1, 1, 0))\n", "(-827.0458507821862, -440.7321369173512, -13.359564647020647)\n", "-100.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (3, 0, -1, 0))\n", "(-827.0458507821862, -329.0008516475736, -13.359564647020647)\n", "0.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (3, 0, -1, 0))\n", "(-1027.0458507821863, -529.0008516475737, -30.95585251296086)\n", "200.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (4, -2, 0, 0))\n", "(-944.6421386481263, -629.0008516475737, -130.95585251296086)\n", "100.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(-444.6421386481263, -129.00085164757365, 257.3128622172612)\n", "-500.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (-1, 1, 0, 0))\n", "(-611.5130442518639, -29.000851647573654, 357.3128622172612)\n", "-100.0\n", "((0, 0, 0, 0), (0, 0, -1, 1), (-2, 0, 0, 1))\n", "(-311.5130442518639, 270.99914835242635, 502.17324188330167)\n", "-300.0\n", "((0, 0, 0, 0), (0, 0, -1, 1), (3, 0, -1, 0))\n", "(-1011.5130442518639, -429.00085164757365, -42.68713778273877)\n", "700.0\n", "((0, 0, 0, 0), (0, 0, -1, 1), (-2, 0, 0, 1))\n", "(-1411.513044251864, -940.7321369173515, -442.6871377827388)\n", "400.0\n", "((0, 0, 0, 0), (-4, 1, 0, 1), (-2, 0, 0, 1))\n", "(-1527.045850782186, -1140.7321369173515, -642.6871377827388)\n", "200.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (0, -1, 1, 0))\n", "(-1427.045850782186, -1040.7321369173515, -338.7771360519639)\n", "-100.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-3, 1, 1, 0))\n", "(172.9541492178139, 559.2678630826485, 670.9991483524263)\n", "-1600.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(72.95414921781389, 184.68543448759146, 570.9991483524263)\n", "100.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (2, -1, 0, 0))\n", "(-30.95585251296106, 284.68543448759146, 670.9991483524263)\n", "-100.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (-1, 1, 0, 0))\n", "(-1730.955852512961, -1415.3145655124085, -917.2695663777957)\n", "1700.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(-1813.359564647021, -1315.3145655124085, -817.2695663777957)\n", "-100.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (4, -2, 0, 0))\n", "(-1401.6282793772432, -1015.3145655124085, -517.2695663777957)\n", "-300.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (0, -1, 1, 0))\n", "(-1.6282793772431887, 384.68543448759146, 496.4167197573694)\n", "-1400.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(-1201.6282793772432, -815.3145655124085, -113.35956464702076)\n", "1200.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-3, 1, 1, 0))\n", "(-701.6282793772432, -315.31456551240854, 0.32672148814447155)\n", "-500.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-1, 1, 0, 0))\n", "(-101.62827937724319, 284.68543448759146, 396.4167197573695)\n", "-600.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(-1.6282793772431887, 110.10300589253438, 496.4167197573695)\n", "-100.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (2, -1, 0, 0))\n", "(-776.2107079723003, -389.8969941074656, -3.583280242630508)\n", "500.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-4, 0, 2, 0))\n", "(-76.21070797230027, 310.1030058925344, 421.8342911623123)\n", "-700.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(-291.851994972853, 410.1030058925344, 521.8342911623123)\n", "-100.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (3, 0, -1, 0))\n", "(-91.85199497285299, 335.52057729747736, 721.8342911623123)\n", "-200.0\n", "((0, 0, 0, 0), (5, 0, -2, 0), (3, 0, -1, 0))\n", "(-1991.851994972853, -1289.8969941074656, -1178.1657088376878)\n", "1900.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (3, 0, -1, 0))\n", "(-1791.851994972853, -1089.8969941074656, -703.583280242631)\n", "-200.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (-3, 1, 1, 0))\n", "(-891.8519949728529, -189.89699410746562, 41.27709942340914)\n", "-900.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (2, 1, 0, -1))\n", "(-791.8519949728529, -89.89699410746562, 21.834291162312184)\n", "-100.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (3, 0, -1, 0))\n", "(-591.8519949728529, -276.21070797230016, 221.83429116231218)\n", "-200.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(-691.8519949728529, -376.21070797230016, 10.10300589253427)\n", "100.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (-1, 1, 0, 0))\n", "(-1491.851994972853, -1176.2107079723, -678.1657088376878)\n", "800.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(-891.8519949728529, -505.53828110801805, -78.16570883768782)\n", "-600.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (3, 0, -1, 0))\n", "(-1591.851994972853, -1205.538281108018, -503.58328024263096)\n", "700.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-3, 1, 1, 0))\n", "(-817.2695663777959, -705.538281108018, -3.5832802426309627)\n", "-500.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (3, 0, -1, 0))\n", "(-1017.2695663777959, -630.955852512961, -203.58328024263096)\n", "200.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (3, 0, -1, 0))\n", "(-1717.2695663777959, -1330.955852512961, -629.0008516475741)\n", "700.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-3, 1, 1, 0))\n", "(-1817.2695663777959, -1115.3145655124083, -729.0008516475741)\n", "100.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (-3, 1, 1, 0))\n", "(-1113.359564647021, -615.3145655124083, -229.0008516475741)\n", "-500.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (0, -1, 1, 0))\n", "(-513.359564647021, -15.314565512408308, 215.8595280184661)\n", "-600.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (5, -1, 0, -1))\n", "(-652.9663784506586, 84.68543448759169, 315.8595280184661)\n", "-100.0\n", "((0, 0, 0, 0), (-5, 0, 0, 2), (-2, 0, 0, 1))\n", "(-1052.9663784506586, -786.095472846921, -84.14047198153389)\n", "400.0\n", "((0, 0, 0, 0), (-1, -1, 0, 1), (-2, 0, 0, 1))\n", "(-697.8267581166988, -586.095472846921, 115.85952801846611)\n", "-200.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (3, 0, -1, 0))\n", "(-797.8267581166988, -566.6526645858237, 15.859528018466108)\n", "100.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (3, 0, -1, 0))\n", "(-697.8267581166988, -466.6526645858237, 4.128242748688194)\n", "-100.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (-1, 1, 0, 0))\n", "(-397.8267581166988, -166.6526645858237, -11.513044251864414)\n", "-300.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (-2, 0, 1, 0))\n", "(-1097.8267581166988, -866.6526645858237, -52.96637845065902)\n", "700.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (6, 0, -1, -1))\n", "(-1221.7922849197837, -1066.6526645858237, -252.96637845065902)\n", "200.0\n", "((0, 0, 0, 0), (-5, 0, 1, 1), (-2, 0, 0, 1))\n", "(-1121.7922849197837, -854.9213793160461, -152.96637845065902)\n", "-100.0\n", "((0, 0, 0, 0), (-1, -1, 0, 1), (-2, 0, 0, 1))\n", "(-1021.7922849197837, -790.6181913889084, -52.96637845065902)\n", "-100.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (-2, 0, 0, 1))\n", "(-1221.7922849197837, -990.6181913889084, -176.9319052537437)\n", "200.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (6, 0, -1, -1))\n", "(-1245.7578117228686, -1090.6181913889084, -276.9319052537437)\n", "100.0\n", "((0, 0, 0, 0), (-5, 0, 1, 1), (-2, 0, 0, 1))\n", "(-1421.7922849197837, -1190.6181913889084, -376.9319052537437)\n", "100.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (6, 0, -1, -1))\n", "(-1121.7922849197837, -308.105998784618, -76.93190525374371)\n", "-300.0\n", "((0, 0, 0, 0), (3, 0, -1, 0), (6, 0, -1, -1))\n", "(-1210.060999650006, -508.105998784618, -276.9319052537437)\n", "200.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (2, 1, 0, -1))\n", "(-710.0609996500059, -8.10599878461801, 103.62528648515934)\n", "-500.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (3, 0, -1, 0))\n", "(-1410.060999650006, -708.105998784618, -321.7922849197838)\n", "700.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (-3, 1, 1, 0))\n", "(-510.0609996500059, 191.894001215382, 303.62528648515934)\n", "-900.0\n", "((0, 0, 0, 0), (-1, 1, 0, 0), (3, 0, -1, 0))\n", "(-610.0609996500059, -498.32971438022764, 203.62528648515934)\n", "100.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (3, 0, -1, 0))\n", "(-1210.060999650006, -823.7472857851706, -396.37471351484066)\n", "600.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (3, 0, -1, 0))\n", "(-410.0609996500059, -23.74728578517056, 87.98399948460644)\n", "-800.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(-310.0609996500059, -43.19009404626809, 187.98399948460644)\n", "-100.0\n", "((0, 0, 0, 0), (-1, -1, 0, 1), (2, -1, 0, 0))\n", "(-241.23509318088088, 256.8099059537319, 487.98399948460644)\n", "-300.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (5, -1, 0, -1))\n", "(-1241.235093180881, -743.1900940462681, -245.14509491165597)\n", "1000.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (4, -2, 0, 0))\n", "(-1229.5038079111032, -843.1900940462681, -345.145094911656)\n", "100.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (0, -1, 1, 0))\n", "(-1429.5038079111032, -1043.190094046268, -341.2350931808811)\n", "200.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-3, 1, 1, 0))\n", "(-1174.3641875771434, -943.1900940462681, -241.2350931808811)\n", "-100.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (2, 1, 0, -1))\n", "(-674.3641875771434, -443.1900940462681, 27.59081328824402)\n", "-500.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (-1, 1, 0, 0))\n", "(-474.3641875771434, -243.1900940462681, 23.680811557469042)\n", "-200.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (2, -1, 0, 0))\n", "(-1274.3641875771434, -1043.190094046268, -229.5038079111032)\n", "800.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (6, 0, -1, -1))\n", "(-1298.3297143802283, -1143.190094046268, -329.5038079111032)\n", "100.0\n", "((0, 0, 0, 0), (-5, 0, 1, 1), (-2, 0, 0, 1))\n", "(-98.32971438022832, 56.80990595373191, 287.9839994846068)\n", "-1200.0\n", "((0, 0, 0, 0), (-5, 0, 1, 1), (-2, 0, 1, 0))\n", "(-898.3297143802283, -743.1900940462681, 70.4961920888968)\n", "800.0\n", "((0, 0, 0, 0), (-5, 0, 1, 1), (-2, 0, 0, 1))\n", "(101.67028561977168, 256.8099059537319, 487.9839994846068)\n", "-1000.0\n", "((0, 0, 0, 0), (-5, 0, 1, 1), (-2, 0, 1, 0))\n", "(-756.8763801814338, 56.80990595373191, 287.9839994846068)\n", "200.0\n", "((0, 0, 0, 0), (3, 0, -1, 0), (6, 0, -1, -1))\n", "(-1710.0609996500057, -1443.190094046268, -1212.0160005153932)\n", "1500.0\n", "((0, 0, 0, 0), (-1, -1, 0, 1), (2, -1, 0, 0))\n", "(-541.2350931808805, -43.19009404626809, 187.98399948460678)\n", "-1400.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (5, -1, 0, -1))\n", "(-1741.2350931808805, -1243.190094046268, -745.1450949116556)\n", "1200.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (4, -2, 0, 0))\n", "(-1347.100095777043, -1143.190094046268, -645.1450949116556)\n", "-100.0\n", "((0, 0, 0, 0), (-3, 2, 0, 0), (-1, 1, 0, 0))\n", "(-241.23509318088054, 256.8099059537319, 754.8549050883444)\n", "-1400.0\n", "((0, 0, 0, 0), (2, -1, 0, 0), (4, -2, 0, 0))\n", "(-1258.8313810468205, -943.1900940462681, -445.14509491165563)\n", "1200.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(-758.8313810468205, -372.5176671819861, 54.85490508834437)\n", "-500.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (3, 0, -1, 0))\n", "(-858.8313810468205, -472.5176671819861, 25.527331952626355)\n", "100.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (0, -1, 1, 0))\n", "(-1458.8313810468205, -1072.517667181986, -370.5626663165988)\n", "600.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-3, 1, 1, 0))\n", "(-1139.3885727857232, -872.5176671819861, -170.56266631659878)\n", "-200.0\n", "((0, 0, 0, 0), (-1, -1, 0, 1), (-2, 0, 0, 1))\n", "(-239.38857278572323, 27.4823328180139, 258.6564263488888)\n", "-900.0\n", "((0, 0, 0, 0), (-1, -1, 0, 1), (2, -1, 0, 0))\n", "(296.30823928713926, 527.4823328180139, 758.6564263488888)\n", "-500.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (6, 0, 0, -2))\n", "(-903.6917607128607, -672.5176671819861, 29.437333683400993)\n", "1200.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (2, 1, 0, -1))\n", "(396.30823928713926, 627.4823328180139, 782.6219531519735)\n", "-1300.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (-2, 0, 1, 0))\n", "(-803.6917607128607, -572.5176671819861, 9.994525422303923)\n", "1200.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (3, 0, -1, 0))\n", "(-403.69176071286074, -172.5176671819861, -17.3780468480266)\n", "-400.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (-2, 0, 1, 0))\n", "(-1103.6917607128607, -872.5176671819861, -58.83138104682121)\n", "700.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (6, 0, -1, -1))\n", "(296.30823928713926, 527.4823328180139, 682.6219531519735)\n", "-1400.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (-2, 0, 1, 0))\n", "(-103.69176071286074, 51.4478596210987, 282.62195315197346)\n", "400.0\n", "((0, 0, 0, 0), (-5, 0, 1, 1), (-2, 0, 1, 0))\n", "(-219.33304771341363, 251.4478596210987, 482.62195315197346)\n", "-200.0\n", "((0, 0, 0, 0), (-4, 1, 0, 1), (-1, 1, 0, 0))\n", "(-1519.3330477134136, -1048.5521403789012, -550.5071412442891)\n", "1300.0\n", "((0, 0, 0, 0), (-4, 1, 0, 1), (-2, 0, 0, 1))\n", "(-719.3330477134136, -248.55214037890119, -17.378046848026543)\n", "-800.0\n", "((0, 0, 0, 0), (-4, 1, 0, 1), (-1, 1, 0, 0))\n", "(-819.3330477134136, -503.6917607128607, -117.37804684802654)\n", "100.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (-1, 1, 0, 0))\n", "(-1519.3330477134136, -1203.6917607128607, -705.6467615782486)\n", "700.0\n", "((0, 0, 0, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(-1419.3330477134136, -1033.0193338485788, -605.6467615782486)\n", "-100.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (3, 0, -1, 0))\n", "(-719.3330477134136, -333.01933384857875, -17.378046848026543)\n", "-700.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-1, 1, 0, 0))\n", "(-1519.3330477134136, -1133.0193338485788, -431.0643329831918)\n", "800.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (-3, 1, 1, 0))\n", "(-919.3330477134136, -533.0193338485788, -34.97433471396664)\n", "-600.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (0, -1, 1, 0))\n", "(-819.3330477134136, -433.01933384857875, -5.646761578248629)\n", "-100.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (3, 0, -1, 0))\n", "(-119.33304771341363, 266.98066615142125, 378.7119514211985)\n", "-700.0\n", "((0, 0, 0, 0), (-2, 0, 1, 0), (2, -1, 0, 0))\n", "(-319.33304771341363, -88.1589541825386, 178.71195142119848)\n", "200.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (2, -1, 0, 0))\n", "(-419.33304771341363, -188.1589541825386, -33.01933384857915)\n", "100.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (-2, 0, 1, 0))\n", "(-719.3330477134136, -488.1589541825386, -17.378046848026543)\n", "300.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (-1, 1, 0, 0))\n", "(-519.3330477134136, -288.1589541825386, -21.288048578801522)\n", "-200.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (2, -1, 0, 0))\n", "(-219.33304771341363, 11.841045817461406, 166.98066615142085)\n", "-300.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (-2, 0, 1, 0))\n", "(-619.3330477134136, -388.1589541825386, -1.845240317704338)\n", "400.0\n", "((0, 0, 0, 0), (3, 0, 0, -1), (1, 0, 1, -1))\n", "(-499.8902394523164, -388.1589541825386, -1.845240317704338)\n", "0.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (2, -1, 0, 0))\n", "(-699.8902394523163, -588.1589541825385, 113.79604668284856)\n", "200.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (3, 0, -1, 0))\n", "(-599.8902394523163, -488.15895418253854, -101.84524031770434)\n", "-100.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (2, -1, 0, 0))\n", "(-699.8902394523163, -588.1589541825385, 113.79604668284856)\n", "100.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (3, 0, -1, 0))\n", "(-599.8902394523163, -488.15895418253854, -101.84524031770434)\n", "-100.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (2, -1, 0, 0))\n", "(-699.8902394523163, -588.1589541825385, 113.79604668284856)\n", "100.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (3, 0, -1, 0))\n", "(-599.8902394523163, -488.15895418253854, -101.84524031770434)\n", "-100.0\n", "((0, 0, 0, 0), (4, -1, -1, 0), (2, -1, 0, 0))\n", "(-574.4726680473734, -188.15895418253854, 198.15475968229566)\n", "-300.0\n", "(1.525, 0.425, 1.225, 0.65, 0.375, 0.65, 0.175, 0.925, 0.4, 0.4, 0.7, 0.25, 0.625, 0.1, 1.175, 0.475, 0.1, 0.225, 0.625, 0.525, 0.2, 0.625, 0.05, 0.175, 0.65, 1.0, 0.075, 0.075, 1.2, 0.525, 0.3, 0.075, 1.225, 0.325, 0.3, 0.15, 0.075, 0.525, 0.225, 2.275, 0.125, 0.025, 0.225, 0.025, 0.125, 0.25, 0.25, 0.8, 0.125, 0.325, 0.275, 0.375, 0.425, 0.125, 1.1, 0.375, 0.05, 0.1, 0.4, 1.15, 0.15, 0.1, 0.075, 0.75, 0.575, 0.05, 0.325, 0.9, 0.375, 0.575, 0.05, 0.125, 0.075, 0.125, 0.4, 0.275, 0.125, 0.525, 0.65, 0.975, 0.725, 0.275, 0.175, 1.65, 0.7, 0.1, 0.05, 0.225, 0.4, 0.375, 0.325, 0.2, 0.225, 0.425, 2.05, 0.025, 0.125, 0.075, 0.45, 0.075, 0.225, 0.075, 0.35, 0.15, 0.3, 0.175, 0.1, 0.525, 0.55, 0.325, 0.375, 0.075, 0.5, 0.525, 0.7, 0.3, 0.05, 0.55, 0.65, 0.675, 0.25, 0.7, 0.85, 0.9, 1.15, 0.25, 0.025, 0.1, 0.475, 0.125, 1.0, 0.35, 0.075, 0.725, 0.3, 0.2, 0.1, 0.25, 0.2, 0.975, 0.55, 0.025, 0.225, 0.425, 0.525, 1.45, 0.025, 0.175, 0.275, 0.025, 0.35, 0.4, 0.4, 0.075, 0.7, 0.35, 0.1, 0.4, 0.175, 0.275, 1.425, 0.775, 0.475, 0.85, 1.375, 0.25, 0.55, 0.075, 1.425, 0.325, 0.525, 0.3, 0.825, 0.525, 0.15, 0.075, 0.375, 0.125, 0.05, 0.3, 0.675, 1.4, 0.9, 0.475, 0.425, 0.475, 0.275, 1.175, 0.3, 0.45, 1.375, 0.225, 0.25, 0.1, 0.05, 0.15, 0.6, 0.225, 0.55, 0.45, 0.275, 0.15, 0.05, 1.45, 0.225, 0.225, 0.75, 0.25, 0.55, 0.525, 0.925, 1.4, 0.725, 0.8, 0.775)\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", "print(durs)\n", "write_chord_sequence(list(zip(durs, path_to_chords(path, root))))" ] }, { "cell_type": "code", "execution_count": 381, "id": "57c834bf-fee7-4ef4-b648-2173099fbb56", "metadata": {}, "outputs": [], "source": [ "from random import choice, choices\n", "\n", "def hd_sum(chord):\n", " distances = []\n", " size = len(chord)\n", " for i in range(size):\n", " for j in range(i+1, size):\n", " distances += [sum([abs(dist) * log(dims[idx], 2) for idx, dist in enumerate(pitch_difference(chord[i], chord[j]))])]\n", " return sum(distances)\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", " #if tuple(new_chord) != chord and max(new_pitch_up[1:]) <= 1 and min(new_pitch_up[1:]) >= 0 and sum(new_pitch_up[1:]) <= 2:\n", " if tuple(new_chord) != chord:\n", " yield tuple(new_chord)\n", " new_chord[sdx] = tuple(new_pitch_down)\n", " if tuple(new_chord) != chord:\n", " #if tuple(new_chord) != chord and max(new_pitch_down[1:]) <= 1 and min(new_pitch_down[1:]) >= 0 and sum(new_pitch_up[1:]) <= 2:\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([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 10 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 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", " s_chord = sorted(e[1], key=hs_array_to_fr)\n", " yield 5 if hs_array_to_fr(sorted(e[1], key=hs_array_to_fr)[0]) >= 0.25 else 0\n", "\n", " def hd_weight(edges):\n", " for e in edges:\n", " yield 2 * (1/pow(hd_sum(e[1]), 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 favor_bass(edges, ins):\n", "\n", " def ins_check(edge, ins):\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", " if ins == 2:\n", " return 1\n", " elif ins == 1 and ordered_source[0] != ordered_destination[0]:\n", " return 1\n", " else:\n", " return 0\n", "\n", " for e in edges:\n", " yield ins_check(e, ins)\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 == voice):\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", " target = target_melody_data[len(path)+1][-1]\n", " ins = target_melody_data[len(path)+1][-2]\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, c_devs, ins),\n", " #symdiff_weights(out_edges),\n", " hd_weight(out_edges),\n", " #favor_bass(out_edges, ins),\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)][-2])\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": 382, "id": "8912c650-a43d-4539-ae24-b5acf9bc543d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(-1044.8603796660402, -231.17409353087487, 0)\n", "((0, 0, 0, 0), (3, 0, -1, 0), (6, 0, -1, -1))\n", "(-1244.8603796660402, -431.17409353087487, -44.86037966604022)\n", "2\n", "200.0\n", "((0, 0, 0, 0), (3, 0, -1, 0), (1, 0, 0, 0))\n", "(-1044.8603796660402, -231.17409353087487, 0.0)\n", "2\n", "-200.0\n", "((0, 0, 0, 0), (3, 0, -1, 0), (6, 0, -1, -1))\n", "(-544.8603796660402, 1.955000865387774, 500.0)\n", "1\n", "-500.0\n", "((0, 0, 0, 0), (4, 1, -1, -1), (6, 0, -1, -1))\n", "(-344.8603796660402, -1.9550008653875466, 700.0)\n", "1\n", "-200.0\n", "((0, 0, 0, 0), (7, -1, -1, -1), (6, 0, -1, -1))\n", "(-844.8603796660402, -501.95500086538755, -3.910001730774866)\n", "2\n", "500.0\n", "((0, 0, 0, 0), (7, -1, -1, -1), (9, -2, -1, -1))\n", "(-744.8603796660402, -401.95500086538755, -15.641287000552666)\n", "2\n", "-100.0\n", "((0, 0, 0, 0), (7, -1, -1, -1), (5, -1, 0, -1))\n", "(-17.5962878659401, 298.04499913461245, 684.3587129994473)\n", "0\n", "-700.0\n", "((6, -2, 0, -1), (7, -1, -1, -1), (5, -1, 0, -1))\n", "(-2.842170943040401e-14, 498.04499913461245, 884.3587129994473)\n", "0\n", "-200.0\n", "((5, 0, -1, -1), (7, -1, -1, -1), (5, -1, 0, -1))\n", "(-1000.0, -501.95500086538755, -31.17409353087487)\n", "2\n", "1000.0\n", "((5, 0, -1, -1), (7, -1, -1, -1), (3, 0, -1, 0))\n", "(-300.0, -33.12909439626242, 668.8259064691251)\n", "1\n", "-700.0\n", "((5, 0, -1, -1), (4, -1, -1, 0), (3, 0, -1, 0))\n", "(-1200.0, -933.1290943962624, 35.696812072862485)\n", "2\n", "900.0\n", "((5, 0, -1, -1), (4, -1, -1, 0), (2, -1, -1, 1))\n", "(-200.0, 31.174093530874984, 1035.6968120728625)\n", "1\n", "-1000.0\n", "((5, 0, -1, -1), (8, 0, -1, -2), (2, -1, -1, 1))\n", "(-1300.0, -801.9550008653874, -64.30318792713751)\n", "2\n", "1100.0\n", "((5, 0, -1, -1), (7, -1, -1, -1), (2, -1, -1, 1))\n", "(-1200.0, -498.0449991346121, 35.696812072862485)\n", "2\n", "-100.0\n", "((5, 0, -1, -1), (4, 1, -1, -1), (2, -1, -1, 1))\n", "(-300.0, -33.12909439626242, 935.6968120728625)\n", "1\n", "-900.0\n", "((5, 0, -1, -1), (4, -1, -1, 0), (2, -1, -1, 1))\n", "(-1000.0, -733.1290943962624, -31.17409353087487)\n", "2\n", "700.0\n", "((5, 0, -1, -1), (4, -1, -1, 0), (3, 0, -1, 0))\n", "(-1629.2190926654873, -633.1290943962624, 68.82590646912513)\n", "2\n", "-100.0\n", "((0, 1, -1, 0), (4, -1, -1, 0), (3, 0, -1, 0))\n", "(-31.17409353087487, 466.8709056037376, 1168.8259064691251)\n", "0\n", "-1100.0\n", "((2, 0, -1, 0), (4, -1, -1, 0), (3, 0, -1, 0))\n", "(-731.1740935308749, -29.219092665487324, 468.82590646912513)\n", "1\n", "700.0\n", "((2, 0, -1, 0), (1, 1, -1, 0), (3, 0, -1, 0))\n", "(68.82590646912513, 770.7809073345127, 1970.7809073345127)\n", "0\n", "-800.0\n", "((2, 0, -1, 0), (1, 1, -1, 0), (2, 1, -1, 0))\n", "(-1431.1740935308749, -729.2190926654873, 0.0)\n", "2\n", "1500.0\n", "((2, 0, -1, 0), (1, 1, -1, 0), (6, 0, -1, -1))\n", "(-831.1740935308749, -17.48780739570975, 600.0)\n", "1\n", "-600.0\n", "((2, 0, -1, 0), (5, 0, -2, 0), (6, 0, -1, -1))\n", "(-731.1740935308749, -29.219092665487267, 700.0)\n", "1\n", "-100.0\n", "((2, 0, -1, 0), (1, 1, -1, 0), (6, 0, -1, -1))\n", "(-1631.1740935308749, -929.2190926654873, 39.606813803637806)\n", "2\n", "900.0\n", "((2, 0, -1, 0), (1, 1, -1, 0), (-1, 1, -1, 1))\n", "(-1431.1740935308749, -729.2190926654873, 0.0)\n", "2\n", "-200.0\n", "((2, 0, -1, 0), (1, 1, -1, 0), (6, 0, -1, -1))\n", "(-531.1740935308749, -33.12909439626242, 900.0)\n", "1\n", "-900.0\n", "((2, 0, -1, 0), (4, -1, -1, 0), (6, 0, -1, -1))\n", "(-431.17409353087487, 31.17409353087494, 1000.0)\n", "1\n", "-100.0\n", "((2, 0, -1, 0), (8, 0, -1, -2), (6, 0, -1, -1))\n", "(-31.17409353087487, 431.1740935308749, 2129.2190926654876)\n", "0\n", "-400.0\n", "((2, 0, -1, 0), (8, 0, -1, -2), (11, -1, -1, -2))\n", "(-1531.1740935308749, -1068.8259064691251, 55.139620333959556)\n", "2\n", "1500.0\n", "((2, 0, -1, 0), (8, 0, -1, -2), (1, 0, 0, 0))\n", "(-1131.1740935308749, -668.8259064691251, 33.12909439626253)\n", "2\n", "-400.0\n", "((2, 0, -1, 0), (8, 0, -1, -2), (7, 1, -1, -2))\n", "(-731.1740935308749, -29.219092665487324, 433.12909439626253)\n", "1\n", "-400.0\n", "((2, 0, -1, 0), (1, 1, -1, 0), (7, 1, -1, -2))\n", "(-27.264091800100005, 470.7809073345127, 933.1290943962625)\n", "0\n", "-500.0\n", "((-1, 2, -1, 0), (1, 1, -1, 0), (7, 1, -1, -2))\n", "(-727.2640918001, 1.955000865387774, 233.12909439626253)\n", "1\n", "700.0\n", "((-1, 2, -1, 0), (4, 1, -1, -1), (7, 1, -1, -2))\n", "(-1427.2640918001, -698.0449991346122, 3.910001730774411)\n", "2\n", "700.0\n", "((-1, 2, -1, 0), (4, 1, -1, -1), (3, 2, -1, -1))\n", "(103.91000173077487, 601.9550008653878, 1303.9100017307744)\n", "0\n", "-1300.0\n", "((2, 2, -1, -1), (4, 1, -1, -1), (3, 2, -1, -1))\n", "(1.7053025658242404e-13, 701.9550008653878, 1403.9100017307744)\n", "0\n", "-100.0\n", "((5, 0, -1, -1), (4, 1, -1, -1), (3, 2, -1, -1))\n", "(-499.99999999999983, -1.9550008653875466, 903.9100017307744)\n", "1\n", "500.0\n", "((5, 0, -1, -1), (7, -1, -1, -1), (3, 2, -1, -1))\n", "(-1199.9999999999998, -701.9550008653875, -2.2737367544323206e-13)\n", "2\n", "700.0\n", "((5, 0, -1, -1), (7, -1, -1, -1), (6, 0, -1, -1))\n", "(-999.9999999999998, -501.95500086538755, -3.910001730775093)\n", "2\n", "-200.0\n", "((5, 0, -1, -1), (7, -1, -1, -1), (9, -2, -1, -1))\n", "(-599.9999999999998, 9.776284404390367, 396.0899982692249)\n", "1\n", "-400.0\n", "((5, 0, -1, -1), (11, -2, -2, -1), (9, -2, -1, -1))\n", "(-1299.9999999999998, -690.2237155956096, 11.731285269777572)\n", "2\n", "700.0\n", "((5, 0, -1, -1), (11, -2, -2, -1), (10, -1, -2, -1))\n", "(-1399.9999999999998, -790.2237155956096, 23.462570539555372)\n", "2\n", "100.0\n", "((5, 0, -1, -1), (11, -2, -2, -1), (14, -2, -3, -1))\n", "(-3.9100017307746384, 809.7762844043904, 1623.4625705395554)\n", "0\n", "-1600.0\n", "((8, -2, -1, -1), (11, -2, -2, -1), (14, -2, -3, -1))\n", "(-1503.9100017307746, -690.2237155956096, 11.731285269777572)\n", "2\n", "1500.0\n", "((8, -2, -1, -1), (11, -2, -2, -1), (10, -1, -2, -1))\n", "(25.41757140494292, 909.7762844043904, 1611.7312852697776)\n", "0\n", "-1600.0\n", "((11, -1, -3, -1), (11, -2, -2, -1), (10, -1, -2, -1))\n", "(-474.5824285950571, 23.462570539555486, 1111.7312852697776)\n", "1\n", "500.0\n", "((11, -1, -3, -1), (13, -2, -3, -1), (10, -1, -2, -1))\n", "(-1474.582428595057, -976.5374294604445, -7.711522991319725)\n", "2\n", "1000.0\n", "((11, -1, -3, -1), (13, -2, -3, -1), (11, -2, -3, 0))\n", "(-1574.582428595057, -1076.5374294604444, 11.731285269777572)\n", "2\n", "100.0\n", "((11, -1, -3, -1), (13, -2, -3, -1), (10, -1, -2, -1))\n", "(-1474.582428595057, -976.5374294604444, -7.711522991319725)\n", "2\n", "-100.0\n", "((11, -1, -3, -1), (13, -2, -3, -1), (11, -2, -3, 0))\n", "(-1274.582428595057, -776.5374294604444, 37.148856674720605)\n", "2\n", "-200.0\n", "((11, -1, -3, -1), (13, -2, -3, -1), (16, -2, -4, -1))\n", "(-1174.582428595057, -676.5374294604444, 25.417571404942578)\n", "2\n", "-100.0\n", "((11, -1, -3, -1), (13, -2, -3, -1), (12, -1, -3, -1))\n", "(-974.5824285950571, -476.5374294604444, -5.7565221259322925)\n", "2\n", "-200.0\n", "((11, -1, -3, -1), (13, -2, -3, -1), (9, -1, -3, 0))\n", "(-974.5824285950571, -160.89614245989185, -5.7565221259322925)\n", "1\n", "0.0\n", "((11, -1, -3, -1), (14, -1, -4, -1), (9, -1, -3, 0))\n", "(-7.711522991319498, 539.1038575401082, 694.2434778740677)\n", "0\n", "-700.0\n", "((10, -2, -3, 0), (14, -1, -4, -1), (9, -1, -3, 0))\n", "(-458.9411415945043, 39.10385754010815, 194.2434778740677)\n", "1\n", "500.0\n", "((12, 0, -4, -1), (14, -1, -4, -1), (9, -1, -3, 0))\n", "(-258.9411415945043, 7.92976400923331, 394.2434778740677)\n", "1\n", "-200.0\n", "((12, 0, -4, -1), (11, -1, -4, 0), (9, -1, -3, 0))\n", "(-1158.9411415945042, -892.0702359907667, -78.38394985560194)\n", "2\n", "900.0\n", "((12, 0, -4, -1), (11, -1, -4, 0), (14, -1, -5, 0))\n", "(-1258.9411415945042, -992.0702359907667, -23.244329521642157)\n", "2\n", "100.0\n", "((12, 0, -4, -1), (11, -1, -4, 0), (9, -1, -4, 1))\n", "(-123.2443295216417, 107.92976400923328, 1076.7556704783578)\n", "0\n", "-1100.0\n", "((8, -1, -4, 1), (11, -1, -4, 0), (9, -1, -4, 1))\n", "(-1423.2443295216417, -1192.0702359907668, 7.92976400923294)\n", "2\n", "1300.0\n", "((8, -1, -4, 1), (11, -1, -4, 0), (12, -1, -4, 0))\n", "(-1623.2443295216417, -1392.0702359907668, -36.93061565680728)\n", "2\n", "200.0\n", "((8, -1, -4, 1), (11, -1, -4, 0), (7, -1, -3, 1))\n", "(-1723.2443295216417, -1492.0702359907668, -25.199330387029477)\n", "2\n", "100.0\n", "((8, -1, -4, 1), (11, -1, -4, 0), (11, -2, -4, 1))\n", "(76.7556704783583, 307.92976400923317, 1663.0693843431927)\n", "0\n", "-1800.0\n", "((8, -1, -4, 1), (11, -1, -4, 0), (7, -1, -3, 1))\n", "(-1323.2443295216417, -1092.0702359907668, -123.24432952164216)\n", "2\n", "1400.0\n", "((8, -1, -4, 1), (11, -1, -4, 0), (9, -1, -4, 1))\n", "(-523.2443295216417, -25.19933038702925, 676.7556704783578)\n", "1\n", "-800.0\n", "((8, -1, -4, 1), (10, -2, -4, 1), (9, -1, -4, 1))\n", "(-623.2443295216417, 78.71067134374539, 576.7556704783578)\n", "1\n", "100.0\n", "((8, -1, -4, 1), (7, 0, -4, 1), (9, -1, -4, 1))\n", "(-523.2443295216417, -25.19933038702925, 676.7556704783578)\n", "1\n", "-100.0\n", "((8, -1, -4, 1), (10, -2, -4, 1), (9, -1, -4, 1))\n", "(-423.2443295216417, -36.93061565680733, 776.7556704783578)\n", "1\n", "-100.0\n", "((8, -1, -4, 1), (6, -1, -3, 1), (9, -1, -4, 1))\n", "(-1723.2443295216417, -1336.9306156568073, -25.199330387029477)\n", "2\n", "1300.0\n", "((8, -1, -4, 1), (6, -1, -3, 1), (11, -2, -4, 1))\n", "(-1523.2443295216417, -1136.9306156568073, 63.06938434319272)\n", "2\n", "-200.0\n", "((8, -1, -4, 1), (6, -1, -3, 1), (7, -1, -3, 1))\n", "(-1423.2443295216417, -1036.9306156568073, 7.92976400923294)\n", "2\n", "-100.0\n", "((8, -1, -4, 1), (6, -1, -3, 1), (12, -1, -4, 0))\n", "(-523.2443295216417, -25.19933038702925, 907.9297640092329)\n", "1\n", "-900.0\n", "((8, -1, -4, 1), (10, -2, -4, 1), (12, -1, -4, 0))\n", "(-1123.2443295216417, -625.1993303870292, 76.75567047835784)\n", "2\n", "600.0\n", "((8, -1, -4, 1), (10, -2, -4, 1), (9, -1, -4, 1))\n", "(-423.2443295216417, -36.93061565680728, 776.7556704783578)\n", "1\n", "-700.0\n", "((8, -1, -4, 1), (6, -1, -3, 1), (9, -1, -4, 1))\n", "(-223.2443295216417, 7.929764009233253, 976.7556704783578)\n", "1\n", "-200.0\n", "((8, -1, -4, 1), (11, -1, -4, 0), (9, -1, -4, 1))\n", "(-23.244329521641703, 474.80066961297086, 1176.7556704783578)\n", "0\n", "-200.0\n", "((8, -1, -4, 1), (10, -2, -4, 1), (9, -1, -4, 1))\n", "(-123.2443295216417, 107.92976400923328, 1076.7556704783578)\n", "1\n", "100.0\n", "((8, -1, -4, 1), (11, -1, -4, 0), (9, -1, -4, 1))\n", "(-736.930615656807, 307.9297640092333, 1276.7556704783578)\n", "1\n", "-200.0\n", "((5, -1, -3, 1), (11, -1, -4, 0), (9, -1, -4, 1))\n", "(-9.558043386476527, 607.9297640092333, 1576.7556704783578)\n", "0\n", "-300.0\n", "((10, -1, -5, 1), (11, -1, -4, 0), (9, -1, -4, 1))\n", "(-1709.5580433864766, -1092.0702359907668, -11.513044251864358)\n", "2\n", "1700.0\n", "((10, -1, -5, 1), (11, -1, -4, 0), (13, -2, -5, 1))\n", "(-1509.5580433864766, -892.0702359907668, 76.75567047835784)\n", "2\n", "-200.0\n", "((10, -1, -5, 1), (11, -1, -4, 0), (9, -1, -4, 1))\n", "(-809.5580433864766, 4.128242748688194, 776.7556704783578)\n", "1\n", "-700.0\n", "((10, -1, -5, 1), (13, -1, -6, 1), (9, -1, -4, 1))\n", "(-909.5580433864766, -25.199330387029306, 676.7556704783578)\n", "1\n", "100.0\n", "((10, -1, -5, 1), (10, -2, -4, 1), (9, -1, -4, 1))\n", "(-11.513044251864017, 374.8006696129707, 1076.7556704783578)\n", "0\n", "-400.0\n", "((12, -2, -5, 1), (10, -2, -4, 1), (9, -1, -4, 1))\n", "(-611.513044251864, -21.28932865625461, 476.75567047835784)\n", "1\n", "600.0\n", "((12, -2, -5, 1), (7, 0, -4, 1), (9, -1, -4, 1))\n", "(-811.513044251864, -221.2893286562546, 2.173241883300534)\n", "2\n", "200.0\n", "((12, -2, -5, 1), (7, 0, -4, 1), (15, -2, -6, 1))\n", "(-811.513044251864, -109.55804338647692, 2.173241883300534)\n", "1\n", "0.0\n", "((12, -2, -5, 1), (11, -1, -5, 1), (15, -2, -6, 1))\n", "(-911.513044251864, -209.55804338647692, 288.48695574813564)\n", "1\n", "100.0\n", "((12, -2, -5, 1), (11, -1, -5, 1), (13, -2, -5, 1))\n", "(-711.513044251864, -9.558043386476925, 102.17324188330053)\n", "2\n", "-200.0\n", "((12, -2, -5, 1), (11, -1, -5, 1), (15, -2, -6, 1))\n", "(33.34733541417609, 890.4419566135231, 1002.1732418833005)\n", "0\n", "-900.0\n", "((17, -2, -6, 0), (11, -1, -5, 1), (15, -2, -6, 1))\n", "(-666.6526645858239, 35.302336279563406, 302.17324188330053)\n", "1\n", "700.0\n", "((17, -2, -6, 0), (16, -1, -6, 0), (15, -2, -6, 1))\n", "(-33.52357018956138, 935.3023362795634, 1202.1732418833005)\n", "0\n", "-900.0\n", "((18, -1, -6, -1), (16, -1, -6, 0), (15, -2, -6, 1))\n", "(-1233.5235701895613, -966.6526645858243, 2.173241883300534)\n", "2\n", "1200.0\n", "((18, -1, -6, -1), (17, -2, -6, 0), (15, -2, -6, 1))\n", "(-1433.5235701895613, -1166.6526645858244, -2.3494766586868536)\n", "2\n", "200.0\n", "((18, -1, -6, -1), (17, -2, -6, 0), (22, -1, -6, -2))\n", "(-1333.5235701895613, -947.2098563247268, 97.65052334131315)\n", "2\n", "-100.0\n", "((18, -1, -6, -1), (16, -1, -5, -1), (22, -1, -6, -2))\n", "(-1333.5235701895613, -133.52357018956184, 97.65052334131315)\n", "1\n", "0.0\n", "((18, -1, -6, -1), (19, -1, -6, -1), (22, -1, -6, -2))\n", "(-1800.3944757932989, -333.52357018956184, -102.34947665868685)\n", "2\n", "200.0\n", "((19, 0, -6, -2), (19, -1, -6, -1), (22, -1, -6, -2))\n", "(-1900.3944757932989, -433.52357018956184, 1.5605250720882395)\n", "2\n", "100.0\n", "((19, 0, -6, -2), (19, -1, -6, -1), (19, 1, -6, -2))\n", "(-1400.3944757932989, 3.5155259374756724, 501.56052507208824)\n", "1\n", "-500.0\n", "((19, 0, -6, -2), (17, 2, -6, -2), (19, 1, -6, -2))\n", "(-1798.4394749279113, 103.51552593747567, 601.5605250720882)\n", "1\n", "-100.0\n", "((17, 1, -6, -2), (17, 2, -6, -2), (19, 1, -6, -2))\n", "(-1498.4394749279113, 87.87423893692312, 901.5605250720882)\n", "1\n", "-300.0\n", "((17, 1, -6, -2), (16, 1, -5, -2), (19, 1, -6, -2))\n", "(-2198.4394749279113, -612.1257610630769, -29.613568458786858)\n", "2\n", "700.0\n", "((17, 1, -6, -2), (16, 1, -5, -2), (16, 1, -6, -1))\n", "(-2598.4394749279113, -1012.1257610630769, 32.73461860296334)\n", "2\n", "400.0\n", "((17, 1, -6, -2), (16, 1, -5, -2), (22, 1, -6, -3))\n", "(-2798.4394749279113, -1212.1257610630769, -12.125761063077107)\n", "2\n", "200.0\n", "((17, 1, -6, -2), (16, 1, -5, -2), (17, 1, -5, -2))\n", "(-1925.8120471982413, -1112.1257610630769, 87.8742389369229)\n", "2\n", "-100.0\n", "((13, 1, -4, -2), (16, 1, -5, -2), (17, 1, -5, -2))\n", "(-10.170760197688878, 487.8742389369231, 1687.874238936923)\n", "0\n", "-1600.0\n", "((14, 2, -5, -2), (16, 1, -5, -2), (17, 1, -5, -2))\n", "(1.5605250720888932, 387.8742389369231, 1587.874238936923)\n", "0\n", "100.0\n", "((18, 1, -6, -2), (16, 1, -5, -2), (17, 1, -5, -2))\n", "(-10.170760197688878, 487.8742389369231, 1687.874238936923)\n", "0\n", "-100.0\n", "((14, 2, -5, -2), (16, 1, -5, -2), (17, 1, -5, -2))\n", "(-1443.299854593951, -1212.1257610630769, -12.125761063077107)\n", "2\n", "1700.0\n", "((13, 1, -5, -1), (16, 1, -5, -2), (17, 1, -5, -2))\n", "(-1610.1707601976889, -1112.1257610630769, 87.8742389369229)\n", "2\n", "-100.0\n", "((14, 2, -5, -2), (16, 1, -5, -2), (17, 1, -5, -2))\n", "(-1310.1707601976889, -812.1257610630769, 1.5605250720882395)\n", "2\n", "-300.0\n", "((14, 2, -5, -2), (16, 1, -5, -2), (19, 1, -6, -2))\n", "(-29.613568458786176, 587.8742389369231, 1401.5605250720882)\n", "0\n", "-1400.0\n", "((15, 1, -6, -1), (16, 1, -5, -2), (19, 1, -6, -2))\n", "(-1229.6135684587862, -612.1257610630769, 89.82923980231044)\n", "2\n", "1200.0\n", "((15, 1, -6, -1), (16, 1, -5, -2), (15, 2, -5, -2))\n", "(-729.6135684587862, -27.658567593399425, 589.8292398023104)\n", "1\n", "-500.0\n", "((15, 1, -6, -1), (14, 2, -6, -1), (15, 2, -5, -2))\n", "(74.29643327198869, 572.3414324066006, 1189.8292398023104)\n", "0\n", "-600.0\n", "((12, 3, -6, -1), (14, 2, -6, -1), (15, 2, -5, -2))\n", "(-29.613568458786148, 672.3414324066006, 1289.8292398023104)\n", "0\n", "-100.0\n", "((15, 1, -6, -1), (14, 2, -6, -1), (15, 2, -5, -2))\n", "(-529.6135684587862, -31.568569324174234, 789.8292398023104)\n", "1\n", "500.0\n", "((15, 1, -6, -1), (17, 0, -6, -1), (15, 2, -5, -2))\n", "(-33.523570189561156, 668.4314306758258, 1489.8292398023104)\n", "0\n", "-700.0\n", "((18, -1, -6, -1), (17, 0, -6, -1), (15, 2, -5, -2))\n", "(3.5155259374763546, 768.4314306758258, 1589.8292398023104)\n", "0\n", "-100.0\n", "((16, 2, -6, -2), (17, 0, -6, -1), (15, 2, -5, -2))\n", "(-0.39447579329879545, 968.4314306758258, 1789.8292398023104)\n", "0\n", "-200.0\n", "((19, 0, -6, -2), (17, 0, -6, -1), (15, 2, -5, -2))\n", "(-1900.3944757932989, -931.5685693241742, 1.5605250720882395)\n", "2\n", "1900.0\n", "((19, 0, -6, -2), (17, 0, -6, -1), (19, 1, -6, -2))\n", "(-1700.3944757932989, -731.5685693241742, -2.3494766586868536)\n", "2\n", "-200.0\n", "((19, 0, -6, -2), (17, 0, -6, -1), (22, -1, -6, -2))\n", "(-800.3944757932989, 13.29181034186604, 897.6505233413131)\n", "1\n", "-900.0\n", "((19, 0, -6, -2), (22, 0, -7, -2), (22, -1, -6, -2))\n", "(-700.3944757932989, 1.5605250720883106, 997.6505233413131)\n", "1\n", "-100.0\n", "((19, 0, -6, -2), (18, 1, -6, -2), (22, -1, -6, -2))\n", "(-29.613568458786233, 201.5605250720883, 1197.6505233413131)\n", "0\n", "-200.0\n", "((15, 1, -6, -1), (18, 1, -6, -2), (22, -1, -6, -2))\n", "(-129.61356845878623, 101.5605250720883, 1456.7001454060483)\n", "0\n", "100.0\n", "((15, 1, -6, -1), (18, 1, -6, -2), (14, 1, -5, -1))\n", "(-929.6135684587862, -698.4394749279118, 3.5155259374755587)\n", "2\n", "800.0\n", "((15, 1, -6, -1), (18, 1, -6, -2), (17, 2, -6, -2))\n", "(-1067.265381397036, -98.43947492791176, 603.5155259374756)\n", "1\n", "-600.0\n", "((20, 1, -6, -3), (18, 1, -6, -2), (17, 2, -6, -2))\n", "(-1767.265381397036, -798.4394749279118, 15.246811207253131)\n", "2\n", "700.0\n", "((20, 1, -6, -3), (18, 1, -6, -2), (21, 1, -7, -2))\n", "(-1267.265381397036, 17.20181207264079, 515.2468112072531)\n", "1\n", "-500.0\n", "((20, 1, -6, -3), (19, 2, -7, -2), (21, 1, -7, -2))\n", "(-1467.265381397036, -182.7981879273592, -36.09128786616145)\n", "2\n", "200.0\n", "((20, 1, -6, -3), (19, 2, -7, -2), (24, 1, -6, -4))\n", "(-2167.265381397036, -882.7981879273592, 1.5605250720882395)\n", "2\n", "700.0\n", "((20, 1, -6, -3), (19, 2, -7, -2), (19, 1, -6, -2))\n", "(-2267.265381397036, -982.7981879273592, -13.97228145823442)\n", "2\n", "100.0\n", "((20, 1, -6, -3), (19, 2, -7, -2), (17, 2, -7, -1))\n", "(-1767.265381397036, -482.7981879273592, 15.246811207253131)\n", "2\n", "-500.0\n", "((20, 1, -6, -3), (19, 2, -7, -2), (21, 1, -7, -2))\n", "(-1398.4394749279113, 117.20181207264079, 615.2468112072531)\n", "1\n", "-600.0\n", "((17, 1, -6, -2), (19, 2, -7, -2), (21, 1, -7, -2))\n", "(-169.11190179219352, 217.2018120726408, 715.2468112072531)\n", "0\n", "-100.0\n", "((21, 2, -8, -2), (19, 2, -7, -2), (21, 1, -7, -2))\n", "(-569.1119017921935, -71.06690265758135, 315.24681120725313)\n", "1\n", "400.0\n", "((21, 2, -8, -2), (23, 1, -8, -2), (21, 1, -7, -2))\n", "(17.201812072641303, 128.93309734241865, 515.2468112072531)\n", "0\n", "-200.0\n", "((19, 2, -7, -2), (23, 1, -8, -2), (21, 1, -7, -2))\n", "(-82.7981879273587, 28.933097342418648, 1460.1071908732938)\n", "0\n", "100.0\n", "((19, 2, -7, -2), (23, 1, -8, -2), (27, 1, -8, -3))\n", "(17.201812072641303, 128.93309734241865, 1715.2468112072534)\n", "1\n", "-100.0\n", "((19, 2, -7, -2), (23, 1, -8, -2), (22, 1, -7, -2))\n", "(1.5605250720887511, 428.93309734241865, 2015.2468112072534)\n", "0\n", "-300.0\n", "((18, 1, -6, -2), (23, 1, -8, -2), (22, 1, -7, -2))\n", "(-698.4394749279113, 3.5155259374755587, 1315.2468112072534)\n", "1\n", "700.0\n", "((18, 1, -6, -2), (17, 2, -6, -2), (22, 1, -7, -2))\n", "(-898.4394749279113, -84.75318879274687, 1115.2468112072534)\n", "1\n", "200.0\n", "((18, 1, -6, -2), (21, 1, -7, -2), (22, 1, -7, -2))\n", "(-482.79818792735875, 15.246811207253131, 1215.2468112072534)\n", "1\n", "-100.0\n", "((19, 2, -7, -2), (21, 1, -7, -2), (22, 1, -7, -2))\n", "(-382.79818792735875, 115.24681120725313, 319.156812938028)\n", "2\n", "-100.0\n", "((19, 2, -7, -2), (21, 1, -7, -2), (18, 3, -7, -2))\n", "(-582.7981879273588, -84.75318879274687, 1115.2468112072534)\n", "1\n", "200.0\n", "((19, 2, -7, -2), (21, 1, -7, -2), (22, 1, -7, -2))\n", "(-682.7981879273588, -184.75318879274687, 19.156812938027997)\n", "2\n", "100.0\n", "((19, 2, -7, -2), (21, 1, -7, -2), (18, 3, -7, -2))\n", "(-782.7981879273588, -284.75318879274687, 30.888098207805797)\n", "2\n", "100.0\n", "((19, 2, -7, -2), (21, 1, -7, -2), (22, 2, -8, -2))\n", "(-798.4394749279113, 15.246811207253131, 330.8880982078058)\n", "1\n", "-300.0\n", "((18, 1, -6, -2), (21, 1, -7, -2), (22, 2, -8, -2))\n", "(-998.4394749279113, -184.75318879274687, -29.613568458786858)\n", "2\n", "200.0\n", "((18, 1, -6, -2), (21, 1, -7, -2), (16, 1, -6, -1))\n", "(-498.4394749279113, -27.65856759339954, 470.38643154121314)\n", "1\n", "-500.0\n", "((18, 1, -6, -2), (14, 2, -6, -1), (16, 1, -6, -1))\n", "(-1198.4394749279113, -727.6585675933995, -25.703566728011992)\n", "2\n", "700.0\n", "((18, 1, -6, -2), (14, 2, -6, -1), (13, 3, -6, -1))\n", "(-298.4394749279113, 60.61014713682266, 874.296433271988)\n", "1\n", "-900.0\n", "((18, 1, -6, -2), (10, 3, -5, -1), (13, 3, -6, -1))\n", "(-194.52947319713678, -39.38985286317734, 774.296433271988)\n", "0\n", "100.0\n", "((15, 3, -6, -2), (10, 3, -5, -1), (13, 3, -6, -1))\n", "(-794.5294731971368, -639.3898528631773, 19.156812938027997)\n", "2\n", "600.0\n", "((15, 3, -6, -2), (10, 3, -5, -1), (18, 3, -7, -2))\n", "(5.470526802863219, 587.9827194071529, 819.156812938028)\n", "0\n", "-800.0\n", "((15, 3, -6, -2), (15, 3, -7, -1), (18, 3, -7, -2))\n", "(-13.972281458233965, 687.9827194071529, 919.156812938028)\n", "0\n", "-100.0\n", "((16, 2, -7, -1), (15, 3, -7, -1), (18, 3, -7, -2))\n", "(19.156812938028622, 987.9827194071529, 1219.156812938028)\n", "0\n", "-300.0\n", "((17, 3, -7, -2), (15, 3, -7, -1), (18, 3, -7, -2))\n", "(-1913.972281458234, -12.0172805928471, 219.156812938028)\n", "2\n", "1000.0\n", "((15, 2, -7, -1), (15, 3, -7, -1), (18, 3, -7, -2))\n", "(-2013.972281458234, -112.0172805928471, -0.28599532306930087)\n", "2\n", "100.0\n", "((15, 2, -7, -1), (15, 3, -7, -1), (19, 2, -8, -1))\n", "(-2213.9722814582337, -312.0172805928471, -45.14637498910929)\n", "2\n", "200.0\n", "((15, 2, -7, -1), (15, 3, -7, -1), (14, 2, -7, 0))\n", "(-2113.9722814582337, -212.0172805928471, 19.156812938027997)\n", "2\n", "-100.0\n", "((15, 2, -7, -1), (15, 3, -7, -1), (18, 3, -7, -2))\n", "(-1613.9722814582337, 21.11181380341543, 519.156812938028)\n", "1\n", "-500.0\n", "((15, 2, -7, -1), (16, 4, -7, -2), (18, 3, -7, -2))\n", "(-1413.9722814582337, 17.20181207264062, 719.156812938028)\n", "1\n", "-200.0\n", "((15, 2, -7, -1), (19, 2, -7, -2), (18, 3, -7, -2))\n", "(-2213.9722814582337, -782.7981879273593, 30.888098207805797)\n", "2\n", "800.0\n", "((15, 2, -7, -1), (19, 2, -7, -2), (22, 2, -8, -2))\n", "(-3437.9378082613184, -882.7981879273593, -69.1119017921942)\n", "2\n", "100.0\n", "((22, 2, -8, -3), (19, 2, -7, -2), (22, 2, -8, -2))\n", "(-1113.9722814582337, 317.2018120726407, 1130.8880982078058)\n", "0\n", "-1200.0\n", "((15, 2, -7, -1), (19, 2, -7, -2), (22, 2, -8, -2))\n", "(-1913.9722814582337, -482.7981879273593, -12.017280592846987)\n", "2\n", "800.0\n", "((15, 2, -7, -1), (19, 2, -7, -2), (15, 3, -7, -1))\n", "(19.156812938028793, 517.2018120726407, 987.982719407153)\n", "0\n", "-1000.0\n", "((17, 3, -7, -2), (19, 2, -7, -2), (15, 3, -7, -1))\n", "(-180.8431870619712, -25.703566728012163, 787.982719407153)\n", "1\n", "200.0\n", "((17, 3, -7, -2), (12, 3, -6, -1), (15, 3, -7, -1))\n", "(-1680.843187061971, -1525.7035667280122, 17.201812072640678)\n", "2\n", "1500.0\n", "((17, 3, -7, -2), (12, 3, -6, -1), (20, 2, -7, -2))\n", "(-280.8431870619711, -13.972281458234647, 1417.2018120726407)\n", "1\n", "-1400.0\n", "((17, 3, -7, -2), (16, 2, -7, -1), (20, 2, -7, -2))\n", "(-1480.843187061971, -1213.9722814582346, -49.66909353109668)\n", "2\n", "1200.0\n", "((17, 3, -7, -2), (16, 2, -7, -1), (21, 3, -7, -3))\n", "(-1815.927282323621, -1113.9722814582346, 50.33090646890332)\n", "2\n", "-100.0\n", "((17, 1, -7, -1), (16, 2, -7, -1), (21, 3, -7, -3))\n", "(-415.92728232362106, 19.156812938027997, 1450.3309064689033)\n", "1\n", "-1400.0\n", "((17, 1, -7, -1), (17, 3, -7, -2), (21, 3, -7, -3))\n", "(-1615.927282323621, -1180.843187061972, -29.613568458786858)\n", "2\n", "1200.0\n", "((17, 1, -7, -1), (17, 3, -7, -2), (16, 1, -6, -1))\n", "(-1115.927282323621, -27.658567593399653, 470.38643154121314)\n", "1\n", "-500.0\n", "((17, 1, -7, -1), (14, 2, -6, -1), (16, 1, -6, -1))\n", "(-1215.927282323621, -15.92728232362208, 370.38643154121314)\n", "1\n", "100.0\n", "((17, 1, -7, -1), (18, 1, -7, -1), (16, 1, -6, -1))\n", "(-1815.927282323621, -615.9272823236221, 86.02771854176558)\n", "2\n", "600.0\n", "((17, 1, -7, -1), (18, 1, -7, -1), (17, 2, -7, -1))\n", "(-1615.927282323621, -415.9272823236221, -29.613568458786858)\n", "2\n", "-200.0\n", "((17, 1, -7, -1), (18, 1, -7, -1), (16, 1, -6, -1))\n", "(-715.9272823236211, -13.972281458234647, 870.3864315412131)\n", "1\n", "-900.0\n", "((17, 1, -7, -1), (16, 2, -7, -1), (16, 1, -6, -1))\n", "(-12.017280592846078, 486.02771854176535, 1370.3864315412131)\n", "0\n", "-500.0\n", "((14, 3, -7, -1), (16, 2, -7, -1), (16, 1, -6, -1))\n", "(-1212.017280592846, -713.9722814582346, -12.017280592846873)\n", "2\n", "1200.0\n", "((14, 3, -7, -1), (16, 2, -7, -1), (15, 3, -7, -1))\n", "(87.98271940715404, 789.9377202725406, 1287.9827194071531)\n", "0\n", "-1300.0\n", "((14, 3, -7, -1), (13, 4, -7, -1), (15, 3, -7, -1))\n", "(-1112.017280592846, -410.06227972745944, -23.748565862624673)\n", "2\n", "1200.0\n", "((14, 3, -7, -1), (13, 4, -7, -1), (11, 4, -6, -1))\n", "(-1054.9226593934989, -10.06227972745944, 376.2514341373753)\n", "1\n", "-400.0\n", "((7, 4, -6, 0), (13, 4, -7, -1), (11, 4, -6, -1))\n", "(-1754.9226593934989, -710.0622797274594, -8.107278862072008)\n", "2\n", "700.0\n", "((7, 4, -6, 0), (13, 4, -7, -1), (12, 5, -7, -1))\n", "(-12.017280592845964, 689.9377202725406, 1391.892721137928)\n", "0\n", "-1400.0\n", "((14, 3, -7, -1), (13, 4, -7, -1), (12, 5, -7, -1))\n", "(-412.01728059284596, 23.06681466880252, 991.892721137928)\n", "1\n", "400.0\n", "((14, 3, -7, -1), (14, 5, -7, -2), (12, 5, -7, -1))\n", "(-8.107278862071155, 223.06681466880252, 1191.892721137928)\n", "0\n", "-200.0\n", "((11, 5, -7, -1), (14, 5, -7, -2), (12, 5, -7, -1))\n", "(-1308.107278862071, -494.420992726907, -108.10727886207201)\n", "2\n", "1300.0\n", "((11, 5, -7, -1), (14, 5, -8, -1), (12, 5, -7, -1))\n", "(-508.1072788620711, -10.062279727459554, 691.892721137928)\n", "1\n", "-800.0\n", "((11, 5, -7, -1), (13, 4, -7, -1), (12, 5, -7, -1))\n", "(-923.7485658626239, -110.06227972745955, 591.892721137928)\n", "1\n", "100.0\n", "((10, 4, -6, -1), (13, 4, -7, -1), (12, 5, -7, -1))\n", "(-1623.7485658626238, -810.0622797274596, 3.6240064077060197)\n", "2\n", "700.0\n", "((10, 4, -6, -1), (13, 4, -7, -1), (16, 4, -8, -1))\n", "(-1523.7485658626238, -710.0622797274596, -8.107278862072008)\n", "2\n", "-100.0\n", "((10, 4, -6, -1), (13, 4, -7, -1), (12, 5, -7, -1))\n", "(-1939.2813723929457, -10.062279727459554, 691.892721137928)\n", "1\n", "-700.0\n", "((7, 5, -7, 0), (13, 4, -7, -1), (12, 5, -7, -1))\n", "(-2739.2813723929457, -810.0622797274596, 3.6240064077060197)\n", "2\n", "800.0\n", "((7, 5, -7, 0), (13, 4, -7, -1), (16, 4, -8, -1))\n", "(-2139.2813723929457, 29.54453407617757, 603.624006407706)\n", "1\n", "-600.0\n", "((7, 5, -7, 0), (6, 5, -7, 1), (16, 4, -8, -1))\n", "(-2039.2813723929457, -25.5950862577821, 703.624006407706)\n", "1\n", "-100.0\n", "((7, 5, -7, 0), (11, 5, -8, 0), (16, 4, -8, -1))\n", "(-182.6897074571275, 674.4049137422179, 1403.624006407706)\n", "0\n", "-700.0\n", "((17, 4, -9, -1), (11, 5, -8, 0), (16, 4, -8, -1))\n", "(-23.640085392392848, 474.4049137422179, 1203.624006407706)\n", "0\n", "200.0\n", "((9, 6, -8, 0), (11, 5, -8, 0), (16, 4, -8, -1))\n", "(-11.908800122615261, 374.4049137422179, 1103.624006407706)\n", "0\n", "100.0\n", "((13, 5, -9, 0), (11, 5, -8, 0), (16, 4, -8, -1))\n", "(-311.9088001226153, -10.062279727459497, 803.624006407706)\n", "1\n", "300.0\n", "((13, 5, -9, 0), (13, 4, -7, -1), (16, 4, -8, -1))\n", "(-111.90880012261528, 34.79809993858041, 1003.624006407706)\n", "1\n", "-200.0\n", "((13, 5, -9, 0), (18, 4, -8, -2), (16, 4, -8, -1))\n", "(-51.51561392625234, 334.79809993858044, 1303.624006407706)\n", "0\n", "-300.0\n", "((20, 4, -9, -2), (18, 4, -8, -2), (16, 4, -8, -1))\n", "(-451.51561392625234, -65.20190006141956, 1562.1706722089111)\n", "1\n", "400.0\n", "((20, 4, -9, -2), (18, 4, -8, -2), (24, 4, -10, -2))\n", "(-135.8743269256998, -65.20190006141956, 1562.1706722089111)\n", "0\n", "0.0\n", "((21, 5, -10, -2), (18, 4, -8, -2), (24, 4, -10, -2))\n", "(-335.8743269256998, -265.20190006141956, 1321.1118138034158)\n", "0\n", "200.0\n", "((21, 5, -10, -2), (18, 4, -8, -2), (17, 4, -7, -2))\n", "(-235.8743269256998, -165.20190006141956, 466.0806739396861)\n", "0\n", "-100.0\n", "((21, 5, -10, -2), (18, 4, -8, -2), (20, 6, -10, -2))\n", "(-335.8743269256998, -20.233039925149086, 366.0806739396861)\n", "1\n", "100.0\n", "((21, 5, -10, -2), (22, 6, -11, -2), (20, 6, -10, -2))\n", "(-235.8743269256998, -31.964325194926886, 466.0806739396861)\n", "1\n", "-100.0\n", "((21, 5, -10, -2), (18, 7, -10, -2), (20, 6, -10, -2))\n", "(-335.8743269256998, -131.9643251949269, 477.81195920946357)\n", "0\n", "100.0\n", "((21, 5, -10, -2), (18, 7, -10, -2), (24, 5, -11, -2))\n", "(-124.1430416559221, -31.964325194926886, 577.8119592094636)\n", "0\n", "-100.0\n", "((25, 4, -11, -2), (18, 7, -10, -2), (24, 5, -11, -2))\n", "(36.86158127419992, 268.0356748050731, 877.8119592094636)\n", "0\n", "-300.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": 185, "id": "6a13bec1-1a48-4647-821e-f1779976d80f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.63746202768425" ] }, "execution_count": 185, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hs_array_to_fr((14, -5, -3, 0, -1, 1))" ] } ], "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 }