Skip to content

Commit

Permalink
👍 Remove dotted component in tuplet
Browse files Browse the repository at this point in the history
  • Loading branch information
AutumnSky1010 committed Mar 15, 2024
1 parent d5d2df7 commit 2ce4002
Showing 5 changed files with 10 additions and 24 deletions.
18 changes: 2 additions & 16 deletions src/SoundMaker/ScoreData/SMSC/Parser.cs
Original file line number Diff line number Diff line change
@@ -248,15 +248,8 @@ private ParseResult<ISoundComponent> ParseTuplet()
{
// 'rest'のトークンを破棄
_ = _tokens.Dequeue();
var isDottedRest = false;
// '.'の場合は付点休符とする
if (_tokens.TryPeek(out var dotToken) && dotToken.Type is TokenType.Dot)
{
_ = _tokens.Dequeue();
isDottedRest = true;
}
// 連符なので長さは適当に入れる
var rest = new Rest(LengthType.Whole, isDottedRest);
var rest = new Rest(LengthType.Whole, false);
components.Add(rest);
}
// 上記以外は音符として解析するが、連符専用の書き方なのでここで実装する。
@@ -268,15 +261,8 @@ private ParseResult<ISoundComponent> ParseTuplet()
{
return new(null, scaleResult.Error);
}
var isDottedNote = false;
// '.'の場合は付点音符とする
if (_tokens.TryPeek(out var dotToken) && dotToken.Type is TokenType.Dot)
{
_ = _tokens.Dequeue();
isDottedNote = true;
}
// 連符なので長さは適当に入れる
var note = new Note(scale.Scale, scale.ScaleNumber, LengthType.Whole, isDottedNote);
var note = new Note(scale.Scale, scale.ScaleNumber, LengthType.Whole, false);
components.Add(note);
}
}
2 changes: 1 addition & 1 deletion src/SoundMaker/ScoreData/SMSC/SMSC.bnf
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ rest ::= 'rest' ',' <length>
tie ::= 'tie' '(' <scale> ',' <length>|'rest' {',' <length>|'rest'}* ')'

# 連符の表記方法 - Tuplet notation
tuplet ::= 'tup' '(' <length> ',' {<scale> '.'?}|{'rest' '.'?}|<tie> {',' {<scale> '.'?}|{'rest' '.'?}|<tie>}* ')'
tuplet ::= 'tup' '(' <length> ',' <scale>|'rest'|<tie> {',' <scale>|'rest'|<tie>}* ')'

# 文末 - End of statement
endOfStatement ::= ';'|\n|\r|\r\n
2 changes: 1 addition & 1 deletion src/SoundMaker/ScoreData/SMSC/SMSCSerializer.cs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ public static string Serialize(IEnumerable<ISoundComponent> components)
Tuplet tuplet => SerializeTuplet(tuplet),
_ => "",
};
_ = smscBuilder.AppendLine(line);
_ = smscBuilder.Append(line).Append('\n');
}
return smscBuilder.ToString();
}
6 changes: 3 additions & 3 deletions test/UnitTests/ScoreData/SMSC/ParserTest.cs
Original file line number Diff line number Diff line change
@@ -155,7 +155,7 @@ public void TestParse_Tie()
[Fact(DisplayName = "連符を解析できるか")]
public void TestParse_Tuplet()
{
var data = "tup(16, C#4, rest, E4.)";
var data = "tup(16, C#4, rest, E4)";
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
@@ -263,7 +263,7 @@ public void Test_NotFoundCommaErrors(string data, int expectedCount)
}

[Theory(DisplayName = ")が見つからないエラーのテスト")]
[InlineData("tie(C4,1;tup(4.,C4.", 2)]
[InlineData("tie(C4,1;tup(4,C4", 2)]
public void Test_NotFoundRightParenthesesErrors(string data, int expectedCount)
{
var lexer = new Lexer(data);
@@ -274,7 +274,7 @@ public void Test_NotFoundRightParenthesesErrors(string data, int expectedCount)
}

[Theory(DisplayName = "(が見つからないエラーのテスト")]
[InlineData("tie)C4,1;tup4.,C4.", 2)]
[InlineData("tie)C4,1;tup.4,C4", 2)]
public void Test_NotFoundLeftParenthesesErrors(string data, int expectedCount)
{
var lexer = new Lexer(data);
6 changes: 3 additions & 3 deletions test/UnitTests/ScoreData/SMSC/SMSCSerializerTest.cs
Original file line number Diff line number Diff line change
@@ -8,11 +8,11 @@ public class SMSCSerializerTest
public void TestSerialize()
{
var note = new Note(Scale.C, 4, LengthType.Whole, true);

var tupletNote = new Note(Scale.C, 4, LengthType.Whole);
var expected = @"C4,1.
rest,4
tie(C4,1.,1.,1.)
tup(2,C4.,C4.,C4.)
tup(2,C4,C4,C4)
";

var components = new List<ISoundComponent>()
@@ -23,7 +23,7 @@ public void TestSerialize()
{
note, note
}),
new Tuplet(new List<ISoundComponent>() {note, note, note}, LengthType.Half, false)
new Tuplet(new List<ISoundComponent>() { tupletNote, tupletNote, tupletNote}, LengthType.Half, false)
};

var actual = SMSCSerializer.Serialize(components);

0 comments on commit 2ce4002

Please sign in to comment.