alda-lang / alda-core

The core machinery of Alda
80 stars 26 forks source link

Unclear semantics for markers within repeated sequences #88

Closed dhpiggott closed 4 years ago

dhpiggott commented 4 years ago

It isn't to me clear from the documentation for markers and sequences/repetitions whether they are supported in combination, and if so what the semantics are, but given the documentation at https://github.com/alda-lang/alda/blob/master/doc/markers.md#markers my best guess would be to expect both repetitions of the following to render in the same way:

cello: o3 [%steps c d e f g a b > c @steps c < b a g f e d c]*2

The first repetition renders as I would expect it to (the two scales play simultaneously), but the second repetition renders as though the marker reference isn't there (the ascending scale plays first, followed by the descending scale).

I realise this may be a particularly pedantic issue to raise - so if you'd prefer I didn't, please tell me and I'll hold fire on any more!

A bit more context for how/why I found this and the others that I've opened: I started experimentally building something for programmatic music generation in Scala a few months ago and, happily, discovered Alda Lang soon after starting. Rather than attempting to reinvent the wheel by defining my own DSL, I'm effectively trying to write a clone of (parts of) Alda in Scala. I'm mostly using the docs in https://github.com/alda-lang/alda/blob/master/doc (as opposed to reading the source), which puts me in a mindset where I find ambiguities/edge cases!

daveyarwood commented 4 years ago

I do appreciate these issues - please keep them coming!

I've never intended for markers to be used inside of repeated figures. The idea is that a marker represents a single moment in time. I suppose it might make sense to make it a compile-time error if a marker is encountered in a context like this, I just haven't bothered to do so.

Out of curiosity, I tried running your example using the WIP ground-up rewrite of Alda (Alda v2), and it actually happens to work the way you're expecting it to work! I didn't plan it that way, it just happens to work. But I guess I have some thinking to do about whether that's the way I really want it to work.

Something that makes this especially interesting is that I did have a thought, a while back, about using markers as a way to synchronize parts during a live-coding session. In a setting like that, it would actually be really convenient to have a named point in time that a new part could "latch onto" so that it starts exactly in sync with the existing parts. Imagine that you had an infinitely looped bass line, something like:

This "infinite loop" syntax is imaginary. It'll happen someday in the not-so-distant future!

electric-bass:
  [ %sync o1 g4. > d4. f4 |~4. d8 f4 g ] **

Then, while the bass line is looping, let's say you want to add a drum pattern, but you want the first note to line up exactly with the first note of some repetition of the bass line. You don't care which repetition, it's just important that it lines up exactly with the %sync marker, the next time it rolls around in the loop. So, maybe you could add the drum pattern like this:

midi-percussion:
  @sync [ ... notes go here ... ] **

That's just an off-the-cuff idea from a while back. My point is, it's quite possible that at some point in the future, it will make sense to use markers inside of repeated figures. For now, it's not something that Alda officially supports, and I don't think it's very useful in the absence of the live coding feature that I described above.

In the case of your example, you could use voices instead, like this:

cello:
  [V1: o3 c d e f g a b > c
   V2: o3 c < b a g f e d c]*2
daveyarwood commented 4 years ago

By the way, keep me in the loop about your Scala music generation project, it sounds very interesting! Especially if it builds on top of Alda, naturally :)

I wrote an article recently that I think you might find useful: Implementing an Alda library. It's all about how Alda can be used as not just a language, but as a platform for programmatic composition and live coding, and how you can write an idiomatic library in any programming language that drives Alda to make music programmatically. So far, libraries have been implemented in Clojure and Ruby. It would be awesome to add Scala to that list!

dhpiggott commented 4 years ago

I've never intended for markers to be used inside of repeated figures. The idea is that a marker represents a single moment in time. I suppose it might make sense to make it a compile-time error if a marker is encountered in a context like this, I just haven't bothered to do so.

Yup that makes sense - I was also thinking a compile-time error could be another way to define the behaviour in this context.

Out of curiosity, I tried running your example using the WIP ground-up rewrite of Alda (Alda v2), and it actually happens to work the way you're expecting it to work! I didn't plan it that way, it just happens to work. But I guess I have some thinking to do about whether that's the way I really want it to work.

Oh that's cool! My Scala WIP handles it this way too - and not really by design, but just because that's the way I've handled sequence rendering. I'm not super attached to this interpretation but for now at least I think I'll keep this behaviour because it is consistent with one version of Alda. But if you decide it should work another way I'd definitely want to update my implementation to maintain some consistency.

In the case of your example, you could use voices instead, like this:

I thought you might tell me that :) This sample is just part of a test score I'm building up for the manual testing I'm doing. I'd already written the equivalent using voices - I just repeated it this way as a test case for markers.

By the way, keep me in the loop about your Scala music generation project, it sounds very interesting! Especially if it builds on top of Alda, naturally :)

It's still very much WIP, and I need to acknowledge what I've borrowed from Alda Lang, but if you want to look at what I've done so far it's on GitHub here: https://github.com/dhpiggott/apollo (I also need to make sure I actually have a go at making some music with it rather than spending all the time adding to it!)

I wrote an article recently that I think you might find useful: Implementing an Alda library. It's all about how Alda can be used as not just a language, but as a platform for programmatic composition and live coding, and how you can write an idiomatic library in any programming language that drives Alda to make music programmatically. So far, libraries have been implemented in Clojure and Ruby. It would be awesome to add Scala to that list!

I read it around the time I read https://blog.djy.io/alda-a-manifesto-and-gentle-introduction/ and a couple of your other Alda posts - which are what made me realise I should borrow as much as I can from Alda! :)

The reason I'm doing what I'm doing in Scala is because the two things I want to do with the project are:

  1. Develop my understanding of music and have some fun with it (I realise I could do this using Alda alone).
  2. Develop a somewhat complex Scala app of my own, as a CPD project of sorts (I'm a Scala developer but I'm less hands on at work these days). My hunch was that writing a library wouldn't be enough complexity for that goal.

I hadn't realised you're working on a v2. I just took a look at https://github.com/alda-lang/alda/compare/v2 - it looks really interesting. I'll be keen to read more about it!

daveyarwood commented 4 years ago

I had a quick look at Apollo - looks neat, nice work so far!

I haven't written much at all "officially" about Alda v2, but if you're curious, probably the best way to learn about the big picture (Why am I rewriting Alda from scratch? Why Go and Kotlin instead of Clojure? How does Clojure fit into the picture now? etc.) is to watch this talk I gave at Strange Loop last year. Alda v2 still has a little ways to go, but as of right now, it can pretty much do all of the things that Alda v1 can do, and it has a number of added benefits that I'm really excited about. Hopefully I'll get to writing about those soon!

Hope it's OK if I close this issue - we can always reopen it if there's further discussion to be had about markers in repeated sequences!

dhpiggott commented 4 years ago

I had a quick look at Apollo - looks neat, nice work so far!

Thank you!

watch this talk I gave at Strange Loop last year

Nice - watched!

Hope it's OK if I close this issue - we can always reopen it if there's further discussion to be had about markers in repeated sequences!

Absolutely!