# Function that counts number of consecutive elements after iterator in Table command

I have a 1D Table, something like this, that I want to turn into musical notes:

    U = {10, None, None, 0, 2, 3, 5, None, 2, 0, 3, None, 7, None, None, 3, 2, 3, 7, None, None, 0, 5, None, 5, None, 2, 3, None, None, 7, None}


'None' signifies a rest. I'm currently using this line to do that (dur is the duration of each note, len is the length of U):

Sound[Table[SoundNote[U[[i]], {dur*i, dur*(i + 1)}], {i, 1, len}]]


This works, but I'd like to extend the duration of the notes preceding a rest (one or more 'None's) to get a legato effect. So how can I write a function (pure or defined) that counts the number of consecutive None's immediately following a location, i, in the list, U (if there are any at all)? So it would work something like this:

Sound[Table[SoundNote[U[[i]], {dur*i, dur*(i + 1 + Number_Of_Consecutive_Nones_Following[i,U])}], {i, 1, len}]]


Thank you!!

• Replace Number_Of_Nones_Following[i,U] with Count[U[[i ;;]], None] Commented Mar 28, 2016 at 6:33
• Added clarification. I need a function that tells me how many consecutive Nones there are immediately after the ith location (if there are any at all), not the total number. Commented Mar 28, 2016 at 6:53

U = {10, None, None, 0, 2, 3, 5, None, 2, 0, 3, None, 7, None, None, 3, 2, 3, 7, None, None, 0, 5, None, 5, None, 2, 3, None, None, 7, None};

dur = 1; len = Length@U;

Sound[
Table[
SoundNote[
U[[i]], {dur*i, dur*(i + 1 + LengthWhile[U[[i + 1 ;;]], # == None &])}], {i, 1, len}
]
]


• LengthWhile +1 Commented Mar 28, 2016 at 7:42