GTCMT / DataToMusicAPI

MIT License
27 stars 5 forks source link

add: interleave #16

Closed taylorbf closed 5 years ago

taylorbf commented 7 years ago

This is an interleave function I added to my fork. It may be different than what you are planning! There are a lot of options for interleaving. But I wanted to share this in case it is similar to what you expected.

This approach allows an optional ‘depth’ for each array, which is the number of items from that array that are used before alternating.

Given:

a = dtm.data(1,2,3,4)
b = dtm.data(5)

Example 1:

a.interleave(b)
// => [1,5,2,5,3,5,4,5]

Example 2:

a.interleave(b,2)
// array1 depth is now 2
// => [1,2,5,3,4,5]

Example 3:

a.interleave(b,1,3)
// array1 depth is 1
// array2 depth is 3
// => [1,5,5,5,2,5,5,5,3,5,5,5,4,5,5,5]
ttsuchiya commented 7 years ago

Sorry for the slow response... I added the above code in dtm.data (in data.js:3335; not using transform.js). The results are not quite exact as your examples, so perhaps you could help me fixing them (either edit the code or change the specs). You can also utilize the unit tests (test/data.spec:52). I'm adding you as a collaborator in GH.