Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poc: fix the double shortname issue #1100 . #1102

Draft
wants to merge 1 commit into
base: master-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion architecture/android/app/oboe
Submodule oboe updated 743 files
2 changes: 1 addition & 1 deletion architecture/faust/gui/APIUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
11 changes: 8 additions & 3 deletions architecture/faust/gui/JSONUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class FAUST_API JSONUIReal : public PathBuilder, public Meta, public UIReal<REAL
{
if (popLabel()) {
// Shortnames can be computed when all fullnames are known
computeShortNames();
computeShortNamesNew();
}
fTab -= 1;
tab(fTab, fUI); fUI << "]";
Expand All @@ -313,6 +313,7 @@ class FAUST_API JSONUIReal : public PathBuilder, public Meta, public UIReal<REAL
{
std::string path = buildPath(label);
fFullPaths.push_back(path);
fFullPathsNew.push_back({path,varname});

fUI << fCloseUIPar;
tab(fTab, fUI); fUI << "{";
Expand Down Expand Up @@ -364,6 +365,7 @@ class FAUST_API JSONUIReal : public PathBuilder, public Meta, public UIReal<REAL
{
std::string path = buildPath(label);
fFullPaths.push_back(path);
fFullPathsNew.push_back({path,varname});

fUI << fCloseUIPar;
tab(fTab, fUI); fUI << "{";
Expand Down Expand Up @@ -429,7 +431,8 @@ class FAUST_API JSONUIReal : public PathBuilder, public Meta, public UIReal<REAL
{
std::string path = buildPath(label);
fFullPaths.push_back(path);

fFullPathsNew.push_back({path,varname});

fUI << fCloseUIPar;
tab(fTab, fUI); fUI << "{";
fTab += 1;
Expand Down Expand Up @@ -637,7 +640,9 @@ class FAUST_API JSONUIReal : public PathBuilder, public Meta, public UIReal<REAL
fUI.str("");
// Add N-1 sections
for (size_t i = 0; i < fAllUI.size()-1; i++) {
fUI << fAllUI[i] << fFull2Short[fFullPaths[i]] << "\",";
auto t = fFullPathsNew[i];
auto varname = std::get<1>(t);
fUI << fAllUI[i] << fVarname2Short[varname] << "\",";
}
// And the last one
fUI << fAllUI[fAllUI.size()-1];
Expand Down
2 changes: 1 addition & 1 deletion architecture/faust/gui/MapUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
130 changes: 130 additions & 0 deletions architecture/faust/gui/PathBuilder.cpp
Original file line number Diff line number Diff line change
@@ -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 <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <iostream> //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<std::string> uniquePathsNew; // all full paths transformed but made unique with a prefix
std::map<std::string, std::string> unique2varname; // all full paths transformed but made unique with a prefix

std::vector<std::string> uniquePaths; // all full paths transformed but made unique with a prefix
std::map<std::string, std::string> 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<std::string, int> 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<std::string> collisionSet;
std::map<std::string, std::string> 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;
}
}


11 changes: 9 additions & 2 deletions architecture/faust/gui/PathBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <map>
#include <string>
#include <algorithm>
#include <iostream> //for debugging

#include "faust/export.h"

Expand All @@ -44,7 +45,9 @@ class FAUST_API PathBuilder {

std::vector<std::string> fControlsLevel;
std::vector<std::string> fFullPaths;
std::vector<std::tuple<std::string,std::string>> fFullPathsNew;
std::map<std::string, std::string> fFull2Short; // filled by computeShortNames()
std::map<std::string, std::string> fVarname2Short; // filled by computeShortNamesNew()

/**
* @brief check if a character is acceptable for an ID
Expand Down Expand Up @@ -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<std::string> uniquePaths; // all full paths transformed but made unique with a prefix
Expand Down Expand Up @@ -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; }

};
Expand Down
2 changes: 1 addition & 1 deletion architecture/faust/gui/mspUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion architecture/smartKeyboard/android/app/oboe
Submodule oboe updated 743 files
2 changes: 1 addition & 1 deletion build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

####################################
Expand Down
8 changes: 4 additions & 4 deletions compiler/generator/json_instructions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading