alda-lang / alda

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

Is there a language specification for the latest version of Alda? #352

Closed Nagyhal closed 1 year ago

Nagyhal commented 3 years ago

Hi, I hope I'm posting this in the right place. In brief, I'd like to create support for alda in a new editor. However, I can't find any overarching specification for the language.

The best thing I have is this old file: https://github.com/alda-lang/alda-cljs/blob/master/grammar/alda.bnf, but I believe that alda syntax has changed quite a bit since then (isn't there no support for multi-line comments, for example?)

As I'm really worried I'll miss small (but important) elements of alda's syntax, the best I can do is copy existing alda plugins for other editors. Not only is this cargo-culting, but what I'd really like to do instead is write some very robust syntax highlighting, with inlined Clojure, the works!

Thanks if you can help, and I look forward to contributing to the alda community!

elydpg commented 3 years ago

This might be better suited for the subreddit or the slack group. I don't know if there's a formal grammar, but you can learn more about current syntax from the docs.

Edit: also inline clojure is not being supported in the future, so it might not be worth it to add...

daveyarwood commented 3 years ago

Echoing what I said on Slack:

I'd be very surprised if anyone had an updated BNF grammar for Alda. If there is, I'd love to see it, make corrections and make it part of the Alda repo to sort of "standardize" it. I think having a language spec would be a very good thing, for example to support use cases like yours where you want to add editor support, and you want to base your work on a canonical source of truth. I'd be happy to do what I can to push us further in that direction, although my time is limited (especially with my current focus on getting Alda 2 released!), so I probably won't be able to find time to write an updated BNF grammar myself for a while.

Alda 2 will be released soon, and it's worth noting that from a language perspective, Alda 2 is almost identical to Alda 1. The one breaking change is that inline Clojure code is no longer a part of the language. As luck would have it, over the weekend, I wrote up an Alda 2 migration guide, where I discussed in detail what changed. Syntactically, the only difference is that the Lisp expressions aren't Clojure anymore; now it's very simple, bespoke Lisp. For example, Alda 1 (Clojure) (key-sig! [:a :major])vs. Alda 2 (alda-lisp) (key-sig! '(a major))

severak commented 3 years ago

Hi. I am working on javascript DAW called Cyber Music Studio.

I am thinking about adding subset/superset of Alda to it as sequencer tool. I am not sure how to implement it, I have two different ideas:

a) just support some subset of language and throw some regexes to parse it b) construct proper javascript parser for alda (probably) using Peggy

I think the latter would be useful for wider Alda community (we can implement Alda in browser now!) but it will be more work.

Also - I am not sure how old BNF reflects current status of Alda and what rules for whitespaces Alda follows. Latter is especially confusing.

daveyarwood commented 3 years ago

I'd say that old BNF is probably a reasonable starting point. It probably needs to be updated in various ways. Maybe a good smoke test would be to try implementing a parser (using Peggy or whatever) with that BNF grammar, and then parse these example scores and let the parse errors guide you to the places in the grammar that need to be updated.

daveyarwood commented 3 years ago

I am thinking about adding subset/superset of Alda to it as sequencer tool

This is an amazing idea, BTW! I'd love to be able to input notes in a DAW via Alda instead of a piano roll, etc.

severak commented 3 years ago

I started working on Alda reimplementation in javascript here.

I'd love to be able to input notes in a DAW via Alda instead of a piano roll, etc.

It can be IMHO done now - either via importing MIDI fire from alda export or by recording MIDI output (if new version can do it). This just need to be wrapped in some sort of plugin.

severak commented 3 years ago

After some time I did some improvements on my parser and I ran into some things I cannot parse and I have no idea what these are:

Also I am not sure where is whitespace optinal and where is mandatory. Also it seems that newlines does not have semantical values unless you are parsing variable definition.

daveyarwood commented 3 years ago

Here is some information about accidental syntax (_) and key signatures in the Alda docs.

This blog post I wrote is also a good introduction to pitch, accidentals and key signatures.

d4~|1 is the same as d4~1 (a D quarter note tied to a D whole note, i.e. 1 beat + 4 beats = 5 beats of D), there is just a barline between the quarter note and the whole note. Classical musicians would say that the note is tied "over" the barline.

Cram expressions are documented here.

I hope this helps! Let me know if you have any further questions. Maybe Slack would be a better place, so that we can keep this issue on topic.

daveyarwood commented 3 years ago

In general, whitespace is not significant in Alda. ~There are a couple of exceptions, which I can explain later when I have time.~

The one exception is that a newline can end a variable definition. One line variable definition:

cScale = c8 d e f g a b > c

piano: cScale

Multi-line definition:

cScale = [
  c8 d e f
  g a b >
  c
]

piano: cScale

A variable definition becomes multi-line if you start an event sequence or cram expression and don't end it before the end of the line.

Unless I'm forgetting something, I think that's the only case where newlines are significant.