Skip to content

Commit

Permalink
Fixed 'export selected audio on file menu'
Browse files Browse the repository at this point in the history
Fixed analyse all for situations where all files are saved in diskDB
  • Loading branch information
Mattk70 committed Mar 7, 2024
1 parent fbb9524 commit ab98c8a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 13 deletions.
16 changes: 10 additions & 6 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,10 @@ function adjustSpecDims(redraw, fftSamples) {
specElement.style.zIndex = 0;
document.querySelector('.spec-labels').style.width = '55px';
}
if (wavesurfer && redraw) {}
specOffset = DOM.spectrogramWrapper.offsetHeight;
} else {
if (wavesurfer && redraw) {
specOffset = DOM.spectrogramWrapper.offsetHeight;
}
} else {
specOffset = 0
}
DOM.resultTableElement.style.height = (contentHeight - specOffset - formOffset) + 'px';
Expand Down Expand Up @@ -1482,6 +1483,7 @@ window.onload = async () => {
if (config.model === 'birdnet') config.backend = 'tensorflow';
// Rename migrants list from old versions to new name: nocturnal
if (config.list === 'migrants') config.list = 'nocturnal';

// switch off fullscreen mode - we don't want to persist that setting
config.fullscreen = false;
// switch off debug mode we don't want this to be remembered
Expand Down Expand Up @@ -4060,7 +4062,7 @@ DOM.gain.addEventListener('input', () => {
case 'open': { showOpenDialog(); break }
case 'saveLabels': { showSaveDialog(); break }
case 'saveCSV': { export2CSV(); break }
case 'export-audio': { export2audio(); break }
case 'export-audio': { exportAudio(); break }
case 'exit': { exitApplication(); break }

case 'save2db': { worker.postMessage({ action: 'save2db', file: currentFile }); break }
Expand Down Expand Up @@ -4468,10 +4470,12 @@ function track(event, action, name, value){
}
const xc = document.getElementById('context-xc');
if (region?.attributes.label || hideInSummary) {
// the following line errors out when there's no active row: "undefined is not iterable"
// will need to think how to get sname in that situation (and how you can have a lebel without an active row!)
let [,,,sname,cname] = activeRow?.getAttribute('name').split('|');
const XC_type = cname.includes('(song)') ? "song" :
cname.includes('call)') ? "nocturnal flight call" : "";
xc.href = `https://xeno-canto.org/explore?query=${sname}%20type:"${XC_type}`;
cname.includes('call)') ? "call" : "";
xc.href = `https://xeno-canto.org/explore?query=${sname}%20type:"${XC_type}"`;
// only offer XC lookup if we have an sname
sname && xc.classList.remove('d-none');
}
Expand Down
12 changes: 8 additions & 4 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,14 @@ const prepSummaryStatement = (included) => {
// BECAUSE we want to change state.db to disk if they are
let allCached = true;
for (let i = 0; i < FILE_QUEUE.length; i++) {
if (!await getSavedFileInfo(FILE_QUEUE[i])) {
const file = FILE_QUEUE[i];
const row = await getSavedFileInfo(file)
if (row) {
await setMetadata({file: file})
} else {
allCached = false;
break;
}
}
}
const retrieveFromDatabase = ((allCached && !reanalyse && !STATE.selection) || circleClicked);
if (retrieveFromDatabase) {
Expand Down Expand Up @@ -906,7 +910,7 @@ const prepSummaryStatement = (included) => {
goToRegion = true
}) {

const found = await getWorkingFile(file);
const found = metadata[file]?.proxy || await getWorkingFile(file);
if (found) {
await fetchAudioBuffer({ file, start, end })
.then((buffer) => {
Expand Down Expand Up @@ -2548,7 +2552,7 @@ const prepSummaryStatement = (included) => {
if (!row) {
const baseName = file.replace(/^(.*)\..*$/g, '$1%');
row = await diskDB.getAsync('SELECT * FROM files LEFT JOIN locations ON files.locationID = locations.id WHERE name LIKE (?)',baseName);
}
}
return row
};

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chirpity",
"version": "1.5.0",
"version": "1.5.1",
"description": "Chirpity Nocmig",
"main": "main.js",
"scripts": {
Expand All @@ -13,6 +13,7 @@
"type": "git",
"url": "git+https://github.com/mattk70/Chirpity-Electron.git"
},
"beforeBuild": "prebuild.js",
"build": {
"appId": "com.electron.chirpity",
"publish": [
Expand All @@ -29,18 +30,17 @@
"!.vscode${/*}",
"!.idea{*/}",
"!kernels.txt",
"!prebuild.js",
"!minify.js",
"!playwright.*",
"!dist${/*}",
"!BirdNet${/*}",
"!*fixed_roll*${/*}",
"!Help/example.mp3",
"!venv${/*}",
"!test${/*}",
"!custom_tfjs${/*}",
"!*git*${/*}",
"!package-lock.json",
"!poetry.lock*",
"!pyproject.toml",
"!README.md",
"!saved_model$(/*)",
Expand Down
47 changes: 47 additions & 0 deletions prebuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const fs = require('fs');
const path = require('path');

// Define the directory where your source files are located
const SOURCE_DIR = "C:/Users/simpo/PycharmProjects/Chirpity-Electron";

// Function to recursively search for patterns in files
function searchPatterns(directory, patterns) {
const files = fs.readdirSync(directory);

files.forEach(file => {
const filePath = path.join(directory, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory() || file.endsWith('.js')){
if (stats.isDirectory()) {
if (! filePath.includes('node_modules')) {
searchPatterns(filePath, patterns);
}
} else if (stats.isFile()) {
const content = fs.readFileSync(filePath, 'utf8');
patterns.forEach(pattern => {
if (content.match(pattern)) {
throw new Error(`Pattern '${pattern}' found in file: ${filePath}`);
// You can add further actions here if needed
}
});
}
}
});
}

// Define the patterns you want to search for
const patterns = [
/DEBUG\s*=\s*true/,
/ID_SITE\s*=\s*3/
// Add more patterns as needed
];

// Search for the patterns in the source directory
try {
searchPatterns(SOURCE_DIR, patterns);
console.log("No patterns found. Proceeding with the build...");
} catch (error) {
console.error("An error occurred while searching for the patterns:", error.message);
console.error("One or more patterns found. Aborting the build.");
process.exit(1);
}

0 comments on commit ab98c8a

Please sign in to comment.