Skip to content

Commit

Permalink
sustain pedal support
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgamage committed Jan 20, 2021
1 parent d9157f9 commit 8035703
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 40 deletions.
Binary file modified Chord Sight.amxd
Binary file not shown.
104 changes: 64 additions & 40 deletions chords.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@
// note count (string)
outlets = 3;

var _ref, _ref2;

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true,
});
} else {
obj[key] = value;
}
return obj;
}

var removeDuplicatesSimple = function removeDuplicatesSimple(array) {
return array.filter(function (item, pos, self) {
return self.indexOf(item) == pos;
Expand Down Expand Up @@ -597,32 +581,19 @@ var matchChords = function matchChords(notes) {
return matches;
};

var activeNotes = [];
var activeChords = [];
var holdTimeouts = {};
var holdDuration = 0;
var noteOn = function (note) {
// cancel existing timeouts
if (holdTimeouts[note.index]) {
holdTimeouts[note.index].cancel();
} else {
activeNotes.push(note);
}

var msg_float = function float(holdTime) {
holdDuration = holdTime;
detectChords();
};

var list = function list(noteIndex, vel) {
var note = {
index: noteIndex,
black: blackForIndex(noteIndex),
note: noteForIndex(noteIndex),
octave: octaveForIndex(noteIndex),
};

if (vel > 0) {
// cancel existing timeouts
if (holdTimeouts[note.index]) {
holdTimeouts[note.index].cancel();
} else {
activeNotes.push(note);
}

detectChords();
var noteOff = function (note) {
if (pedalSustained) {
sustainedNotes.push(note);
} else {
// delay noteOff
holdTimeouts[note.index] = new Task(function () {
Expand Down Expand Up @@ -658,3 +629,56 @@ var detectChords = function detectChords() {
outlet(1, notesString || "-");
outlet(2, dedupedActiveNotes.length);
};

// State variables
var activeNotes = [];
var activeChords = [];
var holdTimeouts = {};
var holdDuration = 0;
var pedalSustained = false;
var sustainedNotes = [];

//
// Inputs
//

// Input: Hold Text Input
var msg_float = function float(holdTime) {
holdDuration = holdTime;
};

// Input: MIDI Events (Sustain Pedal)
var midievent = function midievent(status, cc, value) {
if (status === 176) {
// Sustain pedal
if (cc === 64) {
// on
if (value > 64) {
pedalSustained = true;
} else {
pedalSustained = false;
sustainedNotes.forEach(function (note) {
noteOff(note);
});
sustainedNotes = [];
}
detectChords();
}
}
};

// Input: Notes
var list = function list(noteIndex, vel) {
var note = {
index: noteIndex,
black: blackForIndex(noteIndex),
note: noteForIndex(noteIndex),
octave: octaveForIndex(noteIndex),
};

if (vel > 0) {
noteOn(note);
} else {
noteOff(note);
}
};

0 comments on commit 8035703

Please sign in to comment.