randomize radio switch select

Discuss Lemur and share techniques.
Post Reply
drewboles
Newbie
Posts: 20
Joined: 01 Feb 2012 19:03

randomize radio switch select

Post by drewboles »

Hey everybody -
I'm wondering if there is an easy way to randomize which of 16 radio-engaged switches gets selected. I basically have a bank of presets, and it would be nice to have a random button that randomizes which one gets chosen. Any recommendations? Thanks!

Drew
blablub
Newbie
Posts: 1
Joined: 04 Jun 2012 18:01

Re: randomize radio switch select

Post by blablub »

I do have the exakt same question... anybody?
bxsj
Regular
Posts: 116
Joined: 24 Dec 2011 06:47
Location: Vienna

Re: randomize radio switch select

Post by bxsj »

Attached is an example. Hope that helps.
BxSj
Edit: Attachment removed, see below.
Last edited by bxsj on 08 Jun 2012 18:58, edited 1 time in total.
Win7 64, Ipad Lemur, Cubase6 and a bunch of Roland Synths and Samplers
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: randomize radio switch select

Post by Macciza »

Hi
Was going to post something - similar to yours but slightly more minimal . . .

Instead this provides an opportunity for comment on program design approachs.
There are many ways to achieve the same thing in programming - Lemur is no exception.

In bxsj's example there is a pad and a bank of radio-switches - the pad randomly selects a switch
In this case the Pad itself has the code to change the switch - I would call this a 'procedural' approach
if something else wants to change it you copy the code; to change something else you edit it etc . ..

Looking at them as 'objects' - it becomes a bit different - Let's focus on the Pad/Switches object relationship instead. . .
I am a Pad - I tell people my value when it is changed
I am a Switch - I know my value and I can change and display my values

So now we could take that same script out from the Pad and put it in the Switch as a rand_sel script.
If you set it to execute on Pads.x you have essentially the same situation as previously except local to the Switches.
Ofcourse now if you want some thing else to change it you have to add logical condition to the execution mode

The other option is to make the above script a manual script / function, instead of executing on Pads.x
Then add an action script to the Pad - that calls the Switches.rand_sel function.
This Switches.rand_sel function could then be called from anywhere very easily

Hope that makes some sense
MM
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
bxsj
Regular
Posts: 116
Joined: 24 Dec 2011 06:47
Location: Vienna

Re: randomize radio switch select

Post by bxsj »

Hi Macciza,

I just read your post, point taken. My example is an example of bad design :oops: At least I'd call it an convoluted shot from the hip :roll:
Here is the approach you described, which makes the example more elegant and comprehensive.
Humble and ashamed,
BxSj
Attachments
test9.jzml
(4.28 KiB) Downloaded 107 times
Win7 64, Ipad Lemur, Cubase6 and a bunch of Roland Synths and Samplers
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: randomize radio switch select

Post by Macciza »

Hi Bxsj
No worries, Not necessarily bad, or convoluted - just somewhat procedural in perspective . . .
And nothing really 'wrong' with it - if it works, it works (finer points of code efficiency put aside)

It just allowed a good example to show differing ways of approaching problems and putting together solutions for people new to coding . . .
Procedural is often very hands on and quick to get something ie the Pad randomises the Switches - pretty straight forward, code away . . .
But the 'object' thinking often takes that little while longer, and sometimes is not immediately visible as needed
When one brings re-usability into the equation the object approach really comes to the fore - ie getting other things to trigger the randomising script.
I think I had my random function under the Switches so you end up doing Switches.random sort of thing, but external is good to - I like the idea of a functions container here
I guess the next stage of refactoring as a global function might be to make a function that you could hand any object to, and say randomise this, and it would . . .

I guess looking up Object-Oriented vs Procedural Programming would help some people here,
Also Model View Controller approach might help conceptually - though there are several versions of this, I don't mind Apples view here
Basically a View takes User input and sends it to a Controller that updates the Model and notifies the Controller that then gets the View to update.

So nothing to be humbled or ashamed for, you should be proud of having provided a solution,
I'm glad you did, I had been quite busy of late and not on as much or had time to answer as many questions.

cheers
MM
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
Post Reply