コード例 #1
0
        private List <SheetmusicInfo> importToStorage(FileReader reader)
        {
            List <SheetmusicInfo> sheetmusicInfos = new List <SheetmusicInfo>();
            var sheetNames = reader.Filenames.Where(f => f.EndsWith(".sm"));

            foreach (string name in sheetNames)
            {
                using (var raw = reader.GetStream(name))
                    using (var ms = new MemoryStream()) //we need a memory stream so we can seek and shit
                        using (var sr = new StreamReader(ms)) {
                            copyTo(raw, ms);
                            ms.Position = 0;

                            var        decoder    = SheetmusicDecoder.GetDecoder(sr);
                            Sheetmusic sheetmusic = decoder.Decode(sr);
                            sheetmusic.SheetmusicInfo.Path = name;
                            RulesetInfo rulesetInfo = rulesets.Where(r => r.RulesetInfo.ID == sheetmusic.SheetmusicInfo.RulesetID)
                                                      .FirstOrDefault().RulesetInfo;
                            sheetmusic.SheetmusicInfo.RulesetInfo = rulesetInfo;

                            sheetmusicInfos.Add(sheetmusic.SheetmusicInfo);
                        }
            }
            return(sheetmusicInfos);
        }
コード例 #2
0
        /// <summary>
        /// 當workingSheetmusic的sheetmusic是null時,就會呼叫GetSheetmusic來擺進Sheetmusic裡
        /// </summary>
        /// <returns></returns>
        protected override Sheetmusic GetSheetmusic()
        {
            try {
                Sheetmusic sheetmusic;

                SheetmusicDecoder decoder;
                // TODO: 把音樂擺的位置設成可變動的參數,應該是存在SheetmusicInfo,一開始就知道的path位置
                using (var stream = new StreamReader((Application.dataPath + "/Resources/Sheetmusics/" + SheetmusicInfo.Path))) {
                    decoder    = SheetmusicDecoder.GetDecoder(stream);
                    sheetmusic = decoder.Decode(stream);
                }
                return(sheetmusic);
            } catch {
                return(null);
            }
        }