Skip to content

Commit cdbcc0b

Browse files
committed
[+] Majdata的扩展伪双押语法(连续多个'`',每个128分音)的支持
See: https://github.com/LingFeng-bbben/MajdataEdit/blob/963812b6ec3e023360993f50fbbd7f51e9de9180/SimaiProcess.cs#L245-L258
1 parent db6b642 commit cdbcc0b

7 files changed

Lines changed: 84 additions & 17 deletions

File tree

i18n/Locale.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

i18n/Locale.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@
163163
<data name="PrepFix4" xml:space="preserve">
164164
<value>Attempted to fix {0} syntax error(s) in the chart (redundant duplicate parentheses, possibly from extra typing): {1}</value>
165165
</data>
166+
<data name="VisitFix1" xml:space="preserve">
167+
<value>Attempted to fix a syntax error in the chart (redundant duplicate EACH '/' or fake EACH '`' symbols, possibly from extra typing): {0}</value>
168+
</data>
169+
<data name="ExtenedFalseEach" xml:space="preserve">
170+
<value>You used multiple consecutive fake EACH '`' symbols. This is not standard Simai syntax, but following the behavior of other charting tools, it is interpreted as two notes staggered further apart in time (each '`' offsets timing by a 128th note). If this was not intentional, please review your input to avoid mistakes.</value>
171+
</data>
166172
<data name="BreakExIn103" xml:space="preserve">
167173
<value>The chart contains features not supported by MA2 1.03 (BreakEx). Those features were ignored and converted back to a pure break.</value>
168174
</data>

i18n/Locale.zh-hans.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@
163163
<data name="PrepFix4" xml:space="preserve">
164164
<value>尝试修复了谱面中的{0}处语法错误(重复的括号,可能是多打了一些): {1}</value>
165165
</data>
166+
<data name="VisitFix1" xml:space="preserve">
167+
<value>尝试修复了谱面中的语法错误(重复的双押"/"或伪双押"`"符号,可能是多打了一些): {0}</value>
168+
</data>
169+
<data name="ExtenedFalseEach" xml:space="preserve">
170+
<value>您使用了连续多个伪双押'`'的语法。这并非Simai标准语法,但遵循其他制谱软件的行为,解释为错开时间更长的两个音符(每个'`'错开128分音)。如果您并非有意为之,请检查您的输入以防输入错误。</value>
171+
</data>
166172
<data name="BreakExIn103" xml:space="preserve">
167173
<value>谱面中含有MA2 1.03所不支持的特性(绝赞+保护套)。相关特性已被忽略、还原回非保护绝赞。</value>
168174
</data>

i18n/Locale.zh-hant.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@
163163
<data name="PrepFix4" xml:space="preserve">
164164
<value>嘗試修復了譜面中的{0}處語法錯誤(重複的括號,可能是多打了一些): {1}</value>
165165
</data>
166+
<data name="VisitFix1" xml:space="preserve">
167+
<value>嘗試修復了譜面中的語法錯誤(重複的雙押「/」或偽雙押「`」符號,可能是多打了一些): {0}</value>
168+
</data>
169+
<data name="ExtenedFalseEach" xml:space="preserve">
170+
<value>您使用了連續多個偽雙押「`」的語法。這並非 Simai 標準語法,但遵循其他製譜軟體的行為,解釋為錯開時間更長的兩個音符(每個「`」錯開 128 分音)。若您並非有意為之,請檢查您的輸入以防輸入錯誤。</value>
171+
</data>
166172
<data name="BreakExIn103" xml:space="preserve">
167173
<value>譜面中含有 MA2 1.03 所不支援的特性(絕贊 + 保護套)。相關特性已被忽略,並還原回非保護絕贊。</value>
168174
</data>

parser/simai/Simai.g4

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ modifiers: (MODIFIER | TAP_TO_STAR)*;
3838
chart: (notations ',')* CHART_END? EOF;
3939

4040
// 同一时刻的所有标记,包括note标记、bpm标记等等
41-
notations: (bpmTag | absulouteStepTag | metTag)* noteGroup*;
42-
43-
noteGroup: note (eachNote | falseEachNote)*;
41+
notations: (bpmTag | absulouteStepTag | metTag)* noteGroup?;
4442

45-
eachNote: '/' note;
46-
falseEachNote: '`' note;
43+
noteGroup: note eachNote*;
44+
eachSeparators: ('/' | '`')+;
45+
eachNote: eachSeparators note;
4746

4847
bpmTag: '(' number ')';
4948
absulouteStepTag: '{' '#' number '}';

parser/simai/SimaiParser.cs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ public partial class SimaiParser : SimaiBaseVisitor<object>, IParser
1818
private Rational now = 0;
1919
private Rational step = new(1, 4);
2020
private decimal? absoluteTimeStep; // 此项必须和step本体一起更改
21+
private Rational extendedFalseEach = 0; // 扩展伪双押语法(多个连续的`)累计后移了多少时间。每次遇到逗号时,这个数字需要清零。
2122

2223
private ParserRuleContext? currContext; // 供调试报错AddAlert函数使用
2324
private Note? currNote; // 用于在部分visitor之间传递额外的参数,如visitDuration、visitSlideBody等,都需要Note对象作为参数传入的情况
2425
private bool isRealExactWaitTime; // 用于在VisitSlideBody和VisitSlideDuration之间传递额外的参数
2526
private readonly List<string> extraModifiers = [];
27+
2628
private bool absoluteTimeStepWarned; // 用于确保Warning只打印一次
29+
private bool extendedFalseEachWarned;
2730

2831
public SimaiParser(bool bigTouch = false, int clockCount = 4)
2932
{
@@ -174,6 +177,11 @@ public sealed override object VisitChart(P.ChartContext context)
174177
{
175178
VisitNotations(notations);
176179
if (chart.BpmList.Count == 0) AddDefaultBpm();
180+
if (extendedFalseEach > 0)
181+
{ // 如果之前的解析过程中,触发了extendedFalseEach的话。则要把被额外增加的时间扣回来。
182+
now -= extendedFalseEach;
183+
extendedFalseEach = 0;
184+
}
177185
now = (now + step).CanonicalForm;
178186
}
179187
return true;
@@ -264,11 +272,35 @@ public sealed override object VisitNoteGroup(P.NoteGroupContext context)
264272
{
265273
P.NoteContext noteC;
266274
if (child is P.NoteContext c1) noteC = c1;
267-
else if (child is P.EachNoteContext c2) noteC = c2.note();
268-
else if (child is P.FalseEachNoteContext c3)
275+
else if (child is P.EachNoteContext c2)
269276
{
270-
noteC = c3.note();
271-
falseEachIdx++;
277+
noteC = c2.note();
278+
279+
var separators = c2.eachSeparators().GetText()!;
280+
if (separators.Length >= 2 && separators.All(c=>c=='`'))
281+
{
282+
// 出现连续多个反引号的情况,如"2``3"。
283+
// 这并不是标准的simai语法。但是,MajdataView中对此提供了支持,将每个`实现为128分音。
284+
// 因此,我们也支持这一特性,在遇到大于一个`时,不实现成FalseEachIndex,而是直接给予相同的实现、每个`错后128分音。
285+
var length = separators.Length * new Rational(1, 128);
286+
now = (now + length).CanonicalForm;
287+
extendedFalseEach += length;
288+
falseEachIdx = 0;
289+
if (!extendedFalseEachWarned)
290+
{
291+
AddAlert(Warning, Locale.ExtenedFalseEach, context);
292+
extendedFalseEachWarned = true;
293+
}
294+
}
295+
else
296+
{
297+
if (separators[0] == '`') falseEachIdx++; // (出于鲁棒性,只看开头符号)属于伪双押类型。自增falseEachIndex
298+
// 否则,就一定是'/'开头,属于普通双押,什么都不用做。
299+
if (separators.Length > 1)
300+
{ // 如果连续出现多个双押符号,如上所示只采信第一个,然后给警告。
301+
AddAlert(Warning, string.Format(Locale.VisitFix1, separators), context);
302+
}
303+
}
272304
}
273305
else throw Utils.Fail();
274306

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
simai: "{12}8h[1:0],7h[1:0],6h[1:0],5h[1:0],,2``3,,6``5,,"
22
ma2: |
3-
NMTHO 0 32 7 0
4-
NMTHO 0 64 6 0
5-
NMTHO 0 96 5 0
6-
NMTHO 0 128 4 0
7-
NMTAP 0 192 1 0
8-
NMTAP 0 198 2 0
9-
NMTAP 0 256 5 0
10-
NMTAP 0 262 4 0
3+
NMHLD 0 0 7 0
4+
NMHLD 0 32 6 0
5+
NMHLD 0 64 5 0
6+
NMHLD 0 96 4 0
7+
NMTAP 0 160 1
8+
NMTAP 0 166 2
9+
NMTAP 0 224 5
10+
NMTAP 0 230 4

0 commit comments

Comments
 (0)