We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm using the reference for createSelect() to make a drop down list, but the function that is called when I select a different option of the list doesn't work. Here is the code:
var audioSignal;
function setup() {
createCanvas(640, 480);
smooth();
background(0);
audioSignal = new p5.AudioIn()
audioSignal.getSources(function(sourceList) {
//print out the array of available sources
audioList = createSelect();
audioList.position(20, 20);
for (var i = 0; i < sourceList.length; i++){
audioList.option(sourceList[i].label);
}
audioList.changed(selectInput);
});
}
function draw() {
}
function selectInput() {
print(audioList.value());
}
So what doesn't work is selectInput(), as I've tried to narrow down the error with print statements. This is what is printed out in the console: 21994: Uncaught not yet implemented
Anyone have any ideas? It's basically a copy of http://p5js.org/reference/#/p5/createSelect
Answers
you're passing a function code to getSources...
Is this possible?
better call it as a separate function and use the value audioList.value() to pass to getSources()
I copied the example from http://p5js.org/reference/#/p5.AudioIn/getSources
I believe this is a famous js anonymous function. very much common in callbacks.
In js people use to define functions like this all the time, sometime even nested functions... Like:
someFunc( parm1, function (function(){//some code}){//code });
very messy IMHO
@SimplyEnvision: change the name of you callback function: 'selectInput' has been attached to p5.prototype: essentially it's the equivalent of a reserved word. Try:
@Chrisir: therein lies the power of JS. @_vk is correct that it's not great practice to nest anonymous functions; but passing a function as an argument in JS is fairly standard practice and allows a lot of flexibility. The pay-off is that if it's not managed well you land up with spaghetti :(|)
Higher-order functions -> https://www.YouTube.com/watch?v=BMUiFMZr7vk