diff --git a/architecture/android/app/oboe b/architecture/android/app/oboe index 7146098e03..272cf29422 160000 --- a/architecture/android/app/oboe +++ b/architecture/android/app/oboe @@ -1 +1 @@ -Subproject commit 7146098e03573eeaf6ad48176ab12b37fec18237 +Subproject commit 272cf29422bd8824d74481ce5cadbbdab66d8332 diff --git a/architecture/faust/gui/APIUI.h b/architecture/faust/gui/APIUI.h index 5a75f954cc..678c85881b 100644 --- a/architecture/faust/gui/APIUI.h +++ b/architecture/faust/gui/APIUI.h @@ -281,7 +281,7 @@ class APIUI : public PathBuilder, public Meta, public UI { if (popLabel()) { // Shortnames can be computed when all fullnames are known - computeShortNames(); + computeShortNamesNew(); // Fill 'shortname' field for each item for (const auto& it : fFull2Short) { int index = getParamIndex(it.first.c_str()); diff --git a/architecture/faust/gui/JSONUI.h b/architecture/faust/gui/JSONUI.h index b45b1de3ee..96b8bda6ec 100644 --- a/architecture/faust/gui/JSONUI.h +++ b/architecture/faust/gui/JSONUI.h @@ -298,7 +298,7 @@ class FAUST_API JSONUIReal : public PathBuilder, public Meta, public UIReal(t); + fUI << fAllUI[i] << fVarname2Short[varname] << "\","; } // And the last one fUI << fAllUI[fAllUI.size()-1]; diff --git a/architecture/faust/gui/MapUI.h b/architecture/faust/gui/MapUI.h index c1a2c3bd32..b6a1afcdee 100644 --- a/architecture/faust/gui/MapUI.h +++ b/architecture/faust/gui/MapUI.h @@ -89,7 +89,7 @@ class FAUST_API MapUI : public UI, public PathBuilder { if (popLabel()) { // Shortnames can be computed when all fullnames are known - computeShortNames(); + computeShortNamesNew(); // Fill 'shortname' map for (const auto& it : fFullPaths) { fShortnameZoneMap[fFull2Short[it]] = fPathZoneMap[it]; diff --git a/architecture/faust/gui/PathBuilder.cpp b/architecture/faust/gui/PathBuilder.cpp new file mode 100644 index 0000000000..523ba67fac --- /dev/null +++ b/architecture/faust/gui/PathBuilder.cpp @@ -0,0 +1,130 @@ +/************************** BEGIN PathBuilder.cpp ************************** + FAUST Architecture File + Copyright (C) 2003-2022 GRAME, Centre National de Creation Musicale + --------------------------------------------------------------------- + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + EXCEPTION : As a special exception, you may create a larger work + that contains this FAUST architecture section and distribute + that work under terms of your choice, so long as this FAUST + architecture section is not modified. + ************************************************************************/ + +#include "PathBuilder.h" +#include +#include +#include +#include +#include +#include //for debugging + +#include "faust/export.h" + +/******************************************************************************* + * PathBuilder : Faust User Interface + * Helper class to build complete hierarchical path for UI items. + ******************************************************************************/ + +void PathBuilder::addFullPathNew(const std::string& label,const std::string& varname) { fFullPathsNew.push_back({buildPath(label),varname}); } + +// Assuming shortnames have been built, return the shortname from a label +std::string PathBuilder::buildShortnameNew(const std::string& varname) + { + return (hasShortname()) ? fVarname2Short[varname] : ""; + } + +void PathBuilder::computeShortNamesNew() + { + std::vector uniquePathsNew; // all full paths transformed but made unique with a prefix + std::map unique2varname; // all full paths transformed but made unique with a prefix + + std::vector uniquePaths; // all full paths transformed but made unique with a prefix + std::map unique2full; // all full paths transformed but made unique with a prefix + char num_buffer[16]; + int pnum = 0; + + std::cerr << "fFullPaths len:"<< fFullPaths.size() << std::endl; + std::cerr << "fFullPathsNew len:"<< fFullPathsNew.size() << std::endl; + for (const auto& t : fFullPathsNew) { + std::string s; + std::string varname; + std::tie(s,varname) = t; + std::cerr << "fFullPathsNew s:"<< s << std::endl; + std::cerr << "fFullPathsNew varname:"<< varname << std::endl; + snprintf(num_buffer, 16, "%d", pnum++); + std::string u = "/P" + std::string(num_buffer) + str2ID(remove0x00(s)); + uniquePathsNew.push_back(u); + unique2varname[u] = varname; // remember the varname associated to a unique path + } + + pnum = 0; + for (const auto& s : fFullPaths) { + // std::string s; + // std::string varname; + // std::tie(s,varname) = t; + // std::cerr << "s:"<< s << std::endl; + // std::cerr << "v:"<< varname << std::endl; + + // Using snprintf since Teensy does not have the std::to_string function + snprintf(num_buffer, 16, "%d", pnum++); + std::string u = "/P" + std::string(num_buffer) + str2ID(remove0x00(s)); + uniquePaths.push_back(u); + unique2full[u] = s; // remember the full path associated to a unique path + std::cerr << "uniquePath u:"<< u << std::endl; + std::cerr << "fullPath s:"<< s << std::endl; + } + + std::map uniquePath2level; // map path to level + for (const auto& s : uniquePaths) uniquePath2level[s] = 1; // we init all levels to 1 + bool have_collisions = true; + + while (have_collisions) { + // compute collision list + std::set collisionSet; + std::map short2full; + have_collisions = false; + for (const auto& it : uniquePath2level) { + std::string u = it.first; + int n = it.second; + std::string shortName = cut(u, n); + auto p = short2full.find(shortName); + if (p == short2full.end()) { + // no collision + short2full[shortName] = u; + } else { + // we have a collision, add the two paths to the collision set + have_collisions = true; + collisionSet.insert(u); + collisionSet.insert(p->second); + } + } + for (const auto& s : collisionSet) uniquePath2level[s]++; // increase level of colliding path + } + + for (const auto& it : uniquePath2level) { + std::string u = it.first; + int n = it.second; + std::string shortName = replaceCharList(cut(u, n), {'/'}, '_'); + std::cerr << "u:" << u << std::endl; + std::cerr << "n:" << n << std::endl; + std::cerr << "cut(u, n):" << cut(u, n) << std::endl; + std::cerr << "shortName:" << shortName << std::endl; + fFull2Short[unique2full[u]] = shortName; + fVarname2Short[unique2varname[u]] = shortName; + // fFull2Short[varname] = shortName; + } + } + + diff --git a/architecture/faust/gui/PathBuilder.h b/architecture/faust/gui/PathBuilder.h index d688407e56..b6a8e6d78c 100644 --- a/architecture/faust/gui/PathBuilder.h +++ b/architecture/faust/gui/PathBuilder.h @@ -30,6 +30,7 @@ #include #include #include +#include //for debugging #include "faust/export.h" @@ -44,7 +45,9 @@ class FAUST_API PathBuilder { std::vector fControlsLevel; std::vector fFullPaths; + std::vector> fFullPathsNew; std::map fFull2Short; // filled by computeShortNames() + std::map fVarname2Short; // filled by computeShortNamesNew() /** * @brief check if a character is acceptable for an ID @@ -128,10 +131,11 @@ class FAUST_API PathBuilder { } void addFullPath(const std::string& label) { fFullPaths.push_back(buildPath(label)); } - + void addFullPathNew(const std::string& label,const std::string& varname); /** * @brief Compute the mapping between full path and short names */ + void computeShortNamesNew(); void computeShortNames() { std::vector uniquePaths; // all full paths transformed but made unique with a prefix @@ -225,7 +229,10 @@ class FAUST_API PathBuilder { { return (hasShortname()) ? fFull2Short[buildPath(label)] : ""; } - + + // Assuming shortnames have been built, return the shortname from a label + std::string buildShortnameNew(const std::string& varname); + bool hasShortname() { return fFull2Short.size() > 0; } }; diff --git a/architecture/faust/gui/mspUI.h b/architecture/faust/gui/mspUI.h index 0782438c6e..13b5d1ddff 100644 --- a/architecture/faust/gui/mspUI.h +++ b/architecture/faust/gui/mspUI.h @@ -342,7 +342,7 @@ class mspUI : public UI, public PathBuilder fDeclareTable.clear(); if (popLabel()) { // Shortnames can be computed when all fullnames are known - computeShortNames(); + computeShortNamesNew(); // Fill 'shortname' map for (const auto& path : fFullPaths) { if (fInputPathTable.count(path)) { diff --git a/architecture/max-msp/py2max b/architecture/max-msp/py2max index 3aaa8cad3f..b7ca256184 160000 --- a/architecture/max-msp/py2max +++ b/architecture/max-msp/py2max @@ -1 +1 @@ -Subproject commit 3aaa8cad3f2d777a5e586c8a3b8063e1e9092c5b +Subproject commit b7ca256184f5da07b2d11bcd6601aeb5ef5d1871 diff --git a/architecture/smartKeyboard/android/app/oboe b/architecture/smartKeyboard/android/app/oboe index 7146098e03..272cf29422 160000 --- a/architecture/smartKeyboard/android/app/oboe +++ b/architecture/smartKeyboard/android/app/oboe @@ -1 +1 @@ -Subproject commit 7146098e03573eeaf6ad48176ab12b37fec18237 +Subproject commit 272cf29422bd8824d74481ce5cadbbdab66d8332 diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 0681ab21ff..26882d5b24 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -50,7 +50,7 @@ endif() #################################### # source and headers files -file (GLOB SRC ${SRCDIR}/*.cpp ${SRCDIR}/*/*.cpp ${SRCDIR}/draw/*/*.cpp ${SRCDIR}/generator/fir/*.cpp) +file (GLOB SRC ${SRCDIR}/*.cpp ${SRCDIR}/*/*.cpp ${SRCDIR}/draw/*/*.cpp ${SRCDIR}/generator/fir/*.cpp ${ROOT}/architecture/faust/gui/*.cpp) file (GLOB HH ${SRCDIR}/*.hh ${SRCDIR}/*/*.hh ${SRCDIR}/generator/fir/*.hh) #################################### diff --git a/compiler/generator/json_instructions.hh b/compiler/generator/json_instructions.hh index 1f6a410950..1e45f00759 100644 --- a/compiler/generator/json_instructions.hh +++ b/compiler/generator/json_instructions.hh @@ -200,15 +200,15 @@ struct ShortnameInstVisitor : public DispatchVisitor, public PathBuilder { { if (popLabel()) { // Shortnames can be computed when all fullnames are known - computeShortNames(); + computeShortNamesNew(); } } - virtual void visit(AddButtonInst* inst) override { addFullPath(inst->fLabel); } + virtual void visit(AddButtonInst* inst) override { addFullPath(inst->fLabel); addFullPathNew(inst->fLabel,inst->fZone); } - virtual void visit(AddSliderInst* inst) override { addFullPath(inst->fLabel); } + virtual void visit(AddSliderInst* inst) override { addFullPath(inst->fLabel); addFullPathNew(inst->fLabel,inst->fZone); } - virtual void visit(AddBargraphInst* inst) override { addFullPath(inst->fLabel); } + virtual void visit(AddBargraphInst* inst) override { addFullPath(inst->fLabel); addFullPathNew(inst->fLabel,inst->fZone); } }; #endif