Skip to content

Commit 4040e36

Browse files
authored
Merge pull request #1 from holodan/release/1.0.0
Release/1.0.0
2 parents b5e4bbc + c60bdd4 commit 4040e36

23 files changed

Lines changed: 3161 additions & 26532 deletions

package-lock.json

Lines changed: 2371 additions & 26120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"just-detect-adblock": "1.1.0",
2525
"lodash": "4.17.10",
2626
"nexusui": "2.1.6",
27+
"tippy.js": "6.3.7",
2728
"tone": "14.8.35"
2829
},
2930
"devDependencies": {
5.05 KB
Loading

src/static/images/logo-text.png

-1.56 KB
Loading
10.6 MB
Binary file not shown.

src/static/scripts/modules/Asteroid.js

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import Cookies from 'js-cookie';
55
import Main from './Main';
66
import Sequencer from './Sequencer';
77
import Controls from './Controls';
8-
import Signal from './Signal';
8+
import Instrument from './Instrument';
99
import Effects from './Effects';
1010
import Audio from './Audio';
1111

1212
import * as backup from '../data/backup.json';
1313

1414
import { fetchAsync } from '../utils/fetchAsync';
15+
import { isMobile } from '../utils/isMobile';
1516

1617
const Asteroid = {
1718
elem: document.querySelector('.intro__wrapper'),
@@ -169,68 +170,68 @@ const Asteroid = {
169170

170171
renderInfo(i) {
171172
let html = `
172-
<div class="flex flex-wrap pb3 mb3 bb bc-black">
173+
<div class="flex flex-wrap pb3 mb3 bb bc-black f6">
173174
Asteroid's Data:
174175
</div>
175176
<div class="flex flex-wrap">
176177
<div class="w-100">
177-
<div class="flex flex-wrap pb2">
178+
<div class="flex flex-wrap pb0 pb2-md">
178179
<div class="col-12">
179-
<span class="fw7">Name:</span>
180+
<span class="f7 f6-md fw7">Name:</span>
180181
</div>
181182
<div class="col-12 intro__statistic">
182183
${Asteroid.selected.name}
183184
</div>
184185
</div>
185186
186-
<div class="flex flex-wrap pb2">
187+
<div class="flex flex-wrap pb0 pb2-md">
187188
<div class="col-12">
188-
<span class="fw7">Potentially Dangerous:</span>
189+
<span class="f7 f6-md fw7"><span class="dn di-md">Potentially</span> Dangerous:</span>
189190
</div>
190191
<div class="col-12 intro__statistic">
191192
${Asteroid.selected.hazardous}
192193
</div>
193194
</div>
194195
195-
<div class="flex flex-wrap pb2">
196+
<div class="flex flex-wrap pb0 pb2-md">
196197
<div class="col-12">
197-
<span class="fw7">Close Approach Date:</span>
198+
<span class="f7 f6-md fw7"><span class="dn di-md">Close</span> Approach Date:</span>
198199
</div>
199200
<div class="col-12 intro__statistic">
200201
${Asteroid.selected.close_approach_date}
201202
</div>
202203
</div>
203204
204-
<div class="flex flex-wrap pb2">
205+
<div class="flex flex-wrap pb0 pb2-md">
205206
<div class="col-12">
206-
<span class="fw7">Orbiting Body:</span>
207+
<span class="f7 f6-md fw7">Orbiting Body:</span>
207208
</div>
208209
<div class="col-12 intro__statistic">
209210
${Asteroid.selected.orbiting_body}
210211
</div>
211212
</div>
212213
213-
<div class="flex flex-wrap pb2">
214+
<div class="flex flex-wrap pb0 pb2-md">
214215
<div class="col-12">
215-
<span class="fw7">Est. Diamater (km):</span>
216+
<span class="f7 f6-md fw7">Est. Diamater (km):</span>
216217
</div>
217218
<div class="col-12 intro__statistic">
218219
${Asteroid.selected.diameter}
219220
</div>
220221
</div>
221222
222-
<div class="flex flex-wrap pb2">
223+
<div class="flex flex-wrap pb0 pb2-md">
223224
<div class="col-12">
224-
<span class="fw7">Miss Distance (km):</span>
225+
<span class="f7 f6-md fw7">Miss Distance (km):</span>
225226
</div>
226227
<div class="col-12 intro__statistic">
227228
${Asteroid.selected.miss_distance}
228229
</div>
229230
</div>
230231
231-
<div class="flex flex-wrap pb2">
232+
<div class="flex flex-wrap pb0 pb2-md">
232233
<div class="col-12">
233-
<span class="fw7">Relatice Velocity (mph):</span>
234+
<span class="f7 f6-md fw7"><span class="dn di-md">Relative</span> Velocity (mph):</span>
234235
</div>
235236
<div class="col-12 intro__statistic">
236237
${Asteroid.selected.velocity}
@@ -297,11 +298,11 @@ const Asteroid = {
297298
let key;
298299
let multitude;
299300

300-
octave = Math.floor(i / Signal.instrumentTypes.length);
301-
multitude = octave * Signal.instrumentTypes.length;
301+
octave = Math.floor(i / Instrument.instrumentTypes.length);
302+
multitude = octave * Instrument.instrumentTypes.length;
302303
key = i - multitude;
303304

304-
Signal.instrumentSelect.value = Signal.instrumentTypes[key];
305+
Instrument.instrumentSelect.value = Instrument.instrumentTypes[key];
305306
};
306307

307308
for (let i = 0; i < Effects.data.length; i++) {
@@ -317,11 +318,11 @@ const Asteroid = {
317318

318319
eventListener() {
319320
let selectsHtml = `
320-
<div class="flex flex-wrap pb3 mb3 bb bc-black">
321+
<div class="flex flex-wrap pb3 mb3 bb bc-black f6">
321322
Select a real-world asteroid:
322323
</div>
323324
<div class="flex flex-wrap">
324-
<div id="asteroids" class="col-12 intro__statistic"></div>
325+
<div id="asteroids" class="intro__statistic"></div>
325326
</div>
326327
`;
327328

@@ -345,9 +346,16 @@ const Asteroid = {
345346
Asteroid.asteroidBeginElem.insertAdjacentHTML('beforeend', buttonHtml);
346347

347348
const beginEl = document.querySelector('#begin');
349+
const selectWidth = isMobile() ? 200 : 300;
350+
const selectHeight = isMobile() ? 20 : 30;
348351

349352
const asteroidSelect = new Nexus.Select('#asteroids', {
350-
size: [300, 30],
353+
size: [selectWidth, 30],
354+
options: Asteroid.asteroids.map(e => e.name)
355+
});
356+
357+
const asteroidSelectChange = new Nexus.Select('#asteroids-change', {
358+
size: [150, selectHeight],
351359
options: Asteroid.asteroids.map(e => e.name)
352360
});
353361

@@ -361,6 +369,11 @@ const Asteroid = {
361369
Asteroid.renderInfo(e.index);
362370
});
363371

372+
asteroidSelectChange.on('change', e => {
373+
Asteroid.selected = Asteroid.asteroids[e.index];
374+
Asteroid.renderInfo(e.index);
375+
});
376+
364377
// midiSelect.on('change', e => {
365378
// const selected = Asteroid.midiSequences[e.index];
366379
// Controls.resetControls();
@@ -377,18 +390,21 @@ const Asteroid = {
377390
return;
378391
}
379392

380-
Main.wrapper.classList.add('active');
381393
Asteroid.elem.classList.remove('active');
382394

383395
setTimeout(() => {
396+
// Hide intro
384397
Asteroid.elem.classList.remove('flex');
385398
Asteroid.elem.classList.add('dn');
386-
}, 300);
387399

388-
Sequencer.renderNotes();
389-
Controls.renderControls();
400+
// Show new elements
401+
Main.wrapper.classList.add('active');
390402

391-
Asteroid.hasOpened = true;
403+
Sequencer.renderNotes();
404+
Controls.renderControls();
405+
406+
Asteroid.hasOpened = true;
407+
}, 300);
392408
},
393409
false
394410
);

src/static/scripts/modules/Audio.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import _ from 'lodash';
66

77
import Controls from './Controls';
88
import Effects from './Effects';
9-
import Signal from './Signal';
9+
import Instrument from './Instrument';
10+
import Envelope from './Envelope';
1011

1112
const Audio = {
1213
lookAhead: 0.5,
1314
instruments: {},
1415
effect: {},
16+
noteLength: 2000, // 120 BPM
17+
tempo: 120,
1518

1619
setContext() {
1720
const context = new Tone.Context({
@@ -23,11 +26,21 @@ const Audio = {
2326
Tone.setContext(context);
2427
},
2528

29+
updateTempo(v) {
30+
const minute = 60000;
31+
const tempo = v;
32+
const quarterNote = minute / tempo;
33+
const fullNote = quarterNote * 4;
34+
35+
Audio.tempo = tempo;
36+
Audio.noteLength = fullNote;
37+
},
38+
2639
setInstruments() {
2740
let instrument;
2841

29-
for (let i = 0; i < Signal.instrumentTypes.length; i++) {
30-
instrument = Signal.instrumentTypes[i];
42+
for (let i = 0; i < Instrument.instrumentTypes.length; i++) {
43+
instrument = Instrument.instrumentTypes[i];
3144
Audio.instruments[instrument] = Tone[instrument];
3245
}
3346
},
@@ -78,14 +91,14 @@ const Audio = {
7891

7992
// Play tone
8093
const synth = new Tone.PolySynth(
81-
Audio.instruments[Signal.currentInstrument]
94+
Audio.instruments[Instrument.currentInstrument]
8295
);
8396

84-
const durationSecs = Controls.noteLength / 1000;
97+
const durationSecs = Audio.noteLength / 1000;
8598
const divideBy = (divide, by) => divide / by;
86-
const attackSecs = divideBy(Signal.envAttack, 1) * Signal.envHold;
87-
const holdSecs = Signal.envHold;
88-
const releaseSecs = divideBy(Signal.envRelease, 1) * Signal.envHold;
99+
const attackSecs = divideBy(Envelope.envAttack, 1) * Envelope.envHold;
100+
const holdSecs = Envelope.envHold;
101+
const releaseSecs = divideBy(Envelope.envRelease, 1) * Envelope.envHold;
89102
const envelope = { attack: attackSecs, release: releaseSecs };
90103
const attackRelease = attackSecs + holdSecs + releaseSecs;
91104

src/static/scripts/modules/Controls.js

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,18 @@ import Audio from './Audio';
88
import Sequencer from './Sequencer';
99
import Record from './Record';
1010

11+
import { isMobile } from '../utils/isMobile';
12+
1113
const Controls = {
1214
startEl: document.querySelector('#start'),
1315
stopEl: document.querySelector('#stop'),
1416
recordEl: document.querySelector('#record'),
1517
resetEl: document.querySelector('#reset'),
16-
tempo: 120,
17-
noteLength: 2000, // 120 BPM
18-
19-
updateTempo(v) {
20-
const minute = 60000;
21-
const tempo = v;
22-
const quarterNote = minute / tempo;
23-
const fullNote = quarterNote * 4;
24-
25-
Controls.tempo = tempo;
26-
Controls.noteLength = fullNote;
27-
Sequencer.interval.ms(Controls.noteLength);
28-
},
18+
sequencer: document.querySelector('.sequencer__notes__wrapper'),
19+
effectsToggle: document.querySelectorAll('.effects-toggle'),
20+
effectsWrapper: document.querySelector('.effects__fx'),
21+
envelopeToggle: document.querySelectorAll('.envelope-toggle'),
22+
envelopeWrapper: document.querySelector('.effects__envelope'),
2923

3024
playControls: async () => {
3125
if (Sequencer.isRunning) {
@@ -35,9 +29,9 @@ const Controls = {
3529
await Tone.start();
3630
Nexus.context.resume();
3731
Sequencer.isRunning = true;
32+
Sequencer.restartInterval();
3833
Controls.recordEl.classList.add('disabled');
3934
Controls.startEl.classList.add('disabled');
40-
Sequencer.interval.start();
4135
},
4236

4337
recordControls: async () => {
@@ -46,6 +40,7 @@ const Controls = {
4640
}
4741

4842
const recorder = new Tone.Recorder();
43+
4944
Tone.getContext().destination.connect(recorder);
5045
recorder.start();
5146
Controls.playControls();
@@ -58,9 +53,9 @@ const Controls = {
5853
}
5954

6055
Sequencer.isRunning = false;
56+
Sequencer.destroyInterval();
6157
Controls.recordEl.classList.remove('disabled');
6258
Controls.startEl.classList.remove('disabled');
63-
Sequencer.interval.stop();
6459

6560
for (let i = 0; i < 10; i++) {
6661
if (Sequencer.sequencer.stepper.value !== 0) Sequencer.sequencer.next();
@@ -87,19 +82,21 @@ const Controls = {
8782
},
8883

8984
renderControls() {
85+
const tempoHeight = isMobile() ? 20 : 30;
86+
9087
const number = new Nexus.Number('#tempo', {
91-
size: [120, 30],
92-
value: Controls.tempo,
88+
size: [120, tempoHeight],
89+
value: Audio.tempo,
9390
min: 30,
94-
max: 200,
91+
max: 300,
9592
step: 1
9693
});
9794

9895
number.colorize('accent', '#505483');
9996
number.colorize('fill', '#d8dada');
10097

10198
number.on('change', v => {
102-
Controls.updateTempo(v);
99+
Audio.updateTempo(v);
103100
});
104101

105102
Controls.startEl.addEventListener(
@@ -114,6 +111,18 @@ const Controls = {
114111
false
115112
);
116113

114+
document.body.onkeyup = e => {
115+
if (e.keyCode == 32) {
116+
e.preventDefault();
117+
118+
if (Sequencer.isRunning) {
119+
Controls.stopControls();
120+
} else {
121+
Controls.playControls();
122+
}
123+
}
124+
};
125+
117126
Controls.resetEl.addEventListener(
118127
'click',
119128
() => Controls.resetControls(),
@@ -125,6 +134,26 @@ const Controls = {
125134
() => Controls.recordControls(),
126135
false
127136
);
137+
138+
for (let i = 0; i < Controls.effectsToggle.length; i++) {
139+
Controls.effectsToggle[i].addEventListener(
140+
'click',
141+
() => {
142+
Controls.effectsWrapper.classList.toggle('active');
143+
},
144+
false
145+
);
146+
}
147+
148+
for (let i = 0; i < Controls.envelopeToggle.length; i++) {
149+
Controls.envelopeToggle[i].addEventListener(
150+
'click',
151+
() => {
152+
Controls.envelopeWrapper.classList.toggle('active');
153+
},
154+
false
155+
);
156+
}
128157
}
129158
};
130159

0 commit comments

Comments
 (0)