// class: HarmonicController // desc: // ------------------------------------------------ var HarmonicController = function() { // ---------------- // variables // ---------------- // my main canvas object this.cv; // Array to store Harmonics. this.arrHarmonics = new Array(); // Frequency of the bass lowest note (starting on F) this.startingFrequency = 100; // Old frequency is an F - 174.61; // How many harmonics to make - e.g. 16 would be 4 octaves, 32 would be 5 octaves // We can set it in the url variable, e.g. // http://alexanderchen.github.io/harmonics/?howmany=16 var howmany = getQueryVariable('howmany'); // Cap it so people don't crash their computers, at least var max = 256; var min = 4; var defaultNumber = 16; // default value if not passed in through url if (howmany > max) { howmany = max; } else if (howmany < min) { howmany = min; } else if (isNaN(howmany)) { howmany = defaultNumber; } else if (howmany == null) { howmany = defaultNumber; } this.harmonics = howmany; // initialize this.init(); } // function: mouseDown // ------------------------------------------------ HarmonicController.prototype.init = function() { // canvas this.cv = ctx; // create Harmonics for (var i = 0; i < this.harmonics; i++) { this.arrHarmonics[i] = new Harmonic(i, this); } } /** * ------------------------------------------------ * Begin * ------------------------------------------------ */ HarmonicController.prototype.begin = function() { } // function: upd // desc: // ------------------------------------------------ HarmonicController.prototype.upd = function() { // Update the tracks for (var i = 0; i < this.harmonics; i++) { this.arrHarmonics[i].isATouchOverMe = false; this.arrHarmonics[i].upd(); } // Is the mouse pressed? if (isMousePressing) { // Check if that touch event is intersecting a harmonic for (var j = 0; j < this.harmonics; j++) { this.arrHarmonics[j].checkIfATouchIsOverMe(xMouse, yMouse); } // Else check for touches } else { var currentTouch; // Go through the touch events for (var i=0; i < currentTouches.length; i++) { currentTouch = currentTouches[i]; // Check if that touch event is intersecting a harmonic for (var j = 0; j < this.harmonics; j++) { this.arrHarmonics[j].checkIfATouchIsOverMe(currentTouch.pageX, currentTouch.pageY); } } } // Update the tracks for (var i = 0; i < this.harmonics; i++) { this.arrHarmonics[i].checkIfIShouldBePlaying(); } } /** * ------------------------------------------------ * Update the size. * ------------------------------------------------ */ HarmonicController.prototype.updateSizeAndPosition = function() { for (var i = 0; i < this.harmonics; i++) { var h = this.arrHarmonics[i]; if (h) { h.updateSizeAndPosition(); } } } // function: mouseDown // ------------------------------------------------ HarmonicController.prototype.mouseDown = function() { } // function: mouseUp // ------------------------------------------------ HarmonicController.prototype.mouseUp = function() { }