Re: [linux-audio-dev] Re: Timed Event Editor Framework

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] Re: Timed Event Editor Framework
From: Eli Brandt (eli_AT_v.gp.cs.cmu.edu)
Date: ke syys   01 1999 - 17:54:00 EDT


Andreas Voss wrote:
> There is a well known design pattern called 'iterator', that you will find
> in all object oriented collection classes. Such classes can encapsulate
> the physical (nested) structure of the events. Lets complicate the example
> further, lets assume we want to process only note events in a given time
> range. Without the iterator, this would look like
>
> for each_group in merged_groups
> for each_track in each_group
> if e.type == note
> if e.time >= start_time
> if e.time < stop_time
> // process e
>
> You can encapsulate all this in an Iterator object, e.g.
>
> Iterator it = new Iterator();
> it.setType(note);
> it.setTimeRange(start_time, stop_time);
> while (it.hasNext()) {
> e = it.getNext();
> // process e
> }

Or if the language has higher-order functions, you can do this by
composing the ones you're using to get a new one. So something like
   map (fn group =>
        map (fn track =>
             map_if (fn e => e.time >= start_time &&
                             e.time < stop.time)
                     process_e
                     track)
            group)
        merged_groups

or then name that functional gunk:
var my_so_called_iterator =
   map (fn group =>
        map (fn track =>
             map_if (fn e => e.time >= start_time &&
                             e.time < stop.time)
                     process_e
                     track)
            group)

my_so_called_iterator merged_groups

(Nothing personal, but iterators make me itch.)

-- 
     Eli Brandt  |  eli+@cs.cmu.edu  |  http://www.cs.cmu.edu/~eli/


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : pe maalis 10 2000 - 07:25:53 EST