Skip to content

Commit

Permalink
Adds getSynths() method to flock.band.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinbdclark committed Nov 1, 2015
1 parent 111709b commit 715890c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/synths/band.js
Expand Up @@ -6,7 +6,7 @@
* Dual licensed under the MIT and GPL Version 2 licenses.
*/

/*global require*/
/*global require, flock*/
/*jshint white: false, newcap: true, regexp: true, browser: true,
forin: false, nomen: true, bitwise: false, maxerr: 100,
indent: 4, plusplus: false, curly: true, eqeqeq: true,
Expand Down Expand Up @@ -37,6 +37,11 @@ var fluid = fluid || require("infusion");

set: {
func: "{that}.events.onSet.fire"
},

getSynths: {
funcName: "flock.band.getSynths",
args: ["{that}"]
}
},

Expand Down Expand Up @@ -79,4 +84,15 @@ var fluid = fluid || require("infusion");
}
}
});

flock.band.getSynths = function (that) {
var synths = [];
fluid.each(that.options.components, function (componentDef, name) {
if (fluid.hasGrade(that[name].options, "flock.synth")) {
synths.push(that[name]);
}
});

return synths;
};
}());
41 changes: 41 additions & 0 deletions tests/unit/js/core-tests.js
Expand Up @@ -467,6 +467,47 @@ var fluid = fluid || require("infusion"),
"as the environment itself.");
});

test("getSynths", function () {
fluid.defaults("flock.test.band", {
gradeNames: "flock.band",

components: {
synth1: {
type: "flock.synth",
options: {
synthDef: {
ugen: "flock.ugen.sin"
}
}
},

synth2: {
type: "flock.synth",
options: {
synthDef: {
ugen: "flock.ugen.sin"
}
}
},

nonSynth: {
type: "fluid.component"
}
}
});

var b = flock.test.band();
var synths = b.getSynths();

equal(synths.length, 2,
"The correct number of synths were returned from getSynths().");

fluid.each(synths, function (synth) {
ok(fluid.hasGrade(synth.options, "flock.synth"),
"All synths returned from getSynths() are of the appropriate grade.");
});
});

test("Options clamping", function () {
var enviro = flock.init({
chans: 64,
Expand Down

0 comments on commit 715890c

Please sign in to comment.