create static method
Implementation
static List<InstrumentRegion> create(List<Zone> zones, List<SampleHeader> samples) {
Zone? global;
// Is the first one the global zone?
if (zones[0].generators.isEmpty ||
zones[0].generators.last.type != GeneratorType.sampleID) {
// 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<InstrumentRegion> regions = [];
int count = zones.length - 1;
for (var i = 0; i < count; i++) {
regions.add(InstrumentRegion.fromLists(
global: global.generators,
local: zones[i + 1].generators,
samples: samples));
}
return regions;
} else {
// No global zone.
int count = zones.length;
List<InstrumentRegion> regions = [];
for (var i = 0; i < count; i++) {
regions.add(InstrumentRegion.fromLists(
global: [],
local: zones[i].generators,
samples: samples));
}
return regions;
}
}