UNPKG

qambi

Version:

MIDI sequencer, loads MIDI files, can record and playback MIDI, uses WebMIDI and WebAudio

96 lines (86 loc) 3 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.MIDINote = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _midi_event = require('./midi_event'); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var instanceIndex = 0; var MIDINote = exports.MIDINote = function () { function MIDINote(noteon, noteoff) { _classCallCheck(this, MIDINote); //if(noteon.type !== 144 || noteoff.type !== 128){ if (noteon.type !== 144) { console.warn('cannot create MIDINote'); return; } this.id = this.constructor.name + '_' + instanceIndex++ + '_' + new Date().getTime(); this.noteOn = noteon; noteon.midiNote = this; noteon.midiNoteId = this.id; if (noteoff instanceof _midi_event.MIDIEvent) { this.noteOff = noteoff; noteoff.midiNote = this; noteoff.midiNoteId = this.id; this.durationTicks = noteoff.ticks - noteon.ticks; this.durationMillis = -1; } } _createClass(MIDINote, [{ key: 'addNoteOff', value: function addNoteOff(noteoff) { this.noteOff = noteoff; noteoff.midiNote = this; noteoff.midiNoteId = this.id; this.durationTicks = noteoff.ticks - this.noteOn.ticks; this.durationMillis = -1; } }, { key: 'copy', value: function copy() { return new MIDINote(this.noteOn.copy(), this.noteOff.copy()); } }, { key: 'update', value: function update() { // may use another name for this method this.durationTicks = this.noteOff.ticks - this.noteOn.ticks; } }, { key: 'transpose', value: function transpose(amount) { this.noteOn.transpose(amount); this.noteOff.transpose(amount); } }, { key: 'move', value: function move(ticks) { this.noteOn.move(ticks); this.noteOff.move(ticks); } }, { key: 'moveTo', value: function moveTo(ticks) { this.noteOn.moveTo(ticks); this.noteOff.moveTo(ticks); } }, { key: 'unregister', value: function unregister() { if (this.part) { this.part.removeEvents(this); this.part = null; } if (this.track) { this.track.removeEvents(this); this.track = null; } if (this.song) { this.song.removeEvents(this); this.song = null; } } }]); return MIDINote; }();