how many notes in a melody?

    Apr 25 2014 | 11: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

    • Apr 25 2014 | 12:10 pm
      missed the final zero part
    • Apr 25 2014 | 12:11 pm
      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+.
    • Apr 25 2014 | 12:14 pm
      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)
    • Apr 25 2014 | 1:15 pm
      Hi Rodrigo,
      thanks for the reply, I only see now...
      the same as my below reply though, I need to mantain certain zeroes...
    • Apr 25 2014 | 1:16 pm
      Yup my misreading of what you asked for. Using Rodrigo's idea and substituting 255 for your pauses you could do this...
    • Apr 25 2014 | 1:30 pm
      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!
    • Apr 25 2014 | 2:05 pm
      Another option would be to just count the amount of melody elements you are creating/generating/analyzing/whatever before packing them into a multislider.
    • Apr 25 2014 | 2:24 pm
      Let's try [zl.stack]
    • Apr 25 2014 | 2:52 pm
      That's indeed a step forward, thanks Rick! ;-)
      And thank you Rodrigo!
    • Apr 25 2014 | 3:15 pm
      vexpr $i1!=0 @scalarmode 1
      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.
    • Apr 25 2014 | 3:35 pm
      So basically you want to cut trailing zeros and count elements?
    • Apr 25 2014 | 4:20 pm
      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);