Exemple #1
0
        private static Beatmap decodeLrcLine(string line)
        {
            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new LineBufferedReader(stream))
                    {
                        // Create stream
                        writer.Write(line);
                        writer.Flush();
                        stream.Position = 0;

                        // Create karaoke note decoder
                        var decoder = new LrcDecoder();
                        return(decoder.Decode(reader));
                    }
        }
Exemple #2
0
        public void ImportLrcFile(FileInfo info)
        {
            if (!info.Exists)
            {
                throw new FileNotFoundException("Lyric file does not found!");
            }

            var isFormatMatch = LyricFormatExtensions.Contains(info.Extension);

            if (!isFormatMatch)
            {
                throw new FileLoadException("Only .lrc or .kar karaoke file is supported now");
            }

            var set     = beatmap.Value.BeatmapSetInfo;
            var oldFile = set.Files?.FirstOrDefault(f => f.Filename == backup_lrc_name);

            using (var stream = info.OpenRead())
            {
                // todo : make a backup if has new lyric file.

                /*
                 * if (oldFile != null)
                 *  beatmaps.ReplaceFile(set, oldFile, stream, backup_lrc_name);
                 * else
                 *  beatmaps.AddFile(set, stream, backup_lrc_name);
                 */

                // Import and replace all the file.
                using (var reader = new Game.IO.LineBufferedReader(stream))
                {
                    var decoder    = new LrcDecoder();
                    var lrcBeatmap = decoder.Decode(reader);

                    // remove all hit objects (note and lyric) from beatmap
                    editorBeatmap.Clear();

                    // then re-add the lyric.
                    var lyrics = lrcBeatmap.HitObjects.OfType <Lyric>();
                    editorBeatmap.AddRange(lyrics);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Process test case lyric string format into <see cref="Lyric"/>
        /// </summary>
        /// <example>
        /// "[00:01.00]か[00:02.00]ら[00:03.00]お[00:04.00]け[00:05.00]"
        /// </example>
        /// <param name="str">Lyric string format</param>
        /// <returns><see cref="Lyric"/>Lyric object</returns>
        public static Lyric ParseLyricWithTimeTag(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return(new Lyric());
            }

            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new LineBufferedReader(stream))
                    {
                        // Create stream
                        writer.Write(str);
                        writer.Flush();
                        stream.Position = 0;

                        // Create karaoke note decoder
                        var decoder = new LrcDecoder();
                        return(decoder.Decode(reader).HitObjects.OfType <Lyric>().FirstOrDefault());
                    }
        }
Exemple #4
0
        private static Beatmap decode(string filename, out Beatmap encoded)
        {
            using (var stream = TestResources.OpenLrcResource(filename))
                using (var sr = new LineBufferedReader(stream))
                {
                    // Read file and decode to file
                    var legacyDecoded = new LrcDecoder().Decode(sr);

                    using (var ms = new MemoryStream())
                        using (var sw = new StreamWriter(ms))
                            using (var sr2 = new LineBufferedReader(ms))
                            {
                                // Then encode file to stream
                                var encodeResult = new LrcEncoder().Encode(legacyDecoded);
                                sw.WriteLine(encodeResult);
                                sw.Flush();

                                ms.Position = 0;

                                encoded = new LrcDecoder().Decode(sr2);
                                return(legacyDecoded);
                            }
                }
        }