create static method

List<PresetRegion> create(
  1. List<Zone> zones,
  2. List<Instrument> instruments
)

Implementation

static List<PresetRegion> create(
    List<Zone> zones, List<Instrument> instruments)
{
  Zone? global;

  // Is the first one the global zone?
  if (zones[0].generators.isEmpty ||
      zones[0].generators.last.type != GeneratorType.instrument) {

    // The first one is the global zone.
    global = zones[0];

  }

  if (global != null) {

    // The global zone is regarded as the base setting of subsequent zones.
    List<PresetRegion> regions = [];

    int count = zones.length - 1;

    for (var i = 0; i < count; i++) {
      regions.add(PresetRegion.fromLists(
          global: global.generators,
          local: zones[i + 1].generators,
          instruments: instruments));
    }
    return regions;

  } else {
    // No global zone.
    List<PresetRegion> regions = [];

    int count = zones.length;

    for (var i = 0; i < count; i++) {
      regions.add(PresetRegion.fromLists(
          global: [],
          local: zones[i].generators,
          instruments: instruments));
    }
    return regions;
  }
}