Forums > Max For Live

### Midi Averager

Jan 11 2013 | 6:18 pm

Hey Guys,

I’m new to Max and am attempting to build something which i guess you could describe as a "Midi Averager".
The concept is you play a set of notes overs 2 bars and at the end of 2 bars Max outputs the average note value.
So far I’ve achieved most of that. The only problem I have is I want it to output the single average note, but it doesn’t it gives me a weird confused chord even though the Midi Number object is giving me the average value displays.

I’m sure its something simple I’m missing out but I’ve been pulling my hair out over this for hours.

I’ve attached the patch incase you guys wanna have a looksee.

Cheers,

``````
-- Pasted Max  Patch, click to expand. --

```
```
Jan 11 2013 | 11:14 pm

Maybe more like this? If you want two measures, you’ll need a counter.

``````
-- Pasted Max  Patch, click to expand. --

```
```
Jan 11 2013 | 11:19 pm

slightly better:

``````
-- Pasted Max  Patch, click to expand. --

```
```
Jan 12 2013 | 4:10 pm

If you take the median, you’ll get a value that’s in the notes you played. May be useful if you want the result to be in key.

Jan 13 2013 | 4:09 pm

Mzed, you’re a genius. Thank you very much. This is totally what a needed. Is there a particular reason I was going wrong? Was it because I didn’t have stripnote in the chain?

Also, Peter, it might be fine for it to work chromatically. But how would I go about making it a median? Or even a modal function? is there an object designed for this or do I have to build one?

Jan 13 2013 | 8:22 pm

stripnote cleans things up a little, but isn’t necessary here.

The important change I made was the int object after mean. mean outputs on every new value it gets, so you were getting a new mean for every note. The int object is holding the last value and only outputs when the metro triggers a bang.

Jan 22 2013 | 4:09 pm

Hey again guys,
This MIDI thing has really grown a bit, It now calcuates the mode rather than the mean (or at least it should).
From what I can see, I should have it right. but when I print the final output, I expect to see a stream of 127 0’s. Instead I get erroneous different number appearing, although it seems to generate them in a pattern. Any ideas?

``````
-- Pasted Max  Patch, click to expand. --

```
```
Jan 22 2013 | 4:31 pm

Also on further investigation, zl join doesn’t seem to join all the lists together into one long stream as I’d expect?

Jan 22 2013 | 4:55 pm

send doesn’t accept two arguments, so you’re really just sending everything to the same receive. (lock patch, double click on send list g, and you’ll see what I mean)

I’d recommend reading up on coll. You can do all of this with way less patching. My general rule of thumb is that if I have to scroll my patcher, it’s probably an inflexible solution and not the best way to solve a problem. (and this goes double if you find that you have to add code to accommodate new values!)

``````-- Pasted Max  Patch, click to expand. --

```
```
Jan 22 2013 | 5:42 pm

okay, right, firstly thank you, because you’ve saved me a lot time. But secondly I have no idea whats going on here? haha
Would you mind explaining in a little more detail please?

Jan 22 2013 | 6:34 pm

I’m using coll to store the data. When I have a value, I retrieve its current count, add one to it, and store it again. I sort the coll by count (sort -1 1 = sort in descending order by the second (0-based indexing) value column. Retrieve the first value, which will be the maximum count, to get the mode.

To get the average, dump the entire coll. For each entry, it will be equivalent to value * count, so 60 30 (middle c played 30 times) will contribute 1800 towards the total. Add that value up for the entire coll, then divide by the accumulated count and you have the average.

Jan 22 2013 | 8:21 pm

Okay, cool. I think I kind of get this. Took me a little while to get round the whole coll concept. Now I just need to work out how to clear coll every 4 seconds and I’m golden. Thanks for your help man, its much appreciated.

Viewing 12 posts - 1 through 12 (of 12 total)

Forums > Max For Live