Merge branch 'master' into newXML
Conflicts: ChangeLog (cherry picked from commit aa79e53f0be4308b3cf693c029023bebaaa369ca) Conflicts: src/DSP/FFTwrapper.cpp src/DSP/FFTwrapper.h src/Tests/MicrotonalTest.h
This commit is contained in:
@@ -893,6 +893,23 @@
|
||||
07 Sep 2009 (Mark McCurry)
|
||||
- Fixed glitch in XMLwrapper, which would prevent file loading
|
||||
|
||||
11 Sep 2009 (Mark McCurry)
|
||||
- Moved PADsynth_used from public struct to has/set methods in
|
||||
XMLwrapper
|
||||
- Created wrapper functions, so that XMLwrapper can be somewhat
|
||||
usable when const
|
||||
- Removed multiple addparam methods and replaced it with one
|
||||
variable argument function
|
||||
- Replaced int2str, real2str, str2int, and str2real from XMLwrapper
|
||||
with stringTo<T> and stringFrom<T> function templates in Util.
|
||||
- Moved newFFTFREQS and deleteFFTFREQS from Util to FFTwrapper
|
||||
- Removed unneeded stack from XMLwrapper
|
||||
|
||||
18 Sep 2009 (Mark McCurry)
|
||||
- Started to use versioning information in XMLwrapper
|
||||
- Remove last of stack helper functions in XMLwrapper
|
||||
- Added std::string retreval to XMLwrapper
|
||||
|
||||
20 Sep 2009 (Paul Nasca)
|
||||
- Started to implement the Unison effect for ADsynth
|
||||
|
||||
@@ -914,3 +931,6 @@
|
||||
- Small enhancements and bugfixes to Unison
|
||||
- Started to implement Bandwidth to the Reverb effect
|
||||
|
||||
25 Sep 2009 (Mark McCurry)
|
||||
- Allowed for XMLwrapper to retrieve strings stored in mxml TEXT
|
||||
fields
|
||||
|
||||
@@ -98,3 +98,19 @@ void FFTwrapper::freqs2smps(FFTFREQS freqs,REALTYPE *smps)
|
||||
|
||||
};
|
||||
|
||||
void newFFTFREQS(FFTFREQS *f, int size)
|
||||
{
|
||||
f->c = new REALTYPE[size];
|
||||
f->s = new REALTYPE[size];
|
||||
for (int i=0; i<size; i++) {
|
||||
f->c[i] = 0.0;
|
||||
f->s[i] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void deleteFFTFREQS(FFTFREQS *f)
|
||||
{
|
||||
delete[] f->c;
|
||||
delete[] f->s;
|
||||
f->c = f->s = NULL;
|
||||
}
|
||||
|
||||
@@ -63,5 +63,8 @@ private:
|
||||
fftw_real *tmpfftdata1,*tmpfftdata2;
|
||||
rfftw_plan planfftw,planfftw_inv;
|
||||
};
|
||||
|
||||
void newFFTFREQS(FFTFREQS *f, int size);
|
||||
void deleteFFTFREQS(FFTFREQS *f);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -552,9 +552,9 @@ int Bank::addtobank(int pos, const char *filename, const char* name)
|
||||
//see if PADsynth is used
|
||||
if (config.cfg.CheckPADsynth) {
|
||||
XMLwrapper *xml=new XMLwrapper();
|
||||
xml->checkfileinformation(ins[pos].filename);
|
||||
xml->loadXMLfile(ins[pos].filename);
|
||||
|
||||
ins[pos].info.PADsynth_used=xml->information.PADsynth_used;
|
||||
ins[pos].info.PADsynth_used=xml->hasPadSynth();
|
||||
delete xml;
|
||||
} else ins[pos].info.PADsynth_used=false;
|
||||
|
||||
|
||||
@@ -104,19 +104,3 @@ bool fileexists(const char *filename)
|
||||
return(false);
|
||||
};
|
||||
|
||||
void newFFTFREQS(FFTFREQS *f,int size)
|
||||
{
|
||||
f->c=new REALTYPE[size];
|
||||
f->s=new REALTYPE[size];
|
||||
for (int i=0;i<size;i++) {
|
||||
f->c[i]=0.0;
|
||||
f->s[i]=0.0;
|
||||
};
|
||||
};
|
||||
void deleteFFTFREQS(FFTFREQS *f)
|
||||
{
|
||||
delete[] f->c;
|
||||
delete[] f->s;
|
||||
f->c=f->s=NULL;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,10 +23,9 @@
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#include <pthread.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "../globals.h"
|
||||
#include "Microtonal.h"
|
||||
#include "../DSP/FFTwrapper.h"
|
||||
#include "Config.h"
|
||||
|
||||
//Velocity Sensing function
|
||||
@@ -41,5 +40,23 @@ extern REALTYPE *denormalkillbuf;/**<the buffer to add noise in order to avoid d
|
||||
|
||||
extern Config config;
|
||||
|
||||
template <class T>
|
||||
std::string stringFrom(T x)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << x;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T stringTo(const char * x)
|
||||
{
|
||||
std::string str = x!=NULL ? x : "0"; //should work for the basic float/int
|
||||
std::stringstream ss(str);
|
||||
T ans;
|
||||
ss >> ans;
|
||||
return ans;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
|
||||
XMLwrapper.C - XML wrapper
|
||||
Copyright (C) 2003-2005 Nasca Octavian Paul
|
||||
Copyright (C) 2009-2009 Mark McCurry
|
||||
Author: Nasca Octavian Paul
|
||||
Mark McCurry
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of version 2 of the GNU General Public License
|
||||
@@ -34,8 +36,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
int xml_k=0;
|
||||
char tabs[STACKSIZE+2];
|
||||
int xml_k = 0;
|
||||
bool verbose = false;
|
||||
|
||||
const char *XMLwrapper_whitespace_callback(mxml_node_t *node,int where)
|
||||
{
|
||||
@@ -70,18 +72,32 @@ const char *XMLwrapper_whitespace_callback(mxml_node_t *node,int where)
|
||||
return(0);
|
||||
};
|
||||
|
||||
//temporary const overload of mxmlFindElement
|
||||
const mxml_node_t *mxmlFindElement(const mxml_node_t *node,
|
||||
const mxml_node_t *top, const char *name, const char *attr,
|
||||
const char *value, int descend)
|
||||
{
|
||||
return(const_cast<const mxml_node_t *> (mxmlFindElement(
|
||||
const_cast<mxml_node_t *>(node),
|
||||
const_cast<mxml_node_t *>(top),
|
||||
name, attr, value, descend)));
|
||||
}
|
||||
|
||||
//temporary const overload of mxmlElementGetAttr
|
||||
const char *mxmlElementGetAttr(const mxml_node_t *node, const char *name)
|
||||
{
|
||||
return mxmlElementGetAttr(const_cast<mxml_node_t *>(node),name);
|
||||
}
|
||||
|
||||
XMLwrapper::XMLwrapper()
|
||||
{
|
||||
ZERO(&parentstack,(int)sizeof(parentstack));
|
||||
ZERO(&values,(int)sizeof(values));
|
||||
version.Major = 2;
|
||||
version.Minor = 4;
|
||||
version.Revision = 1;
|
||||
|
||||
minimal=true;
|
||||
stackpos=0;
|
||||
|
||||
information.PADsynth_used=false;
|
||||
|
||||
tree=mxmlNewElement(MXML_NO_PARENT,"?xml version=\"1.0\" encoding=\"UTF-8\"?");
|
||||
node=tree=mxmlNewElement(MXML_NO_PARENT,"?xml version=\"1.0\" encoding=\"UTF-8\"?");
|
||||
/* for mxml 2.1 (and older)
|
||||
tree=mxmlNewElement(MXML_NO_PARENT,"?xml");
|
||||
mxmlElementSetAttr(tree,"version","1.0");
|
||||
@@ -91,14 +107,14 @@ XMLwrapper::XMLwrapper()
|
||||
mxml_node_t *doctype=mxmlNewElement(tree,"!DOCTYPE");
|
||||
mxmlElementSetAttr(doctype,"ZynAddSubFX-data",NULL);
|
||||
|
||||
node=root=mxmlNewElement(tree,"ZynAddSubFX-data");
|
||||
|
||||
mxmlElementSetAttr(root,"version-major","1");
|
||||
mxmlElementSetAttr(root,"version-minor","1");
|
||||
mxmlElementSetAttr(root,"ZynAddSubFX-author","Nasca Octavian Paul");
|
||||
node=root=addparams("ZynAddSubFX-data",4,
|
||||
"version-major", stringFrom<int>(version.Major).c_str(),
|
||||
"version-minor", stringFrom<int>(version.Minor).c_str(),
|
||||
"version-revision", stringFrom<int>(version.Revision).c_str(),
|
||||
"ZynAddSubFX-author", "Nasca Octavian Paul");
|
||||
|
||||
//make the empty branch that will contain the information parameters
|
||||
info=addparams0("INFORMATION");
|
||||
info=addparams("INFORMATION",0);
|
||||
|
||||
//save zynaddsubfx specifications
|
||||
beginbranch("BASE_PARAMETERS");
|
||||
@@ -119,61 +135,41 @@ XMLwrapper::~XMLwrapper()
|
||||
if (tree!=NULL) mxmlDelete(tree);
|
||||
};
|
||||
|
||||
bool XMLwrapper::checkfileinformation(const char *filename)
|
||||
void XMLwrapper::setPadSynth(bool enabled)
|
||||
{
|
||||
stackpos=0;
|
||||
ZERO(&parentstack,(int)sizeof(parentstack));
|
||||
information.PADsynth_used=false;
|
||||
/**@bug this might create multiple nodes when only one is needed*/
|
||||
mxml_node_t *oldnode=node;
|
||||
node=info;
|
||||
//Info storing
|
||||
addparbool("PADsynth_used",enabled);
|
||||
node=oldnode;
|
||||
}
|
||||
|
||||
if (tree!=NULL) mxmlDelete(tree);
|
||||
tree=NULL;
|
||||
char *xmldata=doloadfile(filename);
|
||||
if (xmldata==NULL) return(-1);//the file could not be loaded or uncompressed
|
||||
bool XMLwrapper::hasPadSynth() const
|
||||
{
|
||||
/**Right now this has a copied implementation of setparbool, so this should
|
||||
* be reworked as XMLwrapper evolves*/
|
||||
mxml_node_t * tmp = mxmlFindElement(tree,tree,"INFORMATION",NULL,NULL,MXML_DESCEND);
|
||||
|
||||
|
||||
char *start=strstr(xmldata,"<INFORMATION>");
|
||||
char *end=strstr(xmldata,"</INFORMATION>");
|
||||
|
||||
if ((start==NULL)||(end==NULL)||(start>end)) {
|
||||
delete []xmldata;
|
||||
mxml_node_t * parameter = mxmlFindElement(tmp, tmp, "par_bool", "name",
|
||||
"PADsynth_used", MXML_DESCEND_FIRST);
|
||||
if (parameter==NULL)//no information availiable
|
||||
return(false);
|
||||
};
|
||||
end+=strlen("</INFORMATION>");
|
||||
end[0]='\0';
|
||||
|
||||
tree=mxmlNewElement(MXML_NO_PARENT,"?xml");
|
||||
node=root=mxmlLoadString(tree,xmldata,MXML_OPAQUE_CALLBACK);
|
||||
if (root==NULL) {
|
||||
delete []xmldata;
|
||||
mxmlDelete(tree);
|
||||
node=root=tree=NULL;
|
||||
const char *strval = mxmlElementGetAttr(parameter,"value");
|
||||
if (strval==NULL)//no information available
|
||||
return(false);
|
||||
};
|
||||
|
||||
root=mxmlFindElement(tree,tree,"INFORMATION",NULL,NULL,MXML_DESCEND);
|
||||
push(root);
|
||||
|
||||
if (root==NULL) {
|
||||
delete []xmldata;
|
||||
mxmlDelete(tree);
|
||||
node=root=tree=NULL;
|
||||
if ((strval[0]=='Y')||(strval[0]=='y'))
|
||||
return(true);
|
||||
else
|
||||
return(false);
|
||||
};
|
||||
|
||||
information.PADsynth_used=getparbool("PADsynth_used",false);
|
||||
|
||||
exitbranch();
|
||||
if (tree!=NULL) mxmlDelete(tree);
|
||||
delete []xmldata;
|
||||
node=root=tree=NULL;
|
||||
|
||||
return(true);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/* SAVE XML members */
|
||||
|
||||
int XMLwrapper::saveXMLfile(const string &filename)
|
||||
int XMLwrapper::saveXMLfile(const string &filename) const
|
||||
{
|
||||
char *xmldata=getXMLdata();
|
||||
if (xmldata==NULL) return(-2);
|
||||
@@ -185,25 +181,17 @@ int XMLwrapper::saveXMLfile(const string &filename)
|
||||
return(result);
|
||||
};
|
||||
|
||||
char *XMLwrapper::getXMLdata()
|
||||
char *XMLwrapper::getXMLdata() const
|
||||
{
|
||||
xml_k=0;
|
||||
ZERO(tabs,STACKSIZE+2);
|
||||
|
||||
mxml_node_t *oldnode=node;
|
||||
|
||||
node=info;
|
||||
//Info storing
|
||||
addparbool("PADsynth_used",information.PADsynth_used);
|
||||
|
||||
node=oldnode;
|
||||
char *xmldata=mxmlSaveAllocString(tree,XMLwrapper_whitespace_callback);
|
||||
|
||||
return(xmldata);
|
||||
};
|
||||
|
||||
|
||||
int XMLwrapper::dosavefile(const char *filename,int compression,const char *xmldata)
|
||||
int XMLwrapper::dosavefile(const char *filename,int compression,const char *xmldata) const
|
||||
{
|
||||
if (compression==0) {
|
||||
FILE *file;
|
||||
@@ -231,18 +219,18 @@ int XMLwrapper::dosavefile(const char *filename,int compression,const char *xmld
|
||||
|
||||
void XMLwrapper::addpar(const string &name,int val)
|
||||
{
|
||||
addparams2("par","name",name.c_str(),"value",int2str(val));
|
||||
addparams("par",2,"name",name.c_str(),"value",stringFrom<int>(val).c_str());
|
||||
};
|
||||
|
||||
void XMLwrapper::addparreal(const string &name,REALTYPE val)
|
||||
{
|
||||
addparams2("par_real","name",name.c_str(),"value",real2str(val));
|
||||
addparams("par_real",2,"name",name.c_str(),"value",stringFrom<REALTYPE>(val).c_str());
|
||||
};
|
||||
|
||||
void XMLwrapper::addparbool(const string &name,int val)
|
||||
{
|
||||
if (val!=0) addparams2("par_bool","name",name.c_str(),"value","yes");
|
||||
else addparams2("par_bool","name",name.c_str(),"value","no");
|
||||
if (val!=0) addparams("par_bool",2,"name",name.c_str(),"value","yes");
|
||||
else addparams("par_bool",2,"name",name.c_str(),"value","no");
|
||||
};
|
||||
|
||||
void XMLwrapper::addparstr(const string &name,const string &val)
|
||||
@@ -255,19 +243,24 @@ void XMLwrapper::addparstr(const string &name,const string &val)
|
||||
|
||||
void XMLwrapper::beginbranch(const string &name)
|
||||
{
|
||||
push(node);
|
||||
node=addparams0(name.c_str());
|
||||
if(verbose)
|
||||
cout << "beginbranch()" << name << endl;
|
||||
node = addparams(name.c_str(),0);
|
||||
};
|
||||
|
||||
void XMLwrapper::beginbranch(const string &name,int id)
|
||||
{
|
||||
push(node);
|
||||
node=addparams1(name.c_str(),"id",int2str(id));
|
||||
if(verbose)
|
||||
cout << "beginbranch(" << id << ")" << name << endl;
|
||||
node = addparams(name.c_str(),1,"id",stringFrom<int>(id).c_str());
|
||||
};
|
||||
|
||||
void XMLwrapper::endbranch()
|
||||
{
|
||||
node=pop();
|
||||
if(verbose)
|
||||
cout << "endbranch()" << node << "-" << node->value.element.name << " To "
|
||||
<< node->parent << "-" << node->parent->value.element.name << endl;
|
||||
node = node->parent;
|
||||
};
|
||||
|
||||
|
||||
@@ -279,11 +272,6 @@ int XMLwrapper::loadXMLfile(const string &filename)
|
||||
if (tree!=NULL) mxmlDelete(tree);
|
||||
tree=NULL;
|
||||
|
||||
ZERO(&parentstack,(int)sizeof(parentstack));
|
||||
ZERO(&values,(int)sizeof(values));
|
||||
|
||||
stackpos=0;
|
||||
|
||||
const char *xmldata=doloadfile(filename.c_str());
|
||||
if (xmldata==NULL) return(-1);//the file could not be loaded or uncompressed
|
||||
|
||||
@@ -294,18 +282,23 @@ int XMLwrapper::loadXMLfile(const string &filename)
|
||||
if (tree==NULL) return(-2);//this is not XML
|
||||
|
||||
|
||||
node=root=mxmlFindElement(tree,tree,"ZynAddSubFX-data",NULL,NULL,MXML_DESCEND);
|
||||
node = root = mxmlFindElement(tree,tree,"ZynAddSubFX-data",NULL,NULL,MXML_DESCEND);
|
||||
if (root==NULL) return(-3);//the XML doesnt embbed zynaddsubfx data
|
||||
push(root);
|
||||
|
||||
values.xml_version.major=str2int(mxmlElementGetAttr(root,"version-major"));
|
||||
values.xml_version.minor=str2int(mxmlElementGetAttr(root,"version-minor"));
|
||||
//fetch version information
|
||||
version.Major = stringTo<int>(mxmlElementGetAttr(root,"version-major"));
|
||||
version.Minor = stringTo<int>(mxmlElementGetAttr(root,"version-minor"));
|
||||
version.Revision = stringTo<int>(mxmlElementGetAttr(root,"version-revision"));
|
||||
|
||||
if(verbose)
|
||||
cout << "loadXMLfile() version: " << version.Major << '.' << version.Minor << '.' << version.Revision << endl;
|
||||
|
||||
|
||||
return(0);
|
||||
};
|
||||
|
||||
|
||||
char *XMLwrapper::doloadfile(const string &filename)
|
||||
char *XMLwrapper::doloadfile(const string &filename) const
|
||||
{
|
||||
char * xmldata = NULL;
|
||||
gzFile gzfile = gzopen(filename.c_str(),"rb");
|
||||
@@ -338,23 +331,20 @@ char *XMLwrapper::doloadfile(const string &filename)
|
||||
|
||||
bool XMLwrapper::putXMLdata(const char *xmldata)
|
||||
{
|
||||
if (tree!=NULL) mxmlDelete(tree);
|
||||
if (tree!=NULL)
|
||||
mxmlDelete(tree);
|
||||
|
||||
tree=NULL;
|
||||
if (xmldata==NULL)
|
||||
return (false);
|
||||
|
||||
ZERO(&parentstack,(int)sizeof(parentstack));
|
||||
ZERO(&values,(int)sizeof(values));
|
||||
root = tree = mxmlLoadString(NULL,xmldata,MXML_OPAQUE_CALLBACK);
|
||||
if (tree==NULL)
|
||||
return(false);
|
||||
|
||||
stackpos=0;
|
||||
|
||||
if (xmldata==NULL) return (false);
|
||||
|
||||
root=tree=mxmlLoadString(NULL,xmldata,MXML_OPAQUE_CALLBACK);
|
||||
|
||||
if (tree==NULL) return(false);
|
||||
|
||||
node=root=mxmlFindElement(tree,tree,"ZynAddSubFX-data",NULL,NULL,MXML_DESCEND);
|
||||
if (root==NULL) return (false);;
|
||||
push(root);
|
||||
node = root = mxmlFindElement(tree,tree,"ZynAddSubFX-data",NULL,NULL,MXML_DESCEND);
|
||||
if (root==NULL)
|
||||
return (false);
|
||||
|
||||
return(true);
|
||||
};
|
||||
@@ -363,34 +353,41 @@ bool XMLwrapper::putXMLdata(const char *xmldata)
|
||||
|
||||
int XMLwrapper::enterbranch(const string &name)
|
||||
{
|
||||
node=mxmlFindElement(peek(),peek(),name.c_str(),NULL,NULL,MXML_DESCEND_FIRST);
|
||||
if (node==NULL) return(0);
|
||||
if(verbose)
|
||||
cout << "enterbranch() " << name << endl;
|
||||
mxml_node_t *tmp = mxmlFindElement(node,node,name.c_str(),NULL,NULL,MXML_DESCEND_FIRST);
|
||||
if (tmp==NULL)
|
||||
return(0);
|
||||
|
||||
push(node);
|
||||
node = tmp;
|
||||
return(1);
|
||||
};
|
||||
|
||||
int XMLwrapper::enterbranch(const string &name,int id)
|
||||
{
|
||||
snprintf(tmpstr,TMPSTR_SIZE,"%d",id);
|
||||
node=mxmlFindElement(peek(),peek(),name.c_str(),"id",tmpstr,MXML_DESCEND_FIRST);
|
||||
if (node==NULL) return(0);
|
||||
if(verbose)
|
||||
cout << "enterbranch("<<id<<") " << name << endl;
|
||||
mxml_node_t *tmp = mxmlFindElement(node,node,name.c_str(),"id",stringFrom<int>(id).c_str(),MXML_DESCEND_FIRST);
|
||||
if (tmp==NULL)
|
||||
return(0);
|
||||
|
||||
push(node);
|
||||
node = tmp;
|
||||
return(1);
|
||||
};
|
||||
|
||||
|
||||
void XMLwrapper::exitbranch()
|
||||
{
|
||||
/**@bug Does not set the current node correctly*/
|
||||
pop();
|
||||
if(verbose)
|
||||
cout << "exitbranch()" << node << "-" << node->value.element.name << " To "
|
||||
<< node->parent << "-" << node->parent->value.element.name << endl;
|
||||
node = node->parent;
|
||||
};
|
||||
|
||||
|
||||
int XMLwrapper::getbranchid(int min, int max)
|
||||
int XMLwrapper::getbranchid(int min, int max) const
|
||||
{
|
||||
int id=str2int(mxmlElementGetAttr(node,"id"));
|
||||
int id=stringTo<int>(mxmlElementGetAttr(node,"id"));
|
||||
if ((min==0)&&(max==0)) return(id);
|
||||
|
||||
if (id<min) id=min;
|
||||
@@ -399,63 +396,86 @@ int XMLwrapper::getbranchid(int min, int max)
|
||||
return(id);
|
||||
};
|
||||
|
||||
int XMLwrapper::getpar(const string &name,int defaultpar,int min,int max)
|
||||
int XMLwrapper::getpar(const string &name,int defaultpar,int min,int max) const
|
||||
{
|
||||
node=mxmlFindElement(peek(),peek(),"par","name",name.c_str(),MXML_DESCEND_FIRST);
|
||||
if (node==NULL) return(defaultpar);
|
||||
const mxml_node_t * tmp = mxmlFindElement(node,node,"par","name",name.c_str(),MXML_DESCEND_FIRST);
|
||||
|
||||
const char *strval=mxmlElementGetAttr(node,"value");
|
||||
if (tmp==NULL) return(defaultpar);
|
||||
|
||||
const char *strval=mxmlElementGetAttr(tmp,"value");
|
||||
if (strval==NULL) return(defaultpar);
|
||||
|
||||
int val=str2int(strval);
|
||||
int val=stringTo<int>(strval);
|
||||
if (val<min) val=min;
|
||||
else if (val>max) val=max;
|
||||
|
||||
return(val);
|
||||
};
|
||||
|
||||
int XMLwrapper::getpar127(const string &name,int defaultpar)
|
||||
int XMLwrapper::getpar127(const string &name,int defaultpar) const
|
||||
{
|
||||
return(getpar(name,defaultpar,0,127));
|
||||
};
|
||||
|
||||
int XMLwrapper::getparbool(const string &name,int defaultpar)
|
||||
int XMLwrapper::getparbool(const string &name,int defaultpar) const
|
||||
{
|
||||
node=mxmlFindElement(peek(),peek(),"par_bool","name",name.c_str(),MXML_DESCEND_FIRST);
|
||||
if (node==NULL) return(defaultpar);
|
||||
const mxml_node_t * tmp = mxmlFindElement(node,node,"par_bool","name",name.c_str(),MXML_DESCEND_FIRST);
|
||||
|
||||
const char *strval=mxmlElementGetAttr(node,"value");
|
||||
if (tmp==NULL) return(defaultpar);
|
||||
|
||||
const char *strval=mxmlElementGetAttr(tmp,"value");
|
||||
if (strval==NULL) return(defaultpar);
|
||||
|
||||
if ((strval[0]=='Y')||(strval[0]=='y')) return(1);
|
||||
else return(0);
|
||||
};
|
||||
|
||||
void XMLwrapper::getparstr(const string &name,char *par,int maxstrlen)
|
||||
void XMLwrapper::getparstr(const string &name,char *par,int maxstrlen) const
|
||||
{
|
||||
ZERO(par,maxstrlen);
|
||||
node=mxmlFindElement(peek(),peek(),"string","name",name.c_str(),MXML_DESCEND_FIRST);
|
||||
const mxml_node_t * tmp = mxmlFindElement(node,node,"string","name",name.c_str(),MXML_DESCEND_FIRST);
|
||||
|
||||
if (node==NULL) return;
|
||||
if (node->child==NULL) return;
|
||||
if (node->child->type!=MXML_OPAQUE) return;
|
||||
|
||||
snprintf(par,maxstrlen,"%s",node->child->value.element.name);
|
||||
if (tmp==NULL) return;
|
||||
if (tmp->child==NULL) return;
|
||||
if (tmp->child->type==MXML_OPAQUE){
|
||||
snprintf(par,maxstrlen,"%s",tmp->child->value.element.name);
|
||||
return;
|
||||
}
|
||||
if (tmp->child->type==MXML_TEXT && tmp->child->value.text.string!=NULL){
|
||||
snprintf(par,maxstrlen,"%s",tmp->child->value.text.string);
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
REALTYPE XMLwrapper::getparreal(const char *name,REALTYPE defaultpar)
|
||||
string XMLwrapper::getparstr(const string &name,const std::string &defaultpar) const
|
||||
{
|
||||
node=mxmlFindElement(peek(),peek(),"par_real","name",name,MXML_DESCEND_FIRST);
|
||||
if (node==NULL) return(defaultpar);
|
||||
const mxml_node_t * tmp = mxmlFindElement(node, node, "string", "name", name.c_str(), MXML_DESCEND_FIRST);
|
||||
|
||||
const char *strval=mxmlElementGetAttr(node,"value");
|
||||
if (tmp==NULL||tmp->child==NULL)
|
||||
return defaultpar;
|
||||
|
||||
if (tmp->child->type==MXML_OPAQUE && tmp->child->value.element.name!=NULL)
|
||||
return tmp->child->value.element.name;
|
||||
|
||||
if (tmp->child->type==MXML_TEXT && tmp->child->value.text.string!=NULL)
|
||||
return tmp->child->value.text.string;
|
||||
|
||||
return defaultpar;
|
||||
}
|
||||
|
||||
REALTYPE XMLwrapper::getparreal(const char *name,REALTYPE defaultpar) const
|
||||
{
|
||||
const mxml_node_t * tmp = mxmlFindElement(node,node,"par_real","name",name,MXML_DESCEND_FIRST);
|
||||
if (tmp==NULL) return(defaultpar);
|
||||
|
||||
const char *strval=mxmlElementGetAttr(tmp,"value");
|
||||
if (strval==NULL) return(defaultpar);
|
||||
|
||||
return(str2real(strval));
|
||||
return(stringTo<REALTYPE>(strval));
|
||||
};
|
||||
|
||||
REALTYPE XMLwrapper::getparreal(const char *name,REALTYPE defaultpar,REALTYPE min,REALTYPE max)
|
||||
REALTYPE XMLwrapper::getparreal(const char *name,REALTYPE defaultpar,REALTYPE min,REALTYPE max) const
|
||||
{
|
||||
REALTYPE result=getparreal(name,defaultpar);
|
||||
|
||||
@@ -467,89 +487,26 @@ REALTYPE XMLwrapper::getparreal(const char *name,REALTYPE defaultpar,REALTYPE mi
|
||||
|
||||
/** Private members **/
|
||||
|
||||
char *XMLwrapper::int2str(int x)
|
||||
mxml_node_t *XMLwrapper::addparams(const char *name, unsigned int params, ...) const
|
||||
{
|
||||
snprintf(tmpstr,TMPSTR_SIZE,"%d",x);
|
||||
return(tmpstr);
|
||||
};
|
||||
|
||||
char *XMLwrapper::real2str(REALTYPE x)
|
||||
{
|
||||
snprintf(tmpstr,TMPSTR_SIZE,"%g",x);
|
||||
return(tmpstr);
|
||||
};
|
||||
|
||||
int XMLwrapper::str2int(const char *str)
|
||||
{
|
||||
if (str==NULL) return(0);
|
||||
int result=strtol(str,NULL,10);
|
||||
return(result);
|
||||
};
|
||||
|
||||
REALTYPE XMLwrapper::str2real(const char *str)
|
||||
{
|
||||
if (str==NULL) return(0.0);
|
||||
REALTYPE result=strtod(str,NULL);
|
||||
return(result);
|
||||
};
|
||||
|
||||
|
||||
mxml_node_t *XMLwrapper::addparams0(const char *name)
|
||||
{
|
||||
mxml_node_t *element=mxmlNewElement(node,name);
|
||||
return(element);
|
||||
};
|
||||
|
||||
mxml_node_t *XMLwrapper::addparams1(const char *name,const char *par1,const char *val1)
|
||||
{
|
||||
mxml_node_t *element=mxmlNewElement(node,name);
|
||||
mxmlElementSetAttr(element,par1,val1);
|
||||
return(element);
|
||||
};
|
||||
|
||||
mxml_node_t *XMLwrapper::addparams2(const char *name,const char *par1,const char *val1,const char *par2, const char *val2)
|
||||
{
|
||||
mxml_node_t *element=mxmlNewElement(node,name);
|
||||
mxmlElementSetAttr(element,par1,val1);
|
||||
mxmlElementSetAttr(element,par2,val2);
|
||||
return(element);
|
||||
};
|
||||
|
||||
void XMLwrapper::push(mxml_node_t *node)
|
||||
{
|
||||
if (stackpos>=STACKSIZE-1) {
|
||||
cerr << "BUG!: XMLwrapper::push() - full parentstack" << endl;
|
||||
return;
|
||||
};
|
||||
stackpos++;
|
||||
parentstack[stackpos]=node;
|
||||
|
||||
// printf("push %d - %s\n",stackpos,node->value.element.name);
|
||||
|
||||
};
|
||||
mxml_node_t *XMLwrapper::pop()
|
||||
{
|
||||
if (stackpos<=0) {
|
||||
cerr << "BUG!: XMLwrapper::pop() - empty parentstack" << endl;
|
||||
return (root);
|
||||
};
|
||||
mxml_node_t *node=parentstack[stackpos];
|
||||
parentstack[stackpos]=NULL;
|
||||
|
||||
// printf("pop %d - %s\n",stackpos,node->value.element.name);
|
||||
|
||||
stackpos--;
|
||||
return(node);
|
||||
};
|
||||
|
||||
mxml_node_t *XMLwrapper::peek()
|
||||
{
|
||||
if (stackpos<=0) {
|
||||
cerr << "BUG!: XMLwrapper::peek() - empty parentstack" << endl;
|
||||
return (root);
|
||||
};
|
||||
return(parentstack[stackpos]);
|
||||
};
|
||||
/**@todo make this function send out a good error message if something goes
|
||||
* wrong**/
|
||||
mxml_node_t *element = mxmlNewElement(node, name);
|
||||
|
||||
if(params){
|
||||
va_list variableList;
|
||||
va_start(variableList, params);
|
||||
|
||||
const char *ParamName;
|
||||
const char *ParamValue;
|
||||
while(params--){
|
||||
ParamName = va_arg(variableList, const char *);
|
||||
ParamValue = va_arg(variableList, const char *);
|
||||
if(verbose)
|
||||
cout << "addparams()[" << params << "]=" << name << " " << ParamName <<"=\"" << ParamValue << "\"" << endl;
|
||||
mxmlElementSetAttr(element, ParamName, ParamValue);
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,11 +31,6 @@
|
||||
#ifndef XML_WRAPPER_H
|
||||
#define XML_WRAPPER_H
|
||||
|
||||
#define TMPSTR_SIZE 50
|
||||
|
||||
//the maxim tree depth
|
||||
#define STACKSIZE 100
|
||||
|
||||
/**Mxml wrapper*/
|
||||
class XMLwrapper
|
||||
{
|
||||
@@ -54,14 +49,14 @@ public:
|
||||
* @param filename the name of the destination file.
|
||||
* @returns 0 if ok or -1 if the file cannot be saved.
|
||||
*/
|
||||
int saveXMLfile(const std::string &filename);
|
||||
int saveXMLfile(const std::string &filename) const;
|
||||
|
||||
/**
|
||||
* Return XML tree as a string.
|
||||
* Note: The string must be freed with free() to deallocate
|
||||
* @returns a newly allocated NULL terminated string of the XML data.
|
||||
*/
|
||||
char *getXMLdata();
|
||||
char *getXMLdata() const;
|
||||
|
||||
/**
|
||||
* Add simple parameter.
|
||||
@@ -150,7 +145,7 @@ public:
|
||||
* if there isn't any id, will return min
|
||||
* this must be called only imediately after enterbranch()
|
||||
*/
|
||||
int getbranchid(int min, int max);
|
||||
int getbranchid(int min, int max) const;
|
||||
|
||||
/**
|
||||
* Returns the integer value stored in node name.
|
||||
@@ -162,21 +157,21 @@ public:
|
||||
* @param min The minimum return value.
|
||||
* @param max The maximum return value.
|
||||
*/
|
||||
int getpar(const std::string &name,int defaultpar,int min,int max);
|
||||
int getpar(const std::string &name,int defaultpar,int min,int max) const;
|
||||
|
||||
/**
|
||||
* Returns the integer value stored in the node with range [0,127].
|
||||
* @param name The parameter name.
|
||||
* @param defaultpar The default value if the real value is not found.
|
||||
*/
|
||||
int getpar127(const std::string &name,int defaultpar);
|
||||
int getpar127(const std::string &name,int defaultpar) const;
|
||||
|
||||
/**
|
||||
* Returns the boolean value stored in the node.
|
||||
* @param name The parameter name.
|
||||
* @param defaultpar The default value if the real value is not found.
|
||||
*/
|
||||
int getparbool(const std::string &name,int defaultpar);
|
||||
int getparbool(const std::string &name,int defaultpar) const;
|
||||
|
||||
/**
|
||||
* Get the string value stored in the node.
|
||||
@@ -184,14 +179,21 @@ public:
|
||||
* @param par Pointer to destination string
|
||||
* @param maxstrlen Max string length for destination
|
||||
*/
|
||||
void getparstr(const std::string &name,char *par,int maxstrlen);
|
||||
void getparstr(const std::string &name,char *par,int maxstrlen) const;
|
||||
|
||||
/**
|
||||
* Get the string value stored in the node.
|
||||
* @param name The parameter name.
|
||||
* @param defaultpar The default value if the real value is not found.
|
||||
*/
|
||||
std::string getparstr(const std::string &name,const std::string &defaultpar) const;
|
||||
|
||||
/**
|
||||
* Returns the real value stored in the node.
|
||||
* @param name The parameter name.
|
||||
* @param defaultpar The default value if the real value is not found.
|
||||
*/
|
||||
REALTYPE getparreal(const char *name,REALTYPE defaultpar);
|
||||
REALTYPE getparreal(const char *name,REALTYPE defaultpar) const;
|
||||
|
||||
/**
|
||||
* Returns the real value stored in the node.
|
||||
@@ -200,19 +202,18 @@ public:
|
||||
* @param min The minimum value
|
||||
* @param max The maximum value
|
||||
*/
|
||||
REALTYPE getparreal(const char *name,REALTYPE defaultpar,REALTYPE min,REALTYPE max);
|
||||
REALTYPE getparreal(const char *name,REALTYPE defaultpar,REALTYPE min,REALTYPE max) const;
|
||||
|
||||
bool minimal;/**<false if all parameters will be stored (used only for clipboard)*/
|
||||
|
||||
struct {
|
||||
bool PADsynth_used;/**<if PADsynth is used*/
|
||||
}information;/**<Defines if PADsynth is used*/
|
||||
|
||||
/**
|
||||
* Opens a file and parses the "information" section data on it.
|
||||
* @returns "true" if all went ok or "false" on errors.
|
||||
* Sets the current tree's PAD Synth usage
|
||||
*/
|
||||
bool checkfileinformation(const char *filename);
|
||||
void setPadSynth(bool enabled);
|
||||
/**
|
||||
* Checks the current tree for PADsynth usage
|
||||
*/
|
||||
bool hasPadSynth() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -222,7 +223,7 @@ private:
|
||||
* @param compression Level of gzip compression
|
||||
* @param xmldata String to be saved
|
||||
*/
|
||||
int dosavefile(const char *filename,int compression,const char *xmldata);
|
||||
int dosavefile(const char *filename,int compression,const char *xmldata) const;
|
||||
|
||||
/**
|
||||
* Loads specified file and returns data.
|
||||
@@ -231,86 +232,32 @@ private:
|
||||
* @param filename the file
|
||||
* @return The decompressed data
|
||||
*/
|
||||
char *doloadfile(const std::string &filename);
|
||||
|
||||
char *doloadfile(const std::string &filename) const;
|
||||
|
||||
mxml_node_t *tree;/**<all xml data*/
|
||||
mxml_node_t *root;/**<xml data used by zynaddsubfx*/
|
||||
mxml_node_t *node;/**<current node*/
|
||||
mxml_node_t *node;/**<current subtree in parsing or writing */
|
||||
mxml_node_t *info;/**<Node used to store the information about the data*/
|
||||
|
||||
/**
|
||||
* Adds params like this:
|
||||
* <name>.
|
||||
* @returns The node
|
||||
* Create mxml_node_t with specified name and parameters
|
||||
*
|
||||
* Results should look like:
|
||||
* <name optionalParam1="value1" optionalParam2="value2" ...>
|
||||
*
|
||||
* @param name The name of the xml node
|
||||
* @param params The number of the attributes
|
||||
* @param ... const char * pairs that are in the format attribute_name,
|
||||
* attribute_value
|
||||
*/
|
||||
mxml_node_t *addparams0(const char *name);
|
||||
mxml_node_t *addparams(const char *name, unsigned int params, ...) const;
|
||||
|
||||
/**
|
||||
* Adds params like this:
|
||||
* <name par1="val1">.
|
||||
* @returns The node
|
||||
*/
|
||||
mxml_node_t *addparams1(const char *name,const char *par1,const char *val1);
|
||||
|
||||
/**
|
||||
* Adds params like this:
|
||||
* <name par1="val1" par2="val2">.
|
||||
* @returns the node
|
||||
*/
|
||||
mxml_node_t *addparams2(const char *name,const char *par1,const char *val1,const char *par2, const char *val2);
|
||||
|
||||
/**
|
||||
* Convert integer to string
|
||||
* @param x integer input
|
||||
* @returns string output
|
||||
*/
|
||||
char *int2str(int x);
|
||||
|
||||
/**
|
||||
* Convert integer to string
|
||||
* @param x integer input
|
||||
* @returns string output
|
||||
*/
|
||||
char *real2str(REALTYPE x);
|
||||
|
||||
/**
|
||||
* Convert string to int
|
||||
* @param str string input
|
||||
* @returns integer output
|
||||
*/
|
||||
int str2int(const char *str);
|
||||
|
||||
/**
|
||||
* Convert string to realtype
|
||||
* @param x integer input
|
||||
* @returns string output
|
||||
*/
|
||||
REALTYPE str2real(const char *str);
|
||||
|
||||
/**Temporary string for various uses*/
|
||||
char tmpstr[TMPSTR_SIZE];
|
||||
|
||||
|
||||
/**this is used to store the parents.
|
||||
* @todo Use the stack class provided by C++*/
|
||||
mxml_node_t *parentstack[STACKSIZE];
|
||||
int stackpos;/**<position in stack*/
|
||||
|
||||
|
||||
void push(mxml_node_t *node);
|
||||
|
||||
/**Pops top node off of parent stack*/
|
||||
mxml_node_t *pop();
|
||||
/**Returns top node off of parent stack*/
|
||||
mxml_node_t *peek();
|
||||
|
||||
struct {
|
||||
struct {
|
||||
int major;/**<major version number.*/
|
||||
int minor;/**<minor version number.*/
|
||||
}xml_version;/**<Stores ZynAddSubFX versioning information*/
|
||||
}values;/**< Stores ZynAddSubFX versioning information*/
|
||||
/**@todo keep these numbers up to date*/
|
||||
struct{
|
||||
int Major;/**<major version number.*/
|
||||
int Minor;/**<minor version number.*/
|
||||
int Revision;/**<version revision number.*/
|
||||
}version;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -601,7 +601,7 @@ void PADnoteParameters::export2wav(string basefilename)
|
||||
|
||||
void PADnoteParameters::add2XML(XMLwrapper *xml)
|
||||
{
|
||||
xml->information.PADsynth_used=true;
|
||||
xml->setPadSynth(true);
|
||||
|
||||
xml->addparbool("stereo",PStereo);
|
||||
xml->addpar("mode",Pmode);
|
||||
|
||||
Reference in New Issue
Block a user