Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
iffyloop committed Aug 4, 2024
1 parent 192ab18 commit 9dd8156
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
47 changes: 31 additions & 16 deletions main-src/processQueue.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,20 @@ function killCurChildProcess() {
}
curChildProcess = null
}
}

curProgressFtStemIdx = null
function updateProgressRaw(videoId, progress) {
let mainWindow = BrowserWindow.getAllWindows()[0]
if (!mainWindow) {
return
}
mainWindow.webContents.send('videoStatusUpdate', {
videoId,
status: {
step: 'processing',
progress,
},
})
}

function updateDemucsProgress(videoId, data) {
Expand All @@ -113,24 +125,15 @@ function updateDemucsProgress(videoId, data) {
++curProgressFtStemIdx
}
progress /= 100
// Find the renderer window and send the update
let mainWindow = BrowserWindow.getAllWindows()[0]
if (mainWindow) {
mainWindow.webContents.send('videoStatusUpdate', {
videoId,
status: {
step: 'processing',
progress:
(curProgressFtStemIdx === null
? progress
: (curProgressFtStemIdx - 1) / 4 + progress / 4) * 0.95, // * 0.95 because of conversion step at end
},
})
}
updateProgressRaw(
videoId,
(curProgressFtStemIdx === null ? progress : (curProgressFtStemIdx - 1) / 4 + progress / 4) *
0.95
)
}
}

function spawnAndWait(videoId, cwd, command, args, isDemucs) {
function spawnAndWait(videoId, cwd, command, args, isDemucs, isHybrid) {
return new Promise((resolve, reject) => {
killCurChildProcess()

Expand Down Expand Up @@ -316,6 +319,7 @@ async function _processVideo(video, tmpDir) {
}
await spawnAndWait(video.videoId, tmpDir, DEMUCS_EXE_NAME, demucsExeArgs, true)
curProgressFtStemIdx = null
updateProgressRaw(video.videoId, 0.95)

const demucsBasePath = await findDemucsOutputDir(path.join(tmpDir, 'separated', demucsModelName))
const demucsWavFilesList = await listDemucsOutputFiles(demucsBasePath)
Expand All @@ -332,6 +336,7 @@ async function _processVideo(video, tmpDir) {
filetype: demucsStemsFiletype,
compressionArgs,
})
updateProgressRaw(video.videoId, 0.97)

const instrumentalPath = path.join(tmpDir, `instrumental.${demucsStemsFiletype}`)
console.log(`Mixing down instrumental stems to "${instrumentalPath}"`)
Expand Down Expand Up @@ -363,6 +368,7 @@ async function _processVideo(video, tmpDir) {
`Unable to access instrumental file "${instrumentalPath}" - ffmpeg probably failed`
)
}
updateProgressRaw(video.videoId, 0.98)

let originalOutPath = null
if (needsOriginal) {
Expand All @@ -374,7 +380,14 @@ async function _processVideo(video, tmpDir) {
['-i', mediaPath, ...compressionArgs, originalOutPath],
false
)
const originalSuccess = await ensureFileExists(originalOutPath)
if (!originalSuccess) {
throw new Error(
`Unable to access instrumental file "${originalOutPath}" - ffmpeg probably failed`
)
}
}
updateProgressRaw(video.videoId, 0.99)

const outputBasePathContainingFolder =
video.mediaSource === 'local' && module.exports.getLocalFileOutputToContainingDir()
Expand Down Expand Up @@ -435,6 +448,8 @@ async function processVideo(video) {
setVideoStatusAndPath(video.videoId, { step: 'error' }, null)
}
} finally {
curProgressFtStemIdx = null

try {
await fs.rm(tmpDir, {
recursive: true,
Expand Down
2 changes: 1 addition & 1 deletion renderer-src/components/ProcessQueueCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
Remove
{/if}
{:else if status.step === 'processing'}
Processing ({Math.floor(status.progress)}%)
Processing ({Math.floor(status.progress * 100)}%)
{:else if status.step === 'downloading'}
Downloading
{:else if status.step === 'queued'}
Expand Down

0 comments on commit 9dd8156

Please sign in to comment.