Create sweet tunes with rust
Currently this project is exists in a limbo between library and binary. The easiest way to try it out is to fork this repo and include_str!
your own file.
There are many attempts out there to represent sheet music in some kind of readable ascii but since none of them were to my liking i decided to make my own.
A good place to start is to define your key
Key:
K: [Pitch][Accidental]?(M? | m)
Currently the 30 major, M
, and minor, m
, keys are supported.
If no key is specified C major is assumed.
BPM sets the length of notes by defining how many beats (1/4th notes) are in a minute
BPM:
BPM: [u32]
If no BPM is specified 120 is assumed.
Signature defines the length of each bar
Signature:
[u32]/[u32]
If no Signature is specified 4/4 is assumed.
Optional bar lines can be used to force the program to validate that each bar is the proper length.
Even if bar lines are not used, bar length will be validated when Key, BPM or Signature is set to confirm that these are only changed between two bars.
To play music you need notes, now you have them
Note:
[Pitch][i32]?[Accidental]?[Duration]?
If silence is what you need you should rest
Rest:
R[Duration]?
All notes have a pitch
Pitch:
(A|B|C|D|E|F|G)
Change the pitch by half steps
Accidental:
(#* | b* | n)
Accidental will also be iferred by the key
Durations define the length of a note in fractions or sets thereof
Duration:
/([u32].*~?)+
The given fractional part(s) must be powers of 2