zynaddsubfx

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

commit b49feaebd1051aaf3773fbeb6278332448b2b2e0
parent b2c8ce4176e4673e09ce7afdbec045f6fb244380
Author: friedolino78 <34608315+friedolino78@users.noreply.github.com>
Date:   Sun, 28 Jun 2020 22:21:51 +0200

Merge pull request #49 from friedolino78/preset-handling

add /savexml port 
savexml stores current preset to the file it was loaded from.
new presets are stored to a filename created from date and time.
Diffstat:
Msrc/Misc/Part.cpp | 26++++++++++++++++++++++++--
Msrc/Misc/Part.h | 1+
2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/Misc/Part.cpp b/src/Misc/Part.cpp @@ -165,8 +165,19 @@ static const Ports partPorts = { //d.broadcast("/damage", "s", part_loc); }}, - - + {"savexml:", rProp(internal) rDoc("Save Part to the file it has been loaded from"), 0, + [](const char *, RtData &d) + { + Part *p = (Part*)d.obj; + if (p->loaded_file[0] == '\0') { // if part was never loaded or saved + time_t rawtime; // make a new name from date and time + time (&rawtime); + const struct tm* timeinfo = localtime (&rawtime); + strftime (p->loaded_file,23,"%F_%R.xiz",timeinfo); + } + p->saveXML(p->loaded_file); + fprintf(stderr, "Part %d saved to %s\n", (p->partno + 1), p->loaded_file); + }}, //{"kit#16::T:F", "::Enables or disables kit item", 0, // [](const char *m, RtData &d) { // auto loc = d.loc; @@ -257,6 +268,8 @@ Part::Part(Allocator &alloc, const SYNTH_T &synth_, const AbsTime &time_, gzip_compression(gzip_compression), interpolation(interpolation) { + loaded_file[0] = '\0'; + if(prefix_) fast_strcpy(prefix, prefix_, sizeof(prefix)); else @@ -1077,6 +1090,8 @@ int Part::saveXML(const char *filename) xml.endbranch(); int result = xml.saveXMLfile(filename, gzip_compression); + strncpy(loaded_file,filename, sizeof(loaded_file)); + loaded_file[sizeof(loaded_file)-1] = '\0'; return result; } @@ -1089,6 +1104,13 @@ int Part::loadXMLinstrument(const char *filename) if(xml.enterbranch("INSTRUMENT") == 0) return -10; + + // store filename in member variable + int length = sizeof(loaded_file)-1; + strncpy(loaded_file, filename, length); + // set last element to \0 in case filname is too long or not terminated + loaded_file[length]='\0'; + getfromXMLinstrument(xml); xml.exitbranch(); diff --git a/src/Misc/Part.h b/src/Misc/Part.h @@ -173,6 +173,7 @@ class Part bool Pefxbypass[NUM_PART_EFX]; //if the effects are bypassed int lastnote; + char loaded_file[256]; const static rtosc::Ports &ports;