Skip to content

Commit

Permalink
Allow new Zyn bank creation on Linux (LMMS#4905)
Browse files Browse the repository at this point in the history
Allow new Zyn bank creation on Linux
Closes LMMS#4642
  • Loading branch information
tresf authored Mar 18, 2019
1 parent bf97ed6 commit ea1e7c3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
35 changes: 32 additions & 3 deletions plugins/zynaddsubfx/zynaddsubfx/src/Misc/Bank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ void Bank::loadfromslot(unsigned int ninstrument, Part *part)
*/
int Bank::loadbank(string bankdirname)
{
normalizedirsuffix(bankdirname);
DIR *dir = opendir(bankdirname.c_str());
clearbank();

Expand Down Expand Up @@ -255,9 +256,15 @@ int Bank::newbank(string newbankdirname)
string bankdir;
bankdir = config.cfg.bankRootDirList[0];

if(((bankdir[bankdir.size() - 1]) != '/')
&& ((bankdir[bankdir.size() - 1]) != '\\'))
bankdir += "/";
expanddirname(bankdir);
normalizedirsuffix(bankdir);

// FIXME: Zyn should automatically handle creation of parent directory
#ifdef WIN32
if(mkdir(bankdir.c_str()) < 0) return -1;
#else
if(mkdir(bankdir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) return -1;
#endif

bankdir += newbankdirname;
#ifdef WIN32
Expand Down Expand Up @@ -355,6 +362,8 @@ void Bank::rescanforbanks()

void Bank::scanrootdir(string rootdir)
{
expanddirname(rootdir);

DIR *dir = opendir(rootdir.c_str());
if(dir == NULL)
return;
Expand Down Expand Up @@ -472,3 +481,23 @@ Bank::ins_t::ins_t()
{
info.PADsynth_used = false;
}

void Bank::expanddirname(std::string &dirname) {
if (dirname.empty())
return;

// if the directory name starts with a ~ and the $HOME variable is
// defined in the environment, replace ~ by the content of $HOME
if (dirname.at(0) == '~') {
char *home_dirname = getenv("HOME");
if (home_dirname != NULL) {
dirname = std::string(home_dirname) + dirname.substr(1);
}
}
}

void Bank::normalizedirsuffix(string &dirname) const {
if(((dirname[dirname.size() - 1]) != '/')
&& ((dirname[dirname.size() - 1]) != '\\'))
dirname += "/";
}
7 changes: 7 additions & 0 deletions plugins/zynaddsubfx/zynaddsubfx/src/Misc/Bank.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class Bank
std::string dirname;

void scanrootdir(std::string rootdir); //scans a root dir for banks

/** Expends ~ prefix in dirname, if any */
void expanddirname(std::string &dirname);

/** Ensure that the directory name is suffixed by a
* directory separator */
void normalizedirsuffix(std::string &dirname) const;
};

#endif

0 comments on commit ea1e7c3

Please sign in to comment.