Showing posts with label Script Language = "Javascript". Show all posts
Showing posts with label Script Language = "Javascript". Show all posts

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>

24 February 2012

Quirking with Framesets

There's a way to create a top banner throughout your entire website, such as that you see on Nhv.Org
By clicking HOME, you're actually clicking on "index_home.htm" which is a page that is known as a frameset.

A frameset references two or more pages to create itself.  In this case, it references a file called banner.htm, which is only 60px tall, and stays at the top of the page.  As well as home.htm, which used to be where "home" once linked on the main page.

If you click "News" on the banner, it opens up in Blogspot.  Banner remains.
If you click "Audio" it opens up in Soundcloud.  Banner stays.

Quirking is a term that I use to describe when I get something done in a really simple manner which would have been possible in 1995.  This includes anything done with animated GIF's or Marquee tags.  There are no restraints to quirking, but usually it involves quickening the process of accomplishing something by doing it in a manner that is potentially way more glitchy.  I like glitches, too.  If computers were natural, they'd be natural mistakes.  Instead, they're more like the genius of artificial intelligence.

Creating a frameset with your index page is one way to create a top-banner menu for your entire site, even if you're browsing your content away from your own webpage, like on your Soundcloud page.

Once you create a frameset, the next thing you should do is include this code in the page where the pages split:
<script language="javascript" type="text/javascript">
if (self != top) {
    if (document.images)
        top.location.replace(window.location.href);
    else
        top.location.href = window.location.href;
}
</script>

Because let's say you double back to the main page with the frameset and re-click "home."  Without this code in "index," the framesets could continue to stack upon eachother.  This also prevents other people from doing the same thing to your web pages.

Now, whenever you re-visit the main page, you won't get double or triple banners.  Does not work in Facebook or Youtube, for the obvious potential for misuse.  In the case of NHV, I'm actually using it for a positive purpose: my free hyperlocal community bulletin website.