-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.html
More file actions
158 lines (134 loc) · 5.43 KB
/
debug.html
File metadata and controls
158 lines (134 loc) · 5.43 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chord Player Debug</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
.debug-info { background: #f0f0f0; padding: 10px; margin: 10px 0; border-radius: 5px; }
button { padding: 10px 20px; margin: 5px; font-size: 16px; }
#log { background: #000; color: #0f0; padding: 10px; height: 200px; overflow-y: auto; font-family: monospace; }
</style>
</head>
<body>
<h1>Chord Player Debug</h1>
<div class="debug-info">
<h3>Audio Context Status</h3>
<p>State: <span id="audioState">Not initialized</span></p>
<p>Sample Rate: <span id="sampleRate">-</span></p>
<p>User Gesture: <span id="userGesture">No</span></p>
</div>
<div class="debug-info">
<h3>Controls</h3>
<button onclick="initAudio()">Initialize Audio</button>
<button onclick="playTestTone()">Play Test Tone</button>
<button onclick="playChord()">Play C Major</button>
<button onclick="clearLog()">Clear Log</button>
</div>
<div class="debug-info">
<h3>File Upload Test</h3>
<input type="file" id="testFile" accept="audio/*">
<button onclick="loadTestSample()">Load Sample</button>
</div>
<div id="log"></div>
<script>
let audioEngine;
let chordLibrary;
function log(message) {
const logDiv = document.getElementById('log');
logDiv.innerHTML += new Date().toLocaleTimeString() + ': ' + message + '\n';
logDiv.scrollTop = logDiv.scrollHeight;
}
function clearLog() {
document.getElementById('log').innerHTML = '';
}
function updateStatus() {
if (audioEngine && audioEngine.audioContext) {
document.getElementById('audioState').textContent = audioEngine.audioContext.state;
document.getElementById('sampleRate').textContent = audioEngine.audioContext.sampleRate;
document.getElementById('userGesture').textContent = audioEngine.userGestureReceived ? 'Yes' : 'No';
}
}
async function initAudio() {
try {
log('Initializing audio engine...');
audioEngine = new AudioEngine();
audioEngine.userGestureReceived = true;
await audioEngine.init();
log('Audio engine initialized: ' + audioEngine.initialized);
updateStatus();
} catch (error) {
log('Error initializing audio: ' + error.message);
}
}
async function playTestTone() {
if (!audioEngine || !audioEngine.initialized) {
log('Audio engine not initialized');
return;
}
try {
log('Playing test tone...');
audioEngine.playNote(440, 1.0); // A4 for 1 second
} catch (error) {
log('Error playing test tone: ' + error.message);
}
}
async function playChord() {
if (!audioEngine || !audioEngine.initialized) {
log('Audio engine not initialized');
return;
}
if (!chordLibrary) {
chordLibrary = new ChordLibrary();
}
try {
log('Playing C Major chord...');
const chordNotes = chordLibrary.getChordNotes('C', 'Major', 0);
log('Chord notes: ' + chordNotes.join(', '));
audioEngine.playChord(chordNotes, 2.0);
} catch (error) {
log('Error playing chord: ' + error.message);
}
}
async function loadTestSample() {
const fileInput = document.getElementById('testFile');
const file = fileInput.files[0];
if (!file) {
log('No file selected');
return;
}
if (!audioEngine || !audioEngine.initialized) {
log('Initializing audio first...');
await initAudio();
}
try {
log('Loading sample: ' + file.name);
const success = await audioEngine.loadSample(file);
log('Sample load result: ' + success);
} catch (error) {
log('Error loading sample: ' + error.message);
}
}
// Set up console.log override to capture logs
const originalLog = console.log;
const originalError = console.error;
const originalWarn = console.warn;
console.log = function(...args) {
log('LOG: ' + args.join(' '));
originalLog.apply(console, args);
};
console.error = function(...args) {
log('ERROR: ' + args.join(' '));
originalError.apply(console, args);
};
console.warn = function(...args) {
log('WARN: ' + args.join(' '));
originalWarn.apply(console, args);
};
log('Debug page loaded');
</script>
<script src="js/audio-engine.js"></script>
<script src="js/chord-library.js"></script>
</body>
</html>