MartinusMagneson's picture
Shared by on 2018.04.01 15:24

The node set consists for now of eleven nodes (5 unique, and 2 sets of convenience nodes).

Sort with index

This takes a real-list as an input, and gives out a sorted list from highest to lowest number. More importantly it also spits out an index list of where the highest number exists in the input list. It does this in a highly inefficient manner mind you (at least I think so∞), so connecting it straight to an audio-rate node will choke your composition. Please see example for how to do so under somewhat safe circumstances.

Reorder List

Takes whatever list is presented at its input and reorders it to whatever is present at the "order list" input.

Reorder Layers

Takes a layer list as input and does the same as above.

Change Items In List

Changes items in a list based on their index.

Cut Wrapped List

Similar in function to the built-in Cut List, but the index wraps around the list, making for easy animation of smaller sequences from huge lists.

Get Items from List (2/4/8)

Gets 2/4/8 items from a list given individual indexes.

Get Items from List (2/4/8, sequential)

Gets 2/4/8 sequential items from a list given a starting index.


Changelog


V.4 update

Added Cut Wrapped List, which lets you cut out a segment from a list and wrap around. Useful for animations.


V.3 update

Added breakout boxes for getting 2/4/8 values from a list. Sequential or by indexes.


V.2 update

Added a "Change Items in List" node upon a request from @Bodysoulspirit.


-- Ramblings from earlier iterations:

@Kewl's question about layer sorting (found here: https://vuo.org/node/2181) intrigued me a bit, so I wrote up a couple quick nodes to address the issue. These are to regard as experimental at best, and is as always used entirely on ones own peril.

Note that I made the "Reorder Layers" node because I couldn't quite get it to work with generic types. I think that was just me being stupid about something (like the audio rate), but didn't bother to check after I made the layers one and got that to work. So, probably works, if not - don't say you weren't warned (and send me a message if you try it out and it doesn't).

∞For the programmatically inclined, I used the VuoReal_max() function to sort the list and get the index. Probably shouldn't, but that was as far as my brain managed to get today. Please have a peak at the code and send a message if it's horrible.

+2
Interesting
+2
Helpful
+1
Unique

Example

AttachmentSize
Binary Data Magneson.ListTools.Demo_.vuo12.49 KB

Source code

License

Tested with

Vuo version:
OS version:

Comments

This is amazing Martinus !

Bodysoulspirit's picture
Submitted by

This is amazing Martinus !
Analyzing your method made me realize some errors I suggested in my method on Kewl's question.

I think I have come up with a method using stock nodes only though using make dictionary, but it's not as good as your custom nodes. More nodes required, more type conversions and your composition feels smoother on my Macbook pro !

Sharing if one has to go with stock nodes only.
Basically Reorder List can be replaced with Get Items From List I guess. Although maybe your node is at this point already more optimized for this.
And for the Sort With Index I used a dictionary, indexes as values, and amplitudes as keys, and retrieved the keys sorted using Sort Points by Distance.
Where your node really shines is it does combine all these steps, and I guess that's what makes your method way smoother !

And the composition is also very nice, the colors, the idea of spreading the layers randomly is a cool idea. Anyway, congrats !

PS : Question to the team, is there a reason why Sort Points By Distance does not allow Reals (starting from 2D points only).
PS 2 : Definitely would be cool to have an index / position output on the Sort Points By Distance you know you can also post the nodes to be added to Vuo as stock nodes if you want Martinus ? I remember Alexander Mitchell did that for one audio node if I'm right.

Dictionnary method

Thanks! Good to know it helps

MartinusMagneson's picture
Submitted by

Thanks! Good to know it helps (but test a lot if using it for production!)! I had it running for a couple hours on my 2015 mbp (with Iris graphics) without any apparent issues, but you never know. I intentionally left the compostion at the maximum number of frequencies to stress test so it should crash pretty fast if there is any issues. If it then grinds to a halt it's a sign that something isn't right.

The sorting bit and getting the index can probably be done with stock nodes as it just is an implementation of the "Get Maximum" node for lists. The function itself gives you the index in the list. I really don't know if this is intended use for it regarding efficiency or if there is a better way. From what I understand, internally it uses an array instead of a list to get the raw data, so it should be somewhat more efficient than a pure list approach. There is probably some room for improvement though, as it still takes a roundtrip through a list for every iteration of checking. If all that happens in an (the same) array instead, it might be better.

The way the sorting happens is finding the largest number, then adding it to one list, and the index of it to another list. Then it sets the current number to 0, and repeats. This is probably the least efficient sorting method, I think it's in a general sense comparable to selection sort in this video: https://www.youtube.com/watch?v=kPRA0W1kECg . It might be possible with some "Build List" nodes, but I'm not quite sure. The reorder part as well should be possible in the same vein, but you'd need a fair bit of node wrangling to do so I guess.

Sort points by distance was my first thought as well, the problem I encountered there was that by sorting without having the index, it will put the largest value at index 1 no matter where it is in the spectrum. Sorta works for the random blobs, but you wouldn't get the color separation based on frequency.

(I already have a couple of my shoddy image filter ports included in 1.2.6 ;) Polished by team Vuo of course!)

@Kewl

Bodysoulspirit's picture
Submitted by

@Kewl

This also seems to be working.

Haha you came with a question and you just found the easiest way to achieve this it seems ;)
Dictionaries and Tables could probably still be useful in some cases you'd wanna map lists with different patterns than ascending/descending.
But for this case, your method is the straightforwardest.

Magneson (@MartinusMagneson)

(I already have a couple of my shoddy image filter ports included in 1.2.6 ;) Polished by team Vuo of course!)

Ah ok sorry I did not see that, congrats !

@Magneson, @Kewl,

jstrecker's picture
Submitted by

Magneson (@MartinusMagneson), @Kewl, @Bodysoulspirit, this is great :)

@Kewl, you commented that your composition wasn't as smooth as Magneson's — try inserting a Hold List between the Build List and Get Items from List.

is there a reason why Sort Points By Distance does not allow Reals (starting from 2D points only).

No reason. In fact there's a Sort List node coming in the next major release that will support Reals and many other data types.

Definitely would be cool to have an index / position output on the Sort Points By Distance

Yeah, or I wonder if there's another good way to sort a list by another list — without having to construct and deconstruct a table (for Sort Table) — that might be more approachable to someone less familiar with math/programming.

Don't know where the example/demo went, maybe it'll show up here?

The example composition field was late to the party, but now it's here. Sorry for the confusion.

Jaymie (@jstrecker)

Bodysoulspirit's picture
Submitted by

Jaymie (@jstrecker)

You commented that your composition wasn't as smooth as Magneson's — try inserting a Hold List between the Build List and Get Items from List

Ah yeah good point ! Also initially mine wasn't as smooth also because I had the Receive Live Audio samples going into a Hold List BEFORE going into Calculate Amplitudes which means they had less data to process and therefore it wasn't as smooth.
Since then, pretty much all methods seem as powerful, although on my old Macbook Magneson's method and mine play at about 45 FPS where Kewl's easiest method at 55.

Add comment

Log in or register to post comments