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: Andreas Voss (andreas_AT_avix.rhein-neckar.de)
Date: ke syys   01 1999 - 17:57:02 EDT


On Mon, 30 Aug 1999, Eli Brandt wrote:

> How about escalating the structure's tree-depth? The first version
> gets more for-each levels but the inner loop stays clean:
>
> for each_group in merged_groups
> for each_track in each_group
> old_e.time = e.time; output old_e
> old_e = e

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
        }

One big advantage of this approach is, that you can reuse the logic of the
iterator in other situations.

Andreas


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