slurmulon / gig

:sound: Bach player for JS
MIT License
1 stars 0 forks source link

Support contextual collections #9

Closed slurmulon closed 3 years ago

slurmulon commented 6 years ago

We need to be able to nest intervals that process collections of elements. For example:

@Time = 4|4

:Scales = [
  2 -> Scale('C Lydian')
  2 -> Scale('G Ionian')
]

:Chords = [
  2 -> Chord('Cmaj7')
  2 -> Chord('Gmaj7')
]

!Play {
  :Scales
  :Chords
}

In the Set ({}), the :Scales and :Chords will overlap and will be played at the same time.

In the nested List ([]), each Chord or Scale will be played for 2 measures at a time using their own contextual/internal timers.

The simplest way I know to do this is to introduce a recursive "context" abstraction.

This will also require changes to bach, such that Sets can be defined without a duration value.

slurmulon commented 6 years ago

A less-than-ideal but easier solution is, on each beat, to simply loop through each element in the Set and invoke their callbacks. The downside is that this only works on one level, breaking recursion / hierarchy.

A hybrid approach is also possible. Loop through each element in the Set, and for each element we invoke a contextual step call (would still require step to be refactored).

slurmulon commented 3 years ago

This is now supported in bach v3.