any tips on building a simple state transition model?

alxzndr's icon

I'm trying to get my head around the logic required to build a simple state transition diagram. It's to change the system's emotional states based on the amount of user interaction (a couple of float values). These states in turn are mapped to audio parameter presets. Any tips?

Cheers, Alex

thezer0ist@gmail.com's icon

If you have any experience with Java or Javascript, you may want to try to build the core of the system in an mxj or js object (though I may just be saying this because I come from a more traditional programming background).

Another approach would be to use pattrstorgage (https://cycling74.com/docs/max5/refpages/max-ref/pattrstorage.html) with multiple slots. Each slot can contain either the parameters for the system themselves, or symbols that identify groups of presets for different areas of the system. If you then send a float value into it, it will do an interpolation between the states, or if you just use an int value, it will output that slot's values.
If your system is based on different stimuli causing various transitions between the states, you could have each state (slot) have a transition table that corresponds to it.
For example,
In a "happy" state, "causing excitement" would transition to "manic", whereas in an "angry" state, that same stimulus would transition to an "enraged" state.

A few years back, I started (and never really completed) a system that worked in a similar manner, but with states that smoothly transitioned into each other. It consisted of the following:
- a set of parameters (values for different parts of the system, like frequencies or gain levels)
- 2 "state" values, "happiness" and "excitement", each of which was a value that went from -1 to +1, so that the two formed a 2D square
- each parameter had a square that contained points in various locations that defined its values. For example frequency could have a value 440Hz at the point (0.5 happiness, -1.0 excitement, which i called something like "contentment").
- a cursor which represented the current state, containing a "happiness" value and an "excitement" value (both between -1 and +1)
- the value of each parameter was determined by the point in its square that was closest to the cursor
- different stimuli moved the cursor in various directions

I implemented this (or rather, began to implement it) with a Java external that stored all of these values, and calculated the values of each parameter. I did so because (1) I was a computer science major with a background in traditional programming, and (2) I couldn't figure out a good way to model something this complex directly in a max patch. It may be possible, and if someone figures it out, I'd love to see it.

If you are especially interested, I can post what there is of the code for my project (really unfinished, most of it was just a bunch of scribbles in a notebook).

thezer0ist@gmail.com's icon
alxzndr's icon

Cheers!

I've ended up using conditionals to change the states, on each state change it bangs a random preset from that range (many presets per state). Each preset contains the state changes and variables required. Sometimes I wish max was a normal programming language (nested ifs...argh)

thezer0ist@gmail.com's icon

You may want to check out Max's javascript support (https://cycling74.com/docs/max5/vignettes/js/javascriptinmax.html). Javascript is a fairly easy language to learn, and there is a TON of material about it on the web. A lot of the reference material that's out there is focused on web development and browsers, but some of it is more general (https://developer.mozilla.org/En/JavaScript).
In max, javascript is great for simple objects that do things like data storage (in formats that go a bit beyond coll, pattr, etc), and control logic (if/else/for/while) that [i}can[/i] be done in max, but are generally much simpler in javascript.

Graham Wakefield's icon

@ thezer0ist:

It sounds like what you are doing is a 2D look up table (LUT). I think a Jitter matrix would do the job pretty well. Treat a 2D matrix as your happy / excitement space, and have a plane for each parameter to be controlled. Index the matrix with getcell messages for example. You'd need to scale the state values from (-1, 1) to (0, dim) to index the space.

thezer0ist@gmail.com's icon

lists@grahamwakefield wrote on Sun, 26 July 2009 15:10@ thezer0ist:

It sounds like what you are doing is a 2D look up table (LUT). I think a Jitter matrix would do the job pretty well. Treat a 2D matrix as your happy / excitement space, and have a plane for each parameter to be controlled. Index the matrix with getcell messages for example. You'd need to scale the state values from (-1, 1) to (0, dim) to index the space.

That's sort of what I was using, but with sparse value points instead of a fully-populated lookup table (though it may be possible to generate one from the points, which would speed up performance if the points didn't change frequently).

I just found ej.linterp. It's a java-based object that allows you to linearly interpolate between lists of values. It can have multiple dimensions of lists, which you can interpolate between using a moving point in an x/y area. It also allows you to do this with three dimensions (and presumably more). It also allows you to interpolate between a group of lists, specifying a weight for each one.

thezer0ist@gmail.com's icon

you can get ej.linterp at http://www.e--j.com/ along with a bunch of other really useful stuff.