All files / addon/classes layered-sound.js

23.07% Statements 3/13
50% Branches 1/2
9.09% Functions 1/11
37.5% Lines 3/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105                        1x                                                                                                                                                                         1x 1x            
import { A } from '@ember/array';
import { on } from '@ember/object/evented';
import EmberObject from '@ember/object';
 
/**
 * Allows multiple instances of anything that uses
 * {{#crossLink "Playable"}}{{/crossLink}} to be loaded up and played at the
 * same time.
 *
 * @public
 * @class LayeredSound
 */
const LayeredSound = EmberObject.extend({
  /**
   * Acts as a register for different types of sounds. Anything that uses
   * {{#crossLink "Playable"}}{{/crossLink}} can be added to this register.
   * If not set on instantiation, set to `A()` via `_initSounds`.
   *
   * @public
   * @property sounds
   * @type {array|Sound|Oscillator}
   */
  sounds: null,
 
  /**
   * Maps through objects in `sounds` and calls `play` on each
   *
   * @public
   * @method play
   */
  play() {
    this.sounds.map((sound) => sound.play());
  },
 
  /**
   * Maps through objects in `sounds` and calls `playAt` on each, passing
   * through the `time` param to each sound.
   *
   * @public
   * @method playAt
   *
   * @param {number} time The time to pass to each object's `playAt` method.
   */
  playAt(time) {
    this.sounds.map((sound) => sound.playAt(time));
  },
 
  /**
   * Maps through objects in `sounds` and calls `playIn` on each, passing
   * through the `seconds` param to each sound.
   *
   * @public
   * @method playIn
   *
   * @param {number} seconds The seconds to pass to each object's `playIn` method.
   */
  playIn(seconds) {
    this.sounds.map((sound) => sound.playIn(seconds));
  },
 
  /**
   * Maps through objects in `sounds` and calls `playFor` on each, passing
   * through the `seconds` param to each sound.
   *
   * @public
   * @method playFor
   *
   * @param {number} seconds The seconds to pass to each object's `playFor` method.
   */
  playFor(seconds) {
    this.sounds.map((sound) => sound.playFor(seconds));
  },
 
  /**
   * Maps through objects in `sounds` and calls `playInAndStopAfter` on each,
   * passing through the `playIn` and `stopAfter` params to each sound.
   *
   * @public
   * @method playForIn
   *
   * @param {number} playIn Seconds to pass to each object's
   * `playInAndStopAfter` method.
   *
   * @param {number} stopAfter Seconds to pass to each object's
   * `playInAndStopAfter` method.
   */
  playInAndStopAfter(playIn, stopAfter) {
    this.sounds.map((sound) => sound.playInAndStopAfter(playIn, stopAfter));
  },
 
  /**
   * If `sounds` is null on instantiation, sets it to `A()`
   *
   * @private
   * @method _initSounds
   */
  _initSounds: on('init', function () {
    Eif (!this.sounds) {
      this.set('sounds', A());
    }
  }),
});
 
export default LayeredSound;