alda-lang / alda

A music programming language for musicians. :notes:
https://alda.io
Eclipse Public License 2.0
5.59k stars 286 forks source link

Add support for dynamic markings #358

Closed Scowluga closed 3 years ago

Scowluga commented 3 years ago

Alda supports volume setting via (vol __) and (vol! __) attribute updates. Many scores do not necessarily have numeric volumes, but instead have dynamic markings. This PR introduces basic dynamic markings into Alda via Lisp attribute updates.

Dynamic Markings

This PR will introduce the (mf) and (mp) dynamic markings, as well as the (pppppp), ..., (p) and (ffffff), ..., (f) markings. We choose to support up to 6 pianos or fortes following the MusicXML standard here.

This PR does not add support for more complex dynamics such as fortepiano or sforzando. We believe this would add unnecessary complication into the Alda language.

Dynamic Volumes

A MIDI note's volume is represented by velocity which is an integer in the range [0, 127]. The majority of existing software maps dynamics to velocities following a linear scale. See the Wiki page here. Alda will follow a similar uniform distribution, but supporting up to 6 pianos and fortes instead of the usual 3.

Alda internal representation uses a float in the range [0, 1] instead of velocity. I have added a mapping with velocities commented.

Default Dynamic

With the introduction of dynamics, we will also change every Alda score to start with a default dynamic. We select mf as the default dynamic following MuseScore as explained here.

Scowluga commented 3 years ago

Good point, I hadn't thought much into the examples. I've added dynamics.alda to showcase all the existing dynamics to make sure we can parse without issue. Note that (pppppp) corresponds to a velocity of 1, and I can't even hear it at max volume. But velocity of 1 theoretically makes a sound.

I've also tried to update the existing examples the best I can to account for dynamics. Most do not set volumes, in which they are now just overall more quiet. Some set volumes, but also set volumes at the start. For debussy_quartet.alda I switched the volume updates to use dynamics, but I also started each part at (ff) as otherwise they would start at (mf) which is incorrect.

Scowluga commented 3 years ago

I've updated documentation. See:

This is just what I imagine we might want to do. Let me know how I should change it or feel free to just update it yourself. Let me know.

daveyarwood commented 3 years ago

This is fantastic. Thank you! :100: