This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BEATS_MACHINE.html
589 lines (549 loc) · 40.6 KB
/
BEATS_MACHINE.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
<hr />
<p><strong>BEATS_MACHINE</strong></p>
<hr />
<p><span style="background: #ffff00">The <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/Single-page_application" target="_blank" rel="noopener">single web page application</a> featured in this tutorial web page substantiates a beats machine which allows the user to play zero, one, two, or three sound tracks simultaneously and such that the user can customize the beat <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/Pitch_(music)" target="_blank" rel="noopener">pitch</a> (i.e. monotone sound wave frequency) and the beat <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/Duration_(music)" target="_blank" rel="noopener">duration</a> (i.e. time interval in which the same tone is played immediately in succession) of each one of those three sound tracks play.</span></p>
<p><em>To view hidden text inside each of the preformatted text boxes below, scroll horizontally.</em></p>
<hr />
<p><strong>SOFTWARE_APPLICATION_COMPONENTS</strong></p>
<hr />
<p>Hyper-Text-Markup-Language_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine.html" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine.html</a></p>
<p>Cascading-Style-Sheet_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/karbytes_aesthetic.css" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/karbytes_aesthetic.css</a></p>
<p>JavaScript_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine.js" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine.js</a></p>
<hr />
<p><strong>Hyper-Text-Markup-Language Code</strong></p>
<hr />
<p>The following Hyper-Text-Markup-Language (<a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/HTML" target="_blank" rel="noopener">HTML</a>) code defines the user interface component of the BEATS_MACHINE web page application. Copy the HTML code from the source code file which is linked below into a text editor and save that file as <strong>beats_machine.html</strong>. Use a web browser such as <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/Firefox" target="_blank" rel="noopener">Firefox</a> to open that HTML file (and ensure that the JavaScript and Cascading-Style-Sheet files are in the same file directory as the HTML file).</p>
<p><em><strike>Note that the contents of the HTML file are not displayed in a preformatted text box on this web page due to the fact that the WordPress server makes no distinction between HTML code which is encapsulated inside of a preformatted text box and WordPress web page source code.</strike> <span style="background:#00ffff">(The HTML code has been formatted to be properly displayed on this web page as of 17_SEPTEMBER. For details on how that was accomplished, visit the web page of this website named <a style="background:#000000;color:#ff9000" href="https://karbytesforlifeblog.wordpress.com/karbytes_17_september_2024/" target="_blank" rel="noopener">karbytes_17_september_2024</a>).</span></em></p>
<p><em><strong>If copy-pasting the following HTML code from the preformatted text box below into a text editor, remove the <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/Zero-width_space" target="_blank" rel="noopener">zero-width space</a> Unicode character (<span style="background:#000000;color:#fe9eff">&​#8203;</span>) which is located between the ‘s’ and the ‘r’ in the script tag(s) which each link to a <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/JavaScript" target="_blank" rel="noopener">JavaScript</a> file.</em></strong></p>
<p>Hyper-Text-Markup-Language_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine.html" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine.html</a></p>
<p>image_link: <a style="background: #000000;color: #ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine_html_screenshot.png" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine_html_screenshot.png</a></p>
<hr />
<pre>
<!--
/**
* file: beats_machine.html
* type: Hyper-Text-Markup-Language
* author: karbytes
* date: 09_SEPTEMBER_2024
* license: PUBLIC_DOMAIN
*/
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BEATS_MACHINE</title>
<!--
/**
* The linked Cascading-Style-Sheet file named karbytes_aesthetic.css
* defines how this web page (which is named beats_machine.html) appears
* when this web page is (re)loaded by the web browser.
*/
-->
<link rel="stylesheet" href="karbytes_aesthetic.css">
<!--
/**
* The linked JavaScript file named beats_machine.js
* defines how this web page (which is named beats_machine.html) behaves
* when the user clicks on the menus and start and stop buttons
* (and when this web page is (re)loaded by the web browser).
*/
-->
<script s​rc="beats_machine.js"></script>
<style>
/** Give DIV elements on this web page rounded corners and a MAGENTA border which is 2 pixels thick. */
div {
border-color: #ff00ff;
border-width: 2px;
border-style: solid;
padding: 10px;
margin: 10px;
border-radius: 5px;
}
/**
* Set the button elements on this web page to have a similar visual appearance as other HTML elements
* defined in the linked Cascading-Style-Sheet file (i.e. karbytes_aesthetic.css).
*/
button {
border-color: #ff9000;
border-width: 2px;
border-style: solid;
background: #00ff00;
color: #000000;
padding: 10px;
margin: 10px;
border-radius: 5px;
font-size: 14pt;
}
/** Set the start button's background color to GREEN. */
#start_button {
background: #00ff00;
}
/** Set the stop button's background color to RED. */
#stop_button {
background: #ff0000;
}
/** Cause the start button's background color to turn CYAN when the cursor hovers over it. */
#start_button:hover {
background: #00ffff;
}
/** Cause the stop button's background color to turn CYAN when the cursor hovers over it. */
#stop_button:hover {
background: #00ffff;
}
</style>
</head>
<body onload="initialize_application()">
<div>
<h1>BEATS_MACHINE</h1>
<p>
This application plays zero, one, two, or three sound tracks simultaneously and such that the
user can customize the beat pitch (i.e. monotone sound wave frequency) and the beat duration
(i.e. time interval in which the same tone is played immediately in succession) of each one
of those three sound tracks.
</p>
</div>
<!-- Track 0 -->
<div>
<h3>TRACK_0</h3>
<p>Select Beat Duration: <span id="duration_0_container">???</span></p>
<p>Select Beat Pitch: <span id="pitch_0_container">???</span></p>
</div>
<!-- Track 1 -->
<div>
<h3>TRACK_1</h3>
<p>Select Beat Duration: <span id="duration_1_container">???</span></p>
<p>Select Beat Pitch: <span id="pitch_1_container">???</span></p>
</div>
<!-- Track 2 -->
<div>
<h3>TRACK_2</h3>
<p>Select Beat Duration: <span id="duration_2_container">???</span></p>
<p>Select Beat Pitch: <span id="pitch_2_container">???</span></p>
</div>
<!-- Buttons to start (or stop) playing the beats -->
<button id="start_button" onclick="startBeats()">START_BEATS</button>
<button id="stop_button" onclick="stopBeats()">STOP_BEATS</button>
<!-- CONSOLE -->
<div class="console" id="console">???</div>
</body>
</html>
</pre>
<hr>
<figure class="wp-block-image size-full"><img data-attachment-id="35074" data-permalink="https://karbytesforlifeblog.wordpress.com/beats_machine/beats_machine_html_screenshot/" data-orig-file="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_html_screenshot.png" data-orig-size="1057,2298" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}" data-image-title="beats_machine_html_screenshot" data-image-description="" data-image-caption="" data-medium-file="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_html_screenshot.png?w=138" data-large-file="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_html_screenshot.png?w=471" tabindex="0" role="button" width="1057" height="2298" src="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_html_screenshot.png" alt="" class="wp-image-35074" /></figure>
<hr />
<p><strong>Cascading-Style-Sheet Code</strong></p>
<hr />
<p>The following Cascading-Style-Sheet (<a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/CSS" target="_blank" rel="noopener">CSS</a>) code defines a stylesheet which customizes the appearance of interface components of the BEATS_MACHINE web page application. Copy the CSS code from the source code file which is linked below into a text editor and save that file as <strong>karbytes_aesthetic.css</strong>.</p>
<p>Cascading-Style-Sheet_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/karbytes_aesthetic.css" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/karbytes_aesthetic.css</a></p>
<hr />
<pre>/**
* file: karbytes_aesthetic.css
* type: Cascading-Style-Sheet
* date: 10_JULY_2023
* author: karbytes
* license: PUBLIC_DOMAIN
*/
/** Make the page background BLACK, the text orange and monospace, and the page content width 800 pixels or less. */
body {
background: #000000;
color: #ff9000;
font-family: monospace;
font-size: 16px;
padding: 10px;
width: 800px;
}
/** Make input elements and select elements have an orange rounded border, a BLACK background, and orange monospace text. */
input, select {
background: #000000;
color: #ff9000;
border-color: #ff9000;
border-width: 1px;
border-style: solid;
border-radius: 5px;
padding: 10px;
appearance: none;
font-family: monospace;
font-size: 16px;
}
/** Invert the text color and background color of INPUT and SELECT elements when the cursor (i.e. mouse) hovers over them. */
input:hover, select:hover {
background: #ff9000;
color: #000000;
}
/** Make table data borders one pixel thick and CYAN. Give table data content 10 pixels in padding on all four sides. */
td {
color: #00ffff;
border-color: #00ffff;
border-width: 1px;
border-style: solid;
padding: 10px;
}
/** Set the text color of elements whose identifier (id) is "output" to CYAN. */
#output {
color: #00ffff;
}
/** Set the text color of elements whose class is "console" to GREEN and make the text background of those elements BLACK. */
.console {
color: #00ff00;
background: #000000;
}
</pre>
<hr />
<p><strong>JavaScript Code</strong></p>
<hr />
<p>The following JavaScript (<a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/JavaScript" target="_blank" rel="noopener">JS</a>) code defines the functions which control the behavior of the BEATS_MACHINE web page application. Copy the JS code from the source code file which is linked below into a text editor and save that file as <strong>beats_machine.js</strong>.</p>
<p>The text in the preformatted text box below appears on this web page (while rendered correctly by the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/HTML" target="_blank" rel="noopener">web browser</a>) to be identical to the content of the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/JavaScript" target="_blank" rel="noopener">JavaScript</a> source code file whose <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/URL" target="_blank" rel="noopener">Uniform Resource Locator</a> is displayed in the green <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Hyperlink" target="_blank" rel="noopener">hyperlink</a> below.</p>
<p><em>(Note that angle brackets which resemble <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/HTML" target="_blank" rel="noopener">HTML</a> tags (i.e. an “is less than” symbol (i.e. ‘<‘) followed by an “is greater than” symbol (i.e. ‘>’) displayed in the aforementioned text box have been replaced (at the source code level of this web page) with Unicode symbols <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Less-than_sign" target="_blank" rel="noopener">U+003C</a> (which is rendered by the web browser as ‘<‘) and <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Greater-than_sign" target="_blank" rel="noopener">U+003E</a> (which is rendered by the web browser as ‘>’). That is because the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/WordPress.com" target="_blank" rel="noopener">WordPress</a> web page editor interprets a plain-text versions of an “is less than” symbol followed by an “is greater than” symbol as being an opening HTML tag (which means that the WordPress web page editor deletes the content between those (plain-text) inequality symbols)).</em></p>
<p>JavaScript_file: <a style="background: #000000;color: #00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine.js" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine.js</a></p>
<hr />
<pre>/**
* file: beats_machine.js
* type: JavaScript
* author: karbytes
* date: 10_SEPTEMBER_2024
* license: PUBLIC_DOMAIN
*/
// global program variables
let audioContext;
let intervalIds = [];
/**
* Start playing all three beat tracks with the pitch and duration parameters specified on
* the web page named beats_machine.html. Play all three of those tracks for an indefinitely
* long time period.
*
* Assume that this function is called in response to the event of the START_BUTTON being clicked on
* the web page named beats_machine.html (which is assumed to be in the same local directory as
* this file (i.e. beats_machine.js) and the file named karbytes_aesthetic.css).
*
* This function also prints a time-stamped message indicating when the START_BUTTON was last
* clicked in a DIV element on that web page whose identifier is "console" (and that time-stamped
* message is appended to the message that should already be printed in that DIV during the
* most recent web page load).
*/
function startBeats() {
let time_stamped_message = "", console_div = undefined;
try {
// Populate the div whose identifier is "console" with a time stamped message indicating that this function was called (and when it was called).
time_stamped_message = ("The function named startBeats() was called at time: " + generate_time_stamp());
console.log(time_stamped_message);
time_stamped_message = generate_paragraph_html_element(time_stamped_message);
console_div = document.getElementById("console");
console_div.innerHTML += time_stamped_message;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of startBeats(): " + exception);
}
/**
* Initialize the audio context if it has not already been created.
* Note that the audio context makes it possible to play the beats offline.
* That is because the web browser has built-in sound generating capabilities.
*
* According to ChatGPT-4o, the AudioContext manages a flow of audio data buffers,
* which are processed and sent to the output device (e.g., speakers). When creating an
* AudioContext, the browser communicates with the system's sound hardware, requesting
* access to manage audio streams.
*/
if (!audioContext) {
audioContext = new (window.AudioContext || window.webkitAudioContext)();
}
// Begin playing all three tracks (for an indefinitely long period of time).
startTrack(0);
startTrack(1);
startTrack(2);
}
/**
* Stop playing all three beat tracks simultaneously.
*
* Assume that this function is called in response to the event of the STOP_BUTTON being clicked on
* the web page named beats_machine.html (which is assumed to be in the same local directory as
* this file (i.e. beats_machine.js) and the file named karbytes_aesthetic.css).
*
* This function also prints a time-stamped message indicating when the STOP_BUTTON was last
* clicked in a DIV element on that web page whose identifier is "console" (and that time-stamped
* message is appended to the message that should already be printed in that DIV during the
* most recent web page load).
*/
function stopBeats() {
let time_stamped_message = "", console_div = undefined;
try {
// Populate the div whose identifier is "console" with a time stamped message indicating that this function was called (and when it was called).
time_stamped_message = ("The function named stopBeats() was called at time: " + generate_time_stamp());
console.log(time_stamped_message);
time_stamped_message = generate_paragraph_html_element(time_stamped_message);
console_div = document.getElementById("console");
console_div.innerHTML += time_stamped_message;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of stopBeats(): " + exception);
}
intervalIds.forEach(id => clearInterval(id)); // Clear all intervals.
intervalIds = []; // Reset interval ids array.
}
/**
* Start playing an individual track (whose trackNumber is assumed to be 0, 1, or 2).
*/
function startTrack(trackNumber) {
const durationSelect = document.getElementById(`track_${trackNumber}_duration`);
const pitchSelect = document.getElementById(`track_${trackNumber}_pitch`);
const beatDuration = parseFloat(durationSelect.value);
const beatPitch = parseFloat(pitchSelect.value);
// If the "Do Not Play" option is selected, then do not play the respective track.
if (beatPitch === 0) return;
/**
* Play the respective track using the built-in sound generating capabilities of the web browser.
*
* According to ChatGPT-4o, the oscillator generates a periodic waveform (like a sine wave).
* Physically, an oscillator in sound represents variations in air pressure over time, which,
* when processed digitally, corresponds to a series of numerical samples. These samples are
* fed into the system's audio buffer, which is sent to the speakers to produce sound.
*
* According to ChatGPT-4o, the gain node adjusts the volume of the sound by scaling the
* amplitude of the waveform. At the machine level, this means multiplying each sample in
* the audio buffer by a constant factor before sending it to the output device.
*
* The GainNode controls the amplitude of the tone, creating a short beat that ramps up and down in volume.
*/
function playBeat() {
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();
oscillator.frequency.value = beatPitch;
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
gainNode.gain.setValueAtTime(0, audioContext.currentTime);
gainNode.gain.linearRampToValueAtTime(1, audioContext.currentTime + 0.01);
gainNode.gain.linearRampToValueAtTime(0, audioContext.currentTime + beatDuration);
oscillator.start(audioContext.currentTime);
oscillator.stop(audioContext.currentTime + beatDuration);
}
// Set the interval to play the beat at the selected duration.
const intervalId = setInterval(playBeat, beatDuration * 1000);
intervalIds.push(intervalId);
}
/**
* Return a String type value which describes the number of milliseconds which have elapsed since the Unix Epoch.
*
* Note that the Unix Epoch is 01_JANUARY_1970 at 0 hours, 0 minutes, 0 seconds, and 0 seconds
* (i.e. 00:00:00) (i.e. midnight) (Coordinated Universal Time (UTC)).
*
* @return {String} text which denotes the number of milliseconds which have elapsed since the Unix Epoch.
*/
function generate_time_stamp() {
const milliseconds_elapsed_since_unix_epoch = Date.now();
return milliseconds_elapsed_since_unix_epoch + " milliseconds since midnight on 01_JANUARY_1970.";
}
/**
* Return a String type value which is used to instantiate a paragraph type web page element such that
* the String type value which is passed into this function as its only input is that paragraph element's
* inner HTML content.
*
* Note that the String type constant variable values are broken up into single-character String type values
* to avoid causing the WordPress web page editor to interpret HTML tags in the web page body with
* source code which is hosted on that web page inside of PRE (preformatted) web page elements.
*
* @param {String} inner_HTML is assumed to be plain text or HTML content.
*
* @return {String} a sequence of text characters which is used to instantiate a paragraph (P) web page element.
*/
function generate_paragraph_html_element(inner_html) {
const opening_paragraph_tag = ('<' + 'p' + '>'), closing_paragraph_tag = ('<' + '/' + 'p' + '>');
try {
if (typeof inner_html.length !== "number") throw 'The expression (typeof inner_html.length !== "number") was evaluated to be true.';
return opening_paragraph_tag + inner_html + closing_paragraph_tag;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of generate_paragraph_html_element(inner_html): " + exception);
}
}
/**
* Generate a drop-down menu of various pitches (and a pitch is a particular sound wave frequency).
*
* Return a String type value which is used to instantiate a select type web page element such that
* the String type value which is passed into this function as its only input is that select menu element's
* id property value.
*
* When clicked on, the select menu interface element will expand to display a list of all sound frequencies
* (in units named hertz (which is abreviated as Hz (and which indicates some number of cycles per second)))
* which are nonnegative integers denoting the number of oscillations per second for each of those twenty beat frequencies.
*
* Each of the twenty beat pitch frequencies listed in the drop-down menu are arranged in acending order
* starting with the menu option at the top of the list (which is 0 Hz)
* and then, starting with the second option in the list (which is 200 Hz),
* incrementing the beat pitch frequency value by some constant positive integer number of Hz (i.e. 45)
* until the menu option at the bottom of the list (which is 1010 Hz) is reached.
*
* @param {String} select_id is assumed to be either
* "track_0_pitch" or else
* "track_1_pitch" or else
* "track_2_pitch".
*
* @return {String} a sequence of text characters which is used to instantiate an expandable list menu (SELECT) web page element.
*/
function generate_pitch_menu_select_html_element(select_id) {
let select_menu = '', option = '', i = 0, N = 200;
let default_menu_option_label = "Do Not Play (i.e. 0 Hz)";
try {
if (typeof select_id.length !== "number") throw 'The expression (typeof select_id.length !== "number") was evaluated to be true.';
if ((select_id !== "track_0_pitch") &&
(select_id !== "track_1_pitch") &&
(select_id !== "track_2_pitch"))
throw 'select_id must either be "track_0_pitch" or else "track_1_pitch" or "track_2_pitch".';
select_menu = ('<' + 'select id="' + select_id + '" style="text-align:left"' + '>');
for (i = 0; i < 20; i += 1) {
if (i === 0) option = (('<' + 'option value="0" selected' + '>') + default_menu_option_label + ('<' + '/' + '>'));
else {
option = ('<' + 'option value="' + N + '"' + '>');
option += (N + ' Hz' + ('<' + '/' + 'option' + '>'));
}
select_menu += option;
if (i > 0) N += 45;
}
select_menu += ('<' + '/' + 'select' + '>');
return select_menu;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of generate_pitch_menu_select_html_element(select_id): " + exception);
}
}
/**
* Generate a drop-down menu of various beat durations (and a beat duration is the time interval
* in which the same tone is played immediately in succession).
*
* Return a String type value which is used to instantiate a select type web page element such that
* the String type value which is passed into this function as its only input is that select menu element's
* id property value.
*
* When clicked on, the select menu interface element will expand to display a list of all beat durations
* (in units named seconds (and, according to the International System of Units (SI), the second is defined
* scientifically as the duration of 9,192,631,770 periods of the radiation corresponding to the transition
* between the two hyperfine levels of the ground state of the cesium-133 atom)).
*
* Each of the ten beat durations listed in the drop-down menu are arranged in acending order
* starting with the menu option at the top of the list (which is 1/16 second (i.e. 0.0625 second))
* and then incrementing the beat duration by some positive number of seconds (between 0.0625 seconds and 1 second)
* until the menu option at the bottom of the list (which is 2 seconds) is reached.
*
* @param {String} select_id is assumed to be either
* "track_0_duration" or else
* "track_1_duration" or else
* "track_2_dutation".
*
* @return {String} a sequence of text characters which is used to instantiate an expandable list menu (SELECT) web page element.
*/
function generate_beat_duration_menu_select_html_element(select_id) {
let select_menu = '', option = '', i = 0;
let default_menu_option_label = "1/16 second (i.e. 0.0625 second)";
let menu_option_values = [0.0625, 0.25, 0.5, 0.75, 1, 1.0625, 1.25, 1.5, 1.75, 2];
let menu_option_label_prefaces = ["1/16", "1/4", "1/2", "3/4", "1", "17/16", "5/4", "3/2", "7/4", "2"];
try {
if (typeof select_id.length !== "number") throw 'The expression (typeof select_id.length !== "number") was evaluated to be true.';
if ((select_id !== "track_0_duration") &&
(select_id !== "track_1_duration") &&
(select_id !== "track_2_duration"))
throw 'select_id must either be "track_0_duration" or else "track_1_duration" or "track_2_duration".';
select_menu = ('<' + 'select id="' + select_id + '" style="text-align:left"' + '>');
for (i = 0; i < 10; i += 1) {
if (i === 0) option = (('<' + 'option value="' + menu_option_values[0] + '" selected' + '>') + default_menu_option_label + ('<' + '/' + '>'));
else {
option = ('<' + 'option value="' + menu_option_values[i] + '"' + '>');
option += menu_option_label_prefaces[i];
if (i > 4) option += (' seconds (' + menu_option_values[i] + ' seconds)');
else option += (' second (' + menu_option_values[i] + ' second)');
option += ('<' + '/' + 'option' + '>');
}
select_menu += option;
}
select_menu += ('<' + '/' + 'select' + '>');
return select_menu;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of generate_beat_duration_menu_select_html_element(select_id): " + exception);
}
}
/**
* Respond to the event of the web page named beats_machine.html being loaded by a web browser.
*
* This function populates the six select menus on that web page with their respective menu options
* (and those select menus have the HTML element identifiers (ids) are as follows:
* "track_0_duration",
* "track_0_pitch",
* "track_1_duration",
* "track_1_pitch",
* "track_2_duration", and
* "track_2_pitch").
*
* This function also prints a time-stamped message indicating when the web page was last
* loaded by the web browser in a DIV element on that web page whose identifier is "console".
*
* Assume that all three files which constitute this single web page application are located
* in the same local file directory (and those file are
* karbytes_aesthetic.css, beats_machine.js, and beats_machine.html).
*/
function initialize_application() {
// Initialize variables which are local to this function.
let time_stamped_message = "";
let duration_0_container = undefined, pitch_0_container = undefined;
let duration_1_container = undefined, pitch_1_container = undefined;
let duration_2_container = undefined, pitch_2_container = undefined;
// Execute a try-catch block. If runtime exceptions are found, exit the try block and print an error message to the web browser console.
try {
// Populate the div whose identifier is "console" with a time stamped message indicating that this function was called (and when it was called).
time_stamped_message = ("The function named initialize_application() was called at time: " + generate_time_stamp());
console.log(time_stamped_message);
time_stamped_message = generate_paragraph_html_element(time_stamped_message);
console_div = document.getElementById("console");
console_div.innerHTML = time_stamped_message;
// Populate the "duration_0_container" span element with a select menu for choosing a duration for TRACK_0.
duration_0_container_span = document.getElementById("duration_0_container");
duration_0_container_span.innerHTML = generate_beat_duration_menu_select_html_element("track_0_duration");
// Populate the "pitch_0_container" span element with a select menu for choosing a pitch for TRACK_0.
pitch_0_container_span = document.getElementById("pitch_0_container");
pitch_0_container_span.innerHTML = generate_pitch_menu_select_html_element("track_0_pitch");
// Populate the "duration_1_container" span element with a select menu for choosing a duration for TRACK_1.
duration_1_container_span = document.getElementById("duration_1_container");
duration_1_container_span.innerHTML = generate_beat_duration_menu_select_html_element("track_1_duration");
// Populate the "pitch_1_container" span element with a select menu for choosing a pitch for TRACK_1.
pitch_1_container_span = document.getElementById("pitch_1_container");
pitch_1_container_span.innerHTML = generate_pitch_menu_select_html_element("track_1_pitch");
// Populate the "duration_2_container" span element with a select menu for choosing a duration for TRACK_2.
duration_2_container_span = document.getElementById("duration_2_container");
duration_2_container_span.innerHTML = generate_beat_duration_menu_select_html_element("track_2_duration");
// Populate the "pitch_2_container" span element with a select menu for choosing a pitch for TRACK_2.
pitch_2_container_span = document.getElementById("pitch_2_container");
pitch_2_container_span.innerHTML = generate_pitch_menu_select_html_element("track_2_pitch");
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of initialize_application(): " + exception);
}
}
</pre>
<hr />
<p><strong>BEATS_MACHINE Interface (Initial)</strong></p>
<hr />
<p>The screenshot image below depicts what the BEATS_MACHINE web page interface is supposed to look like when the web page is initially loaded (or reloaded) by a web browser.</p>
<p>image_link: <a style="background: #000000;color: #ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine_interface_screenshot_p0.jpeg" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine_interface_screenshot_p0.jpeg</a></p>
<hr />
<figure class="wp-block-image size-full"><img data-attachment-id="35079" data-permalink="https://karbytesforlifeblog.wordpress.com/beats_machine/beats_machine_interface_screenshot_p0/" data-orig-file="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_interface_screenshot_p0.jpeg" data-orig-size="1024,1286" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}" data-image-title="beats_machine_interface_screenshot_p0" data-image-description="" data-image-caption="" data-medium-file="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_interface_screenshot_p0.jpeg?w=239" data-large-file="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_interface_screenshot_p0.jpeg?w=815" tabindex="0" role="button" width="1024" height="1286" src="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_interface_screenshot_p0.jpeg" alt="" class="wp-image-35079" /></figure>
<hr />
<p><strong>BEATS_MACHINE Interface (After Clicking START_BUTTON)</strong></p>
<hr />
<p>The screenshot image below depicts what the BEATS_MACHINE web page interface could look like after the user selects pitch and duration options for each of the three sound tracks and then clicks the START_BUTTON.</p>
<p>image_link: <a style="background: #000000;color: #ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine_interface_screenshot_p1.jpeg" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine_interface_screenshot_p1.jpeg</a></p>
<hr />
<figure class="wp-block-image size-full"><img data-attachment-id="35082" data-permalink="https://karbytesforlifeblog.wordpress.com/beats_machine/beats_machine_interface_screenshot_p1/" data-orig-file="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_interface_screenshot_p1.jpeg" data-orig-size="1028,1342" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}" data-image-title="beats_machine_interface_screenshot_p1" data-image-description="" data-image-caption="" data-medium-file="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_interface_screenshot_p1.jpeg?w=230" data-large-file="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_interface_screenshot_p1.jpeg?w=784" tabindex="0" role="button" width="1028" height="1342" src="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_interface_screenshot_p1.jpeg" alt="" class="wp-image-35082" /></figure>
<hr />
<p><strong>BEATS_MACHINE Interface (After Clicking STOP_BUTTON)</strong></p>
<hr />
<p>The screenshot image below depicts what the BEATS_MACHINE web page interface could look like after the user selects pitch and duration options for each of the three sound tracks, clicks the START_BUTTON, and then clicks the STOP_BUTTON.</p>
<p>image_link: <a style="background: #000000;color: #ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine_interface_screenshot_p2.jpeg" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine_interface_screenshot_p2.jpeg</a></p>
<hr />
<figure class="wp-block-image size-full"><img data-attachment-id="35085" data-permalink="https://karbytesforlifeblog.wordpress.com/beats_machine/beats_machine_interface_screenshot_p2/" data-orig-file="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_interface_screenshot_p2.jpeg" data-orig-size="1013,1400" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}" data-image-title="beats_machine_interface_screenshot_p2" data-image-description="" data-image-caption="" data-medium-file="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_interface_screenshot_p2.jpeg?w=217" data-large-file="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_interface_screenshot_p2.jpeg?w=741" tabindex="0" role="button" loading="lazy" width="1013" height="1400" src="https://karbytesforlifeblog.wordpress.com/wp-content/uploads/2024/09/beats_machine_interface_screenshot_p2.jpeg" alt="" class="wp-image-35085" /></figure>
<hr />
<p><strong>BEATS_MACHINE Use Case (Demonstration Video)</strong></p>
<hr />
<p>The video file linked below shows karbytes using its finished BEATS_MACHINE application and provides some visual and auditory details about how that application works from the end user’s perspective.</p>
<p>video_link: <a style="background: #000000;color: #ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine_by_karbytes_use_case_10september2024.mp4" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_extension_pack_20/main/beats_machine_by_karbytes_use_case_10september2024.mp4</a></p>
<hr>
<p>This web page was last updated on 18_SEPTEMBER_2024. The content displayed on this web page is licensed as <a style="background:#000000;color:#ff9000" href="https://karlinaobject.wordpress.com/public_domain/" target="_blank" rel="noopener">PUBLIC_DOMAIN</a> intellectual property.</p>
<hr>