Working with Lists
How to work with Lists in RNBO. Common use cases, and tips for working with structured data.
As you start to work with RNBO, you may start to miss two of your favorite Max objects: coll and dict. Of course these are super useful Max objects with tons of functionality that would be impossible to replace succinctly with a handful of RNBO objects. However, you may be surprised how much you can achieve without needing these objects. This document is here to try to address some common use cases, and to make working with lists in RNBO a bit easier.
Lists in RNBO must be numbers only. There is no notion of a "symbol" in RNBO that can be passed between objects, so if you try to put a symbol in a message box you'll see something like this:
In the top-most RNBO patcher, you can use a message box to hold on to a list of numbers, just like you would in Max. However, UI objects like message are not supported in polyphonic subpatchers, as you'll notice if you try to use a message object in that context.
Whenever you would normally use a message box to hold on to a list, but can't for one reason or another (maybe because you're in a polyphonic subpatcher), you can instead use the list.reg object.
With list.reg and some clever patching, you can mostly get around coll and dict not being available in RNBO.
The basic function of coll is to manage a list of lists, where each list is associated with a key. Sending a number followed by a list to coll will store the list using the number as a key. Sending just that number to coll will retrieve the stored list, if it exists. Of course coll can do a lot more than just that, but at its core this is what coll is all about.
In RNBO, the list.store object provides some of the same functionality as coll. The two arguments to list.store initialize the object with a maximum number of internal lists, and a maximum length for each stored list. For example, an object like
[list.store 8 10] can store up to 8 lists, each of which can contain up to 10 elements.
The rightmost inlet sets the index at which the list will be stored. Sending a list to the middle inlet will store that list at the previously set index. Finally, use the left inlet to retrieve the list stored at a given index. You can check out the list.store helpfile for more details on how to use this object. It's important to note that the number that you send to the right inlet is an index, and not a key. So if your first argument to list.store is 10, then you cannot use 15 (or any number 10 or greater) as a key.
Suppose you wanted to associate each MIDI note with a different random chord. Every time a note is played, this patch first checks whether that note has been played before. If not, it generates and stores a new random chord for that note. Finally, it plays the note with its chord. This kind of coll-like use case is perfect for list.store.
Materials in this article