babalae/better-genshin-impact · warning · FormatException

音符 {keys} 缺少时值

Error message

音符 {keys} 缺少时值

What it means

Thrown by MusicScoreParser.ParseYuanQinTokens(string) when after parsing a key or chord, the next character is not '['. In yuanqin sheet syntax, every note or chord must be immediately followed by a duration bracket, e.g. Q[1] or (QW)[2]. If the '[' is missing (end of string or wrong character), the note is considered to lack a duration value.

Source

Thrown at BetterGenshinImpact/GameTask/Music/Service/MusicScoreParser.cs:306

            {
                var end = sheet.IndexOf(')', index + 1);
                if (end < 0)
                {
                    throw new FormatException("和弦缺少右括号");
                }

                keys = sheet[(index + 1)..end];
                index = end + 1;
            }
            else
            {
                keys = sheet[index].ToString();
                index++;
            }

            if (index >= sheet.Length || sheet[index] != '[')
            {
                throw new FormatException($"音符 {keys} 缺少时值");
            }

            var bracketEnd = sheet.IndexOf(']', index + 1);
            if (bracketEnd < 0)
            {
                throw new FormatException($"音符 {keys} 的时值缺少右方括号");
            }

            var value = sheet[(index + 1)..bracketEnd];
            index = bracketEnd + 1;
            if (value is "^" or "&")
            {
                tokens.Add(new YuanQinToken(keys, 0, value));
                continue;
            }

            var separator = value.IndexOf('-');
            var denominatorText = separator >= 0 ? value[..separator] : value;

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Ensure every note/chord in the sheet is immediately followed by a duration bracket, e.g. Q[1], (QW)[2].
  2. Review the sheet around the reported keys value to find the missing bracket.
  3. Validate the sheet format against example yuanqin scores.
Defensive patterns

Strategy: validation

Validate before calling

// Verify each note is followed by a duration bracket
var pattern = @"([A-Z]|\([^)]+\))\[";
// Scan the sheet to ensure all notes have [..] brackets

Try / catch

var score = await parser.ParseAsync(path, rootFolder, ct);
if (!string.IsNullOrEmpty(score.Error)) { logger.LogWarning(score.Error); }

Prevention

When it happens

Trigger: A yuanqin sheet string where a note key is not followed by a '['-delimited duration. For example, 'QW' (missing '[1]') or 'Q[1] W' (W has no duration bracket).

Common situations: Manual editing error omitting duration brackets; a score that uses a shorthand notation not supported by the parser; truncated sheet.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/7f669ed6d922841e. Report an issue: GitHub.