Implement repeats, variables & modules #7
Comments
|
Absolutely brilliant concept. +1 to this, would increase and improve the fork and brevity of this concept. Like shia said, JUST DO IT |
|
Thank you! This is fairly high up on my list of priorities, and I think should be fairly easy to implement. Hopefully will get to it soon. |
|
For repeats, what about using the sheet music symbols? Or perhaps syntactic repetition should be kept separate from melodic repetition. |
|
The idea with repeats is that you'll be able to repeat any arbitrary Alda code, not just notes. You'll be able to encase an entire section of code (or even your entire score) in parentheses and stick a That being said, though, I don't see any reason why we can't have it both ways. We can include both syntaxes for repeats in the grammar. |
|
@daveyarwood guessing the Seems like time is ripe for this feature now |
|
@crisptrutski Oh yeah, good point. We'll have to update our approach now that inline Clojure code is a thing. I think we should implement #104 (at least the I like the idea of representing things between
I'm not really 100% sure how the syntax should look. Maybe there should be brackets around Maybe the For modules, I never really liked the |
|
Have a suspicion that using a macro to repeat the nested code (and parsing repeat contents in the main grammar) will be simpler and more performant than leveraging |
|
re: extra brackets, think it would be nice not to require that. |
Oh yeah! You're probably right. It would be easier to just do the repetition as a transform step in the parser. |
|
Suggestions:
To simplify parsing code, I suggest disallowing spaces around operators. |
|
I'm working on implementing repeats now -- writing tests first so I can plan out exactly how they will work. @Deveritas hinted at the idea that maybe the two proposed syntax ideas for repeats ( Open question: should the number after the musical repetition operator mean "repeat this N times" or "play this N times total"? For example, should this: |
|
I also think the syntax should be |
I like this idea, too. We currently have a similar rule for naming instruments -- a valid name must start with at least two letters. I was planning on using the same rules for variables. It might be slightly tricky to get the parser to recognize variable names as different from instrument names (e.g. |
|
Apologies for jumping in. While I see the value in creating a syntax that follows the user model of sheet music, it may also be useful to consider a syntax that is simple to type (which may correlate with faster music composition times). I've played with syntax ideas for variables, note groups, repetition, sequence reversals, and pitch shift operations. All five of these ideas appear to be syntactically interconnected. After playing with this and actually creating a subset of the Alda in Windows, here is what I have found is simplest (e.g., the fewest characters), from a syntactical and key-pressing perspective: 1 . Variable names must start with two letters, and may optionally contain underscores ("_") and digits (as well as more letters) after the first two. This helps eliminate conflict with notes and octave specifiers (e.g., "o4", "c16", etc.). Variable names may not contain the dash, or minus character ("-"). 2 . Notes and variables can be grouped together and treated as a sequence. Grouping starts with a "[" and ends with a "]". For example:
3 . Groups can be embedded/nested inside other groups. For example:
4 . Groups can span multiple lines if necessary. 5 . Variable assignment syntax looks like this: variableName = {a group, or any sequence of notes or variables up to the end of the line} Examples:
Notice the definition of cChord uses a group of notes that spans two lines. To keep things simple syntactically, variable assignments are restricted to a single line. If you need more than one line to define what's stored in a variable, use the group delimiters as demonstrated here. 6 . Pitch modifiers ("+" and "-") optionally follow a group or variable and adjust the pitch of all the notes in that variable or note group. Pitch-shift modifiers can be followed by a number (e.g., "-7"), or the "+" and "-" operators can be repeated in any combination for as many semitones you need to adjust (just like Alda's syntax for flat/sharp semitone adjustment). Examples:
7 . Multipliers ("*") repeat the sequence of all the notes held in a variable or defined by a note group by the number of times specified. Just like the pitch operators, multipliers can be repeated (so three asterisks in a row means repeat the group or variable three times). Examples:
I feel strongly that the multiplier operator character should be an asterisk (and not the "x" character as suggested elsewhere) to avoid requiring the space between variable names and the multiplier. IOW, if the asterisk is my multiplier operator, I can write "cStomp*2". But if the "x" is my multiplier operator, I must write "cStomp x2". Forcing the space is inconsistent with Alda's note pitch-shift syntax (e.g., I can write "c+", and I'm never forced to write "c +"). 8 . Sequence reversals are indicated with the "!" operator and reverse the sequence of all the notes held in a variable or note group. Examples:
9 . Multipliers, reversals, and pitch operators can appear in any order after a variable or note group. Examples:
Using this suggested syntax, it would be possible to create relatively sophisticated songs with a just few lines of Alda code:
I also find that using pitch-shift operators, multipliers, and reversal operators, along with meaningful variable names makes it easier to see the structure of the song. |
|
@MillerMark Wow, there are a lot of great ideas here! It is a lot to take in at the moment, and will require further discussion and extended dev time to implement the ideas we want to bring in, but I do want to keep this conversation open. When I get a minute, I will go through your lists and make separate issues out of each idea, so we can discuss and/or implement them. I would prefer to just implement repeats, variables and modules in the scope of this particular issue. That being said, there is stuff here that is definitely worth talking about as I implement repeats, variables and modules. I like the idea of trying to leave out brackets when possible, e.g. when defining variables (on a single line) and then referencing them later. I'm beginning to warm up to the idea of As a Lisp enthusiast, I'm trying to convince myself that it's a good idea to disallow hyphens in variable names :) |
|
Bear with me -- I'm breaking out each idea in this thread (including each of repeats, variables and modules) into a separate issue, to help keep things organized :) |
|
OK, I've broken out this issue into no less than 5 separate issues! When I opened this issue way back in January, I had no idea it would be so wide in scope -- too wide, I think, to discuss sanely in a single issue. Hopefully I've done a good job of summarizing where we are on each issue. Please feel free to chime in on the individual issues if you have any additional insights. I'm really enjoying all the ideas this is generating! |
(None of these are yet defined in the grammar or implemented in the parser behavior.)
EDIT 9/30/15: See below for updated syntax ideas.
Repeats
Self-explanatory. e.g.
c1(~1)x7should expand toc1~1~1~1~1~1~1~1at compile time.Variables
Variables should work like they do in Lilypond. Any piece of code can be enclosed in brackets and defined as a variable, then called in the code any number of times, at any point in time.
Desired syntax:
Modules
Take the variable concept and apply it to entire files.
For example, each instrument's part could be written in a separate file in the same directory as a main file, then in the main file (say, "score.alda"), you could write something like:
and each of these statements would be replaced by the contents of each file at compile time.
This would be especially cool in that you could define custom instruments (e.g. custom synth instruments) as standalone files and then load them in as modules in any piece of music in which you'd like to use them.
NOTE: Modules might be a little tricky to implement and preserve line numbers for error reporting. Ideally we'd be able to report the line/column number and name of the file where the error occurred.
The text was updated successfully, but these errors were encountered: