11using System . Diagnostics ;
22using AlphaTab . Audio . Generator ;
3+ using AlphaTab . Collections ;
4+ using AlphaTab . Importer ;
35using AlphaTab . Model ;
46using AlphaTab . Test . Importer ;
57using AlphaTab . Util ;
@@ -13,60 +15,64 @@ public class MidiPlaybackControllerTest : GpImporterTestBase
1315 [ TestMethod , AsyncTestMethod ]
1416 public void TestRepeatClose ( )
1517 {
16- PrepareImporterWithFile ( "GuitarPro5\\ RepeatClose.gp5" , reader =>
17- {
18- var score = reader . ReadScore ( ) ;
19- var expectedIndexes = new [ ]
18+ PrepareImporterWithFile ( "GuitarPro5\\ RepeatClose.gp5" ,
19+ reader =>
2020 {
21- 0 , 1 , 0 , 1 , 2
22- } ;
21+ var score = reader . ReadScore ( ) ;
22+ var expectedIndexes = new [ ]
23+ {
24+ 0 , 1 , 0 , 1 , 2
25+ } ;
2326
24- TestRepeat ( score , expectedIndexes ) ;
25- } ) ;
27+ TestRepeat ( score , expectedIndexes ) ;
28+ } ) ;
2629 }
2730
2831 [ TestMethod , AsyncTestMethod ]
2932 public void TestRepeatCloseMulti ( )
3033 {
31- PrepareImporterWithFile ( "GuitarPro5\\ RepeatCloseMulti.gp5" , reader =>
32- {
33- var score = reader . ReadScore ( ) ;
34- var expectedIndexes = new [ ]
34+ PrepareImporterWithFile ( "GuitarPro5\\ RepeatCloseMulti.gp5" ,
35+ reader =>
3536 {
36- 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 2
37- } ;
38- TestRepeat ( score , expectedIndexes ) ;
39- } ) ;
37+ var score = reader . ReadScore ( ) ;
38+ var expectedIndexes = new [ ]
39+ {
40+ 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 2
41+ } ;
42+ TestRepeat ( score , expectedIndexes ) ;
43+ } ) ;
4044 }
4145
4246 [ TestMethod , AsyncTestMethod ]
4347 public void TestRepeatCloseWithoutStartAtBeginning ( )
4448 {
45- PrepareImporterWithFile ( "GuitarPro5\\ RepeatCloseWithoutStartAtBeginning.gp5" , reader =>
46- {
47- var score = reader . ReadScore ( ) ;
48- var expectedIndexes = new [ ]
49+ PrepareImporterWithFile ( "GuitarPro5\\ RepeatCloseWithoutStartAtBeginning.gp5" ,
50+ reader =>
4951 {
50- 0 , 1 , 0 , 1
51- } ;
52+ var score = reader . ReadScore ( ) ;
53+ var expectedIndexes = new [ ]
54+ {
55+ 0 , 1 , 0 , 1
56+ } ;
5257
53- TestRepeat ( score , expectedIndexes ) ;
54- } ) ;
58+ TestRepeat ( score , expectedIndexes ) ;
59+ } ) ;
5560 }
5661
5762 [ TestMethod , AsyncTestMethod ]
5863 public void TestRepeatCloseAlternateEndings ( )
5964 {
60- PrepareImporterWithFile ( "GuitarPro5\\ RepeatCloseAlternateEndings.gp5" , reader =>
61- {
62- var score = reader . ReadScore ( ) ;
63- var expectedIndexes = new [ ]
65+ PrepareImporterWithFile ( "GuitarPro5\\ RepeatCloseAlternateEndings.gp5" ,
66+ reader =>
6467 {
65- 0 , 1 , 0 , 2 , 3 , 0 , 1 , 0 , 4
66- } ;
68+ var score = reader . ReadScore ( ) ;
69+ var expectedIndexes = new [ ]
70+ {
71+ 0 , 1 , 0 , 2 , 3 , 0 , 1 , 0 , 4
72+ } ;
6773
68- TestRepeat ( score , expectedIndexes ) ;
69- } ) ;
74+ TestRepeat ( score , expectedIndexes ) ;
75+ } ) ;
7076 }
7177
7278 private void TestRepeat ( Score score , int [ ] expectedIndexes )
@@ -83,11 +89,51 @@ private void TestRepeat(Score score, int[] expectedIndexes)
8389 Assert . AreEqual ( expectedIndexes [ i ] , index ) ;
8490 i ++ ;
8591 }
92+
8693 controller . MoveNext ( ) ;
8794 }
8895
8996 Assert . AreEqual ( expectedIndexes . Length , i ) ;
9097 Assert . IsTrue ( controller . Finished ) ;
9198 }
99+
100+ [ TestMethod ]
101+ public void TestRepeatWithAlphaTex ( )
102+ {
103+ var tex = @"\ro 1.3 2.3 3.3 4.3 | 5.3 6.3 7.3 8.3 | \rc 2 1.3 2.3 3.3 4.3 | \ro \rc 3 1.3 2.3 3.3 4.3" ;
104+ var importer = new AlphaTexImporter ( ) ;
105+ importer . Init ( TestPlatform . CreateStringReader ( tex ) , new Settings ( ) ) ;
106+ var score = importer . ReadScore ( ) ;
107+
108+ var playedBars = new FastList < int > ( ) ;
109+ var controller = new MidiPlaybackController ( score ) ;
110+ while ( ! controller . Finished )
111+ {
112+ var index = controller . Index ;
113+ playedBars . Add ( index ) ;
114+ controller . ProcessCurrent ( ) ;
115+ controller . MoveNext ( ) ;
116+
117+ if ( playedBars . Count > 50 )
118+ {
119+ Assert . Fail ( "Too many bars generated" ) ;
120+ }
121+ }
122+
123+ var expectedBars = new FastList < int >
124+ {
125+ 0 ,
126+ 1 ,
127+ 2 ,
128+ 0 ,
129+ 1 ,
130+ 2 ,
131+ 3 ,
132+ 3 ,
133+ 3
134+ } ;
135+
136+ Assert . AreEqual ( string . Join ( "," , expectedBars ) , string . Join ( "," , playedBars ) ) ;
137+ }
92138 }
93139}
0 commit comments