Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Item Reorder

Post any examples or modules that you want to share here

Re: Item Reorder

Postby Nubeat7 » Tue Mar 17, 2015 3:18 am

tulamide wrote:I once saw a clamp solution that was so elegant and readable, that I want to share it here:
CODE: SELECT ALL
newId = [0, @id + @move, @order.length - 1].sort[1]


EDIT: You should never use a capital letter to start a variable!


thats a very beautiful solution, need to remember this the next time :), also about the capitals

Perfect Human Interface wrote:Once it reaches the end it wraps around to the beginning.

but it doesn't, it also rotates the whole array

Perfect Human Interface wrote:Your example throws an error right away when I load it. I'm using 3.0.4; not sure if that's relevant.


which error? its working here with 3.06 maybe you need to init @select?
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: Item Reorder

Postby RJHollins » Tue Mar 17, 2015 3:47 am

Would someone describe/explain what a 'clamp solution' means/does or what the purpose/need ?

Something 'elegant' and 'readable' are always of great interest :lol:

thx
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: Item Reorder

Postby Perfect Human Interface » Tue Mar 17, 2015 7:40 am

Nubeat7 wrote:
Perfect Human Interface wrote:Once it reaches the end it wraps around to the beginning.

but it doesn't, it also rotates the whole array


You're misunderstanding the logic. When you shift the item all the way around back to the beginning the array won't return to the original order, it will be rotated. It's correct; a natural consequence of reordering items in this manner.

which error? its working here with 3.06 maybe you need to init @select?


Yeah, clicking the @select input seemed to take care of it.
Perfect Human Interface
 
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: Item Reorder

Postby tulamide » Tue Mar 17, 2015 8:34 am

RJHollins wrote:Would someone describe/explain what a 'clamp solution' means/does or what the purpose/need ?

It means exactly what the term indicates: A clamp function takes care that a value is always between a minimum and a maximum value (including both). For example, if you clamp 3 between 2 and 4, the result is 3, but clamping 3 between 4 and 6 returns 4.

The beauty of this solution lies in the clever use of the sort-method, that come with Ruby arrays. The value, min and max build an array that is then sorted. And from the resulting array the second index is returned. As an example, clamping 3 between 4 and 6 with sort:
[6, 3, 4).sort -> returns [3, 4, 6] -> from that array the second entry is taken -> 4

Nubeat7 wrote:but it doesn't, it also rotates the whole array
That's why I said in my other post, that it's not really shifting nor swapping.
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Item Reorder

Postby Nubeat7 » Tue Mar 17, 2015 11:42 am

Perfect Human Interface wrote:You're misunderstanding the logic. When you shift the item all the way around back to the beginning the array won't return to the original order, it will be rotated. It's correct; a natural consequence of reordering items in this manner.


you are are right i don't see some logic in this behaviour, why should the array rotate when the item is moved from the beginning to the end? i don't see any "natural" logic there...
you also said:
Perfect Human Interface wrote:Well, semantics... I think "shifting individual items up and down" is straightforward enough. It's not meant to shift the whole array, of course.

but if you intended it like this, sure, it will be a feature then, not a bug :)

maybe you should explain this in the description then, that people don't get confused what it really should do.

if you want to wrap the item when moving it beyond the array borders, the insert methode would be the better soultion, this is how i understand it
Attachments
ArrayReorder_wrap.fsm
(689 Bytes) Downloaded 995 times
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: Item Reorder

Postby Nubeat7 » Tue Mar 17, 2015 12:58 pm

tulamide wrote:The beauty of this solution lies in the clever use of the sort-method, that come with Ruby arrays. The value, min and max build an array that is then sorted. And from the resulting array the second index is returned. As an example, clamping 3 between 4 and 6 with sort:
[6, 3, 4).sort -> returns [3, 4, 6] -> from that array the second entry is taken -> 4


thanks for the explaining tulamide, you can find this methode also inside the stock knobs, don't know how often i saw it and never thought about how fancy this methode is or how it works :D
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: Item Reorder

Postby Perfect Human Interface » Tue Mar 17, 2015 7:31 pm

Nubeat7 wrote:you are are right i don't see some logic in this behaviour, why should the array rotate when the item is moved from the beginning to the end? i don't see any "natural" logic there...


It's just what happens when you apply this kind of swap/displacement logic circularly. Just like when you move one item down, the items below it shift up; this is that happening but wrapped across the borders. So whether or not that's "desired" that's what this logic gets you. (I have a major-brand synth plugin that has this behavior, for what it's worth.)

if you want to wrap the item when moving it beyond the array borders, the insert methode would be the better soultion, this is how i understand it


This is a really good solution though, maybe better. I'll have to see if I can wrap my brain around this to apply it to the other method (list of positions) and maybe add it to the original post.
Perfect Human Interface
 
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Previous

Return to User Examples

Who is online

Users browsing this forum: No registered users and 43 guests