tmhglnd / mercury

A minimal and human-readable language and environment for the live coding of algorithmic electronic music.
http://www.timohoogland.com/mercury-livecoding
GNU General Public License v3.0
292 stars 13 forks source link

Ring every() accepting floats #23

Closed GuillemGongora closed 4 years ago

GuillemGongora commented 4 years ago

I was wondering if ring every() could accept floats (or fractions) to have rings played other than every full bars.

tmhglnd commented 4 years ago

Good idea! Will surely be possible

tmhglnd commented 4 years ago

This is now possible (or was already possible...? Not sure) since all ring methods moved to the NodeJS total-serialism package. Here is how it works:

every(<ring> <bars> <division> <offset>)

bars (multiply by division) : default = 4
division (length of 1 bar)  : default = 16 
offset (in bars)            : default = 0

The resulting output length is bars * division

ring rtm [1 0 0 1 1]

// default note division is 16
ring barRtm every(rtm 1)
//=> [1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0]
ring rtm [1 0 0 1 1]

// default note division is 16
ring barRtm every(rtm 1.5 8 0.5)
//=> [0 0 0 0 1 0 0 1 1 0 0 0]