zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 4976d1ec1b2582ef9f5c115822cbd8163d3a2d8c
parent a4fbe0dfd59780f77e5902736a616cda27efde17
Author: fundamental <[email protected]>
Date:   Thu, 13 May 2010 18:12:09 -0400

char * -> std::string

Diffstat:
Msrc/Misc/Bank.cpp | 268+++++++++++++++++++++++++++----------------------------------------------------
Msrc/Misc/Bank.h | 36+++++++++++++++++++-----------------
Msrc/Misc/Config.cpp | 116+++++++++++++++++++++++--------------------------------------------------------
Msrc/Misc/Config.h | 6+++---
Msrc/Misc/Dump.cpp | 4++--
Msrc/Misc/Part.cpp | 2+-
Msrc/Misc/Part.h | 2+-
Msrc/Params/PresetsStore.cpp | 8++++----
Msrc/UI/BankUI.fl | 36++++++++++++++++++------------------
Msrc/UI/ConfigUI.fl | 71+++++++++++++++++++++++++++++++++++------------------------------------
10 files changed, 207 insertions(+), 342 deletions(-)

diff --git a/src/Misc/Bank.cpp b/src/Misc/Bank.cpp @@ -26,6 +26,7 @@ #include <stdlib.h> #include <dirent.h> #include <sys/stat.h> +#include <algorithm> #include <sys/types.h> #include <fcntl.h> @@ -39,26 +40,18 @@ //if this file exists into a directory, this make the directory to be considered as a bank, even if it not contains a instrument file #define FORCE_BANK_DIR_FILE ".bankdir" +using namespace std; + Bank::Bank() { - ZERO(defaultinsname, PART_MAX_NAME_LEN); - snprintf(defaultinsname, PART_MAX_NAME_LEN, "%s", " "); + defaultinsname = " "; for(int i = 0; i < BANK_SIZE; i++) { ins[i].used = false; - ins[i].filename = NULL; ins[i].info.PADsynth_used = false; } - dirname = NULL; clearbank(); - - - for(int i = 0; i < MAX_NUM_BANKS; i++) { - banks[i].dir = NULL; - banks[i].name = NULL; - } - bankfiletitle = dirname; loadbank(config.cfg.currentBankDir); @@ -66,20 +59,13 @@ Bank::Bank() Bank::~Bank() { - for(int i = 0; i < MAX_NUM_BANKS; i++) { - if(banks[i].dir != NULL) - delete [] banks[i].dir; - if(banks[i].name != NULL) - delete [] banks[i].name; - } - clearbank(); } /* * Get the name of an instrument from the bank */ -char *Bank::getname(unsigned int ninstrument) +string Bank::getname(unsigned int ninstrument) { if(emptyslot(ninstrument)) return defaultinsname; @@ -89,7 +75,7 @@ char *Bank::getname(unsigned int ninstrument) /* * Get the numbered name of an instrument from the bank */ -char *Bank::getnamenumbered(unsigned int ninstrument) +string Bank::getnamenumbered(unsigned int ninstrument) { if(emptyslot(ninstrument)) return defaultinsname; @@ -97,26 +83,25 @@ char *Bank::getnamenumbered(unsigned int ninstrument) PART_MAX_NAME_LEN + 15, "%d. %s", ninstrument + 1, - getname(ninstrument)); + getname(ninstrument).c_str()); return tmpinsname[ninstrument]; } /* * Changes the name of an instrument (and the filename) */ -void Bank::setname(unsigned int ninstrument, const char *newname, int newslot) +void Bank::setname(unsigned int ninstrument, string newname, int newslot) { if(emptyslot(ninstrument)) return; - char newfilename[1000 + 1], tmpfilename[100 + 1]; + string newfilename; + char tmpfilename[100 + 1]; - ZERO(newfilename, 1001); - ZERO(tmpfilename, 101); if(newslot >= 0) - snprintf(tmpfilename, 100, "%4d-%s", newslot + 1, newname); + snprintf(tmpfilename, 100, "%4d-%s", newslot + 1, newname.c_str()); else - snprintf(tmpfilename, 100, "%4d-%s", ninstrument + 1, newname); + snprintf(tmpfilename, 100, "%4d-%s", ninstrument + 1, newname.c_str()); //add the zeroes at the start of filename for(int i = 0; i < 4; i++) @@ -138,17 +123,12 @@ void Bank::setname(unsigned int ninstrument, const char *newname, int newslot) tmpfilename[i] = '_'; } - snprintf(newfilename, 1000, "%s/%s.xiz", dirname, tmpfilename); + newfilename = dirname + '/' + tmpfilename + ".xiz"; -// printf("rename %s -> %s\n",ins[ninstrument].filename,newfilename);////////////// + rename(ins[ninstrument].filename.c_str(), newfilename.c_str()); - rename(ins[ninstrument].filename, newfilename); - if(ins[ninstrument].filename) - delete [] ins[ninstrument].filename; - ins[ninstrument].filename = new char[strlen(newfilename) + 5]; - snprintf(ins[ninstrument].filename, strlen( - newfilename) + 1, "%s", newfilename); - snprintf(ins[ninstrument].name, PART_MAX_NAME_LEN, "%s", &tmpfilename[5]); + ins[ninstrument].filename = newfilename; + ins[ninstrument].name = tmpfilename; //TODO limit name to PART_MAX_NAME_LEN } /* @@ -158,7 +138,7 @@ int Bank::emptyslot(unsigned int ninstrument) { if(ninstrument >= BANK_SIZE) return 1; - if(ins[ninstrument].filename == NULL) + if(ins[ninstrument].filename.empty()) return 1; if(ins[ninstrument].used) @@ -175,10 +155,7 @@ void Bank::clearslot(unsigned int ninstrument) if(emptyslot(ninstrument)) return; -// printf("remove %s \n",ins[ninstrument].filename);//////////////////////// - - - remove(ins[ninstrument].filename); + remove(ins[ninstrument].filename.c_str()); deletefrombank(ninstrument); } @@ -221,17 +198,11 @@ void Bank::savetoslot(unsigned int ninstrument, Part *part) strncat(tmpfilename, ".xiz", maxfilename + 10); - int fnsize = strlen(dirname) + strlen(tmpfilename) + 10; - char *filename = new char[fnsize + 4]; - ZERO(filename, fnsize + 2); - - snprintf(filename, fnsize, "%s/%s", dirname, tmpfilename); + string filename = dirname + '/' + tmpfilename; - remove(filename); - part->saveXML(filename); + remove(filename.c_str()); + part->saveXML(filename.c_str()); addtobank(ninstrument, tmpfilename, (char *) part->Pname); - - delete[] filename; } /* @@ -244,31 +215,25 @@ void Bank::loadfromslot(unsigned int ninstrument, Part *part) part->defaultsinstrument(); -// printf("load: %s\n",ins[ninstrument].filename); - - part->loadXMLinstrument(ins[ninstrument].filename); + part->loadXMLinstrument(ins[ninstrument].filename.c_str()); } /* * Makes current a bank directory */ -int Bank::loadbank(const char *bankdirname) +int Bank::loadbank(string bankdirname) { - DIR *dir = opendir(bankdirname); + DIR *dir = opendir(bankdirname.c_str()); clearbank(); if(dir == NULL) return -1; - if(dirname != NULL) - delete[] dirname; - dirname = new char[strlen(bankdirname) + 1]; - snprintf(dirname, strlen(bankdirname) + 1, "%s", bankdirname); + dirname = bankdirname; bankfiletitle = dirname; - // printf("loadbank %s/\n",bankdirname); struct dirent *fn; while((fn = readdir(dir))) { @@ -296,31 +261,27 @@ int Bank::loadbank(const char *bankdirname) if((startname + 1) < strlen(filename)) startname++; //to take out the "-" - char name[PART_MAX_NAME_LEN + 1]; - ZERO(name, PART_MAX_NAME_LEN + 1); - snprintf(name, PART_MAX_NAME_LEN, "%s", filename); + string name = filename; //remove the file extension - for(int i = strlen(name) - 1; i >= 2; i--) { + for(int i = name.size() - 1; i >= 2; i--) { if(name[i] == '.') { - name[i] = '\0'; + name = name.substr(0,i); break; } } if(no != 0) //the instrument position in the bank is found - addtobank(no - 1, filename, &name[startname]); + addtobank(no - 1, filename, name.substr(startname)); else addtobank(-1, filename, name); - ; } closedir(dir); - if(dirname != NULL) - sprintf(config.cfg.currentBankDir, "%s", dirname); - ; + if(!dirname.empty()) + config.cfg.currentBankDir = dirname; return 0; } @@ -328,35 +289,30 @@ int Bank::loadbank(const char *bankdirname) /* * Makes a new bank, put it on a file and makes it current bank */ -int Bank::newbank(const char *newbankdirname) +int Bank::newbank(string newbankdirname) { int result; - char tmpfilename[MAX_STRING_SIZE]; - char bankdir[MAX_STRING_SIZE]; - snprintf(bankdir, MAX_STRING_SIZE, "%s", config.cfg.bankRootDirList[0]); - - if(((bankdir[strlen(bankdir) - 1]) != '/') - && ((bankdir[strlen(bankdir) - 1]) != '\\')) - strncat(bankdir, "/", MAX_STRING_SIZE); - ; - strncat(bankdir, newbankdirname, MAX_STRING_SIZE); + string bankdir; + bankdir = config.cfg.bankRootDirList[0]; + + if(((bankdir[bankdir.size() - 1]) != '/') + && ((bankdir[bankdir.size() - 1]) != '\\')) + bankdir += "/"; + + bankdir += newbankdirname; #if OS_WINDOWS - result = mkdir(bankdir); + result = mkdir(bankdir.c_str()); #elif OS_LINUX || OS_CYGWIN - result = mkdir(bankdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + result = mkdir(bankdir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); #else #warning Undefined OS #endif if(result < 0) return -1; - snprintf(tmpfilename, - MAX_STRING_SIZE, - "%s/%s", - bankdir, - FORCE_BANK_DIR_FILE); -// printf("%s\n",tmpfilename); - FILE *tmpfile = fopen(tmpfilename, "w+"); + string tmpfilename = bankdir + '/' + FORCE_BANK_DIR_FILE; + + FILE *tmpfile = fopen(tmpfilename.c_str(), "w+"); fclose(tmpfile); return loadbank(bankdir); @@ -367,7 +323,7 @@ int Bank::newbank(const char *newbankdirname) */ int Bank::locked() { - return dirname == NULL; + return dirname.empty(); } /* @@ -375,6 +331,7 @@ int Bank::locked() */ void Bank::swapslot(unsigned int n1, unsigned int n2) { + //TODO use std::swap if((n1 == n2) || (locked())) return; if(emptyslot(n1) && (emptyslot(n2))) @@ -389,43 +346,35 @@ void Bank::swapslot(unsigned int n1, unsigned int n2) setname(n1, getname(n1), n2); ins[n2] = ins[n1]; ins[n1].used = false; - ins[n1].name[0] = '\0'; - ins[n1].filename = NULL; + ins[n1].name.clear(); + ins[n1].filename.clear(); ins[n1].info.PADsynth_used = 0; } else { //if both slots are used - if(strcmp(ins[n1].name, ins[n2].name) == 0) //change the name of the second instrument if the name are equal - strncat(ins[n2].name, "2", PART_MAX_NAME_LEN); - ; + if(ins[n1].name == ins[n2].name) //change the name of the second instrument if the name are equal + ins[n2].name += "2"; + setname(n1, getname(n1), n2); setname(n2, getname(n2), n1); ins_t tmp; tmp.used = true; - strcpy(tmp.name, ins[n2].name); - char *tmpfilename = ins[n2].filename; + tmp.name = ins[n2].name; + string tmpfilename = ins[n2].filename; bool padsynth_used = ins[n2].info.PADsynth_used; ins[n2] = ins[n1]; - strcpy(ins[n1].name, tmp.name); + ins[n1].name = tmp.name; ins[n1].filename = tmpfilename; ins[n1].info.PADsynth_used = padsynth_used; } } -//a helper function that compares 2 banks[] arrays -int Bank_compar(const void *a, const void *b) +bool Bank::bankstruct::operator<(const bankstruct &b) const { - struct Bank::bankstruct *bank1 = (Bank::bankstruct *)a; - struct Bank::bankstruct *bank2 = (Bank::bankstruct *)b; - if(((bank1->name) == NULL) || ((bank2->name) == NULL)) - return 0; - - int result = strcasecmp(bank1->name, bank2->name); - return result < 0; + return name < b.name; } - /* * Re-scan for directories containing instrument banks */ @@ -433,52 +382,31 @@ int Bank_compar(const void *a, const void *b) void Bank::rescanforbanks() { for(int i = 0; i < MAX_NUM_BANKS; i++) { - if(banks[i].dir != NULL) - delete [] banks[i].dir; - if(banks[i].name != NULL) - delete [] banks[i].name; - banks[i].dir = NULL; - banks[i].name = NULL; + banks[i].dir.clear(); + banks[i].name.clear(); } for(int i = 0; i < MAX_BANK_ROOT_DIRS; i++) - if(config.cfg.bankRootDirList[i] != NULL) + if(!config.cfg.bankRootDirList[i].empty()) scanrootdir(config.cfg.bankRootDirList[i]); //sort the banks - for(int j = 0; j < MAX_NUM_BANKS - 1; j++) { - for(int i = j + 1; i < MAX_NUM_BANKS; i++) { - if(Bank_compar(&banks[i], &banks[j])) { - char *tmpname = banks[i].name; - char *tmpdir = banks[i].dir; - - banks[i].name = banks[j].name; - banks[i].dir = banks[j].dir; - - banks[j].name = tmpname; - banks[j].dir = tmpdir; - } - } - } + sort(banks.begin(), banks.end()); //remove duplicate bank names int dupl = 0; - for(int j = 0; j < MAX_NUM_BANKS - 1; j++) { - for(int i = j + 1; i < MAX_NUM_BANKS; i++) { - if((banks[i].name == NULL) || (banks[j].name == NULL)) + for(int j = 0; j < banks.size() - 1; j++) { + for(int i = j + 1; i < banks.size(); i++) { + if(banks[i].name.empty() || banks[j].name.empty()) continue; - if(strcmp(banks[i].name, banks[j].name) == 0) { //add a [1] to the first bankname and [n] to others - char *tmpname = banks[i].name; - banks[i].name = new char[strlen(tmpname) + 100]; - sprintf(banks[i].name, "%s[%d]", tmpname, dupl + 2); + if(banks[i].name == banks[j].name) { //add a [1] to the first bankname and [n] to others + char *tmpname = new char[strlen(tmpname) + 100]; + sprintf(tmpname, "%s[%d]", tmpname, dupl + 2); + banks[i].name = tmpname; delete[] tmpname; - if(dupl == 0) { - char *tmpname = banks[j].name; - banks[j].name = new char[strlen(tmpname) + 100]; - sprintf(banks[j].name, "%s[1]", tmpname); - delete[] tmpname; - } + if(dupl == 0) + banks[i].name += "[1]"; dupl++; } @@ -492,22 +420,18 @@ void Bank::rescanforbanks() // private stuff -void Bank::scanrootdir(char *rootdir) +void Bank::scanrootdir(string rootdir) { -// printf("Scanning root dir:%s\n",rootdir); - DIR *dir = opendir(rootdir); + DIR *dir = opendir(rootdir.c_str()); if(dir == NULL) return; const int maxdirsize = 1000; - struct { - char dir[maxdirsize]; - char name[maxdirsize]; - } bank; + bankstruct bank; const char *separator = "/"; - if(strlen(rootdir)) { - char tmp = rootdir[strlen(rootdir) - 1]; + if(rootdir.size()) { + char tmp = rootdir[rootdir.size() - 1]; if((tmp == '/') || (tmp == '\\')) separator = ""; } @@ -518,12 +442,12 @@ void Bank::scanrootdir(char *rootdir) if(dirname[0] == '.') continue; - snprintf(bank.dir, maxdirsize, "%s%s%s/", rootdir, separator, dirname); - snprintf(bank.name, maxdirsize, "%s", dirname); + bank.dir = rootdir + separator + dirname + '/'; + bank.name = dirname; //find out if the directory contains at least 1 instrument bool isbank = false; - DIR *d = opendir(bank.dir); + DIR *d = opendir(bank.dir.c_str()); if(d == NULL) continue; @@ -542,17 +466,15 @@ void Bank::scanrootdir(char *rootdir) if(isbank) { int pos = -1; for(int i = 1; i < MAX_NUM_BANKS; i++) { //banks[0] e liber intotdeauna - if(banks[i].name == NULL) { + if(banks[i].name.empty()) { pos = i; break; } } if(pos >= 0) { - banks[pos].name = new char[maxdirsize]; - banks[pos].dir = new char[maxdirsize]; - snprintf(banks[pos].name, maxdirsize, "%s", bank.name); - snprintf(banks[pos].dir, maxdirsize, "%s", bank.dir); + banks[pos].name = bank.name; + banks[pos].dir = bank.dir; } } } @@ -562,15 +484,13 @@ void Bank::scanrootdir(char *rootdir) void Bank::clearbank() { - for(int i = 0; i < BANK_SIZE; i++) - deletefrombank(i); - if(dirname != NULL) - delete[] dirname; - bankfiletitle = NULL; - dirname = NULL; + banks.clear(); + + bankfiletitle.clear(); + dirname.clear(); } -int Bank::addtobank(int pos, const char *filename, const char *name) +int Bank::addtobank(int pos, string filename, string name) { if((pos >= 0) && (pos < BANK_SIZE)) { if(ins[pos].used) @@ -598,14 +518,11 @@ int Bank::addtobank(int pos, const char *filename, const char *name) deletefrombank(pos); ins[pos].used = true; - snprintf(ins[pos].name, PART_MAX_NAME_LEN, "%s", name); + ins[pos].name = name; snprintf(tmpinsname[pos], PART_MAX_NAME_LEN + 10, " "); - int len = strlen(filename) + 1 + strlen(dirname); - ins[pos].filename = new char[len + 2]; - ins[pos].filename[len + 1] = 0; - snprintf(ins[pos].filename, len + 1, "%s/%s", dirname, filename); + ins[pos].filename = dirname + '/' + filename; //see if PADsynth is used if(config.cfg.CheckPADsynth) { @@ -631,14 +548,11 @@ bool Bank::isPADsynth_used(unsigned int ninstrument) void Bank::deletefrombank(int pos) { - if((pos < 0) || (pos >= BANK_SIZE)) + if((pos < 0) || (pos >= banks.size())) return; ins[pos].used = false; - ZERO(ins[pos].name, PART_MAX_NAME_LEN + 1); - if(ins[pos].filename != NULL) { - delete [] ins[pos].filename; - ins[pos].filename = NULL; - } + ins[pos].name.clear(); + ins[pos].filename.clear(); ZERO(tmpinsname[pos], PART_MAX_NAME_LEN + 20); } diff --git a/src/Misc/Bank.h b/src/Misc/Bank.h @@ -23,6 +23,8 @@ #ifndef BANK_H #define BANK_H +#include <string> +#include <vector> #include "../globals.h" #include "Util.h" #include "XMLwrapper.h" @@ -35,17 +37,16 @@ */ #define MAX_NUM_BANKS 400 -/**The instrument Bank - * \todo add in strings to replace char* */ +/**The instrument Bank*/ class Bank { public: /**Constructor*/ Bank(); ~Bank(); - char *getname(unsigned int ninstrument); - char *getnamenumbered(unsigned int ninstrument); - void setname(unsigned int ninstrument, const char *newname, int newslot); //if newslot==-1 then this is ignored, else it will be put on that slot + std::string getname(unsigned int ninstrument); + std::string getnamenumbered(unsigned int ninstrument); + void setname(unsigned int ninstrument, const std::string newname, int newslot); //if newslot==-1 then this is ignored, else it will be put on that slot bool isPADsynth_used(unsigned int ninstrument); /**returns 0 if the slot is not empty or 1 if the slot is empty @@ -62,47 +63,48 @@ class Bank /**Swaps Slots*/ void swapslot(unsigned int n1, unsigned int n2); - int loadbank(const char *bankdirname); - int newbank(const char *newbankdirname); + int loadbank(std::string bankdirname); + int newbank(std::string newbankdirname); - char *bankfiletitle; //this is shown on the UI of the bank (the title of the window) + std::string bankfiletitle; //this is shown on the UI of the bank (the title of the window) int locked(); void rescanforbanks(); struct bankstruct { - char *dir; - char *name; + bool operator<(const bankstruct &b) const; + std::string dir; + std::string name; }; - bankstruct banks[MAX_NUM_BANKS]; + std::vector<bankstruct> banks; private: //it adds a filename to the bank //if pos is -1 it try to find a position //returns -1 if the bank is full, or 0 if the instrument was added - int addtobank(int pos, const char *filename, const char *name); + int addtobank(int pos, std::string filename, std::string name); void deletefrombank(int pos); void clearbank(); - char defaultinsname[PART_MAX_NAME_LEN]; + std::string defaultinsname; char tmpinsname[BANK_SIZE][PART_MAX_NAME_LEN + 20]; //this keeps the numbered names struct ins_t { bool used; - char name[PART_MAX_NAME_LEN + 1]; - char *filename; + std::string name; + std::string filename; struct { bool PADsynth_used; } info; } ins[BANK_SIZE]; - char *dirname; + std::string dirname; - void scanrootdir(char *rootdir); //scans a root dir for banks + void scanrootdir(std::string rootdir); //scans a root dir for banks }; #endif diff --git a/src/Misc/Config.cpp b/src/Misc/Config.cpp @@ -50,8 +50,7 @@ void Config::init() cfg.LinuxOSSSeqInDev = new char[MAX_STRING_SIZE]; snprintf(cfg.LinuxOSSSeqInDev, MAX_STRING_SIZE, "/dev/sequencer"); - cfg.DumpFile = new char[MAX_STRING_SIZE]; - snprintf(cfg.DumpFile, MAX_STRING_SIZE, "zynaddsubfx_dump.txt"); + cfg.DumpFile = "zynaddsubfx_dump.txt"; cfg.WindowsWaveOutId = 0; cfg.WindowsMidiInId = 0; @@ -94,90 +93,56 @@ void Config::init() midiincaps.szPname); ; #endif - for(int i = 0; i < MAX_BANK_ROOT_DIRS; i++) - cfg.bankRootDirList[i] = NULL; - cfg.currentBankDir = new char[MAX_STRING_SIZE]; - sprintf(cfg.currentBankDir, "./testbnk"); - - for(int i = 0; i < MAX_BANK_ROOT_DIRS; i++) - cfg.presetsDirList[i] = NULL; + cfg.currentBankDir = "./testbnk"; char filename[MAX_STRING_SIZE]; getConfigFileName(filename, MAX_STRING_SIZE); readConfig(filename); - if(cfg.bankRootDirList[0] == NULL) { + if(cfg.bankRootDirList[0].empty()) { #if OS_LINUX //banks - cfg.bankRootDirList[0] = new char[MAX_STRING_SIZE]; - sprintf(cfg.bankRootDirList[0], "~/banks"); - - cfg.bankRootDirList[1] = new char[MAX_STRING_SIZE]; - sprintf(cfg.bankRootDirList[1], "./"); - - cfg.bankRootDirList[2] = new char[MAX_STRING_SIZE]; - sprintf(cfg.bankRootDirList[2], "/usr/share/zynaddsubfx/banks"); - - cfg.bankRootDirList[3] = new char[MAX_STRING_SIZE]; - sprintf(cfg.bankRootDirList[3], "/usr/local/share/zynaddsubfx/banks"); - - cfg.bankRootDirList[4] = new char[MAX_STRING_SIZE]; - sprintf(cfg.bankRootDirList[4], "../banks"); - - cfg.bankRootDirList[5] = new char[MAX_STRING_SIZE]; - sprintf(cfg.bankRootDirList[5], "banks"); + cfg.bankRootDirList[0] = "~/banks"; + cfg.bankRootDirList[1] = "./"; + cfg.bankRootDirList[2] = "/usr/share/zynaddsubfx/banks"; + cfg.bankRootDirList[3] = "/usr/local/share/zynaddsubfx/banks"; + cfg.bankRootDirList[4] = "../banks"; + cfg.bankRootDirList[5] = "banks"; #else //banks - cfg.bankRootDirList[0] = new char[MAX_STRING_SIZE]; - sprintf(cfg.bankRootDirList[0], "./"); + cfg.bankRootDirList[0] = "./"; #ifdef VSTAUDIOOUT - cfg.bankRootDirList[1] = new char[MAX_STRING_SIZE]; - sprintf(cfg.bankRootDirList[1], "c:/Program Files/ZynAddSubFX/banks"); + cfg.bankRootDirList[1] = "c:/Program Files/ZynAddSubFX/banks"; #else - cfg.bankRootDirList[1] = new char[MAX_STRING_SIZE]; - sprintf(cfg.bankRootDirList[1], "../banks"); + cfg.bankRootDirList[1] = "../banks"; #endif - cfg.bankRootDirList[2] = new char[MAX_STRING_SIZE]; - sprintf(cfg.bankRootDirList[2], "banks"); + cfg.bankRootDirList[2] = "banks"; #endif } - if(cfg.presetsDirList[0] == NULL) { + if(cfg.presetsDirList[0].empty()) { #if OS_LINUX || OS_CYGWIN //presets - cfg.presetsDirList[0] = new char[MAX_STRING_SIZE]; - sprintf(cfg.presetsDirList[0], "./"); - - cfg.presetsDirList[1] = new char[MAX_STRING_SIZE]; - sprintf(cfg.presetsDirList[1], "../presets"); - - cfg.presetsDirList[2] = new char[MAX_STRING_SIZE]; - sprintf(cfg.presetsDirList[2], "presets"); - - cfg.presetsDirList[3] = new char[MAX_STRING_SIZE]; - sprintf(cfg.presetsDirList[3], "/usr/share/zynaddsubfx/presets"); - - cfg.presetsDirList[4] = new char[MAX_STRING_SIZE]; - sprintf(cfg.presetsDirList[4], "/usr/local/share/zynaddsubfx/presets"); + cfg.presetsDirList[0] = "./"; + cfg.presetsDirList[1] = "../presets"; + cfg.presetsDirList[2] = "presets"; + cfg.presetsDirList[3] = "/usr/share/zynaddsubfx/presets"; + cfg.presetsDirList[4] = "/usr/local/share/zynaddsubfx/presets"; #elif OS_WINDOWS //presets - cfg.presetsDirList[0] = new char[MAX_STRING_SIZE]; - sprintf(cfg.presetsDirList[0], "./"); + cfg.presetsDirList[0] = "./"; #ifdef VSTAUDIOOUT - cfg.presetsDirList[1] = new char[MAX_STRING_SIZE]; - sprintf(cfg.presetsDirList[1], "c:/Program Files/ZynAddSubFX/presets"); + cfg.presetsDirList[1] = "c:/Program Files/ZynAddSubFX/presets"; #else - cfg.presetsDirList[1] = new char[MAX_STRING_SIZE]; - sprintf(cfg.presetsDirList[1], "../presets"); + cfg.presetsDirList[1] = "../presets"; #endif //end vst - cfg.presetsDirList[2] = new char[MAX_STRING_SIZE]; - sprintf(cfg.presetsDirList[2], "presets"); + cfg.presetsDirList[2] = "presets"; #else #error Undefined OS #endif //end OS @@ -190,7 +155,6 @@ Config::~Config() { delete [] cfg.LinuxOSSWaveOutDev; delete [] cfg.LinuxOSSSeqInDev; - delete [] cfg.DumpFile; for(int i = 0; i < winmidimax; i++) delete [] winmididevices[i].name; @@ -207,20 +171,14 @@ void Config::save() void Config::clearbankrootdirlist() { - for(int i = 0; i < MAX_BANK_ROOT_DIRS; i++) { - if(cfg.bankRootDirList[i] == NULL) - delete (cfg.bankRootDirList[i]); - cfg.bankRootDirList[i] = NULL; - } + for(int i = 0; i < MAX_BANK_ROOT_DIRS; i++) + cfg.bankRootDirList[i].clear(); } void Config::clearpresetsdirlist() { - for(int i = 0; i < MAX_BANK_ROOT_DIRS; i++) { - if(cfg.presetsDirList[i] == NULL) - delete (cfg.presetsDirList[i]); - cfg.presetsDirList[i] = NULL; - } + for(int i = 0; i < MAX_BANK_ROOT_DIRS; i++) + cfg.presetsDirList[i].clear(); } void Config::readConfig(const char *filename) @@ -258,14 +216,14 @@ void Config::readConfig(const char *filename) cfg.DumpAppend, 0, 1); - xmlcfg.getparstr("dump_file", cfg.DumpFile, MAX_STRING_SIZE); + cfg.DumpFile = xmlcfg.getparstr("dump_file", ""); cfg.GzipCompression = xmlcfg.getpar("gzip_compression", cfg.GzipCompression, 0, 9); - xmlcfg.getparstr("bank_current", cfg.currentBankDir, MAX_STRING_SIZE); + cfg.currentBankDir = xmlcfg.getparstr("bank_current", ""); cfg.Interpolation = xmlcfg.getpar("interpolation", cfg.Interpolation, 0, @@ -289,10 +247,7 @@ void Config::readConfig(const char *filename) //get bankroot dirs for(int i = 0; i < MAX_BANK_ROOT_DIRS; i++) { if(xmlcfg.enterbranch("BANKROOT", i)) { - cfg.bankRootDirList[i] = new char[MAX_STRING_SIZE]; - xmlcfg.getparstr("bank_root", - cfg.bankRootDirList[i], - MAX_STRING_SIZE); + cfg.bankRootDirList[i] = xmlcfg.getparstr("bank_root", ""); xmlcfg.exitbranch(); } } @@ -300,10 +255,7 @@ void Config::readConfig(const char *filename) //get preset root dirs for(int i = 0; i < MAX_BANK_ROOT_DIRS; i++) { if(xmlcfg.enterbranch("PRESETSROOT", i)) { - cfg.presetsDirList[i] = new char[MAX_STRING_SIZE]; - xmlcfg.getparstr("presets_root", - cfg.presetsDirList[i], - MAX_STRING_SIZE); + cfg.presetsDirList[i] = xmlcfg.getparstr("presets_root", ""); xmlcfg.exitbranch(); } } @@ -359,20 +311,18 @@ void Config::saveConfig(const char *filename) for(int i = 0; i < MAX_BANK_ROOT_DIRS; i++) - if(cfg.bankRootDirList[i] != NULL) { + if(!cfg.bankRootDirList[i].empty()) { xmlcfg->beginbranch("BANKROOT", i); xmlcfg->addparstr("bank_root", cfg.bankRootDirList[i]); xmlcfg->endbranch(); } - ; for(int i = 0; i < MAX_BANK_ROOT_DIRS; i++) - if(cfg.presetsDirList[i] != NULL) { + if(!cfg.presetsDirList[i].empty()) { xmlcfg->beginbranch("PRESETSROOT", i); xmlcfg->addparstr("presets_root", cfg.presetsDirList[i]); xmlcfg->endbranch(); } - ; xmlcfg->addpar("interpolation", cfg.Interpolation); diff --git a/src/Misc/Config.h b/src/Misc/Config.h @@ -43,9 +43,9 @@ class Config int DumpNotesToFile, DumpAppend; int GzipCompression; int Interpolation; - char *DumpFile; - char *bankRootDirList[MAX_BANK_ROOT_DIRS], *currentBankDir; - char *presetsDirList[MAX_BANK_ROOT_DIRS]; + std::string DumpFile; + std::string bankRootDirList[MAX_BANK_ROOT_DIRS], currentBankDir; + std::string presetsDirList[MAX_BANK_ROOT_DIRS]; int CheckPADsynth; int UserInterfaceMode; int VirKeybLayout; diff --git a/src/Misc/Dump.cpp b/src/Misc/Dump.cpp @@ -55,9 +55,9 @@ void Dump::startnow() if(config.cfg.DumpNotesToFile != 0) { if(config.cfg.DumpAppend != 0) - file = fopen(config.cfg.DumpFile, "a"); + file = fopen(config.cfg.DumpFile.c_str(), "a"); else - file = fopen(config.cfg.DumpFile, "w"); + file = fopen(config.cfg.DumpFile.c_str(), "w"); if(file == NULL) return; if(config.cfg.DumpAppend != 0) diff --git a/src/Misc/Part.cpp b/src/Misc/Part.cpp @@ -1217,7 +1217,7 @@ void Part::add2XML(XMLwrapper *xml) xml->endbranch(); } -int Part::saveXML(char *filename) +int Part::saveXML(const char *filename) { XMLwrapper *xml; xml = new XMLwrapper(); diff --git a/src/Misc/Part.h b/src/Misc/Part.h @@ -71,7 +71,7 @@ class Part //saves the instrument settings to a XML file //returns 0 for ok or <0 if there is an error - int saveXML(char *filename); + int saveXML(const char *filename); int loadXMLinstrument(const char *filename); void add2XML(XMLwrapper *xml); diff --git a/src/Params/PresetsStore.cpp b/src/Params/PresetsStore.cpp @@ -110,9 +110,9 @@ void PresetsStore::rescanforpresets(char *type) snprintf(ftype, MAX_STRING_SIZE, ".%s.xpz", type); for(int i = 0; i < MAX_BANK_ROOT_DIRS; i++) { - if(config.cfg.presetsDirList[i] == NULL) + if(config.cfg.presetsDirList[i].empty()) continue; - char *dirname = config.cfg.presetsDirList[i]; + const char *dirname = config.cfg.presetsDirList[i].c_str(); DIR *dir = opendir(dirname); if(dir == NULL) continue; @@ -166,7 +166,7 @@ void PresetsStore::copypreset(XMLwrapper *xml, char *type, const char *name) { char filename[MAX_STRING_SIZE], tmpfilename[MAX_STRING_SIZE]; - if(config.cfg.presetsDirList[0] == NULL) + if(config.cfg.presetsDirList[0].empty()) return; snprintf(tmpfilename, MAX_STRING_SIZE, "%s", name); @@ -185,7 +185,7 @@ void PresetsStore::copypreset(XMLwrapper *xml, char *type, const char *name) tmpfilename[i] = '_'; } - const char *dirname = config.cfg.presetsDirList[0]; + const char *dirname = config.cfg.presetsDirList[0].c_str(); char tmpc = dirname[strlen(dirname) - 1]; const char *tmps; if((tmpc == '/') || (tmpc == '\\')) diff --git a/src/UI/BankUI.fl b/src/UI/BankUI.fl @@ -37,7 +37,7 @@ class BankProcess_ {} { } } -class BankSlot {open : {public Fl_Button,BankProcess_} +class BankSlot {: {public Fl_Button,BankProcess_} } { Function {BankSlot(int x,int y, int w, int h, const char *label=0):Fl_Button(x,y,w,h,label)} {} { code {what=NULL; @@ -59,8 +59,7 @@ int tmp=Fl_Button::handle(event); if ((*what!=0) && Fl::event_inside(this)) (bp->*fnc)(); return(tmp);} {} } - Function {init(int nslot_, int *what_, int *whatslot_,void (BankProcess_:: *fnc_)(void),BankProcess_ *bp_,Bank *bank_,int *nselected_)} {open - } { + Function {init(int nslot_, int *what_, int *whatslot_,void (BankProcess_:: *fnc_)(void),BankProcess_ *bp_,Bank *bank_,int *nselected_)} {} { code {nslot=nslot_; what=what_; whatslot=whatslot_; @@ -74,8 +73,7 @@ labelsize(13); align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP); highlight=0; -refresh();} {selected - } +refresh();} {} } Function {refresh()} {} { code {if (bank->emptyslot(nslot)) { @@ -88,7 +86,7 @@ refresh();} {selected if (*nselected==nslot) color(6); -label(bank->getnamenumbered(nslot));} {} +label(bank->getnamenumbered(nslot).c_str());} {} } decl {int *what,*whatslot,nslot,highlight, *nselected;} {} decl {void (BankProcess_:: *fnc)(void);} {} @@ -100,9 +98,9 @@ class BankUI {: {public BankProcess_} Function {make_window()} {} { Fl_Window bankuiwindow { label Bank - xywh {4 64 785 575} type Double hide - code0 {o->label(bank->bankfiletitle);} - code1 {if (bank->bankfiletitle==NULL) o->label ("Choose a bank from the bank list on the left (or go to settings if to configure the bank location) or choose 'New Bank...' to make a new bank.");} + xywh {5 64 785 575} type Double hide + code0 {o->label(bank->bankfiletitle.c_str());} + code1 {if (bank->bankfiletitle.empty()) o->label ("Choose a bank from the bank list on the left (or go to settings if to configure the bank location) or choose 'New Bank...' to make a new bank.");} } { Fl_Button {} { label Close @@ -193,13 +191,13 @@ refreshmainwindow();} } Fl_Choice banklist { callback {int n=o->value(); -char *dirname=bank->banks[n].dir; -if (dirname==NULL) return; +std::string dirname=bank->banks[n].dir; +if (dirname.empty()) return; if (bank->loadbank(dirname)==2) - fl_alert("Error: Could not load the bank from the directory\\n%s.",dirname); + fl_alert("Error: Could not load the bank from the directory\\n%s.",dirname.c_str()); for (int i=0;i<BANK_SIZE;i++) bs[i]->refresh(); -refreshmainwindow();} open +refreshmainwindow();} xywh {5 8 220 20} down_box BORDER_BOX labelfont 1 align 0 textfont 1 textsize 11 } {} Fl_Button {} { @@ -248,7 +246,7 @@ rescan_for_banks();} {} code {int slot=this->slot; if ((what==2)&&(bank->emptyslot(slot)==0)&&(mode!=4)) {//Rename slot - const char *tmp=fl_input("Slot (instrument) name:",(const char *)bank->getname(slot)); + const char *tmp=fl_input("Slot (instrument) name:",bank->getname(slot).c_str()); if (tmp!=NULL) bank->setname(slot,tmp,-1); bs[slot]->refresh(); }; @@ -258,7 +256,7 @@ if ((what==1)&&(mode==1)&&(!bank->emptyslot(slot))){//Reads from slot bank->loadfromslot(slot,master->part[*npart]); pthread_mutex_unlock(&master->mutex); master->part[*npart]->applyparameters(); - snprintf((char *)master->part[*npart]->Pname,PART_MAX_NAME_LEN,"%s",bank->getname(slot)); + snprintf((char *)master->part[*npart]->Pname,PART_MAX_NAME_LEN,"%s",bank->getname(slot).c_str()); cbwig->do_callback(); if (config.cfg.BankUIAutoClose!=0) @@ -308,7 +306,7 @@ if (mode==4){//swap if (mode!=4) refreshmainwindow();} {} } Function {refreshmainwindow()} {} { - code {bankuiwindow->label(bank->bankfiletitle); + code {bankuiwindow->label(bank->bankfiletitle.c_str()); mode=1;readbutton->value(1);writebutton->value(0);clearbutton->value(0);swapbutton->value(0); nselected=-1; if (bank->locked()){ @@ -320,7 +318,8 @@ if (bank->locked()){ clearbutton->activate(); swapbutton->activate(); }; -for (int i=0;i<BANK_SIZE;i++) bs[i]->refresh();} {} +for (int i=0;i<BANK_SIZE;i++) bs[i]->refresh();} {selected + } } Function {removeselection()} {} { code {if (nselected>=0) { @@ -335,7 +334,8 @@ banklist->add(" "); bank->rescanforbanks(); for (int i=1;i<MAX_NUM_BANKS;i++) { - if (bank->banks[i].name!=NULL) banklist->add(bank->banks[i].name); + if (!bank->banks[i].name.empty()) + banklist->add(bank->banks[i].name.c_str()); };} {} } Function {simplesetmode(bool beginnerui)} {} { diff --git a/src/UI/ConfigUI.fl b/src/UI/ConfigUI.fl @@ -1,5 +1,5 @@ # data file for the Fltk User Interface Designer (fluid) -version 1.0106 +version 1.0107 header_name {.h} code_name {.cc} decl {//Copyright (c) 2002-2005 Nasca Octavian Paul} {} @@ -60,35 +60,35 @@ setsamplerateinput();} xywh {20 50 85 20} down_box BORDER_BOX textsize 10 code0 {o->value(getsamplerateorder());} } { - menuitem {} { + MenuItem {} { label Custom xywh {10 10 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 16000Hz xywh {30 30 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 22050Hz xywh {20 20 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 32000Hz xywh {30 30 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 44100Hz xywh {40 40 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 48000Hz xywh {50 50 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 88200Hz xywh {60 60 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 96000Hz xywh {70 70 100 20} labelfont 1 } @@ -122,35 +122,35 @@ config.cfg.SoundBufferSize=strtoul(o->value(),&tmp,10);} tooltip {ADSynth Oscillator Size (samples)} xywh {175 80 75 20} down_box BORDER_BOX labelfont 1 labelsize 11 textsize 10 code0 {o->value( (int) (log(config.cfg.OscilSize/128.0-1.0)/log(2)) +1);} } { - menuitem {} { + MenuItem {} { label 128 xywh {25 25 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 256 xywh {35 35 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 512 xywh {45 45 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 1024 xywh {45 45 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 2048 xywh {55 55 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 4096 xywh {55 55 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 8192 xywh {65 65 100 20} labelfont 1 } - menuitem {} { + MenuItem {} { label 16384 xywh {75 75 100 20} labelfont 1 } @@ -168,9 +168,9 @@ config.cfg.SoundBufferSize=strtoul(o->value(),&tmp,10);} } { Fl_File_Input {} { label {Dump File} - callback {snprintf(config.cfg.DumpFile,config.maxstringsize,"%s",o->value());} + callback {config.cfg.DumpFile = o->value();} selected xywh {20 170 220 35} align 5 - code0 {o->insert(config.cfg.DumpFile);} + code0 {o->insert(config.cfg.DumpFile.c_str());} } Fl_Check_Button {} { label {Dump notes} @@ -241,38 +241,38 @@ midiinputnamebox->label(config.winmididevices[config.cfg.WindowsMidiInId].name); xywh {175 105 75 15} down_box BORDER_BOX labelsize 10 textsize 11 code0 {o->value(config.cfg.Interpolation);} } { - menuitem {} { + MenuItem {} { label {Linear(fast)} xywh {0 0 100 20} labelfont 1 labelsize 10 } - menuitem {} { + MenuItem {} { label {Cubic(slow)} xywh {10 10 100 20} labelfont 1 labelsize 10 } } Fl_Choice {} { label {Virtual Keyboard Layout} - callback {config.cfg.VirKeybLayout=(int) o->value();;} open selected + callback {config.cfg.VirKeybLayout=(int) o->value();;} xywh {155 235 85 20} down_box BORDER_BOX labelsize 12 textfont 1 textsize 11 code0 {o->value(config.cfg.VirKeybLayout);} } { - menuitem {} { + MenuItem {} { label { } xywh {5 5 100 20} labelfont 1 labelsize 11 deactivate } - menuitem {} { + MenuItem {} { label QWERTY xywh {15 15 100 20} labelfont 1 labelsize 11 } - menuitem {} { + MenuItem {} { label Dvorak xywh {25 25 100 20} labelfont 1 labelsize 11 } - menuitem {} { + MenuItem {} { label QWERTZ xywh {35 35 100 20} labelfont 1 labelsize 11 } - menuitem {} { + MenuItem {} { label AZERTY xywh {45 45 100 20} labelfont 1 labelsize 11 } @@ -395,31 +395,30 @@ readpresetcfg();} {} code {rootsbrowse->clear(); for (int i=0;i<MAX_BANK_ROOT_DIRS;i++){ - if (config.cfg.bankRootDirList[i]!=NULL) rootsbrowse->add(config.cfg.bankRootDirList[i]); + if (!config.cfg.bankRootDirList[i].empty()) + rootsbrowse->add(config.cfg.bankRootDirList[i].c_str()); };} {} } Function {writebankcfg()} {} { code {config.clearbankrootdirlist(); for (int n=0;n<rootsbrowse->size();n++){ - config.cfg.bankRootDirList[n]=new char [MAX_STRING_SIZE]; - strncpy(config.cfg.bankRootDirList[n],rootsbrowse->text(n+1),MAX_STRING_SIZE); + config.cfg.bankRootDirList[n] = rootsbrowse->text(n+1); };} {} } Function {readpresetcfg()} {} { code {presetbrowse->clear(); -for (int i=0;i<MAX_BANK_ROOT_DIRS;i++){ - if (config.cfg.presetsDirList[i]!=NULL) presetbrowse->add(config.cfg.presetsDirList[i]); +for(int i=0;i<MAX_BANK_ROOT_DIRS;i++){ + if(!config.cfg.presetsDirList[i].empty()) + presetbrowse->add(config.cfg.presetsDirList[i].c_str()); };} {} } Function {writepresetcfg()} {} { code {config.clearpresetsdirlist(); -for (int n=0;n<presetbrowse->size();n++){ - config.cfg.presetsDirList[n]=new char [MAX_STRING_SIZE]; - strncpy(config.cfg.presetsDirList[n],presetbrowse->text(n+1),MAX_STRING_SIZE); -};} {} +for (int n=0;n<presetbrowse->size();n++) + config.cfg.presetsDirList[n] = presetbrowse->text(n+1);} {} } Function {getsamplerateorder()} {return_type int } {