public MidiModuleDefinition RegisterOrUpdate(SoundFont sf2)
        {
            var existing = Modules.FirstOrDefault (m => m.Name == sf2.FileInfo.BankName);
            if (existing != null)
                return existing;

            var mod = new MidiModuleDefinition ();
            mod.Name = sf2.FileInfo.BankName;

            // only one map for one sf2.
            var map = new MidiInstrumentMap () { Name = sf2.FileInfo.BankName };
            mod.Instrument.Maps.Add (map);

            foreach (var preset in sf2.Presets.OrderBy (p => p.PatchNumber).ThenBy (p => p.Bank)) {
                var prog = map.Programs.FirstOrDefault (p => p.Index == preset.PatchNumber);
                if (prog == null) {
                    prog = new MidiProgramDefinition () { Index = preset.PatchNumber, Name = preset.Name };
                    map.Programs.Add (prog);
                }
                prog.Banks.Add (new MidiBankDefinition () { Name = preset.Name, Msb = preset.Bank });
            }

            Modules.Add (mod);

            return mod;
        }
예제 #2
0
        public MidiModuleDefinition Import(string file)
        {
            var doc = XDocument.Load(file);
            var mod = doc.Element("ModuleData");
            var mdd = new MidiModuleDefinition()
            {
                Name = mod.Attr("Name")
            };

            foreach (var ilist in mod.Elements("InstrumentList"))
            {
                foreach (var map in ilist.Elements("Map"))
                {
                    var mad = new MidiInstrumentMap()
                    {
                        Name = map.Attr("Name")
                    };
                    mdd.Instrument.Maps.Add(mad);
                    foreach (var pc in map.Elements("PC"))
                    {
                        var pd = new MidiProgramDefinition()
                        {
                            Name = pc.Attr("Name"), Index = pc.AttrAsInt("PC") - 1
                        };                                                                                                                          // the domino XML index begins with 1 up to 128, so decrease here.
                        mad.Programs.Add(pd);
                        foreach (var bank in pc.Elements("Bank"))
                        {
                            if (bank.Attr("MSB") == null)
                            {
                                // Domino XML definition contains extra bank element that mimics mapping. We have to skip it.
                                continue;
                            }
                            pd.Banks.Add(new MidiBankDefinition()
                            {
                                Name = bank.Attr("Name"), Msb = bank.AttrAsInt("MSB"), Lsb = bank.AttrAsInt("LSB")
                            });
                        }
                    }
                }
            }

            return(mdd);
        }
예제 #3
0
 void LoadMaps(XElement mod, string name, IList <MidiInstrumentMap> maps)
 {
     if (maps == null)
     {
         throw new ArgumentException("null maps");
     }
     foreach (var ilist in mod.Elements(name))
     {
         foreach (var map in ilist.Elements("Map"))
         {
             var mad = new MidiInstrumentMap()
             {
                 Name = map.Attr("Name")
             };
             maps.Add(mad);
             foreach (var pc in map.Elements("PC"))
             {
                 var pd = new MidiProgramDefinition()
                 {
                     Name = pc.Attr("Name"), Index = pc.AttrAsInt("PC") - 1
                 };                                                                                                                          // the domino XML index begins with 1 up to 128, so decrease here.
                 mad.Programs.Add(pd);
                 foreach (var bank in pc.Elements("Bank"))
                 {
                     if (bank.Attr("MSB") == null)
                     {
                         // Domino XML definition contains extra bank element that mimics mapping. We have to skip it.
                         continue;
                     }
                     pd.Banks.Add(new MidiBankDefinition()
                     {
                         Name = bank.Attr("Name"), Msb = bank.AttrAsInt("MSB"), Lsb = bank.AttrAsInt("LSB")
                     });
                 }
             }
         }
     }
 }
예제 #4
0
        public MidiModuleDefinition Import(string file)
        {
            var doc = XDocument.Load (file);
            var mod = doc.Element ("ModuleData");
            var mdd = new MidiModuleDefinition () { Name = mod.Attr ("Name") };
            foreach (var ilist in mod.Elements ("InstrumentList"))
                foreach (var map in ilist.Elements ("Map")) {
                    var mad = new MidiInstrumentMap () { Name = map.Attr ("Name") };
                    mdd.Instrument.Maps.Add (mad);
                    foreach (var pc in map.Elements ("PC")) {
                        var pd = new MidiProgramDefinition () { Name = pc.Attr ("Name"), Index = pc.AttrAsInt ("PC") };
                        mad.Programs.Add (pd);
                        foreach (var bank in pc.Elements ("Bank")) {
                            if (bank.Attr ("MSB") == null)
                                // Domino XML definition contains extra bank element that mimics mapping. We have to skip it.
                                continue;
                            pd.Banks.Add (new MidiBankDefinition () {  Name = bank.Attr ("Name"), Msb = bank.AttrAsInt ("MSB"), Lsb = bank.AttrAsInt ("LSB") });
                        }
                    }
                }

            return mdd;
        }