Multimode Pad Array?

Discuss Lemur and share techniques.
Joe Soap
Regular
Posts:475
Joined:07 Jul 2012 15:04
Multimode Pad Array?

Post by Joe Soap » 15 Jul 2014 16:04

So . . . there's this little gem here by AB, the three-state-button:

https://forum.liine.net/viewtopic.php?f ... 263&p=5197

. . . and I was wondering how to code this up as an array?

i.e. A row of (say) four pads, where each pad steps through its own mde / state changes without affecting the other pads in the array.

I thought this would be simple, but I cannot brain! :D

oldgearguy
Regular
Posts:315
Joined:02 Nov 2013 11:19

Re: Multimode Pad Array?

Post by oldgearguy » 15 Jul 2014 17:10

conceptually - a 2 dimensional array -- 4x3

I'd start by changing the count() script from id += 1 to id[firstof(x)] += 1
inside process(), I'd continue the change to id with id[firstof(x)] %= MAX; and stateColors[id] becomes stateColors[id[firstof(x)]], etc for the rest

I'd most likely assign id[firstof(x)] to a local variable, just to save typing.

(this is off the top of my head looking at the raw jzlib - no Lemur editor in sight here to test it)

Note that this would be a "I'm using it and know not to press 2 buttons at once" thing. If you're releasing it to someone else, you just might want to play it safe and decl i; and do a for (i=0; i < 4; i++) { } loop around all uses of id instead of using firstof(x). This approach would brute force the updates across all 4 pads even if a user pressed all 4 at once.

Joe Soap
Regular
Posts:475
Joined:07 Jul 2012 15:04

Re: Multimode Pad Array?

Post by Joe Soap » 15 Jul 2014 18:07

Thanks fella. :)

Yeah, I'll need it to be robust enough to accept simultaneous input from the pads so a looping structure was always gonna be needed, and I figured it would boil down to firstof(x) etc - it's just I was using a completely different example template / jzlib to work from when dealing with the pads array that involved use of nonnull . . . and it totally threw me.

I'll give this a shot, see if my brain has returned from its temporary sabbatical in dev null! :D

oldgearguy
Regular
Posts:315
Joined:02 Nov 2013 11:19

Re: Multimode Pad Array?

Post by oldgearguy » 15 Jul 2014 18:23

Joe Soap wrote:Thanks fella. :)

Yeah, I'll need it to be robust enough to accept simultaneous input from the pads so a looping structure was always gonna be needed, and I figured it would boil down to firstof(x) etc - it's just I was using a completely different example template / jzlib to work from when dealing with the pads array that involved use of nonnull . . . and it totally threw me.

I'll give this a shot, see if my brain has returned from its temporary sabbatical in dev null! :D
To handle multiple pad presses, firstof(x) isn't good. You have to be boring/unclever and do id += 1 inside the for() loop then later on in process() similar slogging: id %= MAX; and the setattributes() inside the for loop. The side effect is that you're (re)setting the color for pads that haven't changed to their same value.

Joe Soap
Regular
Posts:475
Joined:07 Jul 2012 15:04

Re: Multimode Pad Array?

Post by Joe Soap » 15 Jul 2014 18:54

Ahhh - resetting the colour on pads not pressed / not same value would be a problem, negating the whole purpose in fact.

It's not that I particularly want it to handle simultaneous presses - it's instead the case that I want each pad in the array to only effect itself and not its neighbours, a natural consequence of which would be that simultaneous presses were handled robustly?

So . . . I think I need a separate array / variable to track state for each pad[i] at the very least? The idea being I can manipulate colour according to the individual state of the array element - which I can already do, just not moderated via any 'state' flag.

Anyway, you've set me on the right road i think, cheers.

oldgearguy
Regular
Posts:315
Joined:02 Nov 2013 11:19

Re: Multimode Pad Array?

Post by oldgearguy » 16 Jul 2014 00:38

It won't reset the colors, it will set it to whatever the current x value is, I think. Have to play with it, like you said.

Joe Soap
Regular
Posts:475
Joined:07 Jul 2012 15:04

Re: Multimode Pad Array?

Post by Joe Soap » 16 Jul 2014 05:14

Heh, yeah. played with it and I've got it working about as far as all that - with the upshot that it does indeed reset the state on new presses . . . and also for unpressed pads. But that's okay, I can probably (hopefully!) sort that.

Total brain failure on my part, having not looked at Lemur for the duration of the World Cup. Thanks for the kickstart.

That . . . was a lot of football.

lABl
Lemur Guru
Posts:269
Joined:09 Dec 2011 15:56
Contact:

Re: Multimode Pad Array?

Post by lABl » 16 Jul 2014 05:49

Hi There,

@Joe , that example in particular is not ready to work with arrays, and as oldgearguy mentioned it uses firstof(x) which is not ideal if you click several pads simultaneously, check attachment for an example with arrays.

Hope that helps.

Cheers
Last edited by lABl on 17 Jul 2014 09:56, edited 1 time in total.

Joe Soap
Regular
Posts:475
Joined:07 Jul 2012 15:04

Re: Multimode Pad Array?

Post by Joe Soap » 16 Jul 2014 18:17

Yup - I had a semi-working version using a loop and nonnull but it had problems resetting itself, among other niggles . . . but this is perfect.

Exactly what I asked for, thanks a bunch Antonio! :)

Now to see if I can (AB)use (:D) it beyond stock config!

lABl
Lemur Guru
Posts:269
Joined:09 Dec 2011 15:56
Contact:

Re: Multimode Pad Array?

Post by lABl » 17 Jul 2014 10:12

Cool, glad that helps Joe!

Ya, initialization is a bit tricky sometimes in lemur.

In reponse to how to (AB)use :lol: of this gem, it's easy though, only two steps are required:

1- Sets the num of states in statesNum variable, you asked for 3 states button, so type 3 there, padValues will return an array where each element will rotate its value 0..1..2

2- On changecolors() script, fill "myColors" array with the colors you want for each state, it's easy!

Cheers man, hope that helps.

btw- redownload the module, I've updated it to works with 3 states by default.
Attachments
AB Rotate Pads Color.jzlib
(3.56KiB)Downloaded 85 times

Post Reply