Building a music DSL in Elixir
Now that we know the fundamentals of metaprogramming in Elixir, let’s build a DSL. This DSL will be used to compose music using Elixir.
Here are the features of the DSL that we will be building:
- The DSL will provide a simple interface to compose music using Elixir
- It will utilize the
ALSA
aplay
command to play a note - The DSL should be able to define a sequence of notes so that the sequence can be reused throughout the track
- A note should have the following attributes:
- A class:
C
,D
,E
,F
,G
,A
,B,
orrest
- A modifier:
sharp
orbase
- A duration in seconds
- A volume
- An octet to determine the final frequency
- A class:
- A sequence should be able to embed notes from another sequence
- The DSL should be easy to read, idiomatic, and deterministic
Now, let’s come up with the shape of the DSL.
One of my favorite DSLs in Elixir is the Phoenix router. The interface is very simple and easy to learn, while still giving a lot of transparency...