"""
Arc diagram of a melody
=======================

Wattenberg's arc diagram (2002) joins consecutive occurrences of every repeated
subsequence of one long sequence by a semicircle; thickness is the length of
the repeat. Beethoven's *Ode to Joy* shows its form at once: the opening phrase
returns, the bridge stands apart.
"""

import matplotlib.pyplot as plt

import spmviz as sv
from spmviz.viz import plot_arc_diagram

songs = sv.datasets.load_melodies("song")
titles = songs.attributes["song"].tolist()
ode = songs[titles.index("Ode to Joy")]
plot_arc_diagram([e[0] for e in ode], min_length=3, title="Ode to Joy: repeats of at least three notes")
# %%
# Twinkle, Twinkle, Little Star
# -----------------------------
tw = songs[titles.index("Twinkle, Twinkle, Little Star")]
plot_arc_diagram([e[0] for e in tw], min_length=3)
plt.show()
