remembering the Import directory

When I import an audio file to do a quick edit I almost always want to Export it right back where it came from.

Currently Audacity stores the previously used save path for Export. So if I Export a file to d:songs/rock/artist/album then Import one from c:music/pop/artist/album, do a bit of editing then choose File>Export…, the file dialog opens on the OLD directory ( d:songs/rock/artist/album ) and (at least on Windows) the file save dialog is really clunky and getting from way down in d:songs/rock/artist/album to the location I want ( c:music/pop/artist/album ) is a lot of clicking.

I realize that for some workflows having the Export dialog always open in the same directory is good but for my workflow (after Import) I want it to open for Export in the Import directory. As it turns out this is easy to accomplish.

First, add a new public wxString mImportPath to the AudacityProject class (it does not really matter where as long as it is in a public section), so in Project.h around line 389 it seems that on Linux it might really matter where in the header the new variable goes); so, in Project.h at the very end of the file:

   // Are we currently closing as the result of a menu command?
   bool mMenuClose;

public:
    wxString mImportPath;//efm5
    DECLARE_EVENT_TABLE()
};

#endif

We will not initialize mImportPath as we rely on wxString to be created empty.

Next we need to store the path of the Import directory, so in Project.cpp around line 3372:

bool AudacityProject::Import(wxString fileName, WaveTrackArray* pTrackArray /*= NULL*/)
{
   //efm5 start
   AudacityProject * project = GetActiveProject();
   wxFileName tempFilename(fileName);
   project->mImportPath = tempFilename.GetPath();
   //efm5 end
   Track **newTracks;

Finally, when we Export we need to use the stored path, in Export.cpp around line 542:

   maskString.RemoveLast();

   //efm5 start
   if (mProject->mImportPath.IsEmpty())
      mFilename.SetPath(gPrefs->Read(wxT("/Export/Path"), ::wxGetCwd()));
   else
      mFilename.SetPath(mProject->mImportPath);
   //efm5 end
   mFilename.SetName(mProject->GetName());

   while (true) {

      FileDialog fd(mProject,

This is all tested against SVN HEAD 17Feb2011 but only on Windows7. If you Drag ‘n’ Drop a supported audio file on the program icon or a Project window or choose the menu items File>Import>Audio… then choose File>Export the Import path will be used when opening the file dialog. If you open an empty Project and record or generate audio and choose File>Export the OLD path saved in the configuration file will be used.

In the above code I have included a line or two before and after my changes for continuity. I have noted or wrapped changes with //efm5 comments.

Ed has linked to this topic on Wiki Feature Requests so it should be moved to “General Audio Programming” rather than deleted when its month here is up. As I recall, the Forum will cope with the redirection OK.


Peter: Duly noted, will do.


Gale

I’ve got a problem with this on Linux.
I think I applied the changes correctly, then built against SVN HEAD 21Feb2011
It seems to build OK, but as soon as I click on the File menu, Audacity crashes with a segmentation fault.

I like the idea a lot and would find it very useful.

[Update: I’ve backed out of the changes and Audacity is working, so unfortunately it looks like these code changes caused the seg fault]

Hi Steve!

First, can you build a Debug version then run under a debugger?

Regardless, try an incremental approach. First just do the addition of the new Public variable to Project.h (step 1); compile, run then test; do you still segfault?

If you DO segfault, then it is likely to be the location of the new variable in Project.h (I doubt this will happen, but…) the absolute safest place to put the new variable would be at the very end of the file:

// Are we currently closing as the result of a menu command?
   bool mMenuClose;

 public:
/*here*/wxString mImportPath;//efm5
    DECLARE_EVENT_TABLE()
};

#endif

If (as I expect) your placement of the variable is good and not affecting the segfault, leave the new variable in place (step 1 or the new step 1) and additionally implement the second step (store the path of the Import directory in Project.cpp around line 3372), Again, compile, run then test–If you DO segfault, stop here and get back to me with the answer to my question about running under the debugger.

If you DO NOT segfault, replace step 3 in the previous post with:

   maskString.RemoveLast();

   mFilename.SetPath(gPrefs->Read(wxT("/Export/Path"), ::wxGetCwd()));
   wxMessageBox(mProject->mImportPath);//efm5
   mFilename.SetName(mProject->GetName());

   while (true) {

      FileDialog fd(mProject,

This results in “stock” behavior but will display the text stored in the variable. Let me know what happens!

PS We can take this to e-mail or PM if you desire.
PPS Who can we draft to test this on Mac and XP?

Good news Edgar.
The old step 1 was the problem.

Applying the NEW step 1 with steps 2 and 3 WORKS :smiley:

I think Bill (billw58) and Bruno (bgravato) use Macs, but I don’t know if either of them build on Macs. You could PM them and ask.

Great! I will edit the original to reflect this. Will also PM Bill & Bruno.

I think I never built audacity on Mac, but I can try. I’ll have a look at it later today.

Thanks, Bill was not able to help as he does not compile.