Beispiel #1
0
        internal static InstrumentRegion[] Create(Instrument instrument, Span <Zone> zones, SampleHeader[] samples)
        {
            Zone global = null;

            // Is the first one the global zone?
            if (zones[0].Generators.Length == 0 || 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.
                var regions = new InstrumentRegion[zones.Length - 1];
                for (var i = 0; i < regions.Length; i++)
                {
                    regions[i] = new InstrumentRegion(instrument, global.Generators, zones[i + 1].Generators, samples);
                }
                return(regions);
            }
            else
            {
                // No global zone.
                var regions = new InstrumentRegion[zones.Length];
                for (var i = 0; i < regions.Length; i++)
                {
                    regions[i] = new InstrumentRegion(instrument, null, zones[i].Generators, samples);
                }
                return(regions);
            }
        }
Beispiel #2
0
        public Voice RequestNew(InstrumentRegion region, int channel)
        {
            Voice free           = null;
            Voice low            = null;
            var   lowestPriority = float.MaxValue;

            var exclusiveClass = region.ExclusiveClass;

            if (exclusiveClass == 0)
            {
                for (var i = 0; i < activeVoiceCount; i++)
                {
                    var voice = voices[i];
                    if (voice.Priority < lowestPriority)
                    {
                        lowestPriority = voice.Priority;
                        low            = voice;
                    }
                }
            }
            else
            {
                for (var i = 0; i < activeVoiceCount; i++)
                {
                    var voice = voices[i];
                    if (voice.ExclusiveClass == exclusiveClass && voice.Channel == channel)
                    {
                        voice.Kill();
                        free = voice;
                    }
                    if (voice.Priority < lowestPriority)
                    {
                        lowestPriority = voice.Priority;
                        low            = voice;
                    }
                }
            }

            if (free != null)
            {
                return(free);
            }

            if (activeVoiceCount < voices.Length)
            {
                free = voices[activeVoiceCount];
                activeVoiceCount++;
                return(free);
            }
            else
            {
                return(low);
            }
        }
Beispiel #3
0
        private Instrument(InstrumentInfo info, Zone[] zones, SampleHeader[] samples)
        {
            this.name = info.Name;

            var zoneCount = info.ZoneEndIndex - info.ZoneStartIndex + 1;

            if (zoneCount <= 0)
            {
                throw new InvalidDataException($"The instrument '{info.Name}' has no zone.");
            }

            var zoneSpan = zones.AsSpan(info.ZoneStartIndex, zoneCount);

            regions = InstrumentRegion.Create(this, zoneSpan, samples);
        }
 public static void StartModulation(this Lfo lfo, InstrumentRegion region, int key, int velocity)
 {
     StartModulation(lfo, new RegionPair(PresetRegion.Default, region), key, velocity);
 }
 public static void Start(this Oscillator oscillator, short[] data, InstrumentRegion region)
 {
     Start(oscillator, data, new RegionPair(PresetRegion.Default, region));
 }
 public static void Start(this ModulationEnvelope envelope, InstrumentRegion region, int key, int velocity)
 {
     Start(envelope, new RegionPair(PresetRegion.Default, region), key, velocity);
 }
 internal RegionPair(PresetRegion preset, InstrumentRegion instrument)
 {
     this.preset     = preset;
     this.instrument = instrument;
 }