Initial git commit version 1.7.2
This commit is contained in:
commit
0c32a0dcb1
45
css/css.css
Normal file
45
css/css.css
Normal file
@ -0,0 +1,45 @@
|
||||
*|* {
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
justify-content:center;
|
||||
align-items:center;
|
||||
}
|
||||
|
||||
#disc {
|
||||
display:block;
|
||||
width:80%;
|
||||
min-height:60%;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.library {
|
||||
background: rgba(200,200,200,1);
|
||||
text-align:left;
|
||||
margin:5px 5px -15px 5px;
|
||||
padding:5px 5px 20px 5px;
|
||||
min-height:10%;
|
||||
border:solid 1px rgba(140,140,140,1);
|
||||
border-radius:10px 10px 0px 0px;
|
||||
}
|
||||
|
||||
.button {
|
||||
display: inline-block;
|
||||
background: rgba(150,150,150,0.7);
|
||||
user-select: none;
|
||||
margin:1px;
|
||||
padding:2px;
|
||||
border:solid 1px rgba(90,90,90,0.5);
|
||||
border-radius:5px;
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background: rgba(140,140,140,1);
|
||||
margin:0px;
|
||||
padding:3px;
|
||||
transition:0.2s;
|
||||
}
|
51
index.html
Normal file
51
index.html
Normal file
@ -0,0 +1,51 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>bluelibs</title>
|
||||
<link href="css/css.css" rel="stylesheet" />
|
||||
<script src="libs/bluecore.js"></script>
|
||||
<script src="libs/blueaudio.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
This project is to develop and test my own small private javascript libraries.
|
||||
</p>
|
||||
<p>
|
||||
bluecore.js - 1.7.2 - This is as its named very basic functions like grabbing things asynchronously and such. All libraries will require this basic library.
|
||||
</p>
|
||||
<p>
|
||||
blueaudio.js - 1.0.4 - This is for adding/loading audio assets to a project.
|
||||
</p>
|
||||
<p>
|
||||
bluepixle.js - Planned - This will be for adding/loading/handling graphical assets within a HTML5 canvas context.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
<script>
|
||||
document.body.innerHTML = "";
|
||||
elementPlace("body","disc",null,"div",null);
|
||||
elementPlace("#disc",null,null,"p",null).innerText = "This project is to develop and test my own small private javascript libraries.";
|
||||
elementPlace("#disc","bluecore","library","p",null).innerText = "bluecore.js - 1.7.2 - This is as its named very basic functions like grabbing things asynchronously and such. All libraries will require this basic library.";
|
||||
elementPlace("#disc","blueaudio","library","p",null).innerText = "blueaudio.js - 1.0.4 - This is for adding/loading audio assets to a project.";
|
||||
elementPlace("#disc","bluepixle","library","p",null).innerText = "bluepixle.js - Planned - This will be for adding/loading/handling graphical assets within a HTML5 canvas context.";
|
||||
var mySound = elementPlace("#blueaudio",null,"button","a",null);
|
||||
var mySequence = elementPlace("#blueaudio","sequenceText",null,"input",null);
|
||||
mySequence.style.width = "100%";
|
||||
mySequence.style.textAlign = "center";
|
||||
mySequence.value = "5ab1/8;5g1/8;5e1/8;4bb1/8;4an1/8;5f1/8;5an1/8;6db3/8";
|
||||
mySound.innerText = "Click Me for blueaudio.js demo";
|
||||
var bluePlayer = new AudioContext();
|
||||
mySound.onclick = function () {
|
||||
playSequence(window.bluePlayer,parseSequence(mySequence.value),"triangle",60
|
||||
//[
|
||||
// {"note":8,"octave":5,"length":0.50,"type":"triangle"},
|
||||
// {"note":7,"octave":5,"length":0.50,"type":"triangle"},
|
||||
// {"note":4,"octave":5,"length":0.50,"type":"triangle"},
|
||||
// {"note":10,"octave":4,"length":0.50,"type":"triangle"},
|
||||
// {"note":9,"octave":4,"length":0.50,"type":"triangle"},
|
||||
// {"note":5,"octave":5,"length":0.50,"type":"triangle"},
|
||||
// {"note":9,"octave":5,"length":0.50,"type":"triangle"},
|
||||
// {"note":1,"octave":6,"length":1.50,"type":"triangle"}
|
||||
// ]
|
||||
);
|
||||
}
|
||||
</script>
|
87
libs/blueaudio.js
Normal file
87
libs/blueaudio.js
Normal file
@ -0,0 +1,87 @@
|
||||
/////////////////////// BlueAudio 1.0.4 \\\\\\\\\\\\\\\\\\\\\\\\\\
|
||||
// This requires BlueCore in order to run and assumes it is \\
|
||||
// already loaded. It will not work without BlueCore loaded \\
|
||||
// first. \\
|
||||
//////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
|
||||
|
||||
function getFrequency (note, octave) {
|
||||
// octaves double value
|
||||
// half steps are calculated using fn = f0*(2^(1/12))^n
|
||||
var base = 16.35; // bottom c
|
||||
var a = Math.pow(2,1/12); // Defining a
|
||||
// Check our inputs for sanity
|
||||
if ("number" != typeof note) { note = 1; }
|
||||
if ("number" != typeof octave) { octave = 4; }
|
||||
if (note < 0) { note = 0;}
|
||||
if (note > 11) { note = 11; }
|
||||
if (octave < 0) { octave = 0; }
|
||||
if (octave > 8) { octave = 8; }
|
||||
return (base*Math.pow(a,note))*Math.pow(2,octave);
|
||||
}
|
||||
|
||||
function parseNote (string) {
|
||||
if ("string" != typeof string) { string = "4c1/4"; }
|
||||
var noteReg = new RegExp(/^([1-8])([a-g][nb#]?)(\d)\/(\d{1,2})/i);
|
||||
var noteArray = string.match(noteReg);
|
||||
if (noteArray) { if (noteArray.length == 5) {
|
||||
var noteTranslationObject = {"cb":11,"cn":0,"c":0,"c#":1,"db":1,"dn":2,"d":2,"d#":3,"eb":3,"en":4,"e":4,"e#":5,"fb":4,"fn":5,"f":5,"f#":6,"gb":6,"gn":7,"g":7,"g#":8,"ab":8,"an":9,"a":9,"a#":10,"bb":10,"bn":11,"b":11,"b#":0};
|
||||
var octave = noteArray[1]-0;
|
||||
var length = (noteArray[3]/noteArray[4]);
|
||||
var step = noteTranslationObject[noteArray[2]];
|
||||
if ("cb" == noteArray[2]) { octave--; }
|
||||
if ("b#" == noteArray[2]) { octave++; }
|
||||
return {"note":step,"octave":octave,"length":length};
|
||||
} else {
|
||||
console.log("bad note: "+noteArray.join(" "));
|
||||
return {};
|
||||
}} else {
|
||||
console.log("bad note");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function parseSequence (string) {
|
||||
if ("string" != typeof string) { string = "4c1/4;"; }
|
||||
var notes = string.split(";");
|
||||
var sequence = [];
|
||||
notes.forEach( function (note) {
|
||||
sequence.push( parseNote(note) );
|
||||
});
|
||||
return sequence;
|
||||
}
|
||||
|
||||
function playNote (soundObject, note, octave, length, wave, delay) {
|
||||
if ("string" != typeof wave) { wave = "sine"; }
|
||||
if ("number" != typeof length) { length = 1; }
|
||||
if ("number" != typeof octave) { octave = 4; }
|
||||
if ("number" != typeof note) { note = 0; }
|
||||
if ("object" != typeof soundObject) { soundObject = new AudioContext(); }
|
||||
if ("number" != typeof delay) { delay = 0; }
|
||||
var waveform = soundObject.createOscillator();
|
||||
var gain = soundObject.createGain();
|
||||
waveform.connect(gain);
|
||||
gain.connect(soundObject.destination);
|
||||
|
||||
waveform.type = wave;
|
||||
waveform.frequency.setValueAtTime(getFrequency(note,octave), 0);
|
||||
gain.gain.setValueAtTime(1, soundObject.currentTime+delay);
|
||||
waveform.start(soundObject.currentTime+delay);
|
||||
gain.gain.exponentialRampToValueAtTime(0.00001,soundObject.currentTime+length+delay);
|
||||
waveform.stop(soundObject.currentTime+(length*1.5)+delay);
|
||||
}
|
||||
|
||||
function playSequence (soundObject, sequenceArray, defaultWave, tempo) {
|
||||
if ("object" != typeof soundObject) { soundObject = new AudioContext(); }
|
||||
if ("string" != typeof defaultWave) { defaultWave = "sine"; }
|
||||
if ("sine" != defaultWave && "square" != defaultWave && "triangle" != defaultWave && "sawtooth" != defaultWave) { defaultWave = "sine"; }
|
||||
if ("number" != typeof tempo) { tempo = 60; }
|
||||
if (0 >= tempo) { tempo = 1; }
|
||||
if ("object" != typeof sequenceArray) { sequenceArray = [{"note":0,"octave":4,"length":1,"type":"sine"}]; }
|
||||
var timing = 0;
|
||||
sequenceArray.forEach( function (thisNote) {
|
||||
var adjustedLength = (thisNote.length*(60/tempo))*4;
|
||||
if ("undefined" == typeof thisNote.type) { thisNote.type = defaultWave; }
|
||||
playNote(soundObject, thisNote.note, thisNote.octave, adjustedLength, thisNote.type, timing);
|
||||
timing += adjustedLength/4;
|
||||
});
|
||||
}
|
127
libs/bluecore.js
Normal file
127
libs/bluecore.js
Normal file
@ -0,0 +1,127 @@
|
||||
"use strict";
|
||||
/////////////////////// BlueCore 1.7.2 \\\\\\\\\\\\\\\\\\\\\\\\\\
|
||||
|
||||
function getData(url,dothis,tothis,type,body) {
|
||||
var DataRequest = new XMLHttpRequest();
|
||||
if (undefined == type) { type = "GET"; }
|
||||
if (undefined == body) { body = ""; }
|
||||
DataRequest.open(type, url, true);
|
||||
DataRequest.onreadystatechange = function () {
|
||||
if ( (DataRequest.readyState === XMLHttpRequest.DONE) && (DataRequest.status === 200) ) {
|
||||
dothis(DataRequest.responseText,tothis);
|
||||
}
|
||||
};
|
||||
DataRequest.send(body);
|
||||
}
|
||||
|
||||
function isEmpty(object) {
|
||||
console.log(object);
|
||||
console.log(typeof object);
|
||||
if ( "object" == typeof object ) {
|
||||
for ( var propery in object ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function addJavascript(string,action) {
|
||||
try {
|
||||
window.eval(string);
|
||||
if ("function" == typeof action) { action(); }
|
||||
}
|
||||
catch (e) { console.log("Error with external script: "+e); }
|
||||
}
|
||||
|
||||
function getJavascript(url,action) {
|
||||
getData(url,addJavascript,action);
|
||||
}
|
||||
|
||||
function addHTMLfrag(string,target) {
|
||||
target.innerHTML = string;
|
||||
}
|
||||
|
||||
function getHTMLfrag(url,targetNode) {
|
||||
var target = document.querySelector(targetNode);
|
||||
target.innerHTML = "Loading...";
|
||||
getData(url,addHTMLfrag,target);
|
||||
}
|
||||
|
||||
function elementMake (ID,Class,element) { //new and improved, I can use more than just divs for things now.
|
||||
return (function (myElement) {
|
||||
if ("string" == typeof ID) { myElement.id = ID; }
|
||||
if ("string" == typeof Class) { myElement.className = Class; }
|
||||
return myElement;
|
||||
})(document.createElement(element));
|
||||
}
|
||||
|
||||
function elementPlace (parentID, ID, Class, element, position) {
|
||||
var newElement = elementMake(ID,Class,element);
|
||||
if ( (typeof document.querySelector(parentID).append && typeof document.querySelector(parentID).prepend) !== "undefined") { // Are we compliant?
|
||||
if ("before" == position) {
|
||||
document.querySelector(parentID).prepend(newElement);
|
||||
} else {
|
||||
document.querySelector(parentID).append(newElement);
|
||||
}
|
||||
} else { //No? Ok we will use the old way.
|
||||
if ("before" == position) {
|
||||
var p = document.querySelector(parentID);
|
||||
p.insertBefore(newElement,p.firstChild);
|
||||
} else {
|
||||
document.querySelector(parentID).appendChild(newElement);
|
||||
}
|
||||
}
|
||||
return newElement;
|
||||
}
|
||||
|
||||
function buttonAdd (ParentID,ID,Label,Action,Class,Element) {
|
||||
if ( "undefined" == typeof Class ) { Class = ""; }
|
||||
if ( "undefined" == typeof Element) { Element = "div"; }
|
||||
(function (button) {
|
||||
button.innerHTML = Label;
|
||||
button.onclick = function () { Action(); }
|
||||
})(elementPlace(ParentID,ID,"button "+Class,Element));
|
||||
}
|
||||
|
||||
function dialogControlsGen(parentDialog,DialogBack,type,returnVar) { //I need to refactor this, these if statments are too similar.
|
||||
if ( "sub_window" == type ) {
|
||||
var closeButton = elementPlace(parentDialog,"closeButton",null,"div"); //Also need to change this, to help standardize the look and feel of the UI
|
||||
closeButton.innerHTML = "X";
|
||||
closeButton.onclick = function () { document.getElementById("body").removeChild(DialogBack); }
|
||||
//More controls will go here probably as I flesh out the sub window design
|
||||
}
|
||||
if ( "input" == type ) {
|
||||
var inputArea = elementPlace(parentDialog,"listID","inputField","input",null);
|
||||
var submitButton = buttonAdd(parentDialog,"SubmitButton","Submit",function () {
|
||||
returnVar.value = inputArea.value;
|
||||
document.getElementById("body").removeChild(DialogBack);
|
||||
},"UI UIbutton");
|
||||
}
|
||||
if ( "input_password" == type ) {
|
||||
var inputArea = elementPlace(parentDialog,"listID","inputField","input",null);
|
||||
inputArea.type = "password";
|
||||
var submitButton = buttonAdd(parentDialog,"SubmitButton","Submit",function () {
|
||||
returnVar.value = inputArea.value;
|
||||
document.getElementById("body").removeChild(DialogBack);
|
||||
},"UI UIbutton");
|
||||
}
|
||||
if ( "info" == type ) {
|
||||
var closeButton = elementPlace(parentDialog,"closeButton",null,"div");
|
||||
closeButton.innerHTML = "Close";
|
||||
closeButton.onclick = function () { document.getElementById("body").removeChild(DialogBack); }
|
||||
}
|
||||
if ( "end" == type ) {
|
||||
var closeButton = elementPlace(parentDialog,"closeButton",null,"div");
|
||||
closeButton.innerHTML = "Play Again";
|
||||
closeButton.onclick = function () { document.getElementById("body").removeChild(DialogBack); gameInit(); }
|
||||
}
|
||||
}
|
||||
|
||||
function dialogMessage (content,type,returnVar) {
|
||||
var message = elementPlace("#body","app_message_back","app_Message_Back","div");
|
||||
var dialog = elementPlace("#app_message_back","app_message","app_Message","div");
|
||||
dialog.innerHTML = content;
|
||||
dialogControlsGen("#app_message",message, type, returnVar);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user