[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] detect / detectIndex



I'm trying to parse a buffer of MIDI notes into a
structure that handles grace notes and chord notes (so
that eventually I can do math on the buffer without
breaking up chords or grace note flourishes). Roughly,
the algorithm is:

1. Find the next note that is not a grace note.
2. Create a new note object based on that note.
3. Copy the grace notes into the new note.
4. The next bunch of notes might belong to a chord, so
identify them and add them to the new note object.
5. If the end of the buffer isn't reached, go back to
1.

Would be nice if I could say for #1:

noteIndex = buf.detectIndex({ |n| n.isGraceNote.not },
startIndex)

instead of:

startIndex = noteIndex;
{ (noteIndex < notes.size) and: {
notes[noteIndex].isGraceNote } }.while({ noteIndex =
noteIndex + 1 });

detectIndex would be a lot more concise and easier to
read, but hey, I can't use it because it "has never
been needed in Lisp or Smalltalk."

Because the division between "events" is not so
simple, I can't simply .separate the buffer in advance
and do all the operations on the subcollections. But
if you have another way around it (that won't explode
the iterations way past the max approx. 2*N I think I
have now (usually less than that)), I'm all ears.

hjh

--- James McCartney <asynth@xxxxxx> wrote:
> 
> This has never been needed in Lisp or Smalltalk. I'd
> be against adding 
> this unless some precedent can be found.
> I'm curious what the situation is. How are you using
> the collection 
> that you need to do this?
> 


=====
____   James Harkins /// dewdrop world
\  /   jamshark70@xxxxxxxxx
 \/    http://www.duke.edu/~jharkins

"... love and hot pants, peace, harmony..."
  -- Dick Lee, Hot Pants: The Musical


	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover