Esempio n. 1
0
        protected override void OnXrniCreated(XInstrument xrni)
        {
            count++;
            string name = xrni.Name;
            var    path = Path.Combine(xrni_dir, NormalizeFileName(count + "_" + name)) + ".xrni";

            using (var fs = new FileStream(path, FileMode.Create))
                xrni.Save(fs);
        }
Esempio n. 2
0
        public void Import(string file, string filter)
        {
            var sf2 = new SoundFont (file);
            foreach (var preset in sf2.Presets) {
                if (filter != null && preset.Name.IndexOf (filter) < 0)
                    continue;
                Console.WriteLine ("Processing " + preset.Name);
                var xrni = new XInstrument ();
                xrni.Name = NormalizePathName (preset.Name);
                ImportSamples (sf2, preset, xrni);

                OnXrniCreated (xrni);
            }
        }
Esempio n. 3
0
        public void Import(string file, string filter)
        {
            var sf2 = new SoundFont(file);

            foreach (var preset in sf2.Presets)
            {
                if (filter != null && preset.Name.IndexOf(filter) < 0)
                {
                    continue;
                }
                Console.WriteLine("Processing " + preset.Name);
                var xrni = new XInstrument();
                xrni.Name = NormalizePathName(preset.Name);
                ImportSamples(sf2, preset, xrni);

                OnXrniCreated(xrni);
            }
        }
Esempio n. 4
0
        public static int Main(string [] args)
        {
            if (args.Length == 0) {
                Console.WriteLine ("Usage: xrni2sf2 [xnrifiles...]");
                return 1;
            }

            var files = new List<string> ();
            foreach (var arg in args) {
                files.Add (arg);
            }

            foreach (var file in files) {
                var path = Path.GetFileNameWithoutExtension(file);
                if (!Directory.Exists (path))
                    Directory.CreateDirectory (path);
                var instrument = new XInstrument();
                instrument.Load(file);
            }

            return 0;
        }
Esempio n. 5
0
 protected virtual void OnXrniCreated(XInstrument xrni)
 {
     xinstruments.Add (xrni);
 }
Esempio n. 6
0
 protected override void OnXrniCreated(XInstrument xrni)
 {
     count++;
     string name = xrni.Name;
     var path = Path.Combine (xrni_dir, count + "_" + name) + ".xrni";
     using (var fs = new FileStream (path, FileMode.Create))
         xrni.Save (fs);
 }
Esempio n. 7
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 ();
        }
Esempio n. 8
0
 protected virtual void OnXrniCreated(XInstrument xrni)
 {
     xinstruments.Add(xrni);
 }
Esempio n. 9
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();
        }