/**
 * Description: This is a SoundFont2 parser.
 *
 * @package     midi-Synth
 * @category    module js
 * @author      Mrtenz <https://github.com/Mrtenz/soundfont2>
 * @copyright   soundfont2
 * @license     GPL-2.0-or-later
 */

/**
 * Generator (or modulator) types. These are defined in a specific order, following the spec. The
 * enum ID corresponds with the ID in the spec, so the unused and reserved fields should not be
 * removed.
 */
let GeneratorType

;(function(GeneratorType) {
  GeneratorType[(GeneratorType["StartAddrsOffset"] = 0)] = "StartAddrsOffset"
  GeneratorType[(GeneratorType["EndAddrsOffset"] = 1)] = "EndAddrsOffset"
  GeneratorType[(GeneratorType["StartLoopAddrsOffset"] = 2)] =
    "StartLoopAddrsOffset"
  GeneratorType[(GeneratorType["EndLoopAddrsOffset"] = 3)] =
    "EndLoopAddrsOffset"
  GeneratorType[(GeneratorType["StartAddrsCoarseOffset"] = 4)] =
    "StartAddrsCoarseOffset"
  GeneratorType[(GeneratorType["ModLFOToPitch"] = 5)] = "ModLFOToPitch"
  GeneratorType[(GeneratorType["VibLFOToPitch"] = 6)] = "VibLFOToPitch"
  GeneratorType[(GeneratorType["ModEnvToPitch"] = 7)] = "ModEnvToPitch"
  GeneratorType[(GeneratorType["InitialFilterFc"] = 8)] = "InitialFilterFc"
  GeneratorType[(GeneratorType["InitialFilterQ"] = 9)] = "InitialFilterQ"
  GeneratorType[(GeneratorType["ModLFOToFilterFc"] = 10)] = "ModLFOToFilterFc"
  GeneratorType[(GeneratorType["ModEnvToFilterFc"] = 11)] = "ModEnvToFilterFc"
  GeneratorType[(GeneratorType["EndAddrsCoarseOffset"] = 12)] =
    "EndAddrsCoarseOffset"
  GeneratorType[(GeneratorType["ModLFOToVolume"] = 13)] = "ModLFOToVolume"
  GeneratorType[(GeneratorType["Unused1"] = 14)] = "Unused1"
  GeneratorType[(GeneratorType["ChorusEffectsSend"] = 15)] = "ChorusEffectsSend"
  GeneratorType[(GeneratorType["ReverbEffectsSend"] = 16)] = "ReverbEffectsSend"
  GeneratorType[(GeneratorType["Pan"] = 17)] = "Pan"
  GeneratorType[(GeneratorType["Unused2"] = 18)] = "Unused2"
  GeneratorType[(GeneratorType["Unused3"] = 19)] = "Unused3"
  GeneratorType[(GeneratorType["Unused4"] = 20)] = "Unused4"
  GeneratorType[(GeneratorType["DelayModLFO"] = 21)] = "DelayModLFO"
  GeneratorType[(GeneratorType["FreqModLFO"] = 22)] = "FreqModLFO"
  GeneratorType[(GeneratorType["DelayVibLFO"] = 23)] = "DelayVibLFO"
  GeneratorType[(GeneratorType["FreqVibLFO"] = 24)] = "FreqVibLFO"
  GeneratorType[(GeneratorType["DelayModEnv"] = 25)] = "DelayModEnv"
  GeneratorType[(GeneratorType["AttackModEnv"] = 26)] = "AttackModEnv"
  GeneratorType[(GeneratorType["HoldModEnv"] = 27)] = "HoldModEnv"
  GeneratorType[(GeneratorType["DecayModEnv"] = 28)] = "DecayModEnv"
  GeneratorType[(GeneratorType["SustainModEnv"] = 29)] = "SustainModEnv"
  GeneratorType[(GeneratorType["ReleaseModEnv"] = 30)] = "ReleaseModEnv"
  GeneratorType[(GeneratorType["KeyNumToModEnvHold"] = 31)] =
    "KeyNumToModEnvHold"
  GeneratorType[(GeneratorType["KeyNumToModEnvDecay"] = 32)] =
    "KeyNumToModEnvDecay"
  GeneratorType[(GeneratorType["DelayVolEnv"] = 33)] = "DelayVolEnv"
  GeneratorType[(GeneratorType["AttackVolEnv"] = 34)] = "AttackVolEnv"
  GeneratorType[(GeneratorType["HoldVolEnv"] = 35)] = "HoldVolEnv"
  GeneratorType[(GeneratorType["DecayVolEnv"] = 36)] = "DecayVolEnv"
  GeneratorType[(GeneratorType["SustainVolEnv"] = 37)] = "SustainVolEnv"
  GeneratorType[(GeneratorType["ReleaseVolEnv"] = 38)] = "ReleaseVolEnv"
  GeneratorType[(GeneratorType["KeyNumToVolEnvHold"] = 39)] =
    "KeyNumToVolEnvHold"
  GeneratorType[(GeneratorType["KeyNumToVolEnvDecay"] = 40)] =
    "KeyNumToVolEnvDecay"
  GeneratorType[(GeneratorType["Instrument"] = 41)] = "Instrument"
  GeneratorType[(GeneratorType["Reserved1"] = 42)] = "Reserved1"
  GeneratorType[(GeneratorType["KeyRange"] = 43)] = "KeyRange"
  GeneratorType[(GeneratorType["VelRange"] = 44)] = "VelRange"
  GeneratorType[(GeneratorType["StartLoopAddrsCoarseOffset"] = 45)] =
    "StartLoopAddrsCoarseOffset"
  GeneratorType[(GeneratorType["KeyNum"] = 46)] = "KeyNum"
  GeneratorType[(GeneratorType["Velocity"] = 47)] = "Velocity"
  GeneratorType[(GeneratorType["InitialAttenuation"] = 48)] =
    "InitialAttenuation"
  GeneratorType[(GeneratorType["Reserved2"] = 49)] = "Reserved2"
  GeneratorType[(GeneratorType["EndLoopAddrsCoarseOffset"] = 50)] =
    "EndLoopAddrsCoarseOffset"
  GeneratorType[(GeneratorType["CoarseTune"] = 51)] = "CoarseTune"
  GeneratorType[(GeneratorType["FineTune"] = 52)] = "FineTune"
  GeneratorType[(GeneratorType["SampleId"] = 53)] = "SampleId"
  GeneratorType[(GeneratorType["SampleModes"] = 54)] = "SampleModes"
  GeneratorType[(GeneratorType["Reserved3"] = 55)] = "Reserved3"
  GeneratorType[(GeneratorType["ScaleTuning"] = 56)] = "ScaleTuning"
  GeneratorType[(GeneratorType["ExclusiveClass"] = 57)] = "ExclusiveClass"
  GeneratorType[(GeneratorType["OverridingRootKey"] = 58)] = "OverridingRootKey"
  GeneratorType[(GeneratorType["Unused5"] = 59)] = "Unused5"
  GeneratorType[(GeneratorType["EndOper"] = 60)] = "EndOper"
})(GeneratorType || (GeneratorType = {}))

/**
 * The default value for all generator types (where applicable).
 */
const DEFAULT_GENERATOR_VALUES = {
  [GeneratorType.StartAddrsOffset]: 0,
  [GeneratorType.EndAddrsOffset]: 0,
  [GeneratorType.StartLoopAddrsOffset]: 0,
  [GeneratorType.EndLoopAddrsOffset]: 0,
  [GeneratorType.StartAddrsCoarseOffset]: 0,
  [GeneratorType.ModLFOToPitch]: 0,
  [GeneratorType.VibLFOToPitch]: 0,
  [GeneratorType.ModEnvToPitch]: 0,
  [GeneratorType.InitialFilterFc]: 13500,
  [GeneratorType.InitialFilterQ]: 0,
  [GeneratorType.ModLFOToFilterFc]: 0,
  [GeneratorType.ModEnvToFilterFc]: 0,
  [GeneratorType.EndAddrsCoarseOffset]: 0,
  [GeneratorType.ModLFOToVolume]: 0,
  [GeneratorType.ChorusEffectsSend]: 0,
  [GeneratorType.ReverbEffectsSend]: 0,
  [GeneratorType.Pan]: 0,
  [GeneratorType.DelayModLFO]: -12000,
  [GeneratorType.FreqModLFO]: 0,
  [GeneratorType.DelayVibLFO]: -12000,
  [GeneratorType.FreqVibLFO]: 0,
  [GeneratorType.DelayModEnv]: -12000,
  [GeneratorType.AttackModEnv]: -12000,
  [GeneratorType.HoldModEnv]: -12000,
  [GeneratorType.DecayModEnv]: -12000,
  [GeneratorType.SustainModEnv]: 0,
  [GeneratorType.ReleaseModEnv]: -12000,
  [GeneratorType.KeyNumToModEnvHold]: 0,
  [GeneratorType.KeyNumToModEnvDecay]: 0,
  [GeneratorType.DelayVolEnv]: -12000,
  [GeneratorType.AttackVolEnv]: -12000,
  [GeneratorType.HoldVolEnv]: -12000,
  [GeneratorType.DecayVolEnv]: -12000,
  [GeneratorType.SustainVolEnv]: 0,
  [GeneratorType.ReleaseVolEnv]: -12000,
  [GeneratorType.KeyNumToVolEnvHold]: 0,
  [GeneratorType.KeyNumToVolEnvDecay]: 0,
  [GeneratorType.StartLoopAddrsCoarseOffset]: 0,
  [GeneratorType.KeyNum]: -1,
  [GeneratorType.Velocity]: -1,
  [GeneratorType.InitialAttenuation]: 0,
  [GeneratorType.EndLoopAddrsCoarseOffset]: 0,
  [GeneratorType.CoarseTune]: 0,
  [GeneratorType.FineTune]: 0,
  [GeneratorType.SampleModes]: 0,
  [GeneratorType.ScaleTuning]: 100,
  [GeneratorType.ExclusiveClass]: 0,
  [GeneratorType.OverridingRootKey]: -1
}
