/
start.js
159 lines (131 loc) · 4 KB
/
start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
DEBUG_ENABLED = false;
GLOBAL_TIMESTEP = 200;
FADE_BUFFER = 100;
CATCHUP_SPEED = .2;
ALL_PLAY_ALL_THE_TIME = true;
ALL_SONGS = []
TO_PLAY_ALWAYS = []
IS_LIVE = false;
EXPERIENCE_NAME = 'noSelection'
options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function begin() {
console.log("beginning")
console.log(EXPERIENCE_NAME)
makeAllLive()
document.getElementById("beginExperience").style.display = "none"
document.getElementById("exitExperience").style.display = "inline"
}
function exit() {
console.log(EXPERIENCE_NAME)
document.getElementById("beginExperience").style.display = "inline"
document.getElementById("exitExperience").style.display = "none"
makeAllDead(EXPERIENCE_NAME)
}
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition, showError, options);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
// this is the line that makes it location based and not just clicking arround
if (!DEBUG_ENABLED) {
myBestKnownLocation = [position.coords.latitude, position.coords.longitude];
}
console.log(position.coords.latitude + "," + position.coords.longitude);
}
function showError(error) {
console.log("error!: " + error)
}
getLocation();
// the "looping location update" is the function where literally everything happens
window.setInterval(loopingLocationUpdate, GLOBAL_TIMESTEP);
// now we can set up the thing where we choose which experience we want:
songsToLoad = 0
songsActuallyLoaded = 0
EXPERIENCE_NAME = 'default'
function loadAllAudio() {
for (i = 0; i < ALL_SONGS[EXPERIENCE_NAME].length; i++) {
ALL_SONGS[EXPERIENCE_NAME][i].loadAudio()
console.log("loading....")
songsToLoad += 1
}
}
function displayLoading() {
console.log(songsToLoad + " " + songsActuallyLoaded)
document.getElementById("myProgressBar").style.width = ((songsActuallyLoaded * 100.0) / songsToLoad) + "%"
if (songsActuallyLoaded == songsToLoad) {
document.getElementById("loadingText").innerHTML = "Loaded!"
clearInterval(refreshIntervalId);
document.getElementById("allLoading").style.display = "none"
document.getElementById("beginExperience").style.display = "inline"
}
}
function startDisplayLoading() {
refreshIntervalId = setInterval(displayLoading, 100);
}
window.onload = function() {
EXPERIENCE_NAME = getUrlVars()['experience']
loadAllAudio();
startDisplayLoading();
for (i = 0; i < ALL_SONGS[EXPERIENCE_NAME].length; i++) {
ALL_SONGS[EXPERIENCE_NAME][i].addToMap()
}
};
function makeAllDead(key) {
for (i = 0; i < ALL_SONGS[key].length; i++) {
ALL_SONGS[key][i].makeDead()
}
IS_LIVE = false
}
function makeAllLive() {
group = new Pizzicato.Group();
ALL_PLAY_ALL_THE_TIME = TO_PLAY_ALWAYS[EXPERIENCE_NAME];
console.log("We are live wowowowowl")
for (i = 0; i < ALL_SONGS[EXPERIENCE_NAME].length; i++) {
ALL_SONGS[EXPERIENCE_NAME][i].makeLive()
try {
group.addSound(ALL_SONGS[EXPERIENCE_NAME][i].soundFile)
} catch {
// if we are going back and the sounds are already there.
}
}
IS_LIVE = true;
var compressor = new Pizzicato.Effects.Compressor({
threshold: -24,
ratio: 12,
mix: 1
});
group.addEffect(compressor)
}
function doDebug() {
console.log(document.getElementById("debugEnableCheckbox").value)
DEBUG_ENABLED = !DEBUG_ENABLED
console.log(DEBUG_ENABLED)
}
function fetchHeader(url, wch) {
try {
var req = new XMLHttpRequest();
req.open("HEAD", url, false);
req.send(null);
if (req.status == 200) {
res = req.getResponseHeader(wch);
document.getElementById("lastUpdated").innerHTML = "Last updated: " + res
} else return false;
} catch (er) {
return er.message;
}
}
fetchHeader('start.js', 'Last-Modified');
window.onclick = function() {
let context = Pizzicato.context
let source = context.createBufferSource()
source.buffer = context.createBuffer(1, 1, 22050)
source.connect(context.destination)
source.start()
}