@mfcc64/ytms 11.0.2 → 12.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/script.mjs +54 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mfcc64/ytms",
3
- "version": "11.0.2",
3
+ "version": "12.1.0",
4
4
  "description": "YouTube Musical Spectrum",
5
5
  "main": "script.mjs",
6
6
  "scripts": {
package/script.mjs CHANGED
@@ -19,8 +19,7 @@
19
19
  import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
20
20
 
21
21
  (async function(){
22
- const current_script = import.meta.url;
23
- const get_asset = (name) => String(new URL(`../ytms-assets@1.0.0/${name}`, current_script));
22
+ const get_asset = (name) => String(new URL(`../ytms-assets@1.0.0/${name}`, import.meta.url));
24
23
  const axis_list = [
25
24
  "",
26
25
  get_asset("axis-hz-1920x32.png")
@@ -37,13 +36,16 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
37
36
  mic_pan: { def: 0, min:-10, max: 10 },
38
37
  scale_x: { def:100, min: 30, max:100 },
39
38
  scale_y: { def:100, min: 30, max:100 },
39
+ base_note: { def: 16, min: 16, max:100 },
40
+ semitones: { def:120, min: 36, max:120 },
41
+ peak_color: { def:0xffffff, min:0, max:0xffffff },
40
42
  left_color: { def:0xdcb900, min:0, max:0xffffff },
41
43
  right_color:{ def:0x00b9dc, min:0, max:0xffffff },
42
44
  mid_color: { def:0xdcdcdc, min:0, max:0xffffff },
43
45
  interval: { def: 1, min: 1, max: 4 },
44
46
  codecs: { def: 1, min: 0, max: 2 },
45
47
  transparent:{ def: 1, min: 0, max: 1 },
46
- visible: { def: document.location.hostname == "music.youtube.com" ? 1 : 0,
48
+ visible: { def: document.location.hostname != "www.youtube.com" ? 1 : 0,
47
49
  min: 0, max: 1 },
48
50
  axis: { def: 0, min: 0, max: axis_list.length - 1 }
49
51
  };
@@ -116,7 +118,7 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
116
118
  e("li", "If you want to change the axis, click it."),
117
119
  e("li", "If you want to make your change persistent, click ", e("b", "Set as Default Settings"), " button."),
118
120
  e("li", e("b", "New Features:"), " Hz-scale axis, microphone support, YT Music support, scale options to " +
119
- "reduce CPU usage, custom color."),
121
+ "reduce CPU usage, custom color, custom range, peak color."),
120
122
  e("li", e("a", {href: "https://github.com/mfcc64/youtube-musical-spectrum#settings"}, {target: "_blank"}, "Read more..."))
121
123
  ),
122
124
  e("p",
@@ -147,7 +149,7 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
147
149
  af_links.style.display = !af_links_timeout || (child_menu.visible?.checked ?? true) ? "block" : "none";
148
150
  }
149
151
 
150
- const message_version = 8;
152
+ const message_version = 9;
151
153
  af_links.shadowRoot.getElementById("message").style.display = get_opt("message_version") == message_version ? "none" : "block";
152
154
  af_links.shadowRoot.getElementById("close_message").addEventListener("click", function() {
153
155
  set_opt("message_version", message_version);
@@ -351,10 +353,30 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
351
353
  create_child_range_menu("Scale Y", "scale_y", (child) => cqt.dataset.scaleY = child.value);
352
354
  create_child_select_codecs();
353
355
 
356
+ function update_range(child) {
357
+ if (!child_menu.base_note || !child_menu.semitones)
358
+ return;
359
+
360
+ const width = child_menu.semitones.value * 1;
361
+ const base = child_menu.base_note.value - 16;
362
+ if (base + width > 120) {
363
+ child == child_menu.semitones ?
364
+ (child_menu.base_note.value = 120 - width + 16, child_menu.base_note.onchange()) :
365
+ (child_menu.semitones.value = 120 - base, child_menu.semitones.onchange());
366
+ return;
367
+ }
368
+ cqt.style.left = -base / width * 100 + "%";
369
+ cqt.style.width = 12000 / width + "%";
370
+ }
371
+
372
+ create_child_range_menu("Base Note", "base_note", child => update_range(child));
373
+ create_child_range_menu("Semitones", "semitones", child => update_range(child));
374
+
354
375
  const number2color = n => "#" + (n|0).toString(16).padStart(6, "0");
355
376
  const color2number = c => Number.parseInt(c.slice(1), 16);
356
- const color_int = [ 0, 0, 0 ];
377
+ const color_int = [ 0, 0, 0, 0 ];
357
378
  const color_table = new Array(9);
379
+ const peak_color = new Array(3);
358
380
 
359
381
  function create_child_color_menu(title, name, callback) {
360
382
  var tr = get_menu_table_tr();
@@ -386,6 +408,22 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
386
408
  child.onchange();
387
409
  }
388
410
 
411
+ create_child_color_menu("Peak Color", "peak_color", child => color_int[3] = color2number(child.value));
412
+
413
+ function detect_peak(color) {
414
+ if (color_int[3] == 0xffffff)
415
+ return;
416
+
417
+ for (let k = 4; k < color.length - 4; k += 4) {
418
+ if (color[k+3] <= color[k-1] || color[k+3] < color[k+7])
419
+ continue;
420
+
421
+ const alpha = (1 - (k+2) / color.length) ** 2;
422
+ for (let m = 0; m < 3; m++)
423
+ color[k+m] = Math.min(color[k+m], 1) * (1 - alpha + peak_color[m] * alpha);
424
+ }
425
+ }
426
+
389
427
  function update_color_table() {
390
428
  const k = 0xb9/0xdc;
391
429
  const color_tmp = new Array(9);
@@ -400,13 +438,17 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
400
438
  color_table[0+x] = color_tmp[0+x] - k * color_table[3+x];
401
439
  color_table[6+x] = color_tmp[6+x] - k * color_table[3+x];
402
440
  }
441
+
442
+ peak_color[0] = ((color_int[3] >> 16) & 0xff) / 0xff;
443
+ peak_color[1] = ((color_int[3] >> 8) & 0xff) / 0xff;
444
+ peak_color[2] = (color_int[3] & 0xff) / 0xff;
403
445
  }
404
446
 
405
447
  create_child_color_menu("Left Color", "left_color", child => color_int[0] = color2number(child.value));
406
448
  create_child_color_menu("Mid Color", "mid_color", child => color_int[1] = color2number(child.value));
407
449
  create_child_color_menu("Right Color", "right_color", child => color_int[2] = color2number(child.value));
408
450
 
409
- cqt.actual_render_callback = function(color) {
451
+ function transform_color(color) {
410
452
  if (color_int[0] == 0xdcb900 && color_int[1] == 0xdcdcdc && color_int[2] == 0x00b9dc)
411
453
  return;
412
454
 
@@ -418,6 +460,11 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
418
460
  }
419
461
  }
420
462
 
463
+ cqt.actual_render_callback = function(color) {
464
+ transform_color(color);
465
+ detect_peak(color);
466
+ }
467
+
421
468
  function create_child_select_codecs() {
422
469
  var tr = get_menu_table_tr();
423
470
  set_common_tr_style(tr);