Parallel Composition

If you've been paying close attention you've probably realized that the NOTE language can do things that the MUS language can't do. Look at this NOTE program:

It plays two notes that overlap in time. What fun is melody without harmony?

Let's add the ability to play harmonies to the MUS language. We already have the 'seq' operator, now let's add the 'par' operator. Remember that 'seq' means to play left and then play right. The 'par' operator means to play left and also play right simultaneously.

Here's a C major chord in the new MUS.

Before we extend our compiler to the new language, we have to be a bit careful. When adding a feature we always have to ask, how does the new feature interact with all the existing features?

One tricky bit of interaction is defining when songs end. If there can be multiple notes playing and ending at different times, when does the whole song end? We need to know this for the 'seq' operator. The 'seq' operator needs to know when left ends in order to know when to start right.

To write a compiler for the new MUS language to NOTE, I would recommend first figuring out endTime like before. Then use that helper function to write the compiler.

Write a function compile that compiles MUS songs that can contain 'par' into NOTE songs.


Prev Next