@@ -59,9 +59,10 @@ describe('MidiFileGeneratorTest', () => {
5959 for ( let i : number = 0 ; i < actualEvents . length ; i ++ ) {
6060 Logger . info ( 'Test' , `i[${ i } ] ${ actualEvents [ i ] } ` ) ;
6161 if ( i < expectedEvents . length ) {
62- expect ( expectedEvents [ i ] . equals ( actualEvents [ i ] ) , `i[${ i } ] expected[${ expectedEvents [ i ] } ] !== actual[${ actualEvents [ i ] } ]` ) . toBe (
63- true
64- ) ;
62+ expect (
63+ expectedEvents [ i ] . equals ( actualEvents [ i ] ) ,
64+ `i[${ i } ] expected[${ expectedEvents [ i ] } ] !== actual[${ actualEvents [ i ] } ]`
65+ ) . toBe ( true ) ;
6566 }
6667 }
6768 expect ( actualEvents . length ) . toBe ( expectedEvents . length ) ;
@@ -614,54 +615,122 @@ describe('MidiFileGeneratorTest', () => {
614615 assertEvents ( handler . midiEvents , expectedEvents ) ;
615616 } ) ;
616617
617- it ( 'triplet-feel' , ( ) => {
618- const tex : string =
619- '\\ts 2 4 \\tf t8 3.2.8*4 | \\tf t16 3.2.16*8 | \\tf d8 3.2.8*4 | \\tf d16 3.2.16*8 | \\tf s8 3.2.8*4 | \\tf s16 3.2.16*8' ;
620- const score : Score = parseTex ( tex ) ;
621- // prettier-ignore
622- const expectedPlaybackStartTimes : number [ ] = [
623- 0 , 480 , 960 , 1440 , 0 , 240 , 480 , 720 , 960 , 1200 , 1440 , 1680 , 0 , 480 , 960 , 1440 , 0 , 240 , 480 , 720 , 960 , 1200 ,
624- 1440 , 1680 , 0 , 480 , 960 , 1440 , 0 , 240 , 480 , 720 , 960 , 1200 , 1440 , 1680
625- ] ;
626- // prettier-ignore
627- const expectedPlaybackDurations : number [ ] = [
628- 480 , 480 , 480 , 480 , 240 , 240 , 240 , 240 , 240 , 240 , 240 , 240 , 480 , 480 , 480 , 480 , 240 , 240 , 240 , 240 , 240 ,
629- 240 , 240 , 240 , 480 , 480 , 480 , 480 , 240 , 240 , 240 , 240 , 240 , 240 , 240 , 240
630- ] ;
631- const actualPlaybackStartTimes : number [ ] = [ ] ;
632- const actualPlaybackDurations : number [ ] = [ ] ;
633- let beat : Beat | null = score . tracks [ 0 ] . staves [ 0 ] . bars [ 0 ] . voices [ 0 ] . beats [ 0 ] ;
634- while ( beat ) {
635- actualPlaybackStartTimes . push ( beat . playbackStart ) ;
636- actualPlaybackDurations . push ( beat . playbackDuration ) ;
637- beat = beat . nextBeat ;
638- }
639- expect ( actualPlaybackStartTimes . join ( ',' ) ) . toBe ( expectedPlaybackStartTimes . join ( ',' ) ) ;
640- expect ( actualPlaybackDurations . join ( ',' ) ) . toBe ( expectedPlaybackDurations . join ( ',' ) ) ;
641- // prettier-ignore
642- const expectedMidiStartTimes : number [ ] = [
643- 0 , 640 , 960 , 1600 , 1920 , 2240 , 2400 , 2720 , 2880 , 3200 , 3360 , 3680 , 3840 , 4560 , 4800 , 5520 , 5760 , 6120 , 6240 ,
644- 6600 , 6720 , 7080 , 7200 , 7560 , 7680 , 7920 , 8640 , 8880 , 9600 , 9720 , 10080 , 10200 , 10560 , 10680 , 11040 , 11160
645- ] ;
646- // prettier-ignore
647- const expectedMidiDurations : number [ ] = [
648- 640 , 320 , 640 , 320 , 320 , 160 , 320 , 160 , 320 , 160 , 320 , 160 , 720 , 240 , 720 , 240 , 360 , 120 , 360 , 120 , 360 ,
649- 120 , 360 , 120 , 240 , 720 , 240 , 720 , 120 , 360 , 120 , 360 , 120 , 360 , 120 , 360
650- ] ;
651-
652- const actualMidiStartTimes : number [ ] = [ ] ;
653- const actualMidiDurations : number [ ] = [ ] ;
654- const handler : FlatMidiEventGenerator = new FlatMidiEventGenerator ( ) ;
655- const generator : MidiFileGenerator = new MidiFileGenerator ( score , null , handler ) ;
656- generator . generate ( ) ;
657- for ( const midiEvent of handler . midiEvents ) {
658- if ( midiEvent instanceof FlatNoteEvent ) {
659- actualMidiStartTimes . push ( midiEvent . tick ) ;
660- actualMidiDurations . push ( midiEvent . length ) ;
618+ describe ( 'triplet-feel' , ( ) => {
619+ function testTripletFeel (
620+ tex : string ,
621+ expectedPlaybackStartTimes : number [ ] ,
622+ expectedPlaybackDurations : number [ ] ,
623+ expectedMidiStartTimes : number [ ] ,
624+ expectedMidiDurations : number [ ]
625+ ) {
626+ const score : Score = parseTex ( tex ) ;
627+
628+ const actualPlaybackStartTimes : number [ ] = [ ] ;
629+ const actualPlaybackDurations : number [ ] = [ ] ;
630+ let beat : Beat | null = score . tracks [ 0 ] . staves [ 0 ] . bars [ 0 ] . voices [ 0 ] . beats [ 0 ] ;
631+ while ( beat ) {
632+ actualPlaybackStartTimes . push ( beat . playbackStart ) ;
633+ actualPlaybackDurations . push ( beat . playbackDuration ) ;
634+ beat = beat . nextBeat ;
661635 }
636+ expect ( actualPlaybackStartTimes . join ( ',' ) , 'expectedPlaybackStartTimes' ) . toBe (
637+ expectedPlaybackStartTimes . join ( ',' )
638+ ) ;
639+ expect ( actualPlaybackDurations . join ( ',' ) , 'expectedPlaybackDurations' ) . toBe (
640+ expectedPlaybackDurations . join ( ',' )
641+ ) ;
642+
643+ const actualMidiStartTimes : number [ ] = [ ] ;
644+ const actualMidiDurations : number [ ] = [ ] ;
645+ const handler : FlatMidiEventGenerator = new FlatMidiEventGenerator ( ) ;
646+ const generator : MidiFileGenerator = new MidiFileGenerator ( score , null , handler ) ;
647+ generator . generate ( ) ;
648+ for ( const midiEvent of handler . midiEvents ) {
649+ if ( midiEvent instanceof FlatNoteEvent ) {
650+ actualMidiStartTimes . push ( midiEvent . tick ) ;
651+ actualMidiDurations . push ( midiEvent . length ) ;
652+ }
653+ }
654+ expect ( actualMidiStartTimes . join ( ',' ) , 'expectedMidiStartTimes' ) . toBe ( expectedMidiStartTimes . join ( ',' ) ) ;
655+ expect ( actualMidiDurations . join ( ',' ) , 'expectedMidiDurations' ) . toBe ( expectedMidiDurations . join ( ',' ) ) ;
662656 }
663- expect ( actualMidiStartTimes . join ( ',' ) ) . toBe ( expectedMidiStartTimes . join ( ',' ) ) ;
664- expect ( actualMidiDurations . join ( ',' ) ) . toBe ( expectedMidiDurations . join ( ',' ) ) ;
657+
658+ it ( 'variants' , ( ) => {
659+ const tex : string =
660+ '\\ts 2 4 \\tf t8 3.2.8*4 | \\tf t16 3.2.16*8 | \\tf d8 3.2.8*4 | \\tf d16 3.2.16*8 | \\tf s8 3.2.8*4 | \\tf s16 3.2.16*8' ;
661+ const expectedPlaybackStartTimes : number [ ] = [
662+ 0 , 480 , 960 , 1440 , 0 , 240 , 480 , 720 , 960 , 1200 , 1440 , 1680 , 0 , 480 , 960 , 1440 , 0 , 240 , 480 , 720 , 960 ,
663+ 1200 , 1440 , 1680 , 0 , 480 , 960 , 1440 , 0 , 240 , 480 , 720 , 960 , 1200 , 1440 , 1680
664+ ] ;
665+ const expectedPlaybackDurations : number [ ] = [
666+ 480 , 480 , 480 , 480 , 240 , 240 , 240 , 240 , 240 , 240 , 240 , 240 , 480 , 480 , 480 , 480 , 240 , 240 , 240 , 240 , 240 ,
667+ 240 , 240 , 240 , 480 , 480 , 480 , 480 , 240 , 240 , 240 , 240 , 240 , 240 , 240 , 240
668+ ] ;
669+ const expectedMidiStartTimes : number [ ] = [
670+ 0 , 640 , 960 , 1600 , 1920 , 2240 , 2400 , 2720 , 2880 , 3200 , 3360 , 3680 , 3840 , 4560 , 4800 , 5520 , 5760 , 6120 ,
671+ 6240 , 6600 , 6720 , 7080 , 7200 , 7560 , 7680 , 7920 , 8640 , 8880 , 9600 , 9720 , 10080 , 10200 , 10560 , 10680 ,
672+ 11040 , 11160
673+ ] ;
674+ const expectedMidiDurations : number [ ] = [
675+ 640 , 320 , 640 , 320 , 320 , 160 , 320 , 160 , 320 , 160 , 320 , 160 , 720 , 240 , 720 , 240 , 360 , 120 , 360 , 120 , 360 ,
676+ 120 , 360 , 120 , 240 , 720 , 240 , 720 , 120 , 360 , 120 , 360 , 120 , 360 , 120 , 360
677+ ] ;
678+ testTripletFeel (
679+ tex ,
680+ expectedPlaybackStartTimes ,
681+ expectedPlaybackDurations ,
682+ expectedMidiStartTimes ,
683+ expectedMidiDurations
684+ ) ;
685+ } ) ;
686+
687+ it ( 'not-matching-with-grace' , ( ) => {
688+ testTripletFeel (
689+ `
690+ \\tf triplet8th
691+ 0.1.8
692+ 0.1.8{gr onbeat}
693+ 0.1.4
694+ 0.1.8
695+ 0.1.8
696+ 0.1.8
697+ 0.1.8
698+ 0.1.8 |
699+ 0.1.8 * 8
700+ ` ,
701+ // no swing on playback start/durations
702+ [
703+ // Bar 1
704+ 0 , 480 , 600 , 1440 , 1920 , 2400 , 2880 , 3360 ,
705+ // Bar 2
706+ 0 , 480 , 960 , 1440 , 1920 , 2400 , 2880 , 3360
707+ ] ,
708+ [
709+ // Bar 1
710+ 480 , 120 , 840 , 480 , 480 , 480 , 480 , 480 ,
711+ // Bar 2
712+ 480 , 480 , 480 , 480 , 480 , 480 , 480 , 480
713+ ] ,
714+ // swing on generated midi
715+ [
716+ // Bar 1
717+ // no swing on the first 4 notes as they do not align with the swing definition
718+ 0 , 480 , 600 , 1440 ,
719+ // the last two 8th note pairs swing
720+ 1920 , 2560 , 2880 , 3520 ,
721+ // Bar 2 fully swings
722+ 3840 , 4480 , 4800 , 5440 , 5760 , 6400 , 6720 , 7360
723+ ] ,
724+ [
725+ // no swing
726+ 480 , 120 , 840 , 480 ,
727+ // the last two 8th note pairs swing
728+ 640 , 320 , 640 , 320 ,
729+ // Swing on second bar
730+ 640 , 320 , 640 , 320 , 640 , 320 , 640 , 320
731+ ]
732+ ) ;
733+ } ) ;
665734 } ) ;
666735
667736 it ( 'beat-multi-bend' , ( ) => {
0 commit comments