Wanneer je informatie haalt (‘get’) van de Time State of gegevens in de Time State vastlegd (‘set’), kun je ook complexere waarden gebruiken dan de basissymbolen zoals ‘:foo’ en ‘:bar’. Je kan bijvoorbeeld paden in een URL-stijl gebruiken zoals ‘/foo/bar/baz’. Zodra we zulke paden gaan gebruiken, kunnen we voordeel halen uit de slimme patroonherkenning van Sonic Pi, zodat we met vergelijkbare (‘similar’) in plaats van precies gelijke (‘identical’) paden kunnen halen (‘get’) en synchroniseren (‘sync’). Laten we eens kijken.
Let’s assume we want to wait for the next event that has three path segments:
sync "/*/*/*"
This will match any Time State event with exactly three path segments, regardless of their names. For example:
cue "/bla/bar/baz"
cue "/bla/baz/quux"
cue "/eggs/beans/toast"
cue "/moog/synths/rule"
However, it will not match paths with fewer or more path segments. The following will not match:
cue "/bla/bar"
cue "/bla/baz/quux/quaax"
cue "/eggs"
Each *
means any content. So we could match paths with just one segment with /*
or paths with five segments with /*/*/*/*/*
foo
cue "/bla/bar/baz"
cue "/bla/baz/baz"
cue "/bla/beans/baz"
However, it wouldn’t match the following:
cue "/bla/flibble/baz"
cue "/bla/abaz/baz"
cue "/bla/beans/baz/eggs"
foo
foo
cue "/bla/bar/baz"
cue "/bla/bar/beans/baz"
cue "/bla/baz"
cue "/bla/a/b/c/d/e/f/baz"
You can use the ?
character to match against a single char such as "/?oo/bar/baz"
which will match:
cue "/bla/bar/baz"
cue "/goo/bar/baz"
cue "/too/bar/baz"
cue "/woo/bar/baz"
foo
cue "/bla/bar/quux"
cue "/bla/beans/quux"
cue "/bla/eggs/quux"
foo
cue "/bla/aux/baz"
cue "/bla/bux/baz"
cue "/bla/cux/baz"
foo
cue "/bla/aux/baz"
cue "/bla/bux/baz"
cue "/bla/cux/baz"
cue "/bla/dux/baz"
cue "/bla/eux/baz"
When calling sync
or get
you are free to combine matchers in any order you see fit to powerfully match any Time State event created by cue
or set
. Let’s look at a crazy example:
sample :loop_amen
For those curious, these matching rules are based on the Open Sound Control pattern matching specification which is explained in detail here: http://opensoundcontrol.org/spec-1_0