Forums > MaxMSP

how many notes in a melody?

April 25, 2014 | 4:59 am

Hi all!

I’m trying to slim down some patches I did, and would love to simplify, if possible, this one.
It basically gets a list of 32 values, and reports how many values are there which are not final zeroes.
So 1 2 3 0 0 0 should get as a result 3 good values (1 2 3)
And 1 2 0 3 4 0 0 should get 5 good values (1 2 0 3 4).
Only final zeroes are ignored.

So, this is it.
Any tip on how to simplify it?
I guess regexp should come handy

– Pasted Max Patch, click to expand. –

April 25, 2014 | 5:10 am

missed the final zero part

  • This reply was modified 6 months by  Rick.

April 25, 2014 | 5:11 am

Filtering out zeros would be really easy just using [zl filter 0]

So another way to do this would be to only store melody notes from 1+, so you can strip 0s with one object.

So your examples would be
2 3 4 0 0 0 0
2 3 1 4 5 0 0

And if you want you can use vexpr @scalarmode to convert the output back to 0+.


April 25, 2014 | 5:14 am

Thanks Rick,
I thought of that, but it actually filters all zeroes, not only last ones…
While I want to retain the zeroes which are inside the melody (they are pauses)


April 25, 2014 | 6:15 am

Hi Rodrigo,
thanks for the reply, I only see now…
the same as my below reply though, I need to mantain certain zeroes…


April 25, 2014 | 6:16 am

Yup my misreading of what you asked for. Using Rodrigo’s idea and substituting 255 for your pauses you could do this…

– Pasted Max Patch, click to expand. –

April 25, 2014 | 6:30 am

ok, thanks all, this should do in most cases, but I’m actually trying to analyze a multislider output, so I cannot really do a separation between zeroes that are pauses and those that are melody ending… unless i give them a -1 maybe… in a multislider I guess that would be handier than a 255…
anyway, I don’t know if this would be worth for my usage the case, because I actually already have a system which does what I need (see my posted patch), I was just looking for a slimmed down version of it…

btw, thanks for your time replying!


April 25, 2014 | 7:05 am

Another option would be to just count the amount of melody elements you are creating/generating/analyzing/whatever before packing them into a multislider.


April 25, 2014 | 7:24 am

Let’s try [zl.stack]

– Pasted Max Patch, click to expand. –

April 25, 2014 | 7:52 am

That’s indeed a step forward, thanks Rick! ;-)
And thank you Rodrigo!


April 25, 2014 | 8:15 am

vexpr $i1!=0 @scalarmode 1
accum

but there are also several zl based ways. besides the one above you could for example merge the list with a 0 and then measure the length of the output, then substract -1.



ak
April 25, 2014 | 8:35 am

So basically you want to cut trailing zeros and count elements?

– Pasted Max Patch, click to expand. –
  • This reply was modified 6 months by  ak.

April 25, 2014 | 9:20 am

Save this script as a .js file and use js to run it. It will tell you the length of your list up to the trailing zeros, and you can send that number into the right inlet of zl slice.

function list(l) {
var n = arguments.length;
while (arguments[n-1]==0) n–;
outlet(0, n);
}


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