Hey folks! Unsure if there are developers on this list, but figured I'd ask.

I'm looking at the code that picks which directory a capture is saved to, and I wanted to make sure I understand what's already there, and the intention of it, before I make changes.

I'm going to be basing the line numbers off of current master which is: bbc8cc3d47341caa13a0578f8dd4e516e1810885

Ok! So first up we have src/monitor/recmanager.cpp and
src/capture/mediacapture.cpp, which seem pretty similar, but different. I know that audio record tracks go through mediacapture, and the code for mediacapture seems to imply it can handle both audio and video captures, whereas recmanager seems to only do video, but other than that I don't know the difference between them.

Secondly, there are two sets of settings in the "Environment" section of the settings panel, under "Default Folders". The labels they have are "Capture folder" and "Folder for rendering, titles, scripts", but in the code they're called "capturetoprojectfolder" and "videotodefaultfolder"

Both of them support the same options:
0: Default folder
1: Project folder
2: Custom folder

Where custom folder is specified in its own field, and in the code is called "capturefolderurl" and "videofolderurl" respectively.

So! Code!

Both mediacapture and recmanager have similar code that looks like:
`mediacapture.cpp:446`

    if (KdenliveSettings::capturetoprojectfolder() < 2) {
        captureFolder = QDir(pCore->getProjectFolderName(audioCapture));
    } else {
        captureFolder = QDir(KdenliveSettings::capturefolder());
    }

`recmanager:183`

    if (KdenliveSettings::capturetoprojectfolder() < 2) {
        captureFolder = QDir(pCore->getProjectFolderName());
    } else {
        captureFolder = QDir(KdenliveSettings::capturefolder());
    }

So basically, if capture is set to custom we use the custom one, otherwise we call `getProjectFolderName` to figure out where to put this thing. The only difference is that mediacapture sometimes only has audio, so there's a bool to tell it if it's audio only.

The core method just bounces to `src/doc/kdenlivedoc.cpp:790`:
`KdenliveDoc::projectDataFolder`

So right off the bat we have an if on that `folderForAudio` bool. In fact the structure of the code looks like:

    if (folderForAudio) {
        // Logic A, where every branch has a return
    }
    // Logic B, where every branch has a return

Which basically means this is actually two methods, just given one name and a bool to pick between them. There is zero logic or variables in common between Logic A and Logic B. But the two bits are very _similar_ in what they do, even if they don't share anything. They basically both say:

1. If custom, then return custom.
2. If the project file doesn't exist yet, then return the default project folder if we're using the project folder, otherwise the default video folder.
3. If we're using the project folder, return the project folder
4. Return the default video folder

The main difference is that the Logic A version (folderForAudio == true) is using the "capture" settings, and Logic B (folderForAudio == false) is using the other one, "videotodefaultfolder" aka "Folder for rendering, titles, scripts".

The only other quirk is that the video path has a step 1.5 which says "If a newPath has been given to me, and I'm supposed to be picking the project folder, return newPath instead". As far as I can tell this is only used once in all the code, somewhere in the render dialog, but I'm not really sure why. By coming in after step 1 and before the others, it seems to mean "if you're custom just pick custom and ignore newPath, if you're project then use newPath, and if you're system default then use system default and ignore newPath", but I don't know why, and the audio path doesn't do that.

Anyway!
So I have a few things that I find weird, but I don't know if they're bugs or intended.

The first is that in both recmanager and mediacapture we have that `if` on the outside, before we call `getProjectFolderName`, which checks if `capturetoprojectfolder` is set to Custom (2). If so it uses that. But inside that method, if it's audio it uses the value of `capturetoprojectfolder`, but if it's video it uses videotodefaultfolder's value instead.

Which means if I have "Capture folder" set to custom, and "Folder for rendering, titles, scripts" set to project folder, then it will save both audio and video captures to my custom folder. But if I have "Capture folder" set to either default or project folder, then audio captures will use that setting, but video captures will fall through and use the other setting, potentially ending up in a different place.

That feels like a bug to me, but I don't know enough about the intent to be sure.

The second question is really just whether or not video captures _should_ be using a different path from audio captures, specifically the one labeled "Folder for rendering, titles, scripts". There are other parts of the code that use that setting (and not the capture settings) for things like titles, etc. But was it ever intentional that recmanager and mediacapture would put video into that same folder?

I figure there are three options:

1. As-is. Audio capture should go into capture folder, video capture should go into video folder. Maybe the custom folder thing is a bit of a mixup, or maybe it's not, but the broad strokes are intended.

2. Both audio and video capture should use the capture folder settings, whereas other things like titles should use the video folder

3. There should be a third set of options. One for audio capture, one for video capture, and one for renders. Video capture shouldn't necessarily be put in the same place as titles.

That's the current state of things. Now, in case it might change your mind, what I'm planning on _changing_ is making a fourth option for audio captures that puts things in a custom *subfolder* of the project folder. As in "<project folder>/voiceover" or whatever the user picks. So then I wonder how video captures should handle this new plan. Should they go into the capture subfolder now? Should that only be for audio captures? Or should they have a third set of options that allows them to _also_ be put into their _own_ subfolder of the project dir.

I don't really care too much, because I don't make video captures, so it doesn't affect me one way or the other, but I've sorta gotta pick _something_, whether I choose to include them where it is currently excluding them, or if I choose to continue to exclude them even if it's a bit weird.

Those are my thoughts. What are yours?

Reply via email to