Exemplo n.º 1
0
		public override object Read(BinaryReader br) 
		{
			Preset p = new Preset();
			string s = Encoding.ASCII.GetString(br.ReadBytes(20));
			if(s.IndexOf('\0') >= 0) {
				s = s.Substring(0,s.IndexOf('\0'));
			}
			p.Name = s;
			p.PatchNumber = br.ReadUInt16();
			p.Bank = br.ReadUInt16();
			p.startPresetZoneIndex = br.ReadUInt16();
			p.library = br.ReadUInt32();
			p.genre = br.ReadUInt32();
			p.morphology = br.ReadUInt32();			
			if(lastPreset != null)
				lastPreset.endPresetZoneIndex = (ushort) (p.startPresetZoneIndex - 1);
			data.Add(p);
			lastPreset = p;
			return p;
		}
Exemplo n.º 2
0
        void ImportSamples(SoundFont sf2, Preset preset, XInstrument xrni)
        {
            var xl = new List<XSample> ();
            var ml = new List<SampleMap> ();
            var il = new List<int> ();
            foreach (var pzone in preset.Zones) { // perc. bank likely has more than one instrument here.
                var i = pzone.Instrument ();
                var kr = pzone.KeyRange (); // FIXME: where should I use it?
                if (i == null)
                    continue; // FIXME: is it possible?

                var vr = pzone.VelocityRange ();

                // an Instrument contains a set of zones that contain sample headers.
                int sampleCount = 0;
                foreach (var izone in i.Zones) {
                    var ikr = izone.KeyRange ();
                    var ivr = izone.VelocityRange ();
                    var sh = izone.SampleHeader ();
                    if (sh == null)
                        continue; // FIXME: is it possible?

                    // FIXME: sample data must become monoral (panpot neutral)
                    var xs = ConvertSample (sampleCount++, sh, sf2.SampleData, izone);
                    xs.Name = NormalizePathName (sh.SampleName);
                    ml.Add (new SampleMap (ikr, ivr, xs, sh));
                }
            }

            ml.Sort ((m1, m2) =>
                m1.KeyLowRange != m2.KeyLowRange ? m1.KeyLowRange - m2.KeyLowRange :
                m1.KeyHighRange != m2.KeyHighRange ? m1.KeyHighRange - m2.KeyHighRange :
                m1.VelocityLowRange != m2.VelocityLowRange ? m1.VelocityLowRange - m2.VelocityLowRange :
                m1.VelocityHighRange - m2.VelocityHighRange);

            int prev = -1;
            foreach (var m in ml) {
                prev = m.KeyLowRange;
                il.Add (m.KeyLowRange);
                xl.Add (m.Sample);
            }

            xrni.SampleSplitMap = new SampleSplitMap ();
            xrni.SampleSplitMap.NoteOnMappings = new SampleSplitMapNoteOnMappings ();
            var nm = new SampleSplitMapping [ml.Count];
            xrni.SampleSplitMap.NoteOnMappings.NoteOnMapping = nm;
            for (int i = 0; i < ml.Count; i++) {
                var m = ml [i];
                var n = new SampleSplitMapping ();
                n.BaseNote = m.Sample.BaseNote;
                n.NoteStart = m.KeyLowRange;
                n.NoteEnd = m.KeyHighRange <= 0 ? 128 : m.KeyHighRange;
                n.SampleIndex = i;
                if (m.VelocityHighRange > 0) {
                    n.MapVelocityToVolume = true;
                    n.VelocityStart = m.VelocityLowRange;
                    n.VelocityEnd = m.VelocityHighRange;
                }
                nm [i] = n;
            }

            xrni.Samples = new RenoiseInstrumentSamples ();
            xrni.Samples.Sample = xl.ToArray ();
        }