* Applies the given list of FlatSyncPoint to this song. * @param syncPoints The list of sync points to apply. * @since 1.6.0
(syncPoints: FlatSyncPoint[])
| 446 | * @since 1.6.0 |
| 447 | */ |
| 448 | public applyFlatSyncPoints(syncPoints: FlatSyncPoint[]) { |
| 449 | for (const b of this.masterBars) { |
| 450 | b.syncPoints = undefined; |
| 451 | } |
| 452 | |
| 453 | for (const syncPoint of syncPoints) { |
| 454 | const automation = new Automation(); |
| 455 | automation.ratioPosition = Math.min(1, Math.max(0, syncPoint.barPosition)); |
| 456 | automation.type = AutomationType.SyncPoint; |
| 457 | automation.syncPointValue = new SyncPointData(); |
| 458 | automation.syncPointValue.millisecondOffset = syncPoint.millisecondOffset; |
| 459 | automation.syncPointValue.barOccurence = syncPoint.barOccurence; |
| 460 | if (syncPoint.barIndex < this.masterBars.length) { |
| 461 | this.masterBars[syncPoint.barIndex].addSyncPoint(automation); |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | for (const b of this.masterBars) { |
| 466 | if (b.syncPoints) { |
| 467 | b.syncPoints!.sort((a, b) => { |
| 468 | const occurence = a.syncPointValue!.barOccurence - b.syncPointValue!.barOccurence; |
| 469 | if (occurence !== 0) { |
| 470 | return occurence; |
| 471 | } |
| 472 | |
| 473 | return a.ratioPosition - b.ratioPosition; |
| 474 | }); |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * Exports all sync points in this song to a {@link FlatSyncPoint} list. |