dynamic array of Buffers in JS?

Marc Carlton's icon

I'm having trouble working with dynamically created arrays of buffers in javascript.
(I am planning on using javascript to iterate through samples in each buffer which is why I'm not using a polybuffer, where I don't believe you can use peek/poke w a polybuffer.)

User drops a folder of audio files on a [dropfile] and I want to create an array of buffers in javascript. does this look right?

autowatch = 1;

//IO
inlets = 1;
outlets = 1;

var lastAudioFolderPath = '';
var buffer_array = [];
var buffer_array_index = 0;
var player = this.patcher.getnamed("player");
var waveView = this.patcher.getnamed("waveView");

function clear(){
    post();
    post("clear");
    buffer_array_index = 0;
}

function setAudioFolderPath(path){
    post();
    post("path_audioFolder: "+path);
    lastAudioFolderPath = path;
}

function load_audio(audioFile){
    var filePath = lastAudioFolderPath+audioFile;
    buffer_array[buffer_array_index] = new Buffer(audioFile);
    post();
    post("created new buffer ("+audioFile+") at index ("+buffer_array_index+")");
    buffer_array[buffer_array_index].send("replace", filePath);
    buffer_array_index++;
}

function play(){
    post();
    post("play: "+"Bell.wav"); //testing with Bell.wav audio file
    player.message("set", "Bell.wav"); //[play~] called player
    player.message("start");
}

//NO AUDIO PLAYS, NO ERROR

Marc Carlton's icon

is anyone creating arrays of JS Buffers? I would love to see an example.

array[i].send("replace", file); ///returning errors

what is the correct way to hand this?

Peter Mcilwain's icon

I've been working away on this too - I've tried the following:
inlets = 1;
outlets = 1;

var buf = new Buffer("outsidejsui");

function loadBuf1() {
    //method 1 - works
buf.send("replace");
}

function loadBuf2() {
//method 2 - works (with connection to external buffer and prepend replace)
outlet(0, filePath);
}
function loadBuf3() {
//method 3 - she no work
buf.send("replace" + filePath);

}
function loadBuf4() {
//method 3 - well it as never going to work was it!
buf.replace(filePath);