InstrumentRegion.fromLists constructor
InstrumentRegion.fromLists({})
Implementation
factory InstrumentRegion.fromLists(
{required List<Generator> global,
required List<Generator> local,
required List<SampleHeader> samples}) {
// initialize default values
Map<GeneratorType, int> gs = {};
for (GeneratorType gType in GeneratorType.values) {
gs[gType] = 0;
}
gs[GeneratorType.initialFilterCutoffFrequency] = 13500;
gs[GeneratorType.delayModulationLfo] = -12000;
gs[GeneratorType.delayVibratoLfo] = -12000;
gs[GeneratorType.delayModulationEnvelope] = -12000;
gs[GeneratorType.attackModulationEnvelope] = -12000;
gs[GeneratorType.holdModulationEnvelope] = -12000;
gs[GeneratorType.decayModulationEnvelope] = -12000;
gs[GeneratorType.releaseModulationEnvelope] = -12000;
gs[GeneratorType.delayVolumeEnvelope] = -12000;
gs[GeneratorType.attackVolumeEnvelope] = -12000;
gs[GeneratorType.holdVolumeEnvelope] = -12000;
gs[GeneratorType.decayVolumeEnvelope] = -12000;
gs[GeneratorType.releaseVolumeEnvelope] = -12000;
gs[GeneratorType.keyRange] = 0x7F00;
gs[GeneratorType.velocityRange] = 0x7F00;
gs[GeneratorType.keyNumber] = -1;
gs[GeneratorType.velocity] = -1;
gs[GeneratorType.scaleTuning] = 100;
gs[GeneratorType.overridingRootKey] = -1;
for (Generator parameter in global) {
gs[parameter.type] = castToShort(parameter.value);
}
for (Generator parameter in local) {
gs[parameter.type] = castToShort(parameter.value);
}
SampleHeader sampleH = SampleHeader.defaultSampleHeader();
if (samples.isNotEmpty) {
int? id = gs[GeneratorType.sampleID];
if (id == null || id < 0 || id >= samples.length) {
throw "The instrument contains an invalid sample ID '$id'.";
}
sampleH = samples[id];
}
return InstrumentRegion(gs: gs, sample: sampleH);
}