|
|
@@ -145,6 +145,15 @@ async function selectFile(file, listItem) {
|
|
|
}
|
|
|
|
|
|
logMessage(`Selected file: ${file}`);
|
|
|
+
|
|
|
+ // Show the preview container
|
|
|
+ const previewContainer = document.getElementById('pattern-preview-container');
|
|
|
+ if (previewContainer) {
|
|
|
+ previewContainer.classList.remove('hidden');
|
|
|
+ previewContainer.classList.add('visible');
|
|
|
+ }
|
|
|
+
|
|
|
+ // Update the preview
|
|
|
await previewPattern(file);
|
|
|
|
|
|
// Populate the playlist dropdown after selecting a pattern
|
|
|
@@ -384,51 +393,56 @@ async function previewPattern(fileName, containerId = 'pattern-preview-container
|
|
|
body: JSON.stringify({ file_name: fileName })
|
|
|
});
|
|
|
|
|
|
- const result = await response.json();
|
|
|
- if (result.success) {
|
|
|
- // Mirror the theta values in the coordinates
|
|
|
- const coordinates = result.coordinates.map(coord => [
|
|
|
- (coord[0] < Math.PI) ?
|
|
|
- Math.PI - coord[0] : // For first half
|
|
|
- 3 * Math.PI - coord[0], // For second half
|
|
|
- coord[1]
|
|
|
- ]);
|
|
|
-
|
|
|
- // Render the pattern in the specified container
|
|
|
- const canvasId = containerId === 'currently-playing-container'
|
|
|
- ? 'currentlyPlayingCanvas'
|
|
|
- : 'patternPreviewCanvas';
|
|
|
- renderPattern(coordinates, canvasId);
|
|
|
-
|
|
|
- // Update coordinate display
|
|
|
- const firstCoordElement = document.getElementById('first_coordinate');
|
|
|
- const lastCoordElement = document.getElementById('last_coordinate');
|
|
|
-
|
|
|
- if (firstCoordElement) {
|
|
|
- const firstCoord = coordinates[0];
|
|
|
- firstCoordElement.textContent = `First Coordinate: θ=${firstCoord[0].toFixed(2)}, ρ=${firstCoord[1].toFixed(2)}`;
|
|
|
- } else {
|
|
|
- logMessage('First coordinate element not found.', LOG_TYPE.WARNING);
|
|
|
- }
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
+ }
|
|
|
|
|
|
- if (lastCoordElement) {
|
|
|
- const lastCoord = coordinates[coordinates.length - 1];
|
|
|
- lastCoordElement.textContent = `Last Coordinate: θ=${lastCoord[0].toFixed(2)}, ρ=${lastCoord[1].toFixed(2)}`;
|
|
|
- } else {
|
|
|
- logMessage('Last coordinate element not found.', LOG_TYPE.WARNING);
|
|
|
- }
|
|
|
+ const data = await response.json();
|
|
|
+
|
|
|
+ // Get the preview container
|
|
|
+ const previewContainer = document.getElementById(containerId);
|
|
|
+ if (!previewContainer) {
|
|
|
+ logMessage(`Preview container not found: ${containerId}`, LOG_TYPE.ERROR);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // Show the preview container
|
|
|
- const previewContainer = document.getElementById(containerId);
|
|
|
- if (previewContainer) {
|
|
|
- previewContainer.classList.remove('hidden');
|
|
|
- previewContainer.classList.add('visible');
|
|
|
- } else {
|
|
|
- logMessage(`Preview container not found: ${containerId}`, LOG_TYPE.ERROR);
|
|
|
- }
|
|
|
+ // Get the pattern preview section
|
|
|
+ const patternPreview = previewContainer.querySelector('#pattern-preview');
|
|
|
+ if (!patternPreview) {
|
|
|
+ logMessage('Pattern preview section not found', LOG_TYPE.ERROR);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Clear existing content
|
|
|
+ patternPreview.innerHTML = '';
|
|
|
+
|
|
|
+ // Create SVG container
|
|
|
+ const svgContainer = document.createElement('div');
|
|
|
+ svgContainer.className = 'svg-container';
|
|
|
+ svgContainer.innerHTML = data.svg;
|
|
|
+
|
|
|
+ // Create coordinate display
|
|
|
+ const coordDisplay = document.createElement('div');
|
|
|
+ coordDisplay.className = 'coordinate-display';
|
|
|
+
|
|
|
+ // Update coordinate text
|
|
|
+ if (data.first_coordinate && data.last_coordinate) {
|
|
|
+ coordDisplay.innerHTML = `
|
|
|
+ <div>First Coordinate: θ=${data.first_coordinate[0].toFixed(2)}, ρ=${data.first_coordinate[1].toFixed(2)}</div>
|
|
|
+ <div>Last Coordinate: θ=${data.last_coordinate[0].toFixed(2)}, ρ=${data.last_coordinate[1].toFixed(2)}</div>
|
|
|
+ `;
|
|
|
} else {
|
|
|
- logMessage(`Failed to fetch preview for file: ${fileName}`, LOG_TYPE.WARNING);
|
|
|
+ coordDisplay.innerHTML = 'No coordinates available';
|
|
|
}
|
|
|
+
|
|
|
+ // Add elements to the preview
|
|
|
+ patternPreview.appendChild(svgContainer);
|
|
|
+ patternPreview.appendChild(coordDisplay);
|
|
|
+
|
|
|
+ // Show the preview container
|
|
|
+ previewContainer.classList.remove('hidden');
|
|
|
+ previewContainer.classList.add('visible');
|
|
|
+
|
|
|
} catch (error) {
|
|
|
logMessage(`Error previewing pattern: ${error.message}`, LOG_TYPE.ERROR);
|
|
|
}
|