// script_spacemap_galileo.js

// inlets and outlets
inlets = 1;
outlets = 1;

// global variables and arrays
var numpatchers = 0;
var global_messager;
var spacemap_wrappers = new Array(16);

// spacemaps -- generates and initializes spacemaps wrappers in the max patch
function spacemaps()
{   
	if (arguments.length) { // bail if no arguments
        var i;
        
		// parse arguments
		var a = arguments[0];

		// safety check for number of spacemaps
		if (a < 1) a = 0; // too few spacemaps, set to 0
		if (a > 16) a = 16; // too many spacemaps, set to 16
        
		// script spacemap objects
        if (a > numpatchers) {
            // add if number increased
    		for (i = numpatchers; i < a; i++) { // create the new spacemap objects
    			spacemap_wrappers[i] = this.patcher.newdefault(50, 80+(i*30), "MIAP_galileo_instance", i);
    		}    
        }
        else if (a < numpatchers) {
            // remove if number decreased
    		for (i = a; i < numpatchers; i++) {
    			this.patcher.remove(spacemap_wrappers[i]);
    		}    
        }

		numpatchers = a; // update our global number of spacemaps to the new value
	}
	else { // complain about arguments
		post("spacemaps message needs arguments");
		post();
	}
}
