* Ensures the action sequence for every device referenced in this action * sequence is the same length. For devices whose sequence is too short, * this will insert plain #pause pauses so that every device has an * explicit action defined at each tick. * * @param {...!Device} de
(...devices)
| 667 | * @return {!Actions} a self reference. |
| 668 | */ |
| 669 | synchronize(...devices) { |
| 670 | let sequences |
| 671 | let max = 0 |
| 672 | if (devices.length === 0) { |
| 673 | for (const s of this.sequences_.values()) { |
| 674 | max = Math.max(max, s.length) |
| 675 | } |
| 676 | sequences = this.sequences_.values() |
| 677 | } else { |
| 678 | sequences = [] |
| 679 | for (const device of devices) { |
| 680 | const seq = this.sequence_(device) |
| 681 | max = Math.max(max, seq.length) |
| 682 | sequences.push(seq) |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | const pause = { type: Action.Type.PAUSE, duration: 0 } |
| 687 | for (const seq of sequences) { |
| 688 | while (seq.length < max) { |
| 689 | seq.push(pause) |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | return this |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * Inserts a pause action for the specified devices, ensuring each device is |