示例#1
0
        /// <summary>Plays the specified command.</summary>
        /// <param name="cmd">The command.</param>
        /// <exception cref="NotImplementedException"></exception>
        public void Play(ISynchronizedLyricsCommand cmd)
        {
            switch (cmd.Type)
            {
            case SynchronizedLyricsCommandType.None: return;

            case SynchronizedLyricsCommandType.ClearScreen: ClearScreen((SlcWithColorIndex)cmd); break;

            case SynchronizedLyricsCommandType.ReplacePaletteColor: ReplacePaletteColor((SlcReplacePaletteColor)cmd); break;

            case SynchronizedLyricsCommandType.ReplacePaletteColors: ReplacePaletteColors((SlcReplacePaletteColors)cmd); break;

            case SynchronizedLyricsCommandType.SetTransparentColor: SetTransparentColor((SlcWithColorIndex)cmd); break;

            case SynchronizedLyricsCommandType.SetSprite2Colors: SetSprite2Colors((SlcSetSprite2Colors)cmd); break;

            case SynchronizedLyricsCommandType.SetSprite2ColorsXOR: SetSprite2Colors((SlcSetSprite2Colors)cmd); break;

            case SynchronizedLyricsCommandType.ScreenOffset: SetScreenOffset((SlcScreenOffset)cmd); break;

            case SynchronizedLyricsCommandType.ScreenScroll: ScreenScroll((SlcScreenScroll)cmd); break;

            case SynchronizedLyricsCommandType.ScreenRoll: ScreenRoll((SlcScreenRoll)cmd); break;

            default: throw new NotImplementedException();
            }
        }
示例#2
0
        /// <summary>Creates a new <see cref="SynchronizedLyrics"/> instance by parsing the specified stream.</summary>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        public static SynchronizedLyrics FromStream(MemoryStream stream)
        {
            var  items       = new List <SynchronizedLyricsItem>();
            long milliSecond = 0;

            var reader = new DataReader(stream);

            if (reader.ReadString(3) != "SLT")
            {
                throw new InvalidDataException("Invalid format!");
            }

            if (reader.Read7BitEncodedUInt64() != 1)
            {
                throw new InvalidDataException("Invalid version!");
            }

            while (reader.Available > 0)
            {
                long milliSecondDistance = reader.Read7BitEncodedInt64();
                milliSecond += milliSecondDistance;

                var item = new SynchronizedLyricsItemBuilder();
                item.TimeCode = new TimeSpan(milliSecond * TimeSpan.TicksPerMillisecond);
                while (true)
                {
                    ISynchronizedLyricsCommand command = SynchronizedLyricsCommand.Parse(reader);
                    if (command == null)
                    {
                        break;
                    }

                    item.Commands.Add(command);
                }
                items.Add(item.ToSynchronizedLyricsItem());
            }
            return(new SynchronizedLyrics(items));
        }