@@ -2,7 +2,7 @@ import { GeneralMidi } from '@src/midi/GeneralMidi';
22import { ScoreImporter } from '@src/importer/ScoreImporter' ;
33import { UnsupportedFormatError } from '@src/importer/UnsupportedFormatError' ;
44import { AccentuationType } from '@src/model/AccentuationType' ;
5- import { Automation , AutomationType } from '@src/model/Automation' ;
5+ import { Automation , AutomationType , type FlatSyncPoint } from '@src/model/Automation' ;
66import { Bar , BarLineStyle , SustainPedalMarker , SustainPedalMarkerType } from '@src/model/Bar' ;
77import { Beat , BeatBeamingMode } from '@src/model/Beat' ;
88import { BendPoint } from '@src/model/BendPoint' ;
@@ -190,6 +190,7 @@ export class AlphaTexImporter extends ScoreImporter {
190190 private _articulationValueToIndex = new Map < number , number > ( ) ;
191191
192192 private _accidentalMode : AlphaTexAccidentalMode = AlphaTexAccidentalMode . Explicit ;
193+ private _syncPoints : FlatSyncPoint [ ] = [ ] ;
193194
194195 public logErrors : boolean = false ;
195196
@@ -235,11 +236,18 @@ export class AlphaTexImporter extends ScoreImporter {
235236 if ( ! anyMetaRead && ! anyBarsRead ) {
236237 throw new UnsupportedFormatError ( 'No alphaTex data found' ) ;
237238 }
239+
240+ if ( this . _sy === AlphaTexSymbols . Dot ) {
241+ this . _sy = this . newSy ( ) ;
242+ this . syncPoints ( ) ;
243+ }
238244 }
239245
240246 ModelUtils . consolidate ( this . _score ) ;
241247 this . _score . finish ( this . settings ) ;
248+ ModelUtils . trimEmptyBarsAtEnd ( this . _score ) ;
242249 this . _score . rebuildRepeatGroups ( ) ;
250+ this . _score . applyFlatSyncPoints ( this . _syncPoints ) ;
243251 for ( const [ track , lyrics ] of this . _lyrics ) {
244252 this . _score . tracks [ track ] . applyLyrics ( lyrics ) ;
245253 }
@@ -256,6 +264,55 @@ export class AlphaTexImporter extends ScoreImporter {
256264 }
257265 }
258266
267+ private syncPoints ( ) {
268+ while ( this . _sy !== AlphaTexSymbols . Eof ) {
269+ this . syncPoint ( ) ;
270+ }
271+ }
272+
273+ private syncPoint ( ) {
274+ // \sync BarIndex Occurence MillisecondOffset
275+ // \sync BarIndex Occurence MillisecondOffset RatioPosition
276+
277+ if ( this . _sy !== AlphaTexSymbols . MetaCommand || ( this . _syData as string ) !== 'sync' ) {
278+ this . error ( 'syncPoint' , AlphaTexSymbols . MetaCommand , true ) ;
279+ }
280+
281+ this . _sy = this . newSy ( ) ;
282+ if ( this . _sy !== AlphaTexSymbols . Number ) {
283+ this . error ( 'syncPointBarIndex' , AlphaTexSymbols . Number , true ) ;
284+ }
285+ const barIndex = this . _syData as number ;
286+
287+ this . _sy = this . newSy ( ) ;
288+ if ( this . _sy !== AlphaTexSymbols . Number ) {
289+ this . error ( 'syncPointBarOccurence' , AlphaTexSymbols . Number , true ) ;
290+ }
291+ const barOccurence = this . _syData as number ;
292+
293+ this . _sy = this . newSy ( ) ;
294+ if ( this . _sy !== AlphaTexSymbols . Number ) {
295+ this . error ( 'syncPointBarMillis' , AlphaTexSymbols . Number , true ) ;
296+ }
297+ const millisecondOffset = this . _syData as number ;
298+
299+ this . _allowFloat = true ;
300+ this . _sy = this . newSy ( ) ;
301+ this . _allowFloat = false ;
302+ let barPosition = 0 ;
303+ if ( this . _sy === AlphaTexSymbols . Number ) {
304+ barPosition = this . _syData as number ;
305+ this . _sy = this . newSy ( ) ;
306+ }
307+
308+ this . _syncPoints . push ( {
309+ barIndex,
310+ barOccurence,
311+ barPosition,
312+ millisecondOffset
313+ } ) ;
314+ }
315+
259316 private error ( nonterm : string , expected : AlphaTexSymbols , wrongSymbol : boolean = true ) : void {
260317 let receivedSymbol : AlphaTexSymbols ;
261318 let showSyData = false ;
0 commit comments