backbone code repo

bunch of code

by chrisfrisina

JavaScript

// Filename: views/components/componentView.js
/*
  This is the view for one component of the drum kit.
*/
define([
  'jquery',
  'underscore',
  'backbone',
  'backbone/models/component',
  'backbone/models/remainingInstrumentGenerator',
  'backbone/views/measure/measureView',
  'backbone/views/fraction/fractionView',
  'backbone/views/menu/instrumentDropDownView',
  'backbone/views/slider/beatsPerMeasureSliderView',
  'backbone/views/button/deleteInstrumentView',
  'app/dispatch',
  'backbone/models/state',
  'app/log'
], function($, _, Backbone, Component, RemainingInstrumentGenerator, MeasuresView, FractionRepresentationView, InstrumentDropDownView, BPMSliderView, DeleteInstrumentView, dispatch, state, log){
  return Backbone.View.extend({
    // this is needed to recalculate a beat's size
    el: $('.component'),

    //registering two handlers for backbone's click events.
    //the first is for toggling the component's muted state.
    //the second is for setting this component in focus (or selected).
    events : {
      'click .control' : 'toggleMute',
      'click' : 'select'
    },

    /*
      We are receiving options from componentsView, where this view is
      being instantiated.

      We get a component model, a DOM element, and a gainNode.
      this.gainNode is the gainNode responsible for controlling the
      individual muting of this component in the web audio API.
    */
    initialize: function(options){
      if (options) {
        this.component = options.collection;
        this.el = options.el;
        this.gainNode = options.gainNode;
        if (options.defaultMeasureRepresentation) {
          this.defaultMeasureRepresentation = options.defaultMeasureRepresentation;
        }
        if (options.defaultFractionRepresentation) {
          this.defaultFractionRepresentation = options.defaultFractionRepresentation;
        }
        this.unusedInstruments = options.unusedInstruments;
        this.type = options.type;
      } else {
   ...