Skip to content

Commit 1ab2adb

Browse files
author
Lonce Wyse
committed
Improved baseSM API to take param numbers as well as names. Updated demo. Fixed but in Monster voice gain control.
1 parent 9f43bc3 commit 1ab2adb

File tree

13 files changed

+231
-21
lines changed

13 files changed

+231
-21
lines changed

Demo/Demo.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
-->
1010
<html>
1111
<head>
12+
<style type="text/css">
13+
body
14+
{
15+
background-color:black;
16+
background-image: url("Resources/CodeImage.jpg") ;
17+
background-repeat: no-repeat;
18+
}
19+
h3 {color:white;
20+
-webkit-user-select: none;
21+
text-align: center}
22+
</style>
23+
1224
<!--
1325
This code demonstrates
1426
a) Using a dynamically created list selector to choose sound jsaModels,
@@ -20,7 +32,7 @@
2032
<script type="text/javascript" data-main="demo_scripts/main.js" src="scripts/require.js"></script>
2133

2234
</head>
23-
<body>
35+
<body >
2436
<h3> jsaSound Demo: Use the mouse to play a sound. </h3>
2537

2638
</body>

Demo/README.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
README
2+
3+
A demo of how to use jsaSounds in browsers.
4+
5+
First copy folders from jsaSound to your working directory:
6+
jsaCore/
7+
jsaModels/
8+
jsaOpCodes/
9+
10+
Then run.
11+
12+
Note that main.js uses a sound model that lives on animatedsoundworks.com
13+
If you want to use a local sound model, change the one argument to require to refer to a sound in jsaModels rather than to one on animatedsoundworks.com.
14+
15+

Demo/Resources/CodeImage.jpg

94.6 KB
Loading

Demo/Resources/forTextImage.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require.config({
2+
paths: {
3+
"jsaSound": ".."
4+
}
5+
});
6+
require(
7+
["require", "http://animatedsoundworks.com/soundServer/jsaModels/jsaFM"],
8+
function (require, sndFactory) {
9+
10+
// First create the sound model from the factory.
11+
var snd = sndFactory();
12+
13+
// Parameter names are used for setting the parameter values. The names are availabe like this:
14+
// You can also see the parameter names in the sliderBox browser app that comes with jsaSound for playing sounds.
15+
console.log("The sound has " + snd.getNumParams() + " parameters :");
16+
for(var i=0;i<snd.getNumParams();i++){
17+
console.log("snd param #" + i + " is named " + snd.getParamNames()[i]);
18+
}
19+
20+
/* The play(), release(), stop(), and parameter setting with setRangeParamNorm() can be tied to
21+
any event or object in your javascript code. Here we use simple mouse events and motion.
22+
*/
23+
24+
// play the sound
25+
window.onmousedown=function(){
26+
snd.play();
27+
};
28+
// release the sound sending it into its decay segmen (use stop() if you want to stop the sound abruptly)
29+
window.onmouseup=function(){
30+
snd.release();
31+
};
32+
33+
// Setting sound parameters, in this case using normalized values (in [0,1]), and getting parameters by index number.
34+
window.onmousemove=function(e){
35+
var normX = e.clientX/window.innerWidth;
36+
var normY = e.clientY/window.innerWidth;
37+
snd.setRangeParamNorm(snd.getParamNames()[0], normX );
38+
snd.setRangeParamNorm(snd.getParamNames()[1], normY);
39+
};
40+
}
41+
);

Demo/demo_scripts/main.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ require.config({
1818
}
1919
});
2020
require(
21-
["require", "jsaSound/jsaModels/jsaFM"],
21+
["require", "http://animatedsoundworks.com/soundServer/jsaModels/jsaFM"],
22+
//["require", "localhost:8080/jsaModels/jsaFM"], // WHY CANT I LOAD SOUNDs FROM LOCALHOST WHEN I RUN A SERVER THERE??
23+
//["require", "jsaSound/jsaModels/jsaFM"], // This loads a model from a local directory
2224
function (require, sndFactory) {
2325

2426
// First create the sound model from the factory.
@@ -31,26 +33,27 @@ require(
3133
console.log("snd param #" + i + " is named " + snd.getParamNames()[i]);
3234
}
3335

34-
/* The play(), release(), stop(), and parameter setting with setRangeParamNorm() can be tied to
36+
/* The play(), release(), stop(), and parameter setting with setRangeParamNorm() can be tied to
3537
any event or object in your javascript code. Here we use simple mouse events and motion.
36-
*/
38+
*/
3739

3840
// play the sound
3941
window.onmousedown=function(){
4042
snd.play();
41-
}
43+
};
4244

4345
// release the sound sending it into its decay segmen (use stop() if you want to stop the sound abruptly)
4446
window.onmouseup=function(){
4547
snd.release();
46-
}
48+
};
4749

4850
// Setting sound parameters, in this case using normalized values (in [0,1]), and getting parameters by index number.
4951
window.onmousemove=function(e){
5052
var normX = e.clientX/window.innerWidth;
5153
var normY = e.clientY/window.innerWidth;
52-
snd.setRangeParamNorm(snd.getParamNames()[0], normX );
53-
snd.setRangeParamNorm(snd.getParamNames()[1], normY);
54-
}
54+
55+
snd.setRangeParamNorm(0, normX ); // setting by parameter index
56+
snd.setRangeParamNorm("Modulation Index", normY); // setting by parameter name
57+
};
5558
}
5659
);

Demo/scripts/main.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
This jsaSound Code is distributed under LGPL 3
3+
Copyright (C) 2012 National University of Singapore
4+
5+
6+
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version.
7+
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser General Public License for more details.
8+
You should have received a copy of the GNU General Public License and GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>
9+
*/
10+
require.config({
11+
paths: {
12+
// "core": "../jsaCore",
13+
// "baseSM": "../jsaCore/baseSM",
14+
// "models": "../jsaModels",
15+
// "utils": "../jsaCore/utils",
16+
// "opCodes": "../jsaOpCodes",
17+
// "config": "../jsaCore/config",
18+
"jsaSound": ".."
19+
}
20+
});
21+
require(
22+
["require", "jsaSound/jsaCore/sliderBox"],
23+
function (require, makeSliderBox) {
24+
var currentSndModel;
25+
var soundSelectorElem = document.getElementById("soundSelector");
26+
27+
//TODO: Have this auto-load from jsaModels contents (have an "all.json")
28+
//TODO: Then pull names from "<model>Data.json"
29+
var soundList = [
30+
{},
31+
{name: "Square Wave", model: "jsaOsc"},
32+
{name: "Classic FM", model: "jsaFM"},
33+
{name: "Noisy FM", model: "jsaNoisyFM"},
34+
{name: "UglyMetadrone", model: "jsaMetaDrone1"},
35+
{name: "Noise Band", model: "jsaFilteredNoiseBand"},
36+
{name: "Metadrone2", model: "jsaMetaDrone2"},
37+
{name: "ToneTick", model: "jsaToneTick"},
38+
{name: "NoiseTick", model: "jsaNoiseTick"},
39+
{name: "Simple Noise Tick 2", model: "jsaSimpleNoiseTick2"},
40+
{name: "Period Trigger 2", model: "jsaPeriodicTrigger2"},
41+
{name: "Mp3", model: "jsaMp3"},
42+
{name: "Granular Mp3", model: "jsaGranularMp3"},
43+
{name: "Mic Input", model: "jsaMicInput"},
44+
{name: "Mic Input 2", model: "jsaMicInput2"},
45+
{name: "Monster Voice", model: "jsaMonsterVoice"}
46+
];
47+
48+
// Create the html select box using the hard-coded soundList above
49+
function makeSoundListSelector() {
50+
var i;
51+
var currOptionName;
52+
for (i = 0; i < soundList.length; i += 1) {
53+
currOptionName = soundList[i].name || "";
54+
//Add option to end of list
55+
soundSelectorElem.add(new Option(currOptionName));
56+
}
57+
}
58+
59+
// When a sound is selected
60+
function soundChoice() {
61+
var sb;
62+
require(
63+
// Get the model
64+
["jsaSound/jsaModels/" + soundList[soundSelectorElem.selectedIndex].model],
65+
// And open the sliderBox
66+
function (currentSM) {
67+
sb = makeSliderBox(currentSM());
68+
}
69+
);
70+
}
71+
72+
//TODO: Find non-jQuery browser-agnostic way of doing this AFTER the window is loaded
73+
makeSoundListSelector();
74+
75+
soundSelectorElem.addEventListener("change", soundChoice);
76+
77+
}
78+
);

0 commit comments

Comments
 (0)