daveyarwood / alda-clj

A Clojure library for live-coding music with Alda
Eclipse Public License 2.0
63 stars 4 forks source link

Questions regarding the two alda syntaxes. #1

Closed abhi18av closed 5 years ago

abhi18av commented 5 years ago

I was trying to translate the contents of the alda-tutorial from the alda-music-notation syntax to alda-clj syntax. However, I am not quite sure how could I convert the following syntaxes translate into the alda-clj lisp syntax

  1. | - Bar

I know that it's not semantically useful but still it'd be nice to have a visual separater even in the alda-clj based music code generation.

  1. c.. - Dotted notes

  2. c+1 - Ties

  3. e-8

  4. ~ - Tilde

  5. Marker names like

    chorus
    voiceIn
    last-note
    verse(2)
    bass+drums

Could you please guide me a bit here?

daveyarwood commented 5 years ago

Sure! These are all supported in alda-clj.

Barline

(play!
  (part "piano")
  (for [letter [:c :d :e :f]]
    (note (pitch letter)))
  (barline)
  (for [letter [:g :a :b]]
    (note (pitch letter)))
  (octave :up)
  (note (pitch :c)))

;;=> "piano:\nc d e f | g a b (octave :up) c"

(BTW, I just noticed a bug -- I intended for (octave :up) to generate >! I'll fix that.)

Dotted notes

(play!
  (part "piano")
  (note (pitch :g) (note-length 4 {:dots 2})))

;;=> "piano:\ng4.."

Ties

The model here is that you can tie together multiple duration components. A duration component is either a (note-length ...) or a number of milliseconds (ms ...), and you can tie duration components together by passing them as arguments to (duration ...).

(play!
  (part "piano")
  (octave 2)
  ;; A double-dotted quarter note, tied to an eighth note, tied to a note 456ms
  ;; long, tied to a "sixth" note. Try writing THAT in standard musical
  ;; notation!
  (note (pitch :c) (duration (note-length 4 {:dots 2})
                             (note-length 8)
                             (ms 456)
                             (note-length 6))))

;;=> "piano:\no2 c4..~8~456ms~6"

E flat eighth note

(play!
  (part "piano")
  (note (pitch :e :flat) (note-length 8)))

;;=> "piano:\ne-8"

Tilde

There are technically two uses of tildes in Alda. One is ties, see above.

The other is slurs. If you're not familiar with the term from standard notation, a slur is when you leave as little gap as possible between the end of one note and the start of the next. Brass/woodwind players can do this by just not attacking the second note; they breathe out continuously through all of the notes and move their fingers so that the notes flow smoothly together. On a string instrument like violin or guitar, you can attack the first note with your bowing/picking hand, and then move your fretting hand while the note is still ringing out.

The reason I chose to use tilde for both of these concepts is that they look identical in sheet music: a slur or a tie is basically a big parenthesis above or below a group of notes, and it's considered a tie if the notes are all the same pitch, because at that point you're just adding the durations of the notes together to form one note that is the sum of their durations.

Example of slurring in alda-clj:

(play!
  (part "piano")
  (for [letter [:c :d :e :f]]
    (note (pitch letter) (note-length 8) :slur))
  (note (pitch :g) (note-length 2)))

;;=> "piano:\nc8~ d8~ e8~ f8~ g2"

I think it's worth noting that this does the same thing as setting quantization to 100 (the highest value), indicating that the notes should be played as "fully" as possible, i.e. with as little gap as possible between the notes:

(play!
  (part "piano")
  (quant 100)
  (for [letter [:c :d :e :f]]
    (note (pitch letter) (note-length 8) :slur))
  (quant 90)
  (note (pitch :g) (note-length 2)))

;;=> "piano:\n(quant 100) c8~ d8~ e8~ f8~ (quant 90) g2"

Markers

(play!
  (part "piano")
  "o4 c8 d e f"
  (marker "here")
  "g2"

  (part "electric-bass")
  (at-marker "here")
  "o2 g2"

  (part "trombone")
  (at-marker "here")
  "o3 b2")

;;=> "piano:\no4 c8 d e f %here g2 electric-bass:\n@here o2 g2 trombone:\n@here o3 b2"

(BTW, you can include plain strings of Alda code inside of play! as a shorthand! I did that above.)

daveyarwood commented 5 years ago

I just wrote a Getting Started guide which should hopefully make usage of alda-clj (at least the basics) more clear. I hope it's helpful!

abhi18av commented 5 years ago

Hi @daveyarwood , I've gone through the new library and the docs! I find them to be amazing to start with Alda 👍

Thanks 😄