Add Path Generator UI with import/export settings, save/load defaults, and transcribe
This commit is contained in:
parent
30675756c9
commit
c217e04243
647
webapp/generate.html
Normal file
647
webapp/generate.html
Normal file
|
|
@ -0,0 +1,647 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Path Generator</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 20px;
|
||||||
|
background: #000000;
|
||||||
|
color: #cccccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
font-weight: 300;
|
||||||
|
letter-spacing: 2px;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-section {
|
||||||
|
background: #0a0a0a;
|
||||||
|
padding: 15px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid #1a1a1a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-section h3 {
|
||||||
|
margin-top: 0;
|
||||||
|
color: #666666;
|
||||||
|
font-size: 12px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
font-weight: 500;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-row {
|
||||||
|
display: flex;
|
||||||
|
gap: 20px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group label {
|
||||||
|
font-size: 11px;
|
||||||
|
color: #666666;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input[type="number"],
|
||||||
|
.form-group input[type="text"] {
|
||||||
|
padding: 8px;
|
||||||
|
background: #0a0a0a;
|
||||||
|
color: #888888;
|
||||||
|
border: 1px solid #222222;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #444444;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input[type="checkbox"] {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox-group {
|
||||||
|
flex-direction: row !important;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox-group label {
|
||||||
|
margin-bottom: 0;
|
||||||
|
text-transform: none;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #888888;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 15px;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons button {
|
||||||
|
padding: 12px 24px;
|
||||||
|
font-size: 14px;
|
||||||
|
cursor: pointer;
|
||||||
|
background: #0a0a0a;
|
||||||
|
color: #888888;
|
||||||
|
border: 1px solid #222222;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons button:hover {
|
||||||
|
background: #151515;
|
||||||
|
color: #ffffff;
|
||||||
|
border-color: #444444;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons button.primary {
|
||||||
|
background: #1a3a1a;
|
||||||
|
border-color: #2a5a2a;
|
||||||
|
color: #66cc66;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons button.primary:hover {
|
||||||
|
background: #2a4a2a;
|
||||||
|
}
|
||||||
|
|
||||||
|
#message {
|
||||||
|
text-align: center;
|
||||||
|
padding: 15px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
border-radius: 4px;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#message.success {
|
||||||
|
display: block;
|
||||||
|
background: #1a3a1a;
|
||||||
|
border: 1px solid #2a5a2a;
|
||||||
|
color: #66cc66;
|
||||||
|
}
|
||||||
|
|
||||||
|
#message.error {
|
||||||
|
display: block;
|
||||||
|
background: #3a1a1a;
|
||||||
|
border: 1px solid #5a2a2a;
|
||||||
|
color: #cc6666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link a {
|
||||||
|
color: #666666;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link a:hover {
|
||||||
|
color: #888888;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons-row {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
justify-content: center;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons-row button {
|
||||||
|
padding: 8px 16px;
|
||||||
|
font-size: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
background: #0a0a0a;
|
||||||
|
color: #666666;
|
||||||
|
border: 1px solid #222222;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons-row button:hover {
|
||||||
|
background: #151515;
|
||||||
|
color: #888888;
|
||||||
|
border-color: #444444;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Path Generator</h1>
|
||||||
|
|
||||||
|
<div class="buttons-row">
|
||||||
|
<button type="button" id="exportSettingsBtn">Export Settings</button>
|
||||||
|
<button type="button" id="importSettingsBtn">Import Settings</button>
|
||||||
|
<button type="button" id="loadDefaultsBtn">Load Defaults</button>
|
||||||
|
<input type="file" id="importFileInput" accept=".json" style="display: none;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="message"></div>
|
||||||
|
|
||||||
|
<form id="generatorForm">
|
||||||
|
<div class="form-section">
|
||||||
|
<h3>Basic Settings</h3>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Dims</label>
|
||||||
|
<input type="number" id="dims" value="7" min="1" max="10">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Chord Size</label>
|
||||||
|
<input type="number" id="chordSize" value="3" min="1" max="10">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Max Path</label>
|
||||||
|
<input type="number" id="maxPath" value="50" min="1">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Seed (optional)</label>
|
||||||
|
<input type="number" id="seed" placeholder="random">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Output Directory</label>
|
||||||
|
<input type="text" id="outputDir" value="output">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Fundamental (Hz)</label>
|
||||||
|
<input type="number" id="fundamental" value="55" step="any">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Transcribe Name</label>
|
||||||
|
<input type="text" id="transcribeName" value="compact_sets_transcription">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section">
|
||||||
|
<h3>Symdiff / Melodic</h3>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Symdiff Min</label>
|
||||||
|
<input type="number" id="symdiffMin" value="2" min="0">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Symdiff Max</label>
|
||||||
|
<input type="number" id="symdiffMax" value="2" min="0">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Melodic Min</label>
|
||||||
|
<input type="number" id="melodicMin" value="0" min="0">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Melodic Max</label>
|
||||||
|
<input type="number" id="melodicMax" value="500" min="0">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section">
|
||||||
|
<h3>Target Register</h3>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Target Register (octaves)</label>
|
||||||
|
<input type="number" id="targetRegister" value="0" step="any">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Target Register Power</label>
|
||||||
|
<input type="number" id="targetRegisterPower" value="1.0" step="any">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Oscillations</label>
|
||||||
|
<input type="number" id="targetRegisterOscillations" value="0" step="any">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Amplitude</label>
|
||||||
|
<input type="number" id="targetRegisterAmplitude" value="0.25" step="any">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section">
|
||||||
|
<h3>Voice Leading</h3>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group checkbox-group">
|
||||||
|
<input type="checkbox" id="allowVoiceCrossing">
|
||||||
|
<label>Allow Voice Crossing</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-group checkbox-group">
|
||||||
|
<input type="checkbox" id="disableDirectTuning">
|
||||||
|
<label>Disable Direct Tuning</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-group checkbox-group">
|
||||||
|
<input type="checkbox" id="uniformSymdiff">
|
||||||
|
<label>Uniform Symdiff</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section">
|
||||||
|
<h3>Weights</h3>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Weight Melodic</label>
|
||||||
|
<input type="number" id="weightMelodic" value="1" step="any">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Weight Contrary Motion</label>
|
||||||
|
<input type="number" id="weightContraryMotion" value="0" step="any">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Weight DCA Hamiltonian</label>
|
||||||
|
<input type="number" id="weightDcaHamiltonian" value="1" step="any">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Weight DCA Voice Movement</label>
|
||||||
|
<input type="number" id="weightDcaVoiceMovement" value="1" step="any">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Weight RGR Voice Movement</label>
|
||||||
|
<input type="number" id="weightRgrVoiceMovement" value="0" step="any">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>RGR Threshold</label>
|
||||||
|
<input type="number" id="rgrVoiceMovementThreshold" value="5" min="1">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Weight Harmonic Compactness</label>
|
||||||
|
<input type="number" id="weightHarmonicCompactness" value="0" step="any">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Weight Target Register</label>
|
||||||
|
<input type="number" id="weightTargetRegister" value="1" step="any">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section">
|
||||||
|
<h3>Caching</h3>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Cache Directory</label>
|
||||||
|
<input type="text" id="cacheDir" value="cache">
|
||||||
|
</div>
|
||||||
|
<div class="form-group checkbox-group">
|
||||||
|
<input type="checkbox" id="rebuildCache">
|
||||||
|
<label>Rebuild Cache</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-group checkbox-group">
|
||||||
|
<input type="checkbox" id="noCache">
|
||||||
|
<label>No Cache</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="buttons">
|
||||||
|
<button type="button" id="generateBtn">Generate</button>
|
||||||
|
<button type="button" id="viewBtn">View</button>
|
||||||
|
<button type="button" id="transcribeBtn" class="primary">Transcribe</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="nav-link">
|
||||||
|
<a href="/">View Path Navigator</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function getFormData() {
|
||||||
|
return {
|
||||||
|
dims: parseInt(document.getElementById('dims').value) || 7,
|
||||||
|
chordSize: parseInt(document.getElementById('chordSize').value) || 3,
|
||||||
|
maxPath: parseInt(document.getElementById('maxPath').value) || 50,
|
||||||
|
seed: document.getElementById('seed').value ? parseInt(document.getElementById('seed').value) : null,
|
||||||
|
outputDir: document.getElementById('outputDir').value || 'output',
|
||||||
|
fundamental: parseFloat(document.getElementById('fundamental').value) || 55,
|
||||||
|
symdiffMin: parseInt(document.getElementById('symdiffMin').value) || 2,
|
||||||
|
symdiffMax: parseInt(document.getElementById('symdiffMax').value) || 2,
|
||||||
|
melodicMin: parseInt(document.getElementById('melodicMin').value) || 0,
|
||||||
|
melodicMax: parseInt(document.getElementById('melodicMax').value) || 500,
|
||||||
|
targetRegister: parseFloat(document.getElementById('targetRegister').value) || 0,
|
||||||
|
targetRegisterPower: parseFloat(document.getElementById('targetRegisterPower').value) || 1.0,
|
||||||
|
targetRegisterOscillations: parseFloat(document.getElementById('targetRegisterOscillations').value) || 0,
|
||||||
|
targetRegisterAmplitude: parseFloat(document.getElementById('targetRegisterAmplitude').value) || 0.25,
|
||||||
|
allowVoiceCrossing: document.getElementById('allowVoiceCrossing').checked,
|
||||||
|
disableDirectTuning: document.getElementById('disableDirectTuning').checked,
|
||||||
|
uniformSymdiff: document.getElementById('uniformSymdiff').checked,
|
||||||
|
weightMelodic: parseFloat(document.getElementById('weightMelodic').value) || 1,
|
||||||
|
weightContraryMotion: parseFloat(document.getElementById('weightContraryMotion').value) || 0,
|
||||||
|
weightDcaHamiltonian: parseFloat(document.getElementById('weightDcaHamiltonian').value) || 1,
|
||||||
|
weightDcaVoiceMovement: parseFloat(document.getElementById('weightDcaVoiceMovement').value) || 1,
|
||||||
|
weightRgrVoiceMovement: parseFloat(document.getElementById('weightRgrVoiceMovement').value) || 0,
|
||||||
|
rgrVoiceMovementThreshold: parseInt(document.getElementById('rgrVoiceMovementThreshold').value) || 5,
|
||||||
|
weightHarmonicCompactness: parseFloat(document.getElementById('weightHarmonicCompactness').value) || 0,
|
||||||
|
weightTargetRegister: parseFloat(document.getElementById('weightTargetRegister').value) || 1,
|
||||||
|
cacheDir: document.getElementById('cacheDir').value || 'cache',
|
||||||
|
rebuildCache: document.getElementById('rebuildCache').checked,
|
||||||
|
noCache: document.getElementById('noCache').checked,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function showMessage(text, isError = false) {
|
||||||
|
const msg = document.getElementById('message');
|
||||||
|
msg.textContent = text;
|
||||||
|
msg.className = isError ? 'error' : 'success';
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideMessage() {
|
||||||
|
const msg = document.getElementById('message');
|
||||||
|
msg.style.display = 'none';
|
||||||
|
msg.className = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
async function generate() {
|
||||||
|
hideMessage();
|
||||||
|
const data = getFormData();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/generate', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
showMessage('Error: ' + result.error, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update seed field with the seed used
|
||||||
|
document.getElementById('seed').value = result.seed;
|
||||||
|
showMessage('Generated ' + result.totalChords + ' chords (seed: ' + result.seed + ')');
|
||||||
|
} catch (err) {
|
||||||
|
showMessage('Error: ' + err.message, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// View - open Path Navigator in new tab
|
||||||
|
function viewChords() {
|
||||||
|
window.open('/', '_blank');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transcribe - generate if needed, then transcribe
|
||||||
|
async function transcribe() {
|
||||||
|
hideMessage();
|
||||||
|
const transcribeName = document.getElementById('transcribeName').value || 'compact_sets_transcription';
|
||||||
|
const data = getFormData();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// First generate if chords don't exist
|
||||||
|
const response = await fetch('/api/generate', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
showMessage('Error: ' + result.error, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update seed field
|
||||||
|
document.getElementById('seed').value = result.seed;
|
||||||
|
|
||||||
|
// Now transcribe
|
||||||
|
const transcribeResponse = await fetch('/api/transcribe', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: JSON.stringify({ name: transcribeName })
|
||||||
|
});
|
||||||
|
|
||||||
|
const transcribeResult = await transcribeResponse.json();
|
||||||
|
|
||||||
|
if (transcribeResult.error) {
|
||||||
|
showMessage('Transcription error: ' + transcribeResult.error, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
showMessage('Transcribed ' + transcribeResult.chordCount + ' chords to ' + transcribeResult.outputFile);
|
||||||
|
} catch (err) {
|
||||||
|
showMessage('Error: ' + err.message, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('generateBtn').addEventListener('click', generate);
|
||||||
|
document.getElementById('viewBtn').addEventListener('click', viewChords);
|
||||||
|
document.getElementById('transcribeBtn').addEventListener('click', transcribe);
|
||||||
|
|
||||||
|
// Export settings to JSON file
|
||||||
|
function exportSettings() {
|
||||||
|
const data = getFormData();
|
||||||
|
data.exportedAt = new Date().toISOString();
|
||||||
|
const json = JSON.stringify(data, null, 2);
|
||||||
|
const blob = new Blob([json], {type: 'application/json'});
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = 'generator_settings.json';
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
document.body.removeChild(a);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
showMessage('Settings exported to generator_settings.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Import settings from JSON file
|
||||||
|
function importSettings() {
|
||||||
|
document.getElementById('importFileInput').click();
|
||||||
|
}
|
||||||
|
|
||||||
|
function applySettings(data) {
|
||||||
|
// Map of field IDs to data keys
|
||||||
|
const fieldMap = {
|
||||||
|
dims: 'dims',
|
||||||
|
chordSize: 'chordSize',
|
||||||
|
maxPath: 'maxPath',
|
||||||
|
seed: 'seed',
|
||||||
|
outputDir: 'outputDir',
|
||||||
|
fundamental: 'fundamental',
|
||||||
|
symdiffMin: 'symdiffMin',
|
||||||
|
symdiffMax: 'symdiffMax',
|
||||||
|
melodicMin: 'melodicMin',
|
||||||
|
melodicMax: 'melodicMax',
|
||||||
|
targetRegister: 'targetRegister',
|
||||||
|
targetRegisterPower: 'targetRegisterPower',
|
||||||
|
targetRegisterOscillations: 'targetRegisterOscillations',
|
||||||
|
targetRegisterAmplitude: 'targetRegisterAmplitude',
|
||||||
|
allowVoiceCrossing: 'allowVoiceCrossing',
|
||||||
|
disableDirectTuning: 'disableDirectTuning',
|
||||||
|
uniformSymdiff: 'uniformSymdiff',
|
||||||
|
weightMelodic: 'weightMelodic',
|
||||||
|
weightContraryMotion: 'weightContraryMotion',
|
||||||
|
weightDcaHamiltonian: 'weightDcaHamiltonian',
|
||||||
|
weightDcaVoiceMovement: 'weightDcaVoiceMovement',
|
||||||
|
weightRgrVoiceMovement: 'weightRgrVoiceMovement',
|
||||||
|
rgrVoiceMovementThreshold: 'rgrVoiceMovementThreshold',
|
||||||
|
weightHarmonicCompactness: 'weightHarmonicCompactness',
|
||||||
|
weightTargetRegister: 'weightTargetRegister',
|
||||||
|
cacheDir: 'cacheDir',
|
||||||
|
rebuildCache: 'rebuildCache',
|
||||||
|
noCache: 'noCache',
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const [fieldId, dataKey] of Object.entries(fieldMap)) {
|
||||||
|
const input = document.getElementById(fieldId);
|
||||||
|
if (input && data[dataKey] !== undefined) {
|
||||||
|
if (input.type === 'checkbox') {
|
||||||
|
input.checked = data[dataKey];
|
||||||
|
} else {
|
||||||
|
input.value = data[dataKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('exportSettingsBtn').addEventListener('click', exportSettings);
|
||||||
|
document.getElementById('importSettingsBtn').addEventListener('click', importSettings);
|
||||||
|
|
||||||
|
// Load default settings from server
|
||||||
|
async function loadDefaults() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/generator_settings.json');
|
||||||
|
if (!response.ok) {
|
||||||
|
// No defaults file, that's fine
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
applySettings(data);
|
||||||
|
showMessage('Default settings loaded');
|
||||||
|
} catch (err) {
|
||||||
|
// File not found or error, that's fine - use hardcoded defaults
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to load defaults on page load
|
||||||
|
loadDefaults();
|
||||||
|
|
||||||
|
document.getElementById('loadDefaultsBtn').addEventListener('click', function() {
|
||||||
|
// Reset form to hardcoded defaults
|
||||||
|
applySettings({
|
||||||
|
dims: 7,
|
||||||
|
chordSize: 3,
|
||||||
|
maxPath: 50,
|
||||||
|
seed: null,
|
||||||
|
outputDir: 'output',
|
||||||
|
fundamental: 55,
|
||||||
|
symdiffMin: 2,
|
||||||
|
symdiffMax: 2,
|
||||||
|
melodicMin: 0,
|
||||||
|
melodicMax: 500,
|
||||||
|
targetRegister: 0,
|
||||||
|
targetRegisterPower: 1.0,
|
||||||
|
targetRegisterOscillations: 0,
|
||||||
|
targetRegisterAmplitude: 0.25,
|
||||||
|
allowVoiceCrossing: false,
|
||||||
|
disableDirectTuning: false,
|
||||||
|
uniformSymdiff: false,
|
||||||
|
weightMelodic: 1,
|
||||||
|
weightContraryMotion: 0,
|
||||||
|
weightDcaHamiltonian: 1,
|
||||||
|
weightDcaVoiceMovement: 1,
|
||||||
|
weightRgrVoiceMovement: 0,
|
||||||
|
rgrVoiceMovementThreshold: 5,
|
||||||
|
weightHarmonicCompactness: 0,
|
||||||
|
weightTargetRegister: 1,
|
||||||
|
cacheDir: 'cache',
|
||||||
|
rebuildCache: false,
|
||||||
|
noCache: false,
|
||||||
|
});
|
||||||
|
showMessage('Form reset to defaults');
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('importFileInput').addEventListener('change', function(e) {
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (!file) return;
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = function(e) {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(e.target.result);
|
||||||
|
applySettings(data);
|
||||||
|
showMessage('Settings imported from ' + file.name);
|
||||||
|
} catch (err) {
|
||||||
|
showMessage('Error reading file: ' + err.message, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
reader.readAsText(file);
|
||||||
|
this.value = ''; // Reset for re-import
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
201
webapp/server.py
201
webapp/server.py
|
|
@ -320,6 +320,207 @@ def batch_calculate_cents_api():
|
||||||
return jsonify({"error": str(e)}), 400
|
return jsonify({"error": str(e)}), 400
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/generate")
|
||||||
|
def generate_page():
|
||||||
|
"""Render the generator page."""
|
||||||
|
return send_from_directory(app.root_path, "generate.html")
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/generator_settings.json")
|
||||||
|
def default_settings():
|
||||||
|
"""Serve default generator settings from output directory."""
|
||||||
|
settings_path = DATA_DIR / "generator_settings.json"
|
||||||
|
if settings_path.exists():
|
||||||
|
return send_from_directory(DATA_DIR, "generator_settings.json")
|
||||||
|
else:
|
||||||
|
return jsonify({"error": "No default settings file"}), 404
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/transcribe", methods=["POST"])
|
||||||
|
def run_transcribe():
|
||||||
|
"""Run the transcriber to create LilyPond output."""
|
||||||
|
data = request.json
|
||||||
|
transcribe_name = data.get("name", "compact_sets_transcription")
|
||||||
|
fundamental = data.get("fundamental", 55)
|
||||||
|
|
||||||
|
try:
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
|
||||||
|
input_file = DATA_DIR / "output_chords.json"
|
||||||
|
|
||||||
|
if not input_file.exists():
|
||||||
|
return jsonify({"error": "No chords to transcribe. Generate first."}), 400
|
||||||
|
|
||||||
|
# Load chords to get count
|
||||||
|
with open(input_file) as f:
|
||||||
|
chords_data = json.load(f)
|
||||||
|
chord_count = len(chords_data.get("chords", chords_data))
|
||||||
|
|
||||||
|
# Create lilypond directory if needed
|
||||||
|
lilypond_dir = DATA_DIR.parent / "lilypond"
|
||||||
|
os.makedirs(lilypond_dir, exist_ok=True)
|
||||||
|
|
||||||
|
# Run the transcriber
|
||||||
|
args = [
|
||||||
|
sys.executable,
|
||||||
|
"-m",
|
||||||
|
"src.io",
|
||||||
|
"--transcribe",
|
||||||
|
str(input_file),
|
||||||
|
transcribe_name,
|
||||||
|
"--fundamental",
|
||||||
|
str(fundamental),
|
||||||
|
]
|
||||||
|
|
||||||
|
result = subprocess.run(
|
||||||
|
args,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
cwd=os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
|
||||||
|
)
|
||||||
|
|
||||||
|
if result.returncode != 0:
|
||||||
|
return jsonify({"error": result.stderr}), 400
|
||||||
|
|
||||||
|
output_file = lilypond_dir / f"{transcribe_name}.pdf"
|
||||||
|
|
||||||
|
return jsonify(
|
||||||
|
{
|
||||||
|
"status": "success",
|
||||||
|
"chordCount": chord_count,
|
||||||
|
"outputFile": str(output_file),
|
||||||
|
"output": result.stdout,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
traceback.print_exc()
|
||||||
|
return jsonify({"error": str(e)}), 400
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/generate", methods=["POST"])
|
||||||
|
def run_generator():
|
||||||
|
"""Run the path generator with provided options."""
|
||||||
|
data = request.json
|
||||||
|
|
||||||
|
try:
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Build args list
|
||||||
|
args = [
|
||||||
|
sys.executable,
|
||||||
|
"-m",
|
||||||
|
"src.io",
|
||||||
|
"--dims",
|
||||||
|
str(data.get("dims", 7)),
|
||||||
|
"--chord-size",
|
||||||
|
str(data.get("chordSize", 3)),
|
||||||
|
"--max-path",
|
||||||
|
str(data.get("maxPath", 50)),
|
||||||
|
"--symdiff-min",
|
||||||
|
str(data.get("symdiffMin", 2)),
|
||||||
|
"--symdiff-max",
|
||||||
|
str(data.get("symdiffMax", 2)),
|
||||||
|
"--melodic-min",
|
||||||
|
str(data.get("melodicMin", 0)),
|
||||||
|
"--melodic-max",
|
||||||
|
str(data.get("melodicMax", 500)),
|
||||||
|
"--target-register",
|
||||||
|
str(data.get("targetRegister", 0)),
|
||||||
|
"--target-register-power",
|
||||||
|
str(data.get("targetRegisterPower", 1.0)),
|
||||||
|
"--target-register-oscillations",
|
||||||
|
str(data.get("targetRegisterOscillations", 0)),
|
||||||
|
"--target-register-amplitude",
|
||||||
|
str(data.get("targetRegisterAmplitude", 0.25)),
|
||||||
|
"--weight-melodic",
|
||||||
|
str(data.get("weightMelodic", 1)),
|
||||||
|
"--weight-contrary-motion",
|
||||||
|
str(data.get("weightContraryMotion", 0)),
|
||||||
|
"--weight-dca-hamiltonian",
|
||||||
|
str(data.get("weightDcaHamiltonian", 1)),
|
||||||
|
"--weight-dca-voice-movement",
|
||||||
|
str(data.get("weightDcaVoiceMovement", 1)),
|
||||||
|
"--weight-rgr-voice-movement",
|
||||||
|
str(data.get("weightRgrVoiceMovement", 0)),
|
||||||
|
"--rgr-voice-movement-threshold",
|
||||||
|
str(data.get("rgrVoiceMovementThreshold", 5)),
|
||||||
|
"--weight-harmonic-compactness",
|
||||||
|
str(data.get("weightHarmonicCompactness", 0)),
|
||||||
|
"--weight-target-register",
|
||||||
|
str(data.get("weightTargetRegister", 1)),
|
||||||
|
"--output-dir",
|
||||||
|
data.get("outputDir", "output"),
|
||||||
|
"--fundamental",
|
||||||
|
str(data.get("fundamental", 55)),
|
||||||
|
"--cache-dir",
|
||||||
|
data.get("cacheDir", "cache"),
|
||||||
|
]
|
||||||
|
|
||||||
|
seed = data.get("seed")
|
||||||
|
# If no seed provided, generate a random one
|
||||||
|
if seed is None:
|
||||||
|
import random
|
||||||
|
|
||||||
|
seed = random.randint(1, 999999)
|
||||||
|
args.extend(["--seed", str(seed)])
|
||||||
|
if data.get("allowVoiceCrossing", False):
|
||||||
|
args.append("--allow-voice-crossing")
|
||||||
|
if data.get("disableDirectTuning", False):
|
||||||
|
args.append("--disable-direct-tuning")
|
||||||
|
if data.get("uniformSymdiff", False):
|
||||||
|
args.append("--uniform-symdiff")
|
||||||
|
if data.get("rebuildCache", False):
|
||||||
|
args.append("--rebuild-cache")
|
||||||
|
if data.get("noCache", False):
|
||||||
|
args.append("--no-cache")
|
||||||
|
|
||||||
|
# Create output directory
|
||||||
|
os.makedirs(data.get("outputDir", "output"), exist_ok=True)
|
||||||
|
|
||||||
|
# Run the generator
|
||||||
|
result = subprocess.run(
|
||||||
|
args,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
cwd=os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
|
||||||
|
)
|
||||||
|
|
||||||
|
if result.returncode != 0:
|
||||||
|
return jsonify({"error": result.stderr}), 400
|
||||||
|
|
||||||
|
# Try to count generated chords from output
|
||||||
|
total_chords = 0
|
||||||
|
for line in result.stdout.split("\n"):
|
||||||
|
if "Path length:" in line:
|
||||||
|
try:
|
||||||
|
total_chords = int(line.split(":")[-1].strip())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return jsonify(
|
||||||
|
{
|
||||||
|
"totalChords": total_chords,
|
||||||
|
"status": "success",
|
||||||
|
"seed": seed,
|
||||||
|
"output": result.stdout,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
traceback.print_exc()
|
||||||
|
return jsonify({"error": str(e)}), 400
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Starting Path Navigator server...")
|
print("Starting Path Navigator server...")
|
||||||
filepath = DATA_DIR / DEFAULT_FILE
|
filepath = DATA_DIR / DEFAULT_FILE
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue