Skip to content

Commit

Permalink
filterEach method
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanoMarina committed Nov 13, 2021
1 parent 18ecf6a commit efa2bc1
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ exports.Filter = class {
// faders need to update osc path
var result = { "type" : this.outcome.type};

let parser = new Parsers.MIDIParser();

let parser = (this.parser === undefined)
? new Parsers.MIDIParser()
: this.parser;

parser.setMidiMessage(midiMessage);
parser.setValue(score);

Expand Down Expand Up @@ -271,7 +275,7 @@ exports.FilterMap = class {
}

/**
* parses and adds a new filter
* parses a bind and adds a new filter
* @param channel midi channel (0-15) or "all"
* @param bind a bind
* @param disableShell do not add if filter contains shell commands
Expand All @@ -286,6 +290,14 @@ exports.FilterMap = class {
return;

let filter = new exports.Filter(channel, bind);
this.addFilter(filter);
}

/**
* adds a filter object
* @param filter new filter
*/
addFilter(filter) {
let status = filter.status;
if (undefined === this.filterMap[status])
this.filterMap[status] = {};
Expand All @@ -301,6 +313,21 @@ exports.FilterMap = class {
*/
getMap(){return this.filterMap};

/**
* filterEach
* iterates through filters
* @param callback a function or lambda with 'filter' parameter
*/
filterEach( callback ) {
let sb = Object.keys(this.filterMap);
sb.forEach((index) => {
let data1 = Object.keys(this.filterMap[index]);
data1.forEach( (d1) => {
let filters = this.filterMap[index][d1];
filters.forEach( (filter) => { callback(filter); });
});
});
}

/**
* process a midi message
Expand Down

0 comments on commit efa2bc1

Please sign in to comment.