How to visualize and play behavioral events as music
Playing off the idea of plotting behavioral interactions using Music Notation, I wanted to see if I could make these behaviors audible as actual musical notes. To do it, I used R, the music notation program LilyPond, the LilyPond editor Frescobaldi, and file conversion site Zamzar (bonus, these are all free!).
Here’s how:
- In R, assign each individual a note, according to some attribute of that individual. Here, I’ve used dominance rank, with higher-ranked individuals as higher-pitched notes, and lower-ranked individuals as lower notes.
- Still in R, convert a time series of aggression into notes, with rests in between to preserve observed breaks in aggression. Here, I’ve plotted these lulls in aggression with silent rests. Aggression is plotted with the aggressor-note first and the target-note second. The pitch of the note tells you the rank of the actor and target, and the direction of pitch change tells you whether aggression is “up” or “down” the hierarchy (from higher-ranked to lower-ranked or the reverse). I’ve added a slur to visually link the actors in events.
- Copy the note vector from R, paste as text into the LilyPond editor Frescobaldi. Frescobaldi has an embedded score previewer and MIDI player, so you can see how your music looks and test the sound.
- I started my code with a preview of all of the ranks of individuals, from lowest to highest and back to lowest. This gives your listeners an idea of how many octaves you’ll be using and the relative rank of individuals at the beginning.
- In Frescobaldi, make some tweaks to the music. In my original code, some of the pauses between aggression were very long. To keep things interesting, I cut down the length of the rests. I also added a very short (eight-note) rest in between any aggression events to give a more obvious separation between aggressive events. These changes make it so that now events don’t happen in “real time”, but the trade-off is that the piece sounds better.
- In Frescobaldi, set the tempo of the piece and the instrument to use. Engrave your score and save the code as a MIDI file.
- Convert your MIDI file to .mp3 or .wav format — I used Zamzar.
Listen to the score & see the music
Code
Basics of LilyPond coding (edit in Frescobaldi):
This video has a great overview of input formats for LilyPond. Here are the basics:
- LilyPond is whitespace insensitive (spaces don’t matter) but it IS case sensitive. Note pitches are all in lower case.
- Expressions are enclosed in curly brackets { }
- You can use % to comment out text
- Note duration follows directly after note name (1=whole note, 4=quarter note, etc.)
Here is what the code looks like in Frescobaldi:
Tips
- You want to specify the version to use at the beginning
- You can set the language to English (I think the default is Dutch?) — this affects how you specify sharps and flats, if you use them
- You can add a title to the score engraving with \header
- Start the score with \score (enclose all this in curly brackets)
- Specify the MIDI instrument — here I’ve chosen the acoustic grand piano
- Specify the tempo — here, I’ve set it to “Presto” and specified 200 beats/min
- Very important! Set the notes to \absolute (default is \relative) — otherwise the octaves you specified get all skewy
- Specify your time signature
- Add your notes pitches: Quotes raise notes by octaves: a single quote raises it one octave, double raises it two, etc. Commas lower notes by octaves in the same way.
- I started my score with a run through all of the notes used, from the lowest-ranked individual to the highest, and back to the lowest. This facilitates listening for rank.
- Add note lengths: whole notes=1, eighth notes=8, etc.
- Add a slur to connect actor notes with target notes using parentheses: g”8(a8) slurs together two eighth notes
- Add/adjust rests: rests are specified with “r” — here, I’ve got all my rests as silent (sr) to avoid cluttering the score. Specify rest length the same way as note length
- You can listen to the MIDI file within Frescobaldi: go to Edit>Preferences>MIDI player in Frescobaldi to set this up
- The \layout { } command engraves the score to PDF
- The \midi { } command saves a MIDI file
- I converted the MIDI file to MP3 using Zamzar
Code as text
\version “2.18.2”
\language “english”
\header {
title = “Musical Aggression”
composer = “Elizabeth Hobson”
opus = “Group 1: June 19 2008 8-10AM”
}
\score{
\new Staff \with {midiInstrument = #”acoustic grand”} {
\tempo “Presto” 4=200
\absolute {
\time 4/4
f2 f8 g a b c’ d’ e’ f’ g’ a’ b’ c” d” e” f” g” a” b” c”’ d”’ e”’2
e”’8 d”’ c”’ b” a” g” f” e” d” c” b’ a’ g’ f’ e’ d’ c’ b a g f2 r1
sr1 e”8(f8) sr1 c”8(g8) sr1 g”8(a8) sr8 a8(a”8) sr1 f’8(b’8) sr8 a8(f’8) sr1 g”8(e”8) sr8 g”8(a”8) sr1 e”’8(a”8) sr1 e”’8(e’8) sr1 e’8(a8) sr1 d”8(c”8) sr8 c”8(a8) sr1 g”8(g8) sr1 d”’8(e”8) sr8 f’8(e’8) e”’8(a”8) sr1 d’8(f8) sr1 e”’8(e”8) sr1 a’8(b’8) sr8 a’8(b’8) sr8 a’8(b8) sr8 a’8(b’8) sr8 a’8(b8) sr8 c”’8(a’8) sr8 g”8(g’8) sr8 e”8(c”8) sr1 f’8(a8) sr8 e’8(a8) sr8 c”8(e’8) sr8 f’8(a8) sr8 f’8(a8) sr8 e’8(a8) sr1 b”8(f’8) sr8 f’8(a8) c”’8(a8) sr1 b”8(f’8) sr8 c”8(e’8) sr8 f”8(f8) sr1 f’8(c”8) sr8 f’8(a8) sr1 d”8(f”8) sr8 g”8(f”8) sr8 g”8(f’8) sr8 f”8(a8) sr8 d”8(c”8)
}
}
\layout { }
\midi { }
}