13 June 2012

Loop Length Calculator Code



Enter the BPM [tempo]




Your Loop Must Be


Seconds.Milliseconds


Original Calculator Found HERE

The purpose of this calculator is for you to determine how to loop your song.  It's available at SpacePirate.Co.Uk and I designed it.  The program was initially developed as a way of translating DC input wattage to AC output for inverters, in the event that someone was trying to determine how many useable amps an inverter would produce based on the input from the solar array.  It wasn't too difficult to transcribe some of the features over to music.

It performs a very simple calculation.  If your tempo is 120, that means that you have 120 beats per minute. In a single second, that's 2 beats.  Therefore, if you were to cut a sample for a song that was at 120 BPM, it would need to be .5 seconds long for a single beat, or 2 seconds long for a 4-beat measure.

That's a fairly simple calculation when using a simple tempo like 120bpm, but what if it's 135?  That's something more like 1.7 seconds.

You take the tempo, and enter it into the code.  Let's say the tempo is 120 still.


answer.value = (parseInt(timeinput.options[timeinput.selectedIndex].value) / parseInt(bpm.value) ) ;

"Time input" is either 60 or 240.  "bpm.value" is the BPM.

Time input is 60 or 240 for the reason that 1 beat per minute is 60 beats per second.
240 is such because 60 x 4 is 240 and there are 4 beats in a measure.

60/120 = .5 or half a second.
240/120 = 2 or two seconds.


<option value="60">beat</option>
<option value="240">measure</option>


Here is the actual script: 


<script> 
function calculate() {



var dcwatts = document.getElementById('bpm');

var acvolts = document.getElementById('timeinput');


var answer = document.getElementById('answer');

//ORDER OF OPERATIONS



answer.value = (parseInt(timeinput.options[timeinput.selectedIndex].value) / parseInt(bpm.value) ) ;


//alert('my name is '+tf.value);

//alert(final);
}


function dothis() 


{
var obj = document.getElementById('my_select');
//alert(obj.options[obj.selectedIndex].value);


}


    </script>

No comments:

Post a Comment