-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
622 lines (547 loc) · 21.6 KB
/
index.html
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
<!DOCTYPE html>
<html>
<head>
<style>
:root {
--main-bg-color: #000;
--secondary-bg-color: #333;
--primary-color: #fff;
--accent-color: #f00;
--step-button-dimension: 10px; /* smaller size for 64 buttons */
--control-button-dimension: 30px; /* existing size for control buttons */
--box-shadow-style: 0 0 10px var(--main-bg-color) inset;
--margin-style: 10px;
--default-font: Arial, sans-serif;
}
body {
background-color: var(--main-bg-color);
color: var(--primary-color);
font: normal normal normal 100%/1 var(--default-font);
}
#drum-machine {
width: 80%;
margin: 0 auto;
padding: 20px;
background-color: var(--secondary-bg-color);
border: 5px solid var(--main-bg-color);
}
h1 {
text-align: center;
display: flex;
justify-content: space-between;
align-items: center;
}
h1 button {
padding: 10px;
border: none;
border-radius: 5px;
background-color: var(--primary-color);
color: var(--main-bg-color);
font-size: 1em;
cursor: pointer;
box-shadow: var(--box-shadow-style);
}
.title {
font-size: 40px; /* Adjust the font size as needed */
}
#play.selected {
background-color: #00ff00;
}
#stop.selected {
background-color: var(--accent-color);
}
.steps-container {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 2px;
margin: 10px 0;
}
.step-button {
width: calc(100% / 16 - 2px);
height: 30px;
background-color: #555;
border: none;
border-radius: 5px;
color: #fff;
cursor: pointer;
}
.controls-container {
width: 15%;
gap: 5px;
}
.channel {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.step-button,
.control-button {
border-radius: 50%;
border: none;
background-color: var(--primary-color);
box-shadow: var(--box-shadow-style);
}
.step-button {
width: var(--step-button-dimension);
height: var(--step-button-dimension);
}
.control-button {
width: var(--control-button-dimension);
height: var(--control-button-dimension);
}
.step-button:active,
.step-button.selected,
.mute-button.selected {
background-color: var(--accent-color);
}
.volume-slider {
margin-top: var(--margin-style);
width: 100px;
}
.step-button.playing {
background-color: rgb(255, 255, 255);
box-shadow: 0 0 10px rgb(150, 150, 150) inset;
}
.step-button.playing.selected {
background-color: var(--accent-color);
box-shadow: 0 0 10px rgb(150, 1, 1) inset;
}
.channel-controls {
display: flex;
flex-direction: column;
gap: 5px;
}
.clear-button {
background-color: #ff0;
}
.mute-button {
background-color: #800;
}
.load-sample-button {
background-color: #666;
border: none;
padding: 5px calc(var(--margin-style) * 1.25);
border-radius: 5px;
color: var(--primary-color);
cursor: pointer;
transition: width 0.2s;
}
#load-preset {
font-size: 0.5em; /* Reduce the font size */
padding: 5px 10px; /* Adjust the padding */
}
.load-sample-button.loaded {
width: calc(100% * 1.25);
}
#play.selected {
background-color: #00ff00;
}
#stop.selected {
background-color: var(--accent-color);
}
.step-button {
background-color: #555;
}
.step-button:nth-child(16n+1) {
background-color: #ffff00; /* yellow */
}
.step-button:nth-child(4n+1):not(:nth-child(16n+1)) {
background-color: #add8e6; /* light blue */
}
.channel-container .step-button.selected {
background-color: #ff0000; /* red */
}
.step-button.playing {
background-color: #ffffff;
}
.step-button.playing.selected {
background-color: #ff0000;
}
#play.selected {
background-color: #00ff00; /* Green background for the selected state */
}
#audionals-com {
font-size: 20px;
color: #ff0000; /* Bright pink color */
}
#what-are-audionals {
padding: 3px 6px; /* Adjust the padding as needed */
font-size: 25px; /* Adjust the font size as needed */
background-color: #2200ff; /* Blue background for the button */
color: #ffffff; /* White text color */
position: fixed;
bottom: 20px;
right: 600px;
z-index: 1;
cursor: pointer;
}
#audionals-info {
text-align: center;
width: 78%;
margin: 0 auto; /* center the box itself */
display: none; /* Initially hide the text */
margin-top: 20px;
background-color: rgb(66, 66, 66); /* Red background for the text */
padding: 20px;
color: #fff; /* White text color */
position: fixed;
bottom: 65px;
right: 140px;
z-index: 1;
font-size: 16px;
}
</style>
</head>
<body>
<div id="drum-machine">
<h1>
<button id="play">Play</button>
<span class="title">Audional JSON Sequencer (beta)</span>
<button id="stop">Stop</button>
<div class="bpm-container">
BPM: <input type="range" min="60" max="180" value="125" step="1" id="bpm-slider">
<div class="bpm-display" id="bpm-display">125</div>
</div>
</h1>
<div class="channel" id="bass-drum">
<button class="load-sample-button">Load Audional</button>
<div class="channel-container">
<div class="steps-container"></div>
<div class="controls-container">
<div class="channel-controls">
<button class="control-button clear-button">C</button>
<button class="control-button mute-button">M</button>
</div>
<input type="range" min="0" max="1" step="0.01" class="volume-slider">
</div>
</div>
</div>
<div class="channel" id="snare">
<button class="load-sample-button">Load Audional</button>
<div class="channel-container">
<div class="steps-container"></div>
<div class="controls-container">
<div class="channel-controls">
<button class="control-button clear-button">C</button>
<button class="control-button mute-button">M</button>
</div>
<input type="range" min="0" max="1" step="0.01" class="volume-slider">
</div>
</div>
</div>
<div class="channel" id="hi-hat">
<button class="load-sample-button">Load Audional</button>
<div class="channel-container">
<div class="steps-container"></div>
<div class="controls-container">
<div class="channel-controls">
<button class="control-button clear-button">C</button>
<button class="control-button mute-button">M</button>
</div>
<input type="range" min="0" max="1" step="0.01" class="volume-slider">
</div>
</div>
</div>
<div class="channel" id="bass">
<button class="load-sample-button">Load Audional</button>
<div class="channel-container">
<div class="steps-container"></div>
<div class="controls-container">
<div class="channel-controls">
<button class="control-button clear-button">C</button>
<button class="control-button mute-button">M</button>
</div>
<input type="range" min="0" max="1" step="0.01" class="volume-slider">
</div>
</div>
</div>
<a href="http://www.audionals.com" id="audionals-com" target="_blank">Audionals.com</a>
<button id="what-are-audionals">What are Audionals?</button>
<div id="audionals-info">
<p>
Audionals are a groundbreaking new standard for inscribing audio files
on the Bitcoin blockchain, providing a unique tool for musicians, sound
designers, music enthusiasts and audiophile collectors alike. The
platform takes advantage of the transparent, immutable nature of the
blockchain, offering a unique method of inscribing audio directly onto
the blockchain. The innovative approach taken by Audionals.com might
very well disrupt the traditional music industry and usher in a new era
of audio content creation, distribution, and ownership.
</p>
<br />
<p>
The fundamental technology that drives Audionals.com is the inscription
of audio data to the blockchain in the form of Base64 embedded JSON
files. Audio files uploaded to the platform are encoded into a format
known as Base64, which transforms the binary data into a string of ASCII
characters. This audio data is then embedded within a JSON (JavaScript
Object Notation) file, a lightweight data-interchange format that is
easy for humans to read and write and easy for machines to parse and
generate.
</p>
<br />
<p>
The strength of this approach is two-fold. First, the use of JSON format
makes the audio data easily indexable and sortable. Metadata such as the
audio type, the instrument used, genre, key, BPM, and user-defined
parameters can be added to the JSON file, which facilitates searching,
categorisation, and manipulation of the audio files on the platform. It
essentially creates a database of audio files that are easily searchable
and sortable, making it user-friendly and efficient.
</p>
<br />
<p>
Second, the inscribing of audio data directly onto the blockchain has
profound implications for ownership, copyright, and authenticity. Once a
piece of audio is inscribed onto the blockchain, it is permanent and
immutable. It cannot be altered or deleted, and the ownership is
transparent. This technology could revolutionise the way music
copyrights are handled, providing an indisputable record of original
content.
</p>
<br />
<p>
Furthermore, all audionals can be subjected to recursive techniques,
pulling together these Base64 encoded samples to form new sequences,
enabling users to compose and save music directly on-chain. This
provides musicians with a new way of creating and storing their work,
eliminating the need for external storage devices or services. By
leveraging audional technology and the immutable nature of the
blockchain, musicians can establish verifiable ownership and track their
samples and compositions with ease. The transparency and traceability
offered by audional technology enable accurate royalty distribution and
tracking, revolutionising the way musicians receive recognition and
income for their work.
</p>
<br />
<p>
In essence, Audionals.com represents a novel application of blockchain
technology in the realm of audio and music. Its unique approach to audio
inscription, coupled with the innovative on-chain composition feature,
is poised to disrupt the traditional music industry and empower artists
in unprecedented ways. In a world where digital technology continues to
reshape the way we create, distribute, and consume music, Audionals.com
offers a glimpse into a future where music and blockchain become
inextricably linked.
</p>
</div>
</div>
<script>
let isPlaying = false;
document.addEventListener('DOMContentLoaded', async (event) => {
const whatAreAudionalsButton = document.getElementById('what-are-audionals');
const audionalsInfo = document.getElementById('audionals-info');
// Set initial display state
audionalsInfo.style.display = 'none'; // initially hide the info
whatAreAudionalsButton.addEventListener("click", function () {
if (audionalsInfo.style.display === "none") {
audionalsInfo.style.display = "block"; // show the info if it's currently hidden
} else {
audionalsInfo.style.display = "none"; // hide the info if it's currently visible
}
});
let timeoutId;
let stopClickCount = 0;
let channels;
let playButton = document.getElementById('play');
let stopButton = document.getElementById('stop');
let bpm = 125;
let currentStep = 0;
let audioContext;
let currentStepTime;
let startTime;
let nextStepTime;
let stepDuration;
function getIDFromURL(url) {
const parts = url.split('/');
return parts[parts.length - 1];
}
function base64ToArrayBuffer(base64) {
const binaryString = atob(base64);
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes.buffer;
}
const fetchAudio = (url, channelIndex, loadSampleButton) => {
fetch(url)
.then(response => response.json())
.then(data => {
const audioData = base64ToArrayBuffer(data.audioData.split(',')[1]);
const audioBlob = new Blob([audioData], { type: 'audio/mpeg' });
const audioUrl = URL.createObjectURL(audioBlob);
const channel = document.querySelector(`.channel[data-id="Channel-${channelIndex + 1}"]`);
channel.dataset.audioData = audioUrl;
channel.dataset.audioDataLoaded = 'true';
if (loadSampleButton) {
const filename = data.filename || data.fileName; // Check both properties
loadSampleButton.textContent = filename;
}
})
.catch(error => {
console.error('Error fetching audio:', error);
});
};
channels = document.querySelectorAll('.channel');
channels.forEach((channel, index) => {
channel.dataset.id = `Channel-${index + 1}`;
const muteButton = channel.querySelector('.mute-button');
muteButton.addEventListener('click', () => {
channel.dataset.muted = channel.dataset.muted ? '' : 'true';
muteButton.classList.toggle('selected');
});
const clearButton = channel.querySelector('.clear-button');
clearButton.addEventListener('click', () => {
const stepButtons = channel.querySelectorAll('.step-button');
stepButtons.forEach(button => {
button.classList.remove('selected');
});
});
const stepsContainer = channel.querySelector('.steps-container');
stepsContainer.innerHTML = '';
const fragment = document.createDocumentFragment();
for (let i = 0; i < 64; i++) {
const button = document.createElement('button');
button.classList.add('step-button');
button.addEventListener('click', () => {
button.classList.toggle('selected');
});
fragment.appendChild(button);
}
stepsContainer.appendChild(fragment);
const loadSampleButton = channel.querySelector('.load-sample-button');
loadSampleButton.addEventListener('click', () => {
const audionalId = prompt('Enter the ordinal ID for the Audional:');
const audionalUrl = 'https://ordinals.com/content/' + getIDFromURL(audionalId);
fetchAudio(audionalUrl, index, loadSampleButton);
});
});
if (playButton && stopButton) {
const channel1 = document.querySelector('#channel-0 .step-button:nth-child(4n+1)');
if (channel1) channel1.classList.add('selected');
const channel2Beat1 = document.querySelector('#channel-1 .step-button:nth-child(1)');
if (channel2Beat1) channel2Beat1.classList.add('selected');
const channel2Beat6 = document.querySelector('#channel-1 .step-button:nth-child(6)');
if (channel2Beat6) channel2Beat6.classList.add('selected');
playButton.addEventListener('click', () => {
if (!isPlaying) {
startScheduler();
playButton.classList.add('selected');
stopButton.classList.remove('selected');
isPlaying = true;
}
});
stopButton.addEventListener('click', () => {
if (isPlaying) {
stopScheduler();
stopButton.classList.add('selected');
playButton.classList.remove('selected');
isPlaying = false;
}
});
} else {
console.error("Play or Stop button is not defined");
}
const bpmSlider = document.getElementById('bpm-slider');
const bpmDisplay = document.getElementById('bpm-display');
bpmSlider.addEventListener('input', () => {
bpm = bpmSlider.value;
bpmDisplay.textContent = bpm;
});
const presets = {
preset1: {
urls: [
'https://ordinals.com/content/6d962189218b836cf33e2dc1adbc981e90242aa395f0868178773065f76f144ei0',
'https://ordinals.com/content/0b8eff3f39f4095d0f129bb8dd75f29159f8725c7e66046bf41f70ebb9f60d93i0',
'https://ordinals.com/content/6d8be8186e63b4557e51edd66184a567bc6f5f9f5ba4bb34ba8c67e652c1934ei0'
],
triggers: [
['1', '5', '9', '13', '17', '21', '25', '29', '33', '37', '41', '45', '49', '53', '57', '61'],
['1', '7', '33', '39'],
['62']
]
},
};
// Load a preset when the page loads
const presetToLoadOnPageLoad = 'preset1'; // replace with the name of your preset
if (presets[presetToLoadOnPageLoad]) {
loadPreset(presetToLoadOnPageLoad);
} else {
console.error('Preset not found:', presetToLoadOnPageLoad);
}
// Function to load a preset
function loadPreset(preset) {
const { urls, triggers } = presets[preset];
urls.forEach((url, index) => {
const loadSampleButton = document.querySelector(`.channel[data-id="Channel-${index + 1}"] .load-sample-button`);
fetchAudio(url, index, loadSampleButton);
});
triggers.forEach((trigger, index) => {
trigger.forEach(pos => {
const btn = document.querySelector(`.channel[data-id="Channel-${index + 1}"] .step-button:nth-child(${pos})`);
if (btn) btn.classList.add('selected');
});
});
}
function startScheduler() {
audioContext = new AudioContext();
startTime = audioContext.currentTime;
nextStepTime = startTime;
scheduleNextStep();
}
function scheduleNextStep() {
stepDuration = 60 / bpm / 4;
timeoutId = setTimeout(() => {
playStep();
scheduleNextStep();
}, (nextStepTime - audioContext.currentTime) * 1000);
}
function playStep() {
channels.forEach(channel => {
const buttons = channel.querySelectorAll('.step-button');
const isMuted = channel.dataset.muted === 'true';
if (buttons[currentStep]) {
buttons.forEach(button => button.classList.remove('playing'));
buttons[currentStep].classList.add('playing');
}
if (buttons[currentStep].classList.contains('selected') && !isMuted) {
const audioData = channel.dataset.audioData;
if (audioData) {
const audio = new Audio(audioData);
const source = audioContext.createMediaElementSource(audio);
source.connect(audioContext.destination);
audio.play();
}
}
});
currentStep = (currentStep + 1) % 64;
nextStepTime += stepDuration;
}
function stopScheduler() {
if (audioContext) {
audioContext.close();
}
clearTimeout(timeoutId);
}
function resetStepLights() {
const buttons = document.querySelectorAll('.step-button');
buttons.forEach(button => {
button.classList.remove('playing');
});
}
function togglePlayState(isPlaying, startStopFunction, firstButton, secondButton) {
if (!isPlaying) {
isPlaying = true;
startStopFunction();
firstButton.classList.add('selected');
secondButton.classList.remove('selected');
}
}
});
</script>
</body>
</html>