all files / tests/dummy/app/controllers/soundfonts/ index.js

75% Statements 3/4
100% Branches 0/0
50% Functions 1/2
75% Lines 3/4
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                                               
import { inject as service } from '@ember/service';
import { on } from '@ember/object/evented';
import Controller from '@ember/controller';
 
export default Controller.extend({
  audio: service(),
  isLoading: true,
  notes: null,
 
  initSoundFont: on('init', function() {
    // piano.js is a soundfont created with MIDI.js' Ruby-based soundfont converter
    this.get('audio').load('/ember-audio/piano.js').asFont('piano')
      .then((font) => {
        // Slicing just so the whole keyboard doesn't show up on the screen
        this.set('notes', font.get('notes').slice(39, 51));
        this.set('isLoading', false);
      });
  }),
 
  actions: {
    playPianoNote(note) {
      note.play();
    }
  }
});