# Towards modeling alternating patterns through inter-notes relations

Perrine Vantalon, Mathieu Giraud, Richard Groult, Thierry Lecroq

► To cite this version:

Perrine Vantalon, Mathieu Giraud, Richard Groult, Thierry Lecroq. Towards modeling alternating patterns through inter-notes relations. 23rd International Society for Music Information Retrieval Conference (ISMIR 2022), Late-Breaking Demo Session, Dec 2022, Bangalore, India., pp.LV10. hal-03951420

HAL Id: hal-03951420

https://hal.science/hal-03951420

Submitted on 26 Jan 2023

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# TOWARDS MODELING ALTERNATING PATTERNS THROUGH INTER-NOTES RELATIONS

Perrine Vantalon¹

Mathieu Giraud¹

Richard Groult²,³

Thierry Lecroq²

¹ Univ. Lille, CNRS, Centrale Lille, UMR 9189 CRISTAL, F-59000 Lille, France

² Univ. Rouen Normandie, LITIS, UR 4108, F-76000 Rouen, France

³ Univ. Picardie Jules Verne, MIS, UR 4290, F-80000 Amiens, France

<figure><img src="image_2.png" /><figcaption>**Figure 1:** The Prelude I of the Bach Cello Suite #1 contains a pattern alternating between $k = 2$ elements, a chromatic scale $S_a$ and a pedal $P$. The maximal alternating pattern, as defined in Section 2, is here $\llbracket 5, 33 \rrbracket_{S_a,P}$, starting at the triangle.</figcaption></figure>

## ABSTRACT

A monophonic instrument can play at once several voices or lines, for example when interleaving pedal notes and scales. Such patterns may bear both melodic, harmonic, and rhythmic elements and are frequent in cello music. We propose a model of alternating patterns, where regularly spaced pitches are linked with some relation. We also propose an algorithm to list all such patterns. Perspectives include better corpus analysis, and extending and benchmarking such algorithms.

## 1. INTRODUCTION

Western music with a homophonic texture may often be described with melodic and accompaniment lines [1]. These “support” lines [2] may have harmonic and/or rhythmic roles. However such lines are not necessarily played by different instruments: A polyphonic instrument may play several lines at once. But even a monophonic instrument may play a sequence of notes from where several “voices” may emerge. A significant case is for string instruments, such as the cello: Playing alternatively on two (or more strings) rise to patterns with two (or more) interleaved voices. Bach cello suites, written around 1717–1723, gather 36 baroque dances with several such alternating patterns (see Figures 1 and 2).

Many music information retrieval (MIR) studies work on patterns. On one side, most studies model mono-

phonic/melodic patterns [3–6]. On the other side, the studies modeling polyphonic patterns often consider several explicit voices, such as the envelope of two voices from Bach’s chorales [7] or 2- or 3-voices schemata [8]. There are thus very few studies focusing on the implied voices/harmony from a single monophonic sequence. Matching distant pitches could be an option – taking inspiration from the skip-gram techniques [9].

We introduce here a formal modeling of alternating patterns, where several “voices” are merged in a same monophonic melody. In the next sections, we formally define such patterns, showing how this modeling reflects actual patterns in cello music, propose steps towards algorithms detecting such patterns, and report initial statistics on Bach cello suites.

## 2. DEFINING ALTERNATING PATTERNS

We do not consider here rhythm information, and focus on pitches. The alphabet is defined as either $\Sigma = 12\mathbb{Z}$ or $\Sigma = 7\mathbb{Z}$, the letters being the notes of the scale. Let $s \in \Sigma^*$ a sequence of pitches of length $n$.

We consider binary relations defining how the spaced pitches should relate (see Table 1). A relation $\mathcal{R}$ on $\Sigma$ is a subset of $\Sigma \times \Sigma$. When $(x, y) \in \mathcal{R}$, we say that $x$ is related to $y$ and we note $x\mathcal{R}y$.

An alternating pattern is defined as a sequence of letters from $\Sigma^*$ where every set of letters spaced by $k$ positions are related two by two. Formally, an alternating pattern $\llbracket i, j \rrbracket_{\mathcal{R}_{0 \dots k-1}}$ is defined by a start index $i$, an end index $j$, and a sequence of $k$ relations $(\mathcal{R}_m)_{m \in \llbracket 0, k-1 \rrbracket}$, such that

$$ \{ j - i > 2k \\ s_p \mathcal{R}_{(p-i) \bmod k} s_{p+k} \quad \forall p \in \llbracket i, j - k \rrbracket \} $$

The size of the pattern is $j-i$, and the constraint $j-i > 2k$ checks that the pattern appears at least twice.

<figure><img src="image_3.png" /></figure>

© P. Vantalon, M. Giraud, G. Groult, and T. Lecrocq. Licensed under a Creative Commons Attribution 4.0 International License (CC BY 4.0). **Attribution:** P. Vantalon, M. Giraud, G. Groult, and T. Lecrocq, “Towards modeling alternating patterns through inter-notes relations”, in *Extended Abstracts for the Late-Breaking Demo Session of the 23rd Int. Society for Music Information Retrieval Conf.*, Bengaluru, India, 2022.
<table><caption>**Table 1:** Some relations between spaced pitches. *All* acts as a don't-care symbol. Interval relations, such as *T*, depends on the very representation of pitches in 7Z or 12Z.</caption><tr><td>General Relation <i>All</i></td><td>∀x, y, x <i>All</i> y</td></tr><tr><td>Pedal notes <i>P</i></td><td>x <i>P</i> y ⇐⇒ x = y</td></tr><tr><td>Neighbor pitches <i>N</i><sub>c</sub></td><td>x <i>N</i><sub>c</sub> y ⇐⇒ |x - y| = 1</td></tr><tr><td>Asc. chromatic scale <i>S</i><sub>a</sub></td><td>x <i>S</i><sub>a</sub> y ⇐⇒ x + 1 = y</td></tr><tr><td>Desc. chromatic scale <i>S</i><sub>d</sub></td><td>x <i>S</i><sub>d</sub> y ⇐⇒ x - 1 = y</td></tr><tr><td>Third <i>T</i></td><td>x <i>T</i> y ⇐⇒ y is a third of x</td></tr></table>

**Maximality.** As soon as a pattern appears more than twice, the above definition yields to a quadratic number of overlapping patterns. We thus define a maximal pattern

$$ \llbracket i, j \rrbracket \mathcal{R}_{0} \dots \mathcal{R}_{k-1} $$

as a pattern that can not be extended:

$$ \begin{array}{ll} s_{i-1} \mathcal{R}_{(k-1)} s_{i+k-1} & \text{(left maximality)} \\ s_{j-k+1} \mathcal{R}_{(j+1-i) \bmod k} s_{j+1} & \text{(right maximality)} \end{array} $$

As an example, the iconic pattern at the end of the Prelude of the first Bach Cello Suite (Figure 1) alternates between a pedal note (relation *P*, blue) and an (almost) chromatic ascending scale (relation *S*<sub>a</sub>, yellow). This reinforces the dominant until the 6/4 chord at measure 39 that continues with the final cadence.

**Relation inclusion.** When a relation is included in another one, an alternating pattern will be included in another one. We have $S_a \subset N \subset All$, as a scale is being composed of neighbor pitches. On Figure 1, the pattern $\llbracket 5, 33 \rrbracket_{S_a, P}$ can also be modeled as $\llbracket 5, 33 \rrbracket_{N_c, P}$.

**Boundaries.** Some expert musical annotations can differ by a few notes (in either direction) from what is captured by this definition of a (maximal) alternating pattern. Again on Figure 1, one may annotate a musically relevant pattern starting two notes before the maximal alternating pattern: Even if these notes do not exactly respect the relations, they start both the pedal and the ascending scale.

On the Bourée (Figure 2, bottom), the boundaries of a musically relevant pattern are debatable. The last *E* in mesure 24 can be excluded, but will be anyway included by left-maximality in the pattern $\llbracket 8, 21 \rrbracket_{T, T, P, P}$.

### 3. TOWARDS THE DETECTION OF MAXIMAL ALTERNATING PATTERNS

Calling *r* the number of possible relations, there are $r^k$ sequences of *k* relations, repetitions allowed. Alternating patterns can be searched in a similar way than with the naive search for $r^k$ substrings in a text (Algorithm 1), thus in time $O(r^k n^2)$, while extending them maximally to the right:

To keep only the patterns which are also left maximal, patterns are sorted. Let us consider two right-maximal alternating patterns $\llbracket i_1, j \rrbracket \mathcal{R}_{r_1} \dots \mathcal{R}_{r_k}$ and $\llbracket i_2, j \rrbracket \mathcal{R}_{r'_1} \dots \mathcal{R}_{r'_k}$

<figure><img src="image_4.png" /><figcaption>**Figure 2:** Two patterns alternating between $k = 4$ elements. (Top) Suite 1 Courante, $\llbracket 1, 24 \rrbracket_{P, P, P, S_a}$. (Bottom) Suite 3 Bourée I, $\llbracket 8, 21 \rrbracket_{P, P, T, T}$.</figcaption></figure>

**Algorithm 1 Pattern Searching**

**Input:** sequence of notes $s_1...s_n$, relations $\mathcal{R}_1, ..., \mathcal{R}_r$

**Output:** list of maximal alternating patterns

1. **For** each starting position *i*:

2. **For** each possible sequence of relations $\mathcal{R}_{r_1}...\mathcal{R}_{r_k}$:

3. Let $j = i + 2k$

4. **If** $\llbracket i, j \rrbracket \mathcal{R}_{r_1} \dots \mathcal{R}_{r_k}$ is an alternating pattern:

5. Extend *j* to have a right-maximal pattern

6. Sort the patterns and keep only the left-maximal patterns

with the same ending position *j*. The first pattern is an extension of the second one when:

$$ \begin{cases} i_1 < i_2 \\ r_{(m+i_1-i_2)} \bmod k = r'_m \quad \forall m \in \llbracket 0, k-1 \rrbracket \end{cases} $$

This means that $r'_1...r'_k$ is a left circular permutation of $r_1...r_k$ of $i_1 - i_2$ positions. Filtering the patterns can be done linearly in the number of patterns found, so the full algorithm still runs in time $O(r^k n^2)$.

### 4. CONCLUSIONS AND PERSPECTIVES

Focusing on inter/spaced-notes relations enables to model several voices into a same monophonic sequence: The proposed modeling defines thus alternating patterns suitable for the analysis of monophonic sequences implying several voices, even if their boundaries are not always exactly the same than what a musical analysis could yield.

Considering the set of relations $\{P, S_a, S_d, N_c, T\}$, the proposed algorithm finds 2922 maximal alternating patterns of size $> 2k$ with $k \in \{2, 3, 4\}$ on 32 dances of the Bach cello suites. Further work should compare these results against an expert annotation: An initial manual analysis of these 32 dances labeled 881 such “musically pertinent” patterns.

The large number of patterns found by the algorithm can be partially explained by those counted several times due to included relations. The definition could be constrained on some subset of relations, and more efficient algorithms could be designed for either the generic or such more constrained cases.
5. REFERENCES

[1] P. Kokoras, “Towards a holophonic musical texture,” in *International Computer Music Conference (ICMC 2005)*, 2005.

[2] B. Benward and M. Saker, *Music in Theory and Practice (Volume 1)*. McGraw-Hill Professional, 2008 (8th ed.).

[3] M. Mongeau and D. Sankoff, “Comparison of musical sequences,” *Computers and the Humanities*, vol. 24, no. 3, pp. 161–175, 1990.

[4] M. Grachten, J.-L. Arcos, and R. L. de Mántaras, “A comparison of different approaches to melodic similarity,” in *Int. Conf. on Music and Artificial Intelligence (ICMAI 2002)*, 2002.

[5] S. Ahlbäck, “Melodic similarity as a determinant of melody structure,” *Musicae Scientiae*, vol. Discussion Forum 4A, pp. 235–280, 2007.

[6] R. Kumar, A. Biswas, and P. Roy, “Melody extraction from music: A comprehensive study,” in *Applications of Machine Learning*. Springer, 2020, pp. 141–155.

[7] D. Conklin and M. Bergeron, “Discovery of contrapuntal patterns,” 2010.

[8] C. Finkensiep, K. Déguernel, M. Neuwirth, and M. Rohrmeier, “Voice-leading schema recognition using rhythm and pitch features,” in *International Society for Music Information Retrieval Conference (ISMIR 2020)*, 2020, pp. 520–526.

[9] D. R. W. Sears and G. Widmer, “Beneath (or beyond) the surface: Discovering voice-leading patterns with skip-grams,” *Journal of Mathematics and Music*, 2020.