SREAL commited on
Commit
54a93f6
·
verified ·
1 Parent(s): eb7ce46

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +62 -11
index.html CHANGED
@@ -379,6 +379,14 @@ class AdvancedMelodyGenerator {
379
  this.sequence = [];
380
  this.isPlaying = false;
381
  this.currentPart = null;
 
 
 
 
 
 
 
 
382
  this.initUI();
383
  this.setupEventListeners();
384
  }
@@ -400,10 +408,18 @@ class AdvancedMelodyGenerator {
400
  }
401
  }
402
 
403
- document.querySelectorAll('input[type="range"]').forEach(input => {
404
- const display = document.getElementById(`${input.id}-value`);
405
- if (display) display.textContent = input.value;
406
- });
 
 
 
 
 
 
 
 
407
  }
408
 
409
  getAllNotes() {
@@ -443,6 +459,45 @@ class AdvancedMelodyGenerator {
443
  document.getElementById('chordProgression').onchange = (e) => {
444
  this.updateChordDisplay(e.target.value);
445
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  }
447
 
448
  updateChordDisplay(progression) {
@@ -495,14 +550,10 @@ class AdvancedMelodyGenerator {
495
  this.stop();
496
  this.clearGrid();
497
 
498
- const key = document.getElementById('key').value;
499
- const scale = document.getElementById('scale').value;
500
- const complexity = parseInt(document.getElementById('complexity').value);
501
- const baseOctave = parseInt(document.getElementById('octave').value);
502
  const progression = document.getElementById('chordProgression').value;
503
 
504
- const chords = this.getChordProgression(key, progression);
505
- this.sequence = this.createMelodySequence(key, scale, complexity, baseOctave, chords);
506
  this.visualizeSequence();
507
  }
508
 
@@ -571,7 +622,7 @@ class AdvancedMelodyGenerator {
571
 
572
  play() {
573
  this.isPlaying = true;
574
- Tone.Transport.bpm.value = document.getElementById('tempo').value;
575
 
576
  if (this.currentPart) {
577
  this.currentPart.dispose();
 
379
  this.sequence = [];
380
  this.isPlaying = false;
381
  this.currentPart = null;
382
+ this.key = 'C'; // default key
383
+ this.scale = 'major'; // default scale
384
+ this.complexity = 5; // default complexity
385
+ this.baseOctave = 4; // default base octave
386
+ this.direction = 'mixed'; // default direction
387
+ this.tempo = 120; // default tempo
388
+ this.timeSignature = [4, 4]; // default time signature
389
+ this.swing = 0; // default swing
390
  this.initUI();
391
  this.setupEventListeners();
392
  }
 
408
  }
409
  }
410
 
411
+ // Set initial displayed values for sliders and selectors
412
+ document.getElementById('tempo').value = this.tempo;
413
+ document.getElementById('tempo-value').textContent = this.tempo;
414
+ document.getElementById('complexity').value = this.complexity;
415
+ document.getElementById('complexity-value').textContent = this.complexity;
416
+ document.getElementById('octave').value = this.baseOctave;
417
+ document.getElementById('octave-value').textContent = this.baseOctave;
418
+ document.getElementById('direction').value = this.direction;
419
+ document.getElementById('key').value = this.key;
420
+ document.getElementById('scale').value = this.scale;
421
+ document.getElementById('timeSignature').value = this.timeSignature.join('/');
422
+ document.getElementById('swing').value = this.swing * 100;
423
  }
424
 
425
  getAllNotes() {
 
459
  document.getElementById('chordProgression').onchange = (e) => {
460
  this.updateChordDisplay(e.target.value);
461
  };
462
+
463
+ // Add event listeners for other controls
464
+ document.getElementById('tempo').oninput = (e) => {
465
+ this.tempo = e.target.value;
466
+ Tone.Transport.bpm.value = this.tempo;
467
+ document.getElementById('tempo-value').textContent = this.tempo;
468
+ };
469
+
470
+ document.getElementById('timeSignature').onchange = (e) => {
471
+ this.timeSignature = e.target.value.split('/');
472
+ Tone.Transport.timeSignature = this.timeSignature;
473
+ };
474
+
475
+ document.getElementById('swing').oninput = (e) => {
476
+ this.swing = e.target.value / 100;
477
+ Tone.Transport.swing = this.swing;
478
+ };
479
+
480
+ document.getElementById('complexity').oninput = (e) => {
481
+ this.complexity = e.target.value;
482
+ document.getElementById('complexity-value').textContent = this.complexity;
483
+ };
484
+
485
+ document.getElementById('octave').oninput = (e) => {
486
+ this.baseOctave = e.target.value;
487
+ document.getElementById('octave-value').textContent = this.baseOctave;
488
+ };
489
+
490
+ document.getElementById('direction').onchange = (e) => {
491
+ this.direction = e.target.value;
492
+ };
493
+
494
+ document.getElementById('key').onchange = (e) => {
495
+ this.key = e.target.value;
496
+ };
497
+
498
+ document.getElementById('scale').onchange = (e) => {
499
+ this.scale = e.target.value;
500
+ };
501
  }
502
 
503
  updateChordDisplay(progression) {
 
550
  this.stop();
551
  this.clearGrid();
552
 
 
 
 
 
553
  const progression = document.getElementById('chordProgression').value;
554
 
555
+ const chords = this.getChordProgression(this.key, progression);
556
+ this.sequence = this.createMelodySequence(this.key, this.scale, this.complexity, this.baseOctave, chords);
557
  this.visualizeSequence();
558
  }
559
 
 
622
 
623
  play() {
624
  this.isPlaying = true;
625
+ Tone.Transport.bpm.value = this.tempo;
626
 
627
  if (this.currentPart) {
628
  this.currentPart.dispose();