Any good dtutorial on [dict] objects ?

Stephane Morisse's icon

title says it all. Can anyone point me to any link ? I've got a problem I can't seem to solve using [coll] but can't get the basics of dictionaries.

do.while's icon

Hi !
Basics ? in Dict help patch are the basics ! If its still hard to get into it , lets try it here . i believe i can help u out . I cant name any Dict tutorials at the moment .

Mark Durham's icon

I also found dict a bit confusing. My problem was that I found the help files too abstract to actually explain what this was useful for. Perhaps this is easier if you're coming form a computer science background, but I prefer help files which apply the object in some relevant context.

Having said that, I've been using dict for the first time to store and recall settings for a drum machine I'm building and it's proving really useful. the device has 16 pads and an editing section, I'm storing pitch, volume etc in a dict and then recalling these settings to ui objects in the editing bit. I can't post all that, but could adapt it to an example and post that here.

Generally, I think it would be good to have some more dict examples on the forum or wiki.

Stephane Morisse's icon

Mark your first statement seems right to me, and I don't have a computer science background. As dict objects have been introduced in Max6, I expected to find a real tutorial in the Max help in Max7. Do...while, for example, going through the helfiles and reference, I din't find how I can append new values in a dictionary like I do in Coll. Maybe I missed something obvious...

Wetterberg's icon

I feel the same way, really. I *think* I understand how to use dict, but I have trouble finding an application for it. I use pattrstorage for all my preset handling, and I'm not sure it'd be helpful to convert into dict.

I'm basically looking for an excuse to start using it... for *something*.

Mike S's icon

I'm working on a M4L device that addresses a dict object in the patch using JS, this is really handy as you can get and set values in code. I don't think you can do this as easily with any other Max object.

It probably takes a couple of little projects to get a feel for what it can do, but I agree it's pretty confusing what it's for to start with.

Mark Durham's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Here is a basic store and retrieve patch:

I guess using coll for that example would have been easier, but I assume the real value of dict is that you can create a hierarchy and retrieve data by querying parts of that. Is that a fair statement or am I missing something?

Andro's icon

Having key words with values makes it easier for me to handle a lot of separate data. The hierarchy system is great. I use dict.pack to make a lot of my dict objects.
For example. I use 2 dict.pack to create a hierachy
Synth_1 attack: decay: release:
Synth_2 attack: decay: release:
By using dict.unpack synth_1 and then another dict.unpack with attack: decay: release:
I get the values separately.
I think it depends on what your trying to do. Dict is handy with lots of different data types but not necessary with just a little data.

Mark Durham's icon

That's way easier than the way I've been doing it. Note to self: go through help files for new objects more thoroughly in future.

do.while's icon

nice one Mark , nice one Andro .
yeah Dict is intended to create data driven scenarios . Whole Max is a dictionary , under the hood it takes advantage of such hierarchical structure in attributes - pattr , layout , objects itself etc .

When i was starting my application , ive been using Coll . My App flow was determined by midi data (notes) which were triggering different states of application .
Being honest i thought Coll would suit my needs and i didnt want to learn Dict because of weird procedures that u have to provide in order to store or retrieve data . While working on my application ive noticed few things : Coll was a bottleneck of my performance , and i could not pattrize easily its data without a hack .Dict is fast , its really efficient when calling it on midi events , where as said Coll wasnt . Currently my apps takes advantage mostly on whats happening in Dict . My whole UI is updated on midi note , changing values on UI updates Dict . Playing back by retrieving current value state from Dict . its all driven by this little beast . More to that , Dict can replace any database situation . where using SQL would not suit your efficiency as desired .

But the most power and fun of using Dict is to maintain it within Javascript (or C) . Actually only then u will stay creative with it as patching all the fancy dataflow will make your application huge and hard to debug . Yeah building application around data should be considered as a complex and responsive task . Its logic must be clear to read , set , update and stay consistent with the flow or any other conditions that will add another layer of maintenance . While doing it with plain patching u will give up on complexivity ending up with simple scenarios , where actually u would be better using Coll .

Im encouraging u all to check JS tab on Dict help patch and leave Dict patching for learning purposes only .

do.while's icon

Ive already participated in helping with Dict in this forum when i could . U can find answer on most wonderings u can come up with . If im here (im passing by often to get new knowledge) i will take time to help you out if i can . But if by any chance u will try to deal with Dict inside JS or C , i will feel more competent to brainstorm any problems or desires .

@STEPHANE please check Mark's patch

do.while's icon

one more note for people from Coll background .

In Coll u were allowed to store data under numerical index by passing integers and retrieve them by passing those integers again . In Dict this implementation is different , as Dict is using JSON format , every data key is a symbol . Remember that when u will store data under numerical index . In order to retrieve data stored this way u will have to prepend your integer with (convert) tosymbol object . In JS it is quite similar but more obvious .

Peter McCulloch's icon

One use I've found: dict can be used as a way of passing large numbers of parameters into poly~ patches. It's more flexible than a list. (Can do something similar with OSC as well)

Stephane Morisse's icon

thanks guys. I've been looking at the patch by Mark and read all your answers. I feel like it's time for me to approach JS... Fundamentally, I get the advantages of dict over coll, and being able to access data searching any sub content was the reason I tried to turn to dict because I couldn't find a way to do that with coll. I'm going to experiment some stuff then will be back. Nevertheless, looking at the threads about Dict objects it seems that many things need to be clarified for people without computer science education. A suggestion to C74 ?

Stephane Morisse's icon

Andro : that's precisely the way I want to use them. I tried using the helpfiles but couldn't get it. Didn't spend much time though as I needed to be fast on the current project.

do.while's icon

Hi Stephane . Look im not having computer science education . Everything ive learned comes from this forum mainly .Even from people that participated in this thread ! The only thing is that , ive not been in hurry with anything . I bought Max license without any clue what i will do with it and even how .

Ive done the tutorials , but honestly those people like Mike ,Peter , Mark and others taught me all the logic through brainstorming ideas with others on this forum . All the participants are gems . This forum is compendium .
Cycling guys are not a huge team , they have to work hard on everything , have life . But this community is like the other half of this team , providing appropriate knowledge and experience . at least im feeling it that way . I rely on it . I want to be part of i too . I want to give something back . ok enough

Take time Stephane , make stupid things , mistakes , fail but not stress yourself . If your project is a assignment or something similarly urgent then u have to pay some energy for it and make some research . But ... u will gain new knowledge for the future . u will think more opened way from task to task . Next time it will be trivial , and common procedure to achieve your task , and even go beyond it with another research .

Mark Durham's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Lots of truth there. I've definitely learnt more from this forum than anywhere else. Like many, I spent a long time just learning from it, but now I try to give back where I can. In that spirit, here is a slightly better patch:

There are two basic sine wave oscillators with an LFO for amplitude, parameters for both stored in a dictionary called params. A part of the patch generates random combinations of note and lfo speed, another recalls those independently to two dials for the user to modify. Please suggest improvements if you can.

@Peter - Nice idea. I have some sample players where I send long lists to poly~, but that is a much more elegant way of doing things.

@Do...While - All good to know, thanks for being so thorough. Very interesting about coll being a bottleneck in your patches, that's good enough reason to move to dict where possible.