thecollabagepatch commited on
Commit
cb92fd2
·
1 Parent(s): 4843704

sliders update for html

Browse files
Files changed (1) hide show
  1. magentaRT_rt_tester.html +121 -21
magentaRT_rt_tester.html CHANGED
@@ -31,6 +31,15 @@
31
  .err { color: #ff8080; }
32
  .badge { padding: 2px 6px; border-radius: 999px; background: #2a2a3a; font-size: 12px; }
33
  .sep { height: 1px; background: #212133; margin: 12px 0; }
 
 
 
 
 
 
 
 
 
34
  </style>
35
  </head>
36
  <body>
@@ -110,11 +119,16 @@
110
  <button id="btnUpdate" class="btn">Send Update Now</button>
111
  </div>
112
  <div class="col-6">
113
- <label>Styles (comma-separated or prompt text)</label>
114
- <textarea id="txtStyles" placeholder="e.g., acid house, techno">warmup</textarea>
115
- <label>Style weights (comma-separated, optional)</label>
116
- <input id="txtStyleWeights" type="text" placeholder="e.g., 1.0, 0.5" />
117
- <label class="small"><input id="chkUseMixStyle" type="checkbox" /> Use current mix as style</label>
 
 
 
 
 
118
  </div>
119
  </div>
120
  </div>
@@ -202,8 +216,8 @@
202
  const rngGuid = $("rngGuid"), numGuid = $("numGuid");
203
  const rngTopk = $("rngTopk"), numTopk = $("numTopk");
204
  const rngVol = $("rngVol"), numVol = $("numVol");
205
- const txtStyles = $("txtStyles");
206
- const txtStyleWeights = $("txtStyleWeights");
207
  const chkUseMixStyle = $("chkUseMixStyle");
208
  const statusEl = $("status");
209
  const queueEl = $("queue");
@@ -331,20 +345,20 @@ async function scheduleWavBytes(arrayBuffer) {
331
  }
332
  }
333
 
334
- function currentParams() {
335
- return {
336
- temperature: parseFloat(numTemp.value),
337
- topk: parseInt(numTopk.value, 10),
338
- guidance_weight: parseFloat(numGuid.value),
339
- styles: txtStyles.value,
340
- style_weights: txtStyleWeights.value,
341
- use_current_mix_as_style: !!chkUseMixStyle.checked,
342
-
343
- // NEW:
344
- mean: parseFloat(numMean.value),
345
- centroid_weights: centroidWeightsCSV(),
346
- };
347
- }
348
 
349
  function sendUpdate() {
350
  if (!ws || ws.readyState !== 1) return;
@@ -394,6 +408,92 @@ async function scheduleWavBytes(arrayBuffer) {
394
  linkRangeNumber(rngC4, numC4);
395
  linkRangeNumber(rngC5, numC5);
396
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  async function start() {
398
  if (connected) return;
399
  if (!AudioCtx) { alert("Web Audio API not supported"); return; }
 
31
  .err { color: #ff8080; }
32
  .badge { padding: 2px 6px; border-radius: 999px; background: #2a2a3a; font-size: 12px; }
33
  .sep { height: 1px; background: #212133; margin: 12px 0; }
34
+
35
+ .style-list { display: flex; flex-direction: column; gap: 8px; }
36
+ .style-row {
37
+ display: grid;
38
+ grid-template-columns: 1fr 140px 70px 32px; /* name | slider | number | X */
39
+ gap: 10px;
40
+ align-items: center;
41
+ }
42
+ .style-row .remove { padding: 6px 8px; line-height: 1; }
43
  </style>
44
  </head>
45
  <body>
 
119
  <button id="btnUpdate" class="btn">Send Update Now</button>
120
  </div>
121
  <div class="col-6">
122
+ <label>Styles</label>
123
+ <div id="stylesUI">
124
+ <div id="styleRows" class="style-list"></div>
125
+ <div class="controls">
126
+ <button id="btnAddStyle" class="btn" type="button">+ Add style</button>
127
+ <label class="small" style="margin-left:8px;">
128
+ <input id="chkUseMixStyle" type="checkbox" /> Use current mix as style
129
+ </label>
130
+ </div>
131
+ </div>
132
  </div>
133
  </div>
134
  </div>
 
216
  const rngGuid = $("rngGuid"), numGuid = $("numGuid");
217
  const rngTopk = $("rngTopk"), numTopk = $("numTopk");
218
  const rngVol = $("rngVol"), numVol = $("numVol");
219
+ // const txtStyles = $("txtStyles");
220
+ // const txtStyleWeights = $("txtStyleWeights");
221
  const chkUseMixStyle = $("chkUseMixStyle");
222
  const statusEl = $("status");
223
  const queueEl = $("queue");
 
345
  }
346
  }
347
 
348
+ // function currentParams() {
349
+ // return {
350
+ // temperature: parseFloat(numTemp.value),
351
+ // topk: parseInt(numTopk.value, 10),
352
+ // guidance_weight: parseFloat(numGuid.value),
353
+ // styles: txtStyles.value,
354
+ // style_weights: txtStyleWeights.value,
355
+ // use_current_mix_as_style: !!chkUseMixStyle.checked,
356
+
357
+ // // NEW:
358
+ // mean: parseFloat(numMean.value),
359
+ // centroid_weights: centroidWeightsCSV(),
360
+ // };
361
+ // }
362
 
363
  function sendUpdate() {
364
  if (!ws || ws.readyState !== 1) return;
 
408
  linkRangeNumber(rngC4, numC4);
409
  linkRangeNumber(rngC5, numC5);
410
 
411
+
412
+ // --- Dynamic Styles UI ---
413
+ const styleRows = document.getElementById("styleRows");
414
+ const btnAddStyle = document.getElementById("btnAddStyle");
415
+
416
+ function addStyleRow(name = "", weight = 1.0) {
417
+ const row = document.createElement("div");
418
+ row.className = "style-row";
419
+ row.innerHTML = `
420
+ <input class="style-name" type="text" placeholder="e.g. acid house" value="${name}">
421
+ <input class="style-range" type="range" min="0.0" max="2.0" step="0.01" value="${weight}">
422
+ <input class="style-number" type="number" min="0.0" max="2.0" step="0.01" value="${weight}">
423
+ <button class="btn remove" type="button" title="Remove">×</button>
424
+ `;
425
+
426
+ const nameEl = row.querySelector(".style-name");
427
+ const rangeEl = row.querySelector(".style-range");
428
+ const numEl = row.querySelector(".style-number");
429
+ const remove = row.querySelector(".remove");
430
+
431
+ // keep slider/number in sync + auto-update
432
+ const sync = (fromRange) => {
433
+ if (fromRange) numEl.value = rangeEl.value;
434
+ else rangeEl.value = numEl.value;
435
+ };
436
+ rangeEl.addEventListener("input", () => { sync(true); debouncedUpdate(); });
437
+ numEl.addEventListener("input", () => { sync(false); debouncedUpdate(); });
438
+ nameEl.addEventListener("input", () => { debouncedUpdate(); });
439
+
440
+ remove.addEventListener("click", () => { row.remove(); debouncedUpdate(); });
441
+
442
+ styleRows.appendChild(row);
443
+ // initial sync
444
+ sync(true);
445
+ }
446
+
447
+ function stylesCSV() {
448
+ // only include rows with non-empty names
449
+ return [...styleRows.querySelectorAll(".style-row")]
450
+ .map(r => r.querySelector(".style-name").value.trim())
451
+ .filter(s => s.length > 0)
452
+ .join(", ");
453
+ }
454
+
455
+ function styleWeightsCSV() {
456
+ // weights aligned with non-empty names (server defaults to 1.0 if missing)
457
+ const out = [];
458
+ for (const r of styleRows.querySelectorAll(".style-row")) {
459
+ const name = r.querySelector(".style-name").value.trim();
460
+ if (!name) continue;
461
+ const val = parseFloat(r.querySelector(".style-number").value);
462
+ out.push(Number.isFinite(val) ? val : 1.0);
463
+ }
464
+ return out.join(",");
465
+ }
466
+
467
+ // Default row to match your previous "warmup" default
468
+ addStyleRow("warmup", 1.0);
469
+
470
+ // add style on click
471
+ btnAddStyle.addEventListener("click", () => addStyleRow("", 1.0));
472
+
473
+ // --- Wire into your existing param-building ---
474
+ // Replace txtStyles/txtStyleWeights usage inside currentParams()
475
+ const ORIGINAL_currentParams = currentParams; // keep a copy if needed
476
+ currentParams = function () {
477
+ return {
478
+ temperature: parseFloat(numTemp.value),
479
+ topk: parseInt(numTopk.value, 10),
480
+ guidance_weight: parsefloatSafe(numGuid.value, 1.1),
481
+
482
+ // from the dynamic rows:
483
+ styles: stylesCSV(),
484
+ style_weights: styleWeightsCSV(),
485
+ use_current_mix_as_style: !!chkUseMixStyle.checked,
486
+
487
+ mean: parsefloatSafe(numMean?.value, 1.0),
488
+ centroid_weights: centroidWeightsCSV(),
489
+ };
490
+ };
491
+
492
+ function parsefloatSafe(v, dflt) {
493
+ const x = parseFloat(v);
494
+ return Number.isFinite(x) ? x : dflt;
495
+ }
496
+
497
  async function start() {
498
  if (connected) return;
499
  if (!AudioCtx) { alert("Web Audio API not supported"); return; }