Hi all, I'm wondering if somebody could give me a clean way of figuring out how to compare an object (I don't know if it is a list, a symbol, or a message, and would love it if somebody could clear that up too) and bang if they are the same.
Basically, I want my patch to select the correct audio device, which would be bcm2835 ALSA (hardware), but I don't know how to compare and bang if the output from route is the same. I've tried list-compare earlier, but the mismatch of types made me want to bang my head against a wall. Hopefully there is a better way in Pd, thank you!
-
List Comparison
-
@buzzelljason Yes. Well. Everything sent by a control rate object is a message.
The messages can be floats or symbols or lists.
Lists are a list comprising floats or symbols or a mixture of the two.
Items (atoms) in a list are separated by spaces.
It gets complicated.
If the first atom in the list is a float then the "list" tag is automatically applied, and then is silently ignored and dropped as it passes through the next object (except for [route list symbol float].......)
If the first atom in the list is a symbol then that symbol becomes the tag.... the list header..... and the list can be routed by that tag. But if the list passes through a [list] object then "list" is added (prepended) as the header. That is why [list trim] is used almost everywhere after a [list] object...... to remove the header and then be able to [route] by the original tag (if it was a symbol).HINT.. If you install the Zexy library then [rawprint] shows you whether an atom is a "tag", 'symbol' or float....
Trying to work with vanilla OSC objects can be just guesswork without [rawprint].
mmm.pd
The messages arrive from [audiosettings] as a list which is a mixture of floats and symbols........ but the first atom is a symbol and there is no "list" tag.
[listdevices( returns a series of messages..... they are lists...... with the first atom "device"
That is why "device"....... a symbol.... and "0" or "1" can be routed. "1" could not be routed by [route 0 1] unless it is a float and "device" could not be routed by [route device] unless it is a symbol.The device name is a symbol........ it can only be sent on in one hit because it is a symbol...... if it were a list then each part would be sent separately as a space normally "means" "next item".
But once it has passed through [route 0 1] it has lost its "symbol" tag. That can be put back by passing it through [symbol].So the problem for [list-compare] is to create a symbol that is identical. Not easy as a message with component symbols will be treated as a list. Fortunately @ingox gave us a vanilla solution.... [concat].
And then of course to turn them both into lists for the comparison.This will work........ this.zip
It can probably be simplified (and certainly @ingox will shortly post a more elegant solution.... ).
David. -
@whale-av Maybe you could skip the final conversion back to list and just compare them as symbols using [sel symbol]? e.g. https://forum.pdpatchrepo.info/topic/12039/comparing-symbols-lists-and-floats
-
@jameslo Yes, that is less expensive...... good catch......
I had simply assumed it would not work because of the spaces...... but of course the second inlet is handy.
David -
@whale-av Give a look at that link, @Jona seems to have made it work. I tried it with [openpanel] and [symbol file\ name\ with\ spaces( and that worked. Symbols with spaces is something I learned about within the last 18 months--the spaces are just escaped with backslashes.
edit: ha, we cross posted, thereby making my response a non-sequitur (which may be a characteristic of many of my posts)