alda-lang / alda

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

Feature request: Set the key #36

Closed FragLegs closed 8 years ago

FragLegs commented 9 years ago

It would be nice to be able to set the key (either by name or as a series of flatted/sharped notes) as an attribute and global attribute. I don't know Clojure well enough to quickly set up a pull request for this, but if I find time I might try my hand at it. In the meantime, I put this out there for anyone else working on it.

daveyarwood commented 9 years ago

This would be a step in the right direction toward eventually being able to export sheet music for an Alda score.

I think what we want is to define a new top-level thing called *key* that is initialized as an empty map {} when a score is initialized, and any time the key is set via an attribute/global attribute change, the current time marking and the key is recorded in *key*. What would be even more useful is if we could store the current measure number, but we'd have to implement measures first. (currently, Alda just ignores bar lines)

I don't think we'll be able to do much with the key-change data for the time being, but once things get moving with the sheet music export feature, we'll be able to use the key-change data to tell it what key signature to display.

crisptrutski commented 9 years ago

Perhaps this would even change the default meaning of bare notes like c - with a "natural" modifier to escape the key like c.? This would dovetail into microtonal or custom tunings - perhaps "keys" could even introduce new note symbols within their scope - like aa or h or some suitable unicode :notes:

FragLegs commented 9 years ago

Yeah, that's more along the lines of what I was thinking. I just don't want to have to type "b-" for every B flat in a song when the song is in the key of B flat. Motivated by the same laziness that invented key signatures in the first place. :)

On Monday, September 7, 2015, Chris Truter notifications@github.com wrote:

Perhaps this would even change the default meaning of bare notes like c - with a "natural" modifier to escape the key like c.? This would dovetail into microtonal or custom tunings - perhaps "keys" could even introduce new note symbols within their scope - like aa or h or some suitable unicode [image: :notes:]

— Reply to this email directly or view it on GitHub https://github.com/alda-lang/alda/issues/36#issuecomment-138274238.

daveyarwood commented 9 years ago

Aha! I see what you're saying now. I think that's a great idea! Disregard my last comment -- on second thought, I think we should keep track of keys on a per-instrument basis, like everything else. Being able to have 2 instruments playing at the same time in 2 different keys is totally in line with Alda's way of doing things. For example, you can have different tempos for different instruments by doing something like this:

violin: (tempo 180) e f g e f g e f g e f g e f g
viola: (tempo 200) e f g e f g e f g e f g e f g

which creates a nice phase effect. To change the tempo for all instruments, you can do it globally with the tempo! global attribute.

We could do a similar thing with keys -- allowing you to change the key per-instrument with key or for every instrument with key!. An instrument's key can be C major by default, so if you don't provide an accidental for a note, it will be natural by default, which is the way it works currently.

I like the idea of using . to represent a natural note. . is already used for dotted note lengths (e.g. c4. is a dotted quarter note C), but it shouldn't conflict with the . representing a natural, when placed immediately after a note letter name. So, a C natural dotted quarter note could be represented as c.4. This might look slightly weird, but it is fairly uncommon to see natural accidentals, so I don't mind it. Another idea would be to use ,: c,4.

crisptrutski commented 9 years ago

Whoops! Forgot the . is already used - and think that I'd get confused by the overloading (dotted notes with the implicit duration seem common). Perhaps @ or | or=? Struggling to find a character that feels.. natural (comma feels like whitespace or separator)

FragLegs commented 9 years ago

I'm in favor of = as it is right in between + and -

On Monday, September 7, 2015, Chris Truter notifications@github.com wrote:

Whoops! Forgot the . is already used - and think that I'd get confused by the overloading (dotted notes with the implicit duration seem common). Perhaps @ or | or=? Struggling to find a character that feels.. natural (comma feels like whitespace or separator)

— Reply to this email directly or view it on GitHub https://github.com/alda-lang/alda/issues/36#issuecomment-138340155.

crisptrutski commented 9 years ago

Goldilocks :person_with_blond_hair:

FragLegs commented 9 years ago

Another thing that would have to be taken into consideration is what happens when you write c+ in a key that has a c+? Does it become c++ or does the local + override the key's +. In handwritten scores, the local annotation overrides, which I think is what you'd want here. So the key only applies to in annotated notes.

On Monday, September 7, 2015, Shayne Miel miel.shayne@gmail.com wrote:

I'm in favor of = as it is right in between + and -

On Monday, September 7, 2015, Chris Truter <notifications@github.com javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:

Whoops! Forgot the . is already used - and think that I'd get confused by the overloading (dotted notes with the implicit duration seem common). Perhaps @ or | or=? Struggling to find a character that feels.. natural (comma feels like whitespace or separator)

— Reply to this email directly or view it on GitHub https://github.com/alda-lang/alda/issues/36#issuecomment-138340155.

FragLegs commented 9 years ago

That's "unannotated" (stupid autocorrect)

On Monday, September 7, 2015, Shayne Miel miel.shayne@gmail.com wrote:

Another thing that would have to be taken into consideration is what happens when you write c+ in a key that has a c+? Does it become c++ or does the local + override the key's +. In handwritten scores, the local annotation overrides, which I think is what you'd want here. So the key only applies to in annotated notes.

On Monday, September 7, 2015, Shayne Miel <miel.shayne@gmail.com javascript:_e(%7B%7D,'cvml','miel.shayne@gmail.com');> wrote:

I'm in favor of = as it is right in between + and -

On Monday, September 7, 2015, Chris Truter notifications@github.com wrote:

Whoops! Forgot the . is already used - and think that I'd get confused by the overloading (dotted notes with the implicit duration seem common). Perhaps @ or | or=? Struggling to find a character that feels.. natural (comma feels like whitespace or separator)

— Reply to this email directly or view it on GitHub https://github.com/alda-lang/alda/issues/36#issuecomment-138340155.

daveyarwood commented 9 years ago

I like =: it's like you're saying "this note, no more, no less"

EDIT: = will probably also be used for variable definition, but variable names will be required to be at least 2 characters long (so as to differentiate them from notes), so I don't think it will conflict.

I agree that the local accidental should override the key signature -- you see this sometimes in sheet music, where it serves the purpose of making it extra clear to the performer what the accidental of the note is, even if it's in the key signature.