Music Analysis with Python
Chris Wilson
Link To Github https://github.com/jackparsons93/music_project
As someone trained in classical music, I sought to apply data science to that discipline using Python. I used it to explore two questions about composition and to develop a motif detector. For this project, I referred to works by Bach, Mozart, and Beethoven.
The questions I answered were:
- Is a skip in stepwise voice leading used to signal a change in compositional direction?
- Where do the highest notes in a Bach composition occur?
- Is it possible to use code to detect musical motifs?
The skip signal
I began with an analysis of the proposition that a composer usually changes direction after a skip, that is a major second or greater. Generally classical and baroque composers use stepwise voice leading, which is a progression through C-D-E, one note at a time. A skip in the music occurs when skipping a note in the sequence like knocking the D note out of C-D-E to play C-E. C-E skips are typically followed by a change in direction, as we will see in the analysis below.
Melodic curve refers to music that starts off low, grows high close to the center, and then returns to low again. To visualize that, I used a piece of code that plots a line graph of the pitch of the music from the beginning to the end of the composition.
As a result of applying Python code to musical patterns and visualizing the results of the data, we can confirm two answers about classical music. One is that composers tend to put in a change direction for music after skips. The other is that in Bach’s music the highest note occurs smack in the middle. The final diagram with a line plot of invention number 2 by Bach also shows the ascending melodic curve of the music.
Building on the insights gained with Python, , I created a computer program that automatically detects motifs. On that basis, it can contribute to motif data fed into a neural network that could train generative AI to produce music in the style of Beethoven, or J.S. Bach.