Updated smnp.audio.synth (markdown)

Bartłomiej Przemysław Pluta
2020-03-28 12:20:01 +01:00
parent 8aa5bc6306
commit dadd16f6d9

@@ -21,7 +21,7 @@ Or even use a new, _staff construction_ syntax:
```
synth($ 4/4 @c @d @e @f ||);
```
![](https://github.com/bartlomiej-pluta/Simple-Music-Notation-Processor/blob/master/img/notes/cdef.png)
[[notes/cdef.svg]]
### Rests
Rest is nothing but integer placed among the notes. Value of number determines rest's length and works similar to duration part of note literal. For example:
@@ -38,11 +38,11 @@ As long as rests are represented as integers, they don't supports dots which mak
Example of using rests:
```
notes = $ 4/4 @c @d 4 @ | @g @a 4, @c5 ||;
notes = $ 4/4 @c @d 4 @ | @g @a 4 @c5 ||;
synth(notes);
```
This code will play following notes:
![](https://github.com/bartlomiej-pluta/Simple-Music-Notation-Processor/blob/master/img/notes/cd4fga8c.png)
[[notes/cd4fga8c.svg]]
### Polyphony
You can have as many note staffs as you want and you are still able to merge them to one wave, that can be played later.
@@ -50,8 +50,8 @@ You can have as many note staffs as you want and you are still able to merge the
Both [[smnp.audio.synth#wave]] function and [[smnp.audio.synth#synth]] function accept multiple lists of notes as arguments. If you pass more than one list, all of them will be merged and normalised to achieve polyphonic effect.
Let's say you have following voices:
* ![](https://github.com/bartlomiej-pluta/Simple-Music-Notation-Processor/blob/master/img/notes/twinkle1.png)
* ![](https://github.com/bartlomiej-pluta/Simple-Music-Notation-Processor/blob/master/img/notes/twinkle2.png)
[[notes/twinkle1.svg]]
[[notes/twinkle2.svg]]
Notes above can be merged to one wave, as follows:
```
@@ -65,7 +65,7 @@ synth(twinkle1, twinkle2);
```
The result is:
![](https://github.com/bartlomiej-pluta/Simple-Music-Notation-Processor/blob/master/img/notes/twinkle3.png)
[[notes/twinkle.svg]]
### Tuplets
Tuplets can be achieved with [[smnp.music#tuplet]] function (and its derivatives, like [[smnp.music#triplet]] and [[smnp.music#quintuplet]]).
@@ -76,24 +76,25 @@ notes = $ 4/4 @g:2 @d5:2 | triplet(@c5:8, @h:8, @a:8) @g5:2 @d5 ||.flatten();
synth(notes);
```
the code will play following notes:
![](https://github.com/bartlomiej-pluta/Simple-Music-Notation-Processor/blob/master/img/notes/starwars.png)
Note, that because of using [[smnp.music#triplet]] function which produces a list, that we are nesting in our staff (which is actually also a list), we need to make our staff flat using [[smnp.collection#listflatten]] method.
The code will play following notes:
[[notes/starwars.svg]]
### Ties
Notes can be tied using `+` (plus) operator between `note` and `int`. This allows you to achieve arbitrary duration of note that you can meet in regular music sheets.
Example:
```
x = @c + 8;
println(x == @c:4d); # true
x = @c + 8 + 8;
println(x == @c:2); # true
notes = $ @c:2 @c5:2 + 2 @h:2 + 2 @a:2 @a @f @g:2 ||;
notes = $ @c:2 @c5:2 + 2 @h:2 + 2 @a:2 + 4 @f @g:2 ||;
```
[[notes/ties1.svg]]
```
println(@c + 4 + 8 + 16); # C4:(11/16)
```
[[notes/ties2.svg]]
Unfortunately, the _staff construction_ syntax doesn't allow you to tie notes across the measures. If you want to achieve that, you need to do some workarounds, like concatenating lists or getting rid of time signature in _staff construction_.
# Functions
## wave