[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voice decay #57

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'master' into voice-decay
  • Loading branch information
Jon Sakas committed Sep 22, 2018
commit de771deaf6a3e052fb1de53ebc5359c89e5fd41a
73 changes: 64 additions & 9 deletions docs/subtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,64 @@ var Subtractor = function (_Observable) {
}

_createClass(Subtractor, [{
key: 'initMIDIController',
value: function initMIDIController() {
var _this2 = this;

navigator.requestMIDIAccess({ sysex: true }).then(function (midi) {
midi.>

var input = midi.inputs.values();
var result = input.next();
while (!result.done) {
result = input.next();
if (result.value) {
result.value.>
}
}
}).catch(console.error);
}
}, {
key: 'handleMIDIStateChange',
value: function handleMIDIStateChange(e) {
// print information about the (dis)connected MIDI controller
console.log(e.port.name, e.port.manufacturer, e.port.state);
}
}, {
key: 'handleMIDIMessage',
value: function handleMIDIMessage(message) {
switch (message.data[0]) {
case 144:
this.noteOn(message.data[1]);
break;
case 128:
this.noteOff(message.data[1]);
break;
default:
break;
}
}
}, {
key: 'moveNote',
value: function moveNote(n1, n2) {
var _this3 = this;

var voices = this._activeNotes[n1];

Object.keys(voices).filter(function (i) {
return voices[i];
}).forEach(function (voice) {
Object.keys(voice).forEach(function (v) {
voices[voice[v]].move(n2, _this3._polyphony, _this3._detune, _this3.context.currentTime + (0, _maths.knobToSeconds)(_this3._glide));
});
});

(0, _helpers.renameObjectKey)(this._activeNotes, n1, n2);
}
}, {
key: 'noteOn',
value: function noteOn(note) {
var _this2 = this;
var _this4 = this;

var activeNoteKeys = Object.keys(this._activeNotes);

Expand All @@ -618,7 +673,7 @@ var Subtractor = function (_Observable) {
if (!osc.enabled) {
return null;
}
osc.start(note, _this2._polyphony, _this2._detune).map(_this2.pipeline);
osc.start(note, _this4._polyphony, _this4._detune).map(_this4.pipeline);
return osc;
}).reduce(function (acc, cur, i) {
return Object.assign(acc, _defineProperty({}, i + 1, cur));
Expand All @@ -628,23 +683,23 @@ var Subtractor = function (_Observable) {
}, {
key: 'noteOff',
value: function noteOff(note) {
var _this3 = this;
var _this5 = this;

this.getOscsForNote(note).forEach(function (o) {
o.oscs.forEach(function (osc) {
osc.oscEnvelope.reset();
osc.filterEnvelope.reset();
osc. () {
delete _this3._activeNotes[note];
delete _this5._activeNotes[note];
};
osc.stop(_this3.context.currentTime + (0, _maths.knobToSeconds)(_this3.release));
osc.stop(_this5.context.currentTime + (0, _maths.knobToSeconds)(_this5.release));
});
});
}
}, {
key: 'moveNote',
value: function moveNote(n1, n2) {
var _this4 = this;
var _this6 = this;

this.getOscsForNote(n1).forEach(function (osc) {
osc.oscs.forEach(function (o) {
Expand All @@ -654,7 +709,7 @@ var Subtractor = function (_Observable) {
o.oscEnvelope.schedule();
o.filterEnvelope.schedule();
});
osc.move(n2, _this4._polyphony, _this4._detune, _this4.context.currentTime + (0, _maths.knobToSeconds)(_this4._glide));
osc.move(n2, _this6._polyphony, _this6._detune, _this6.context.currentTime + (0, _maths.knobToSeconds)(_this6._glide));
});

(0, _helpers.renameObjectKey)(this._activeNotes, n1, n2);
Expand Down Expand Up @@ -914,13 +969,13 @@ var Subtractor = function (_Observable) {
}, {
key: 'loadPresetFile',
value: function loadPresetFile() {
var _this6 = this;
var _this7 = this;

var fileReader = new FileReader();
fileReader.addEventListener('load', function () {
var fileContents = fileReader.result;
var preset = JSON.parse(fileContents);
_this6.loadPreset(preset);
_this7.loadPreset(preset);
});

var input = document.createElement('input');
Expand Down
36 changes: 36 additions & 0 deletions src/Subtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,42 @@ class Subtractor extends Observable {
window.debug = () => console.log(this)
}

initMIDIController() {
navigator.requestMIDIAccess({ sysex: true })
.then((midi) => {
midi.>

let input = midi.inputs.values();
let result = input.next();
while (!result.done) {
result = input.next();
if (result.value) {
result.value.>
}
}
})
.catch(console.error);

}

handleMIDIStateChange (e) {
// print information about the (dis)connected MIDI controller
console.log(e.port.name, e.port.manufacturer, e.port.state);
}

handleMIDIMessage (message) {
switch (message.data[0]) {
case 144:
this.noteOn(message.data[1]);
break;
case 128:
this.noteOff(message.data[1]);
break;
default:
break
}
}

noteOn(note) {
const activeNoteKeys = Object.keys(this._activeNotes)

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.