Kyma Forum
  Tips & Techniques
  Randomly select from a subset of a collection

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   Randomly select from a subset of a collection
SSC
Administrator
posted 19 December 2006 20:34         Edit/Delete Message   Reply w/Quote
Q: I would like to randomly select from a collection of values. But I would like to be able to eliminate some of the values from consideration, based on switches or toggles that I control from the VCS.

A: If you paste the following code into a SoundToGlobalController, it will generate indexes of randomly selected switches, choosing ONLY from among those switches that are currently turned ON. Then you can use these index values to look up other values from an array.

For the code, please see the tweaky: http://www.symbolicsound.com/cgi-bin/bin/view/How/RandomSelectFromSubset

IP: Logged

JackRosete
Member
posted 20 December 2006 08:47         Edit/Delete Message   Reply w/Quote
Great code! Found a Smalltalk resource on the web that explains some of the more esoteric code, like inject: into: etc.
http://www.ifi.unizh.ch/richter/Classes/oose2/01_Collections/03_smalltalk/03_smalltalk.html#4%20Using%20inject:into:

IP: Logged

SSC
Administrator
posted 20 December 2006 10:33         Edit/Delete Message   Reply w/Quote
See also page 379 of Kyma X Revealed: "Messages for iterating over the contents of collections"


IP: Logged

cristian_vogel
Member
posted 08 January 2007 05:32         Edit/Delete Message   Reply w/Quote
i was working on this variation , which steps through only the switches that are on, rather than jumping randomly around them.

| ctrls index count step expr tick |

ctrls := {(1 to: 8) collect: [ :i | !sw suffix2: i]}.

index := EventVariable new.

tick := 1 bpm: !BPM.

count := ctrls inject: 0 into: [ :a :b | a + b asLogicValue].

step := tick countTriggersMod: count.

expr := (index <+ (step + 1)), 0.


ctrls do: [ :sw |
expr := expr,
(sw
true:
(((index <~ (index - 1)) eq: 0)
true: (ctrls indexOf: sw)
false: nil)
false: nil)].

expr

It works fine, but there is often a rhythm jump when a switch comes in and out - I wanted to make it only execute the block

count := ctrls inject: 0 into: [ :a :b | a + b asLogicValue].

if tick was on the positive edge of its trigger cycle - but I ran up against ' HotVariables cannot ... ' every time I tried to make a conditional to check the status of the tick ( whether logic high or low )

Could SSC suggest a way of doing this?

IP: Logged

cristian_vogel
Member
posted 08 January 2007 06:43         Edit/Delete Message   Reply w/Quote

RhythmicArrayExplorer.kym

 
2nd attempt to post attachment...


I made a sound from the modulo stepping version of the code above, it is great for exploring interesting poly-rhythms and how they can be generated from simple pitch and volume and accenting.


IP: Logged

SSC
Administrator
posted 08 January 2007 13:36         Edit/Delete Message   Reply w/Quote
| ctrls index count step expr tick |

index := EventVariable new.
tick := 1 bpm: !BPM.
ctrls := ({(1 to: 8) collect: [ :i | !sw suffix2: i]}) collect: [ :ctrl | tick sampleAndHold: ctrl].
count := ctrls inject: 0 into: [ :a :b | a + b asLogicValue].
step := tick countTriggersMod: count.


Try replacing the beginning part of the code with this and see if it does what you want. This will make it so that the stepping code sees the switches change only on the beat.

[This message has been edited by SSC (edited 08 January 2007).]

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply

Contact Us | Symbolic Sound Home

This forum is provided solely for the support and edification of the customers of Symbolic Sound Corporation.


Ultimate Bulletin Board 5.45c