Showing posts with label music21. Show all posts
Showing posts with label music21. Show all posts

23 September 2018

Imaginary Museum of Musical Representations

I was rereading Lydia Goehr’s The Imaginary Museum of Musical Works the other evening after a long day spent translating several of music21’s score-representation code packages from Python to JavaScript (for music21j). What struck me when I was reading the introduction, which lays out several pre-existing theories about the work-concept, and the relationship(s) among the musical idea, the building blocks of scores (pitches, etc.), the score-copy, and performances, was my own need to take a stand on the proper relationships of such conceptions when choosing a computational language in which to express musical languages.

Those who haven’t programmed may not know that no modern computer program (or very very few) is built from a single code file, or flowchart leading from input to output. Instead each program is built from components (a file browser, a set of functions for manipulating canvases for drawing, a module for representing tempo) that can be called upon by other components in a systematized but reusable and testable manner. These get bundled or packed or linked together to make a complete or extensible application or library. Different philosophies exist about which structures (or ontologies, to use a word with related but quite different meanings between the humanities and computer science) can be well-formed or desirable.

These philosophies about file linking—importing and exporting—lie close to the marrow of the designs of various computer languages and in many cases evolved in response to the environments within which the languages were originally created. Python, a language run on individual computers that came of age in the era of fast hard drives and, from the user’s perspective, near instantaneous loading of small files, aims to put as few limitations on the possible relationships between modules as possible. JavaScript, on the other hand, which appeared first on the web in the time of dialup internet and unreliable connections, has, even in its most recent incarnations, placed sharper restrictions on connecting resources in the name of efficiency.

Translating music analysis software from the first language to the other has raised complex problems for the representation of music in code. Python allowed me to interweave different levels of musical thought, such that notes could will into existence a measure (say by asking for the creation of an object to encompass them) while a measure could in another context give birth to notes (for instance by asking for a suitable number to fill it, given some metrical, harmonic, and accentual constraints). A score could of course be a container to many measures, but a measure could also be linked or contain many scores (for instance as a key or heading to a catalogue of quotations or standard topoi). As I created the original music21 in Python, I reveled in the multiplicity of possible relationships, in the way some musical philosophers might argue that a score gives rise to a performance which, if transcribed or imagined, gives rise to a new score, which gives rise to a new performance, and so on to infinity.

Rewriting the “same code” posed, and continues to pose, a challenge to my ecumenical notion of musical relationships. (With “same code” in quotation marks since the work-concept-concept for computer works has not been the subject of nearly so much rumination.) In JavaScript, in order to make sure that everything has been loaded before the user closes her browser in frustration, in general if one module (A) uses another module (B) in its code, then the second module (B) cannot use, or import, the first (A) into its code. What some, perhaps those trained as humanists, might exult as a beautiful web of inter-compu-textuality, is called a cyclic or circular dependency and it is easy to find categorial pronouncements that such things are bad or the result of lazy or sloppy thinking. They resist creating a hierarchy of elements, and prevent creating beautiful tree structures that are, or at least were during the time when computers were problem-solving devices and not enablers of exploration, the key to moving in an efficient manner from point A to point Z without getting into an endless loop somewhere around J to M. (A programmer—who had apparently gotten too deep into the trenches of coding to remember that the terms which undergird so many computational structures are metaphors—once criticized a part of my code that had many pointers running up and down a hierarchy by saying, “This is absurd! A child cannot have more than one parent.”)

In Python, I could say that a Note in the presence of another Note created an Interval. (Like in German, in most computer languages, nouns, or Objects, are capitalized.) And, I could simultaneously say that an Interval, given a starting Note for reference, could define a second Note that fulfilled it. Both of these generating relationships seemed not just plausible, but natural and essential to a full representation of the complexity of music. The ambiguity of which came first, the interval or the note can never be resolved. In JavaScript, however, the programming musicologist is left with a decision to be made: either Notes can create Intervals or Intervals can create Notes, but not both. The work creates the score (or performance), or the performance or the score creates the work, but not both. The one who is able to create both Notes and Intervals is an entity that stands outside the system—the calling program—which is perhaps better named “the observer” in the best literary criticism traditions, since the network of Notes and Intervals cannot operate with knowledge that it exists.

(To be fair, there are some complex and fragile ways to work with circular dependencies in JavaScript, and in Python, true circular dependencies are also impossible: either the Note can only become aware of its ability to create Intervals at the moment of action [an import nested in a method] or vice versa.)

I have found that programming musical logic has sharpened my awareness of the ambiguities, hierarchies, and underdefined elements of music. By underdefined elements, I suggest: is the interval from E# to Fb an ascending doubly-diminished second or a descending doubly-diminished second? If spelling matters more than sound, such that C-G is consonant but Dbb-G is dissonant, is the bass of a chord beginning on E##-Fbb-Bb the E## or the Fbb? (If it’s the Fbb, then is a B###-Dbbb-F# chord in root position or first inversion? If the E##, does that mean that we cannot determine the bass of a chord by ear?) These may be absurdities to practicing musicians but deciding a “right answer” to them makes all the difference in how standard musical relationships should be represented and encoded.

It is extremely difficult to tell a computer to hold off on making a decision or to leave a paradox in place to solve later. The human ability (flaw?) in being able to reason around ambiguity, or to hold conflicting ideas without breaking down, is a capacity that those who design practical computing systems have either not been able to replicate or have deliberately chosen not to. Within the limited choices, I have generally been drawn to computing frameworks that let me come as close as possible to representing multiple perspectives. (Ironically, I’ve found the closest match so far in Python, despite its community adopting a motto that says there should be only one way to do it.) There is a danger that when good but still inadequate tools are used to model human behavior and creativity, eventually human behavior will bend to suit the tools, rather than the other way around. It is a force that those who design and use these tools must be aware of and continually fight against.

(updated 2022.02.03 — corrected "revealed" to "reveled")
(updated 2026.02.08 — correct minor grammar issues, fixed broken links.)

17 September 2014

Recent Research

A few recent articles and software of interest and some older articles that might have been missed:

23 May 2014

Web Pages with musical examples...

Through the music21 Javascript port, music21j, any webpage can now include (simple) musical examples easily. Copy and paste the following code somewhere in the webpage:

<script>
window.m21conf = { loadSoundfont: false };
</script>
<script src="https://cdn.jsdelivr.net/npm/music21j@0.20.1/releases/music21.debug.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/music21j@0.20.1/releases/music21j.min.css" rel="stylesheet"> <script>
music21.common.urls.soundfontUrl = 'https://raw.githubusercontent.com/gleitz/midi-js-soundfonts/gh-pages/FluidR3_GM/';
music21.miditools.loadSoundfont('acoustic_grand_piano');
</script>


If you are writing on Blogger or another platform, you will need to switch from "Compose" to "HTML" mode to enter this tag and the div tags below below. I wrote the rest of this post in Compose mode and then added the tags later. If you're an advanced user, you can put the script tag in your Blogger template. It will call the scripts asynchronously, so your page loading will not slow down.

This paragraph is no longer needed. The "data-main" parameter says that music21j is needed, and music21j uses the amazing require.js package, specified in the "src" parameter. Music21j uses new technologies that have been standard in all web browsers released since March 2011. Unfortunately, 20% of people on the Internet still use older browsers. If musical examples are crucial to your page, remove the warnBanner='no' line and a warning message and opportunity to upgrade the browser will be shown. For most of us, a page without examples is better than no page at all, hence why I suggest putting the warnBanner='no' line.

To put in a musical example, put the notation in the TinyNotation format described at moduleTinyNotation inside a tag with classes "music21" and "tinyNotation", like so:

<div class="music21 tinyNotation"> 2/4 c2 d e4 f#8. g16 r4 c'4</div>

The "2/4" is, obviously, the time signature. Notes are given by A-G for bass clef notes, a-g for low treble clef notes, a'-g' for higher treble clef notes, AA-GG for lower bass clef notes. Additional quotes or doubled letters represent even higher or lower notes.  #, b, or n are for sharp, flat, or natural (optional) and follow any quote signs.   "r" stands for a rest.

Durations are specified with 4 = quarter, 2 = half, 1 = whole, 8 = eighth, etc. A dot after the number dots the note.  There aren't ways of doing triplets, etc. currently.  If there is no number then the previous duration still applies.

Here is that example rendered.  Click on it to play it.

2/4 c2 d e4 f#8. g16 r4 c'4
There is no way of specifying the tempo, unfortunately. If you don't like the playback, put "noPlayback" in the class tags. For instance, the following example will not be played:

<div class="music21 tinyNotation noPlayback">3/4 C2 D-4 Dn E- E F2.</div>
3/4 C2 D-4 Dn E- E F2.

I'm working on getting other notation formats, including MusicXML, ABC, MIDI, etc. to work soon; however they will not be converted on the browser, so only TinyNotation will work on a completely off-line application.  This summer will see some amazing new developments in this space.

The rendering is done via VexFlow and the playback is from MIDI.js. Both are amazing projects worthy of supporting. The development of music21j is supported by a Brit D'Arbeloff education grant at MIT.

Updated January 2026: Replaced the previous instructions with ones that work:
<script data-main="http://web.mit.edu/music21/music21j/src/music21"
        src='http://web.mit.edu/music21/music21j/ext/require/require.js'
        warnBanner='no'></script>

08 October 2013

Testing ability to render music in Blogger

Update: January 2026 -- I've disabled the embedding of music21j (formerly hosted at MIT) so this no longer works... The following score was written as: <div class="music21 tinyNotation">c4 d8 e8 f2</div>
c4 d8 e8 f2
and then rendered automatically via some plugins I have.
Here's another one. You can click either of them to hear them:
3/4 d8. f#16 e8 f g a c'#2. d'2.
Hope to be able to release this soon.
This might not work after a bit -- the loading is too slow and I might move the source code... Thanks to the folks at Vexflow and MIDI.js for the idea.

10 July 2012

In Deutschland

Gruß Gott! Am Donnerstag um 10.00 Uhr werde ich einen Vortrag an der Ludwig-Maximilians-Universität zum Thema "Codieren von Musiknoten für analytische Abfragen" halten. Am Montag werden meine Studenten und ich über das Thema Service-orientierte Architekturen für musikalische Analyse bei einem Workshop an der Digital Humanities Konferenz sprechen. Wenn Sie in München oder Hamburg sind und an einer Teilnahme interessiert sind, kontaktieren Sie mich und ich kann eine Wegbeschreibung schicken. Oder wenn Sie in Berlin vom 18.–20. Juli sein werden und wollen uns treffen, lassen Sie es mich wissen.

Unsere Reise wird von einem großzügigen Zuschuss der deutschen Regierung für den kulturellen Austausch und durch den Deutschland Seed Fund des MIT gefördert.
(Added Translation, January 2026; fixed German)
Greetings! On Thursday at 10:00 a.m., I will give a lecture at Ludwig Maximilian University on the topic “Encoding Musical Notation for Analytical Queries.” On Monday, my students and I will speak about service-oriented architectures for musical analysis at a workshop at the Digital Humanities Conference.

If you are in Munich or Hamburg and are interested in attending, please contact me and I can send directions. Or, if you will be in Berlin from July 18–20 and would like to meet, let me know.

Our trip is supported by a generous grant from the German government for cultural exchange, as well as by the MIT Germany Seed Fund.

03 July 2012

New news, Old news, and quotes...

Some news stories old and recent that I've forgotten to post:

Two responses to DarwinTunes (more coming):
Discover Magazine
Michael Scott Cuthbert, who works on computer-aided musical analysis at MIT, is sceptical that the approach tells us anything about the evolution of music. “They have shown that people can sense a glimmer of the things they like about music even when most of it consists of sounds they hate,” he says.  “But it doesn’t give any information about why music sounded differently in the past, why people like different things today, or how music might evolve in the future.”
 
“Suppose you randomly threw car parts into piles and asked people to rate those they’d most like to buy,” he says. “Then you took parts from the highest-rated heaps, and rearranged them into new heaps.  People might hate all of them at first, but they’d probably rate the ones with four tires or a trunk in the back or a steering wheel in the drivers’ seat higher than the rest. Do that long enough and I wouldn’t be surprised that you’d eventually get something that looked like a 2011 Honda Civic.  But that doesn’t mean that that’s how a car is made.”
 
L.A. Times
The study shows that people "can discern the little things they like about music even in the context of a lot of extraneous sounds," said MIT computational musicologist Michael Scott Cuthbert, who wasn't involved in the research. "But what they don't prove is why music today has changed from the popular music of the past. It doesn't show how changing tastes result in changing music and it doesn't give us a hint of what the future holds for music."

Five things from MIT:
MIT News Office on the ELVIS grant
MIT Tech interview on the ELVIS grant (posted previously)
MIT SHASS Magazine article (Spring 2010) on my research
A little blurb about my work
A little piece on a completion of a piece by Zachara da Teramo (defunct)

Many new papers posted at Academia.edu trecento.com.


(Updated Jan 2026 to make the links work)

24 February 2012

MIT Tech Article on Michael Cuthbert

Derek Chang of the MIT Tech published an interview with me in today's issue. Read it here. The opening appears below:

$500,000 grant for music research at MIT

Michael Scott Cuthbert, associate professor of music, was recently awarded a $500,000 grant from the Digging into Data consortium. This grant will support his work in using computational techniques to study changes in Western musical style. He has received $175,000 specifically for his music21 project . On Thursday, Cuthbert sat with The Tech to discuss his work with music21 and his passion for combining computational techniques with music.

The Tech: Many of us with a musical background must be interested in your computational work and how it applies to music. What is the motivation behind your project?

Cuthbert: One of the main ways artists analyze art work or music is examining a piece very carefully, from all possible dimensions. But it’s really hard to put the work into the context of the time. How is the piece representative of its time period, or how does it break the mold? It takes us a very long time to look at one piece. In contrast, computers are good at getting an overview of a particular problem. For example, what patterns exist in how chords progress from one to another? Is the piece being looked at representative of the music grammar for the period? (...read more...)