Skip to content

Commit

Permalink
Changed menu item for "Analyse all open files" when all open files ar…
Browse files Browse the repository at this point in the history
…e saved (a clarification after #105)

Added short period audio guard for fetchAudioBuffer, and in addition checks for the file's existance and notifies when the file is not found (fixes #90 )
Fixed updating the location name in the location select textarea
Added control V shortcut to confirm a record (see #109)
Normalise filter now applied on exported audio.
  • Loading branch information
Mattk70 committed Apr 14, 2024
1 parent 903e748 commit 7a7b099
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 139 deletions.
10 changes: 7 additions & 3 deletions Help/keyboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
</tr>
<tr>
<td><b>Ctrl+ or + </b></td>
<td>Zoom in on the spectrogram. When zooming, Chirpity automatically adjusts the STFT window size to optimize
<td>Zoom in on the spectrogram. When zooming, Chirpity automatically adjusts the short-time Fourier transform (STFT) window size to optimize
the spectral resolution
</td>
</tr>
Expand All @@ -105,12 +105,12 @@
</tr>
<tr>
<td><b>Shift + </b></td>
<td>Reduce FFT window size. Adjusting the FFT window size has the effect of sharpening / blurring the calls. Use this and the
<td>Manually reduce the spectrogram window size. Adjusting the window size has the effect of sharpening / blurring the calls in the spectrogram.
</td>
</tr>
<tr>
<td><b>Shift -</b></td>
<td>Increase the FFT window size
<td>Manually increase the spectrogram window size
</td>
</tr>
<tr>
Expand All @@ -132,6 +132,10 @@
<td><b>Ctrl-Z</b></td>
<td>Restore deleted record(s)</td>
</tr>
<tr>
<td><b>Ctrl-V</b></td>
<td>Validate the current active record (confirm the detection)</td>
</tr>
</table>

</body>
Expand Down
4 changes: 2 additions & 2 deletions Help/usage.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h4 class="text-center text-bg-light p-3">Suggested Workflow</h4>
</figure>
</li>
<li>
Select &quot;<i>Analyse file</i>&quot; from the
Select &quot;<i>Analyse Current File</i>&quot; from the
<b>Analysis</b> menu. Depending on the file length, this may take several minutes. A progress indicator will
appear as a guide to how long this is likely to take. To stop the analysis at any point, press the
<b>Esc</b>
Expand Down Expand Up @@ -107,7 +107,7 @@ <h5 class="pt-2">Saving Results</h5>
<h5 id="reload" class="pt-2">Restoring Results</h5>
<p>When you save your detections in Chirpity, a database is updated with the details of the detections. If
you
reload your file at a later date, and select analyse file, the saved results are restored. <b>N.B.</b> If the
reload your file at a later date, and select &quot;Get Results for Current File&quot;, the saved results are restored. <b>N.B.</b> If the
original file is missing because it has
since been compressed to one of the supported formats ('.mp3', '.wav', '.mpga', '.ogg', '.opus', '.flac',
'.aac'), so long as it
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ <h5>Saved Records</h5>
</a>
<ul class="dropdown-menu" aria-labelledby="navbarAnalysis">
<li><a class="dropdown-item disabled" href="#" id="analyse">
<span class="material-symbols-outlined">search</span> Analyse File
<span class="material-symbols-outlined">search</span> Analyse Current File
<span class="shortcut float-end">Ctrl+A</span> </a></li>
<li><a class="dropdown-item disabled" href="#" id="analyseSelection">
<span class="material-symbols-outlined">manage_search</span> Analyse Selected
Expand All @@ -648,7 +648,7 @@ <h5>Saved Records</h5>
<li class="dropdown-divider"></li>
<li><a class="dropdown-item disabled" href="#" id="reanalyse">
<span class="material-symbols-outlined">youtube_searched_for</span> Re-analyse
File</a></li>
Current File</a></li>
<li><a class="dropdown-item disabled" href="#" id="reanalyseAll">
<span class="material-symbols-outlined">youtube_searched_for</span> Re-analyse All
Open Files</a></li>
Expand Down
239 changes: 136 additions & 103 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,16 +615,30 @@ function renderFilenamePanel() {
customiseAnalysisMenu(isSaved === 'text-info');
}


function customAnalysisAllMenu(saved){
const analyseAllMenu = document.getElementById('analyseAll');
if (saved) {
analyseAllMenu.innerHTML = `<span class="material-symbols-outlined">upload_file</span> Get Results for All Open Files
<span class="shortcut float-end">Ctrl+A</span>`;
enableMenuItem(['reanalyseAll']);
} else {
analyseAllMenu.innerHTML = `<span class="material-symbols-outlined">upload_file</span> Analyse All Open Files
<span class="shortcut float-end">Ctrl+A</span>`;
disableMenuItem(['reanalyseAll']);
}
}

function customiseAnalysisMenu(saved) {
const analyseMenu = document.getElementById('analyse');
if (saved) {
analyseMenu.innerHTML = `<span class="material-symbols-outlined">upload_file</span> Retrieve Results
analyseMenu.innerHTML = `<span class="material-symbols-outlined">upload_file</span> Get Results for Current File
<span class="shortcut float-end">Ctrl+A</span>`;
enableMenuItem(['reanalyse', 'reanalyseAll']);
enableMenuItem(['reanalyse']);
} else {
analyseMenu.innerHTML = `<span class="material-symbols-outlined">search</span> Analyse File
<span class="shortcut float-end">Ctrl+A</span>`;
disableMenuItem(['reanalyse', 'reanalyseAll']);
disableMenuItem(['reanalyse']);
}
}

Expand Down Expand Up @@ -661,7 +675,7 @@ const showLocation = async (fromSelect) => {
const customPlaceEl = document.getElementById('customPlace');
const locationSelect = document.getElementById('savedLocations');
// Check if currentfile has a location id
const id = fromSelect ? locationSelect.value : FILE_LOCATION_MAP[currentFile];
const id = fromSelect ? parseInt(locationSelect.value) : FILE_LOCATION_MAP[currentFile];

if (id) {
newLocation = LOCATIONS.find(obj => obj.id === id);
Expand Down Expand Up @@ -816,6 +830,7 @@ async function onOpenFiles(args) {
resetDiagnostics();
// Store the file list and Load First audio file
fileList = args.filePaths;
fileList.length > 1 && worker.postMessage({action: 'check-all-files-saved', files: fileList});
STATE.openFiles = args.filePaths;
// Sort file by time created (the oldest first):
if (fileList.length > 1) {
Expand Down Expand Up @@ -1630,6 +1645,9 @@ const setUpWorkerMessaging = () => {
const args = e.data;
const event = args.event;
switch (event) {
case 'all-files-saved-check-result': {
customAnalysisAllMenu(args.result)
}
case "analysis-complete": {onAnalysisComplete();
break;
}
Expand All @@ -1639,112 +1657,119 @@ const setUpWorkerMessaging = () => {
case "chart-data": {onChartData(args);
break;
}
case "current-file-week": { STATE.week = args.week}
case "diskDB-has-records": {chartsLink.classList.remove("disabled");
exploreLink.classList.remove("disabled");
break;
}
case "file-location-id": {onFileLocationID(args);
break;
}
case "files": {onOpenFiles(args);
case "current-file-week": {
STATE.week = args.week
break;
}
case "diskDB-has-records": {
chartsLink.classList.remove("disabled");
exploreLink.classList.remove("disabled");
break;
}
case "file-location-id": {onFileLocationID(args);
break;
}
case "files": {onOpenFiles(args);
break;
}
case "generate-alert": {
if (args.updateFilenamePanel) {
renderFilenamePanel();
window.electron.unsavedRecords(false);
document.getElementById("unsaved-icon").classList.add("d-none");
}
if (args.missingFile){
console.log('missing file');
}
generateToast({ message: args.message});
break;
}
case "generate-alert": {
if (args.updateFilenamePanel) {
}
// Called when last result is returned from a database query
case "database-results-complete": {onResultsComplete(args);
break;
}
case "labels": {
LABELS = args.labels;
// Read a custom list if applicable
config.list === 'custom' && setListUIState(config.list);
break }
case "location-list": {LOCATIONS = args.locations;
locationID = args.currentLocation;
break;
}
case "model-ready": {onModelReady(args);
break;
}
case "mode-changed": {
const mode = args.mode;
STATE.mode = mode;
renderFilenamePanel();
window.electron.unsavedRecords(false);
document.getElementById("unsaved-icon").classList.add("d-none");
config.debug && console.log("Mode changed to: " + mode);
if (mode === 'archive' || mode === 'explore') {
enableMenuItem(['purge-file']);
// change header to indicate activation
DOM.resultHeader.classList.remove('text-bg-secondary');
DOM.resultHeader.classList.add('text-bg-dark');
// PREDICTING = false;
// STATE.analysisDone = true;
} else {
disableMenuItem(['purge-file']);
// change header to indicate deactivation
DOM.resultHeader.classList.add('text-bg-secondary');
DOM.resultHeader.classList.remove('text-bg-dark');
}
break;
}
generateToast({ message: args.message});
break;
}
// Called when last result is returned from a database query
case "database-results-complete": {onResultsComplete(args);
break;
}
case "labels": {
LABELS = args.labels;
// Read a custom list if applicable
config.list === 'custom' && setListUIState(config.list);
break }
case "location-list": {LOCATIONS = args.locations;
locationID = args.currentLocation;
break;
}
case "model-ready": {onModelReady(args);
break;
}
case "mode-changed": {
const mode = args.mode;
STATE.mode = mode;
renderFilenamePanel();
config.debug && console.log("Mode changed to: " + mode);
if (mode === 'archive' || mode === 'explore') {
enableMenuItem(['purge-file']);
// change header to indicate activation
DOM.resultHeader.classList.remove('text-bg-secondary');
DOM.resultHeader.classList.add('text-bg-dark');
// PREDICTING = false;
// STATE.analysisDone = true;
} else {
disableMenuItem(['purge-file']);
// change header to indicate deactivation
DOM.resultHeader.classList.add('text-bg-secondary');
DOM.resultHeader.classList.remove('text-bg-dark');
case "summary-complate": {onSummaryComplete(args);
break;
}
break;
}
case "summary-complate": {onSummaryComplete(args);
break;
}
case "new-result": {renderResult(args);
break;
}
case "progress": {onProgress(args);
break;
}
// called when an analysis ends, or when the filesbeingprocessed list is empty
case "processing-complete": {
STATE.analysisDone = true;
//PREDICTING = false;
//DOM.progressDiv.classList.add('d-none');
break;
}
case 'ready-for-tour':{
// New users - show the tour
if (!config.seenTour) {
setTimeout(prepTour, 1500);
case "new-result": {renderResult(args);
break;
}
case "progress": {onProgress(args);
break;
}
// called when an analysis ends, or when the filesbeingprocessed list is empty
case "processing-complete": {
STATE.analysisDone = true;
//PREDICTING = false;
//DOM.progressDiv.classList.add('d-none');
break;
}
case 'ready-for-tour':{
// New users - show the tour
if (!config.seenTour) {
setTimeout(prepTour, 1500);
}
break;
}
case "seen-species-list": {generateBirdList("seenSpecies", args.list);
break;
}
case "valid-species-list": {populateSpeciesModal(args.included, args.excluded);
break;
}
case "total-records": {updatePagination(args.total, args.offset);
break;
}
case "unsaved-records": {window.electron.unsavedRecords(true);
document.getElementById("unsaved-icon").classList.remove("d-none");
break;
}
case "update-audio-duration": {DIAGNOSTICS["Audio Duration"] ??= 0;
DIAGNOSTICS["Audio Duration"] += args.value;
break;
}
case "update-summary": {updateSummary(args);
break;
}
case "worker-loaded-audio": {
onWorkerLoadedAudio(args);
break;
}
default: {generateToast({ message:`Unrecognised message from worker:${args.event}`});
}
}
case "seen-species-list": {generateBirdList("seenSpecies", args.list);
break;
}
case "valid-species-list": {populateSpeciesModal(args.included, args.excluded);
break;
}
case "total-records": {updatePagination(args.total, args.offset);
break;
}
case "unsaved-records": {window.electron.unsavedRecords(true);
document.getElementById("unsaved-icon").classList.remove("d-none");
break;
}
case "update-audio-duration": {DIAGNOSTICS["Audio Duration"] ??= 0;
DIAGNOSTICS["Audio Duration"] += args.value;
break;
}
case "update-summary": {updateSummary(args);
break;
}
case "worker-loaded-audio": {
onWorkerLoadedAudio(args);
break;
}
default: {generateToast({ message:`Unrecognised message from worker:${args.event}`});
}
}
})
})
}
Expand Down Expand Up @@ -2456,6 +2481,14 @@ function onChartData(args) {
KeyT: function (e) {
if ( e.ctrlKey || e.metaKey) timelineToggle(true);
},
KeyV: function(e) {
if (activeRow && (e.ctrlKey || e.metaKey)) {
const nameAttribute = activeRow.getAttribute('name');
const [file, start, end, sname, label] = nameAttribute.split('|');
const cname = label.replace('?', '');
insertManualRecord(cname, parseFloat(start), parseFloat(end), "", "", "", "Update", false, cname)
}
},
KeyZ: function (e) {
if (( e.ctrlKey || e.metaKey) && DELETE_HISTORY.length) insertManualRecord(...DELETE_HISTORY.pop());
},
Expand Down
Loading

0 comments on commit 7a7b099

Please sign in to comment.