text: var inherit = require("../utils/inherit");
  var BaseView = require("./BaseView");
  var Piano = require("./Piano");
  var Oscillator = require("./Oscillator");
  var DrumMachine = require("./DrumMachine");
  var windowsTransport = require("./windowsTransport");
  var commonEventNames = require("../core/commonEventNames");
  
  module.exports = InstrumentView;
  
  /**
   * Create instrument view corresponding to track instrument
   * @param track
   * @constructor
   */
  function InstrumentView(track){
      BaseView.call(this, "instrument-view");
      this.track = track;
  
      this.instrument = null;
      this.prevInstrument = null;
  
      this.setInstrument();
  
      this._build();
  }
  
  inherit(InstrumentView, BaseView);
  
  InstrumentView.prototype._build = function(){
      var container = this.getContainer();
  
      container.append(this.instrument);
  };
  
  InstrumentView.prototype.setTrack = function(track){
      if(track){
          this.track = track;
          this.setInstrument();
          windowsTransport.subscribe(commonEventNames.E_RECORD_TRACK,
                                     this.instrument.recordEvent.bind(this.instrument));
          windowsTransport.subscribe(commonEventNames.E_CLEAR_RECORD_TRACK,
                                     this.instrument.clearEvent.bind(this.instrument));
      }
  };
  
  InstrumentView.prototype.setInstrument = function(){
      if(this.track) {
          if(this.prevInstrument){
              console.log("+++++++++++");
              console.log(this.prevInstrument.track);
              //this.prevInstrument.track.disconnectFromAudioSource();
              // reset reference to track model of previous instrument view
              this.prevInstrument.track = null;
              console.log(this.prevInstrument.track);
          }
          switch (this.track.instrument) {
              case "synth":
                  this.instrument = new Piano(this.track);
                  break;
              case "drum":
                  this.instrument = new DrumMachine(this.track);
                  break;
              case "oscillator":
                  this.instrument = new Oscillator(this.track);
                  break;
          }
          this.prevInstrument = this.instrument;
          this.getContainer().append(this.instrument.getContainer());
      }
  };
  