Sync

Sectie 5.7 introduceerde de functies cue en sync om het synchroniseren van threads af te handelen. Wat niet werd uitgelegd is dat het het tijd toestand systeem is dat deze functionaliteit beschikbaar stelt. Eigenlijk is set een variatie op cue en bouwt voort op dezelfde kernfunctionaliteit: het toevoegen van informatie aan het tijd toestand systeem. Bovendien is sync ook zo ontworpen dat het naadloos samenwerkt met de tijd toestand - alle informatie die we van plan zijn op te slaan in de tijd toestand waarop we kunnen synchroniseren. Met andere woorden - * we sync-en op gebeurtenissen die nog moeten worden ingevoegd in de tijd toestand *.

Wachten op gebeurtenissen

Laten we kort kijken naar hoe sync gebruikt wordt om op nieuwe gebeurtenissen te wachten die worden toegevoegd aan tijd toestand:

in_thread do
  sync :bla
  sample :ambi_lunar_land
end
sleep 2
set :bla, 1

foo

Note that sync always waits for future events and that it will block the current thread waiting for a new event. Also, it will inherit the logical time of the thread which triggered it via set or cue so it may also be used to sync time.

Passing values into the Future

In het bovenstaande voorbeeld is ‘:bla’ op ‘1’ gezet om er vervolgens niets mee te doen. We kunnen de waarde ophalen van de thread door ‘sync’ aan te roepen:

in_thread do
  amp = sync :bla
  sample :ambi_lunar_land, amp: amp
end
sleep 2
set :bla, 0.5

Note that values that are passed through set and cue must be thread safe - i.e. immutable rings, numbers, symbols or frozen strings. Sonic Pi will throw an error if the value you are attempting to store in the Time State is not valid.