Esempio n. 1
0
        public static DlsCollection Read(Stream stream)
        {
            using (var reader = new RiffReader(stream))
            {
                var collectionVersion = default(Version);
                var instruments       = new List <DlsInstrument>();
                var wavePool          = new List <DlsWaveFile>();
                var info = new DlsInfo();
                var id   = default(Guid?);

                foreach (var dlsSubchunk in reader.ReadRiff("DLS ").ReadList())
                {
                    switch (dlsSubchunk.Name)
                    {
                    case "vers":
                        var minor    = dlsSubchunk.ReadUInt16();
                        var major    = dlsSubchunk.ReadUInt16();
                        var revision = dlsSubchunk.ReadUInt16();
                        var build    = dlsSubchunk.ReadUInt16();
                        collectionVersion = new Version(major, minor, build, revision);
                        break;

                    case "dlid":
                        id = ReadDlsId(dlsSubchunk);
                        break;

                    case "lins":
                        instruments.AddRange(
                            from lrgnSubchunk in dlsSubchunk.ReadList()
                            where lrgnSubchunk.Name == "ins "
                            let instrument = ReadDlsInstrument(lrgnSubchunk)
                                             where instrument != null
                                             select instrument.Value);
                        break;

                    case "wvpl":
                        wavePool.AddRange(
                            from wvplSubchunk in dlsSubchunk.ReadList()
                            where wvplSubchunk.Name == "wave"
                            let waveFile = ReadDlsWaveFile(wvplSubchunk)
                                           where waveFile != null
                                           select waveFile.Value);
                        break;

                    case "INFO":
                        info = ReadDlsInfo(dlsSubchunk);
                        break;
                    }
                }

                return(new DlsCollection(id, collectionVersion, info, instruments, wavePool));
            }
        }