public DescriptorList(StreamReader reader)
 {
     List<EnvelopeDescriptor> envList = new List<EnvelopeDescriptor>();
     List<FilterDescriptor> fltrList = new List<FilterDescriptor>();
     List<LfoDescriptor> lfoList = new List<LfoDescriptor>();
     List<GeneratorDescriptor> genList = new List<GeneratorDescriptor>();
     List<CustomDescriptor> cList = new List<CustomDescriptor>();
     List<string> descList = new List<string>();
     while (!reader.EndOfStream)
     {
         string tag = ReadNextTag(reader, descList); 
         switch (tag)
         {
             case "envelope":
             {
                 EnvelopeDescriptor env = new EnvelopeDescriptor();
                 env.Read(descList.ToArray());
                 envList.Add(env);
                 break;
             }
             case "generator":
             {
                 GeneratorDescriptor gen = new GeneratorDescriptor();
                 gen.Read(descList.ToArray());
                 genList.Add(gen);
                 break;
             }
             case "filter":
             {
                 FilterDescriptor fltr = new FilterDescriptor();
                 fltr.Read(descList.ToArray());
                 fltrList.Add(fltr);
                 break;
             }
             case "lfo":
             {
                 LfoDescriptor lfo = new LfoDescriptor();
                 lfo.Read(descList.ToArray());
                 lfoList.Add(lfo);
                 break;
             }
             default:
                 if (!tag.Equals(string.Empty))
                 {
                     CustomDescriptor cus = new CustomDescriptor(tag, 0);
                     cus.Read(descList.ToArray());
                     cList.Add(cus);
                 }
                 break;
         }
         descList.Clear();
     }
     EnvelopeDescriptions = envList.ToArray();
     FilterDescriptions = fltrList.ToArray();
     LfoDescriptions = lfoList.ToArray();
     GenDescriptions = genList.ToArray();
     CustomDescriptions = cList.ToArray();
 }
 //--Methods
 public WhiteNoiseGenerator(GeneratorDescriptor description)
     : base(description)
 {
     if(end < 0)
         end = 1;
     if (start < 0)
         start = 0;
     if (loopEnd < 0)
         loopEnd = end;
     if (loopStart < 0)
         loopStart = start;
     if (genPeriod < 0)
         genPeriod = 1;
     if (root < 0)
         root = 69;
     freq = 440;
 }
 //--Methods
 public SineGenerator(GeneratorDescriptor description)
     : base(description)
 {
     if (end < 0)
         end = Synthesizer.TwoPi;
     if (start < 0)
         start = 0;
     if (loopEnd < 0)
         loopEnd = end;
     if (loopStart < 0)
         loopStart = start;
     if (genPeriod < 0)
         genPeriod = Synthesizer.TwoPi;
     if (root < 0)
         root = 69;
     freq = 440;
 }
 public SampleGenerator(GeneratorDescriptor description, AssetManager assets)
     : base(description)
 {
     SampleDataAsset sample = assets.FindSample(IOHelper.GetFileNameWithoutExtension(description.AssetName));
     if (sample == null)
         throw new Exception("Could not find asset: (" + description.AssetName + ").");
     data = sample.SampleData;
     freq = sample.SampleRate;
     if (end < 0)
         end = sample.End;
     if (start < 0)
         start = sample.Start;
     if (loopEnd < 0)
     {
         if (sample.LoopEnd < 0)
             loopEnd = end;
         else
             loopEnd = sample.LoopEnd;
     }
     if (loopStart < 0)
     {
         if (sample.LoopStart < 0)
             loopStart = start;
         else
             loopStart = sample.LoopStart;
     }
     if (genPeriod < 0)
         genPeriod = 1;
     if (root < 0)
     {
         root = sample.RootKey;
         if (tuneCents == 0)
             tuneCents = sample.Tune;
     }
     //check sample end and loop end for consistency
     if (end > data.Length)
         end = data.Length;
     if (loopEnd > end)
         loopEnd = end;
 }
 public DescriptorList(BinaryReader reader)
 {
     List<EnvelopeDescriptor> envList = new List<EnvelopeDescriptor>();
     List<FilterDescriptor> fltrList = new List<FilterDescriptor>();
     List<LfoDescriptor> lfoList = new List<LfoDescriptor>();
     List<GeneratorDescriptor> genList = new List<GeneratorDescriptor>();
     List<CustomDescriptor> cList = new List<CustomDescriptor>();
     int count = reader.ReadInt16();
     for (int x = 0; x < count; x++)
     {
         string id = new string(IOHelper.Read8BitChars(reader, 4));
         int size = reader.ReadInt32();
         switch (id.ToLower())
         {
             case EnvelopeDescriptor.ID:
             {
                 EnvelopeDescriptor env = new EnvelopeDescriptor();
                 env.Read(reader);
                 envList.Add(env);
                 break;
             }
             case GeneratorDescriptor.ID:
             {
                 GeneratorDescriptor gen = new GeneratorDescriptor();
                 gen.Read(reader);
                 genList.Add(gen);
                 break;
             }
             case FilterDescriptor.ID:
             {
                 FilterDescriptor fltr = new FilterDescriptor();
                 fltr.Read(reader);
                 fltrList.Add(fltr);
                 break;
             }
             case LfoDescriptor.ID:
             {
                 LfoDescriptor lfo = new LfoDescriptor();
                 lfo.Read(reader);
                 lfoList.Add(lfo);
                 break;
             }
             default:
             {
                 CustomDescriptor cus = new CustomDescriptor(id, size);
                 cus.Read(reader);
                 cList.Add(cus);
                 break;
             }
         }
     }
     EnvelopeDescriptions = envList.ToArray();
     FilterDescriptions = fltrList.ToArray();
     LfoDescriptions = lfoList.ToArray();
     GenDescriptions = genList.ToArray();
     CustomDescriptions = cList.ToArray();
 }
 private void LoadSfzGens(SfzRegion region)
 {
     GenDescriptions = new GeneratorDescriptor[1];
     GenDescriptions[0] = new GeneratorDescriptor();
     GenDescriptions[0].SamplerType = Components.WaveformEnum.SampleData;
     GenDescriptions[0].AssetName = region.sample;
     //deal with end point
     if (region.end == -1) //-1 is silent region, so set end to 0 and let the generator figure it out later
         GenDescriptions[0].EndPhase = 0;
     else if (region.end == 0) //set end out of range and let the descriptor default it to the proper end value
         GenDescriptions[0].EndPhase = -1;
     else //add one to the value because its inclusive
         GenDescriptions[0].EndPhase = region.end + 1;
     GenDescriptions[0].KeyTrack = region.pitchKeyTrack;
     //deal with loop end
     if (region.loopEnd < 0)
         GenDescriptions[0].LoopEndPhase = -1;
     else
         GenDescriptions[0].LoopEndPhase = region.loopEnd + 1;
     GenDescriptions[0].LoopMethod = region.loopMode;
     if (region.loopStart < 0)
         GenDescriptions[0].LoopStartPhase = -1;
     else
         GenDescriptions[0].LoopStartPhase = region.loopStart;
     GenDescriptions[0].Offset = region.offset;
     GenDescriptions[0].Rootkey = region.pitchKeyCenter;
     GenDescriptions[0].Tune = (short)(region.tune + region.transpose * 100);
     GenDescriptions[0].VelTrack = region.pitchVelTrack;
 }
 //--Methods
 public Generator(GeneratorDescriptor description)
 {
     loopMethod = description.LoopMethod;
     loopStart = description.LoopStartPhase;
     loopEnd = description.LoopEndPhase;
     start = description.StartPhase;
     end = description.EndPhase;
     startOffset = description.Offset;
     genPeriod = description.Period;
     root = description.Rootkey;
     noteTrack = description.KeyTrack;
     velTrack = description.VelTrack;
     tuneCents = description.Tune;
 }