Krotos Modules 3
Loading...
Searching...
No Matches
UCSToFile.cpp
Go to the documentation of this file.
2
3namespace krotos
4{
5UCSToFile::UCSToFile() : juce::Thread("UCSThread")
6{
7 startThread(); // set a priority?
8}
9
10UCSToFile::~UCSToFile() { stopThread(4000); }
11
13{
14 std::set<std::string> filenames;
15 std::size_t count = 0;
17 for (const auto& path : File(root).findChildFiles(2, true, "*.wav"))
18 {
19 if (threadShouldExit())
20 break;
21
22 auto basename = path.getFileName().toStdString();
23 // try to avoid duplicate files coming from different folders
24 if (filenames.count(basename) == 0)
25 {
26 StringArray tokens;
27 tokens.addTokens(path.getFileName(), StringRef("_"), StringRef(""));
28 if (!tokens.isEmpty())
29 {
30 auto key = tokens[0];
31 if (m_UCS.isValid(key))
32 {
33 // valid UCS CatID found
34 m_filesByCatID[key].push_back(path);
35 ++count;
36 }
37 }
38 }
39 filenames.insert(basename);
40 }
41 filenames.clear();
42
43 m_menu = buildMenu();
44}
45
47{
48 int fileCount = 0;
49
50 std::map<String, PopupMenu> menus;
51 auto catIDMap = m_UCS.catIDMap();
52 for (const auto& element : catIDMap)
53 {
54 const auto key = element.first;
55 const auto value = element.second;
56
57 StringArray tokens;
58 tokens.addTokens(value, StringRef(","), StringRef(""));
59
60 jassert(tokens.size() == 2); // expecting "Category, SubCategory"
61 const auto category = tokens[0];
62 const auto subcategory = tokens[1];
63
64 auto index = std::distance(catIDMap.begin(), catIDMap.find(key));
65 bool isEnabled = true; // check if we have files available for this CatID?
66 if (m_filesByCatID.count(key) > 0)
67 {
68 auto files = m_filesByCatID[key];
69 if (!files.empty())
70 {
71 PopupMenu m;
72 int i = 0;
73 for (auto file : files)
74 {
75 m.addItem(++fileCount, file.getFileName());
76 m_indexToKeyValue.push_back(std::make_pair(key, i));
77 ++i;
78 }
79 menus[category].addSubMenu(subcategory, m);
80 }
81 }
82 }
83
84 PopupMenu m;
85 for (const auto& element : menus)
86 {
87 auto key = element.first; // Category
88 auto value = element.second; // PopupMenu
89 m.addSubMenu(key, value);
90 }
91 return m;
92}
93
94PopupMenu UCSToFile::getMenu() { return m_menu; }
95
97{
98 jassert(index > 0);
99 auto result = m_indexToKeyValue[index - 1];
100 return m_filesByCatID[result.first][result.second];
101}
102} // namespace krotos
static String readFactorySamplesPath()
Definition AssetManager.cpp:112
PopupMenu m_menu
Definition UCSToFile.h:20
std::vector< std::pair< String, int > > m_indexToKeyValue
Definition UCSToFile.h:22
UCSToFile()
Definition UCSToFile.cpp:5
PopupMenu buildMenu()
Definition UCSToFile.cpp:46
File getFileFromMenuID(int index)
Definition UCSToFile.cpp:96
void run() override
Definition UCSToFile.cpp:12
PopupMenu getMenu()
Definition UCSToFile.cpp:94
UniversalCategorySystem m_UCS
Definition UCSToFile.h:18
std::map< String, std::vector< File > > m_filesByCatID
Definition UCSToFile.h:21
~UCSToFile()
Definition UCSToFile.cpp:10
std::map< String, String > catIDMap()
Definition UniversalCategorySystem.h:11
bool isValid(String catID) const
Definition UniversalCategorySystem.cpp:767
Definition AirAbsorptionFilter.cpp:2