gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit 079454ce88742ae7f87ae1809c29c5099b985782
parent e7574e39c4fe14440ffc9a82c98f5cddab480892
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Sat, 14 Dec 2024 02:17:30 +0100

move file system functions to base lib

Diffstat:
Msource/baseLib/CMakeLists.txt | 1+
Asource/baseLib/filesystem.cpp | 413+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asource/baseLib/filesystem.h | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msource/bridge/client/remoteDevice.cpp | 6+++---
Msource/bridge/server/config.cpp | 10+++++-----
Msource/bridge/server/import.cpp | 6+++++-
Msource/bridge/server/romPool.cpp | 12+++++++-----
Msource/hardwareLib/i2cFlash.cpp | 6+++---
Msource/jucePluginEditorLib/filetype.cpp | 4++--
Msource/jucePluginEditorLib/partbutton.cpp | 4+---
Msource/jucePluginEditorLib/patchmanager/datasourcetreeitem.cpp | 5+++--
Msource/jucePluginEditorLib/patchmanager/grouptreeitem.cpp | 4++--
Msource/jucePluginEditorLib/patchmanager/patchmanager.cpp | 6+++---
Msource/jucePluginEditorLib/pluginEditor.cpp | 4+++-
Msource/jucePluginEditorLib/pluginEditorState.cpp | 23+++++++++++++----------
Msource/jucePluginLib/clipboard.cpp | 6++++--
Msource/jucePluginLib/patchdb/db.cpp | 22+++++++++++-----------
Msource/jucePluginLib/processor.cpp | 11++++++-----
Msource/jucePluginLib/tools.cpp | 6+++---
Msource/juceUiLib/editor.cpp | 6+++---
Msource/mqJucePlugin/PluginEditorState.cpp | 2--
Msource/mqJucePlugin/mqController.cpp | 2--
Msource/mqLib/microq.cpp | 1-
Msource/mqLib/mqstate.cpp | 1-
Msource/mqLib/romloader.cpp | 2--
Msource/nord/n2x/n2xJucePlugin/n2xController.cpp | 4++--
Msource/nord/n2x/n2xJucePlugin/n2xPluginEditorState.cpp | 2--
Msource/nord/n2x/n2xLib/n2xflash.cpp | 5++++-
Msource/nord/n2x/n2xLib/n2xmc.cpp | 4++--
Msource/nord/n2x/n2xLib/n2xrom.cpp | 2--
Msource/nord/n2x/n2xLib/n2xromdata.cpp | 6++++--
Msource/synthLib/lv2PresetExport.cpp | 14+++++++-------
Msource/synthLib/midiToSysex.cpp | 4++--
Msource/synthLib/os.cpp | 392++++---------------------------------------------------------------------------
Msource/synthLib/os.h | 45+--------------------------------------------
Msource/synthLib/romLoader.cpp | 10++++++----
Msource/virusIntegrationTest/integrationTest.cpp | 16++++++++--------
Msource/virusJucePlugin/PatchManager.cpp | 1-
Msource/virusJucePlugin/VirusController.cpp | 1-
Msource/virusJucePlugin/VirusEditor.cpp | 2--
Msource/virusJucePlugin/VirusEditorState.cpp | 2--
Msource/virusJucePlugin/VirusProcessor.cpp | 8++++----
Msource/virusLib/demoplayback.cpp | 5+++--
Msource/virusLib/midiFileToRomData.cpp | 1-
Msource/virusLib/romfile.cpp | 2--
Msource/virusLib/romloader.cpp | 18+++++++++---------
Msource/virusTestConsole/virusTestConsole.cpp | 6+++---
Msource/wLib/wRom.cpp | 7++++---
Msource/xtJucePlugin/PluginEditorState.cpp | 2--
Msource/xtJucePlugin/weData.cpp | 19++++++++++---------
Msource/xtJucePlugin/xtController.cpp | 2--
Msource/xtLib/xt.cpp | 2--
Msource/xtLib/xtRomLoader.cpp | 7++++---
Msource/xtLib/xtState.cpp | 1-
Msource/xtTestConsole/xtTestConsole.cpp | 2--
55 files changed, 634 insertions(+), 575 deletions(-)

diff --git a/source/baseLib/CMakeLists.txt b/source/baseLib/CMakeLists.txt @@ -7,6 +7,7 @@ set(SOURCES binarystream.cpp binarystream.h commandline.cpp commandline.h configFile.cpp configFile.h + filesystem.cpp filesystem.h hybridcontainer.h md5.cpp md5.h propertyMap.cpp propertyMap.h diff --git a/source/baseLib/filesystem.cpp b/source/baseLib/filesystem.cpp @@ -0,0 +1,413 @@ +#include "filesystem.h" + +#include <array> +#include <iostream> + +#ifndef _WIN32 +// filesystem is only available on macOS Catalina 10.15+ +// filesystem causes linker errors in gcc-8 if linked statically +#define USE_DIRENT +#include <cstdlib> +#include <cstring> +#include <pwd.h> +#endif + +#ifdef USE_DIRENT +#include <dirent.h> +#include <unistd.h> +#include <sys/stat.h> +#else +#include <filesystem> +#endif + +#ifdef _WIN32 +#define NOMINMAX +#define NOSERVICE +#include <Windows.h> +#include <shlobj_core.h> +#else +#include <dlfcn.h> +#endif + +#ifdef _MSC_VER +#include <cfloat> +#elif defined(HAVE_SSE) +#include <immintrin.h> +#endif + +#ifdef __APPLE__ +#include <sys/types.h> +#include <sys/sysctl.h> +#endif + +namespace baseLib::filesystem +{ +#ifdef _WIN32 + constexpr char g_nativePathSeparator = '\\'; +#else + constexpr char g_nativePathSeparator = '/'; +#endif + constexpr char g_otherPathSeparator = g_nativePathSeparator == '\\' ? '/' : '\\'; + + std::string getCurrentDirectory() + { +#ifdef USE_DIRENT + char temp[1024]; + getcwd(temp, sizeof(temp)); + return temp; +#else + return std::filesystem::current_path().string(); +#endif + } + + bool createDirectory(const std::string& _dir) + { +#ifdef USE_DIRENT + constexpr auto dirAttribs = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH; + for(size_t i=0; i<_dir.size(); ++i) + { + if(_dir[i] == '/' || _dir[i] == '\\') + { + const auto d = _dir.substr(0,i); + mkdir(d.c_str(), dirAttribs); + } + } + return mkdir(_dir.c_str(), dirAttribs) == 0; +#else + return std::filesystem::create_directories(_dir); +#endif + } + + std::string validatePath(std::string _path) + { + if(_path.empty()) + return _path; + + for (char& ch : _path) + { + if(ch == g_otherPathSeparator) + ch = g_nativePathSeparator; + } + + if(_path.back() == g_nativePathSeparator) + return _path; + + _path += g_nativePathSeparator; + return _path; + } + + bool getDirectoryEntries(std::vector<std::string>& _files, const std::string& _folder) + { +#ifdef USE_DIRENT + DIR *dir; + struct dirent *ent; + if ((dir = opendir(_folder.c_str()))) + { + while ((ent = readdir(dir))) + { + std::string f = ent->d_name; + + if(f == "." || f == "..") + continue; + + std::string file = _folder; + + if(file.back() != '/' && file.back() != '\\') + file += '/'; + + file += f; + + _files.push_back(file); + } + closedir(dir); + } + else + { + LOG("Failed to open directory " << _folder << ", error " << errno); + return false; + } +#else + try + { + const auto u8Path = std::filesystem::u8path(_folder); + for (const std::filesystem::directory_entry &entry : std::filesystem::directory_iterator(u8Path)) + { + const auto &file = entry.path(); + + try + { + _files.push_back(file.u8string()); + } + catch(std::exception& e) + { + //LOG(e.what()); + std::cerr << e.what() << '\n'; + } + } + } + catch (std::exception& e) + { + //LOG(e.what()); + std::cerr << e.what() << '\n'; + return false; + } +#endif + return !_files.empty(); + } + + bool findFiles(std::vector<std::string>& _files, const std::string& _rootPath, const std::string& _extension, const size_t _minSize, const size_t _maxSize) + { + std::vector<std::string> files; + + getDirectoryEntries(files, _rootPath); + + for (const auto& file : files) + { + if(!hasExtension(file, _extension)) + continue; + + if (!_minSize && !_maxSize) + { + _files.push_back(file); + continue; + } + + const auto size = getFileSize(file); + + if (_minSize && size < _minSize) + continue; + if (_maxSize && size > _maxSize) + continue; + + _files.push_back(file); + } + return !_files.empty(); + } + + std::string findFile(const std::string& _rootPath, const std::string& _extension, const size_t _minSize, const size_t _maxSize) + { + std::vector<std::string> files; + if(!findFiles(files, _rootPath, _extension, _minSize, _maxSize)) + return {}; + return files.front(); + } + + + std::string lowercase(const std::string &_src) + { + std::string str(_src); + for (char& i : str) + i = static_cast<char>(tolower(i)); + return str; + } + + std::string getExtension(const std::string &_name) + { + const auto pos = _name.find_last_of('.'); + if (pos != std::string::npos) + return _name.substr(pos); + return {}; + } + + std::string stripExtension(const std::string& _name) + { + const auto pos = _name.find_last_of('.'); + if (pos != std::string::npos) + return _name.substr(0, pos); + return _name; + } + + std::string getFilenameWithoutPath(const std::string& _name) + { + const auto pos = _name.find_last_of("/\\"); + if (pos != std::string::npos) + return _name.substr(pos + 1); + return _name; + } + + std::string getPath(const std::string& _filename) + { + const auto pos = _filename.find_last_of("/\\"); + if (pos != std::string::npos) + return _filename.substr(0, pos); + return _filename; + } + + size_t getFileSize(const std::string& _file) + { + FILE* hFile = openFile(_file, "rb"); + if (!hFile) + return 0; + + fseek(hFile, 0, SEEK_END); + const auto size = static_cast<size_t>(ftell(hFile)); + fclose(hFile); + return size; + } + + bool isDirectory(const std::string& _path) + { +#ifdef USE_DIRENT + struct stat statbuf; + stat(_path.c_str(), &statbuf); + if (S_ISDIR(statbuf.st_mode)) + return true; + return false; +#else + return std::filesystem::is_directory(_path); +#endif + } + bool hasExtension(const std::string& _filename, const std::string& _extension) + { + if (_extension.empty()) + return true; + + return lowercase(getExtension(_filename)) == lowercase(_extension); + } + + bool writeFile(const std::string& _filename, const std::vector<uint8_t>& _data) + { + return writeFile(_filename, _data.data(), _data.size()); + } + + bool writeFile(const std::string& _filename, const uint8_t* _data, size_t _size) + { + auto* hFile = openFile(_filename, "wb"); + if(!hFile) + return false; + const auto written = fwrite(&_data[0], 1, _size, hFile); + fclose(hFile); + return written == _size; + } + + bool readFile(std::vector<uint8_t>& _data, const std::string& _filename) + { + auto* hFile = openFile(_filename, "rb"); + if(!hFile) + return false; + + fseek(hFile, 0, SEEK_END); + const auto size = ftell(hFile); + fseek(hFile, 0, SEEK_SET); + + if(!size) + { + fclose(hFile); + _data.clear(); + return true; + } + + if(_data.size() != static_cast<size_t>(size)) + _data.resize(size); + + const auto read = fread(_data.data(), 1, _data.size(), hFile); + fclose(hFile); + return read == _data.size(); + } + + FILE* openFile(const std::string& _name, const char* _mode) + { +#ifdef _WIN32 + // convert filename + std::wstring nameW; + nameW.resize(_name.size()); + const int newSize = MultiByteToWideChar(CP_UTF8, 0, _name.c_str(), static_cast<int>(_name.size()), const_cast<wchar_t *>(nameW.c_str()), static_cast<int>(_name.size())); + nameW.resize(newSize); + + // convert mode + wchar_t mode[32]{0}; + MultiByteToWideChar(CP_UTF8, 0, _mode, static_cast<int>(strlen(_mode)), mode, (int)std::size(mode)); + return _wfopen(nameW.c_str(), mode); +#else + return fopen(_name.c_str(), _mode); +#endif + } + + std::string getHomeDirectory() + { +#ifdef _WIN32 + std::array<char, MAX_PATH<<1> data; + if (SHGetSpecialFolderPathA (nullptr, data.data(), CSIDL_PROFILE, FALSE)) + return validatePath(data.data()); + + const auto* home = getenv("USERPROFILE"); + if (home) + return home; + + const auto* drive = getenv("HOMEDRIVE"); + const auto* path = getenv("HOMEPATH"); + + if (drive && path) + return std::string(drive) + std::string(path); + + return "C:\\Users\\Default"; // meh, what can we do? +#else + const char* home = getenv("HOME"); + if (home && strlen(home) > 0) + return home; + const auto* pw = getpwuid(getuid()); + if(pw) + return std::string(pw->pw_dir); + return "/tmp"; // better ideas welcome +#endif + } + + std::string getSpecialFolderPath(const SpecialFolderType _type) + { +#ifdef _WIN32 + std::array<char, MAX_PATH<<1> path; + + int csidl; + switch (_type) + { + case SpecialFolderType::UserDocuments: + csidl = CSIDL_PERSONAL; + break; + case SpecialFolderType::PrivateAppData: + csidl = CSIDL_APPDATA; + break; + default: + return {}; + } + if (SHGetSpecialFolderPathA (nullptr, path.data(), csidl, FALSE)) + return validatePath(path.data()); +#else + const auto h = std::getenv("HOME"); + const std::string home = validatePath(getHomeDirectory()); + +#if defined(__APPLE__) + switch (_type) + { + case SpecialFolderType::UserDocuments: + return home + "Documents/"; + case SpecialFolderType::PrivateAppData: + return home + "Library/Application Support/"; + default: + return {}; + } +#else + // https://specifications.freedesktop.org/basedir-spec/latest/ + switch (_type) + { + case SpecialFolderType::UserDocuments: + { + const auto* docDir = std::getenv("XDG_DATA_HOME"); + if(docDir && strlen(docDir) > 0) + return validatePath(docDir); + return home + ".local/share/"; + } + case SpecialFolderType::PrivateAppData: + { + const auto* confDir = std::getenv("XDG_CONFIG_HOME"); + if(confDir && strlen(confDir) > 0) + return validatePath(confDir); + return home + ".config/"; + } + default: + return {}; + } +#endif +#endif + return {}; + } +} diff --git a/source/baseLib/filesystem.h b/source/baseLib/filesystem.h @@ -0,0 +1,54 @@ +#pragma once + +#include <string> +#include <vector> +#include <cstdint> +#include <cstddef> + +namespace baseLib +{ + namespace filesystem + { + std::string getCurrentDirectory(); + bool createDirectory(const std::string& _dir); + std::string validatePath(std::string _path); + + std::string lowercase(const std::string &_src); + + std::string getExtension(const std::string& _name); + std::string stripExtension(const std::string& _name); + std::string getFilenameWithoutPath(const std::string& _name); + std::string getPath(const std::string& _filename); + + bool getDirectoryEntries(std::vector<std::string>& _files, const std::string& _folder); + + bool findFiles(std::vector<std::string>& _files, const std::string& _rootPath, const std::string& _extension, size_t _minSize, size_t _maxSize); + std::string findFile(const std::string& _rootPath, const std::string& _extension, const size_t _minSize, const size_t _maxSize); + + bool hasExtension(const std::string& _filename, const std::string& _extension); + size_t getFileSize(const std::string& _file); + + bool isDirectory(const std::string& _path); + + bool writeFile(const std::string& _filename, const std::vector<uint8_t>& _data); + bool writeFile(const std::string& _filename, const uint8_t* _data, size_t _size); + + template<size_t Size> bool writeFile(const std::string& _filename, const std::array<uint8_t, Size>& _data) + { + return writeFile(_filename, &_data[0], _data.size()); + } + + bool readFile(std::vector<uint8_t>& _data, const std::string& _filename); + + FILE* openFile(const std::string& _name, const char* _mode); + + enum class SpecialFolderType : uint8_t + { + UserDocuments, + PrivateAppData + }; + + std::string getHomeDirectory(); + std::string getSpecialFolderPath(SpecialFolderType _type); + }; +} diff --git a/source/bridge/client/remoteDevice.cpp b/source/bridge/client/remoteDevice.cpp @@ -15,11 +15,11 @@ #include <condition_variable> +#include "baseLib/filesystem.h" + #include "networkLib/exception.h" #include "networkLib/logging.h" -#include "synthLib/os.h" - namespace bridgeClient { static constexpr uint32_t g_udpTimeout = 5; // seconds @@ -28,7 +28,7 @@ namespace bridgeClient RemoteDevice::RemoteDevice(const synthLib::DeviceCreateParams& _params, bridgeLib::PluginDesc&& _desc, const std::string& _host/* = {}*/, uint32_t _port/* = 0*/) : Device(_params), m_pluginDesc(std::move(_desc)) { getDeviceCreateParams().romHash = baseLib::MD5(getDeviceCreateParams().romData); - getDeviceCreateParams().romName = synthLib::getFilenameWithoutPath(getDeviceCreateParams().romName); + getDeviceCreateParams().romName = baseLib::filesystem::getFilenameWithoutPath(getDeviceCreateParams().romName); m_pluginDesc.protocolVersion = bridgeLib::g_protocolVersion; createConnection(_host, _port); diff --git a/source/bridge/server/config.cpp b/source/bridge/server/config.cpp @@ -1,10 +1,10 @@ #include "config.h" #include "server.h" + #include "baseLib/commandline.h" #include "baseLib/configFile.h" - -#include "synthLib/os.h" +#include "baseLib/filesystem.h" namespace bridgeServer { @@ -32,12 +32,12 @@ namespace bridgeServer pluginsPath = config.get("pluginsPath", pluginsPath); romsPath = config.get("romsPath", romsPath); - synthLib::createDirectory(pluginsPath); - synthLib::createDirectory(romsPath); + baseLib::filesystem::createDirectory(pluginsPath); + baseLib::filesystem::createDirectory(romsPath); } std::string Config::getDefaultDataPath() { - return synthLib::validatePath(synthLib::getSpecialFolderPath(synthLib::SpecialFolderType::UserDocuments)) + "The Usual Suspects/dspBridgeServer/"; + return baseLib::filesystem::validatePath(baseLib::filesystem::getSpecialFolderPath(baseLib::filesystem::SpecialFolderType::UserDocuments)) + "The Usual Suspects/dspBridgeServer/"; } } diff --git a/source/bridge/server/import.cpp b/source/bridge/server/import.cpp @@ -1,7 +1,11 @@ #include "import.h" #include "config.h" + +#include "baseLib/filesystem.h" + #include "networkLib/logging.h" + #include "synthLib/deviceException.h" #include "synthLib/os.h" @@ -105,7 +109,7 @@ namespace bridgeServer { const auto path = synthLib::getModulePath() + "plugins/"; std::vector<std::string> files; - synthLib::findFiles(files, path, _extension, 0, std::numeric_limits<uint32_t>::max()); + baseLib::filesystem::findFiles(files, path, _extension, 0, std::numeric_limits<uint32_t>::max()); for (const auto& file : files) loadPlugin(file); diff --git a/source/bridge/server/romPool.cpp b/source/bridge/server/romPool.cpp @@ -1,9 +1,11 @@ #include "romPool.h" #include "config.h" + +#include "baseLib/filesystem.h" #include "baseLib/md5.h" + #include "networkLib/logging.h" -#include "synthLib/os.h" namespace bridgeServer { @@ -34,7 +36,7 @@ namespace bridgeServer if(m_roms.find(hash) != m_roms.end()) return; - if(synthLib::writeFile(getRootPath() + _name + '_' + hash.toString() + ".bin", _data)) + if(baseLib::filesystem::writeFile(getRootPath() + _name + '_' + hash.toString() + ".bin", _data)) m_roms.insert({hash, _data}); } @@ -46,13 +48,13 @@ namespace bridgeServer void RomPool::findRoms() { std::vector<std::string> files; - synthLib::findFiles(files, getRootPath(), {}, 0, 16 * 1024 * 1024); + baseLib::filesystem::findFiles(files, getRootPath(), {}, 0, 16 * 1024 * 1024); for (const auto& file : files) { std::vector<uint8_t> romData; - if(!synthLib::readFile(romData, file)) + if(!baseLib::filesystem::readFile(romData, file)) { LOGNET(networkLib::LogLevel::Error, "Failed to load file " << file); continue; @@ -64,7 +66,7 @@ namespace bridgeServer continue; m_roms.insert({hash, std::move(romData)}); - LOGNET(networkLib::LogLevel::Info, "Loaded ROM " << synthLib::getFilenameWithoutPath(file)); + LOGNET(networkLib::LogLevel::Info, "Loaded ROM " << baseLib::filesystem::getFilenameWithoutPath(file)); } } } diff --git a/source/hardwareLib/i2cFlash.cpp b/source/hardwareLib/i2cFlash.cpp @@ -2,15 +2,15 @@ #include <cassert> -#include "dsp56kEmu/logging.h" +#include "baseLib/filesystem.h" -#include "synthLib/os.h" +#include "dsp56kEmu/logging.h" namespace hwLib { void I2cFlash::saveAs(const std::string& _filename) const { - synthLib::writeFile(_filename, m_data); + baseLib::filesystem::writeFile(_filename, m_data); } bool I2cFlash::setData(std::vector<uint8_t>& _data) diff --git a/source/jucePluginEditorLib/filetype.cpp b/source/jucePluginEditorLib/filetype.cpp @@ -1,6 +1,6 @@ #include "filetype.h" -#include "synthLib/os.h" +#include "baseLib/filesystem.h" namespace jucePluginEditorLib { @@ -9,7 +9,7 @@ namespace jucePluginEditorLib bool FileType::operator==(const FileType& _other) const { - return synthLib::lowercase(type) == synthLib::lowercase(_other.type); + return baseLib::filesystem::lowercase(type) == baseLib::filesystem::lowercase(_other.type); } bool FileType::operator!=(const FileType& _other) const diff --git a/source/jucePluginEditorLib/partbutton.cpp b/source/jucePluginEditorLib/partbutton.cpp @@ -2,13 +2,11 @@ #include "pluginEditor.h" #include "pluginProcessor.h" -#include "patchmanager/list.h" + #include "patchmanager/patchmanager.h" #include "patchmanager/savepatchdesc.h" #include "patchmanager/listmodel.h" -#include "synthLib/os.h" - namespace jucePluginEditorLib { namespace diff --git a/source/jucePluginEditorLib/patchmanager/datasourcetreeitem.cpp b/source/jucePluginEditorLib/patchmanager/datasourcetreeitem.cpp @@ -7,13 +7,14 @@ #include "../pluginEditor.h" +#include "baseLib/filesystem.h" + #include "jucePluginEditorLib/filetype.h" #include "jucePluginLib/patchdb/datasource.h" #include "jucePluginLib/patchdb/search.h" #include "synthLib/buildconfig.h" -#include "synthLib/os.h" namespace jucePluginEditorLib::patchManager { @@ -253,6 +254,6 @@ namespace jucePluginEditorLib::patchManager for (const auto& patch : patchesVec) patchesMap.insert({i++, patch}); - return new SavePatchDesc(getPatchManager(), std::move(patchesMap), synthLib::getFilenameWithoutPath(m_dataSource->name)); + return new SavePatchDesc(getPatchManager(), std::move(patchesMap), baseLib::filesystem::getFilenameWithoutPath(m_dataSource->name)); } } diff --git a/source/jucePluginEditorLib/patchmanager/grouptreeitem.cpp b/source/jucePluginEditorLib/patchmanager/grouptreeitem.cpp @@ -5,7 +5,7 @@ #include "search.h" #include "tagtreeitem.h" -#include "synthLib/os.h" +#include "baseLib/filesystem.h" namespace jucePluginEditorLib::patchManager { @@ -363,7 +363,7 @@ namespace jucePluginEditorLib::patchManager continue; pluginLib::patchDB::DataSource ds; - ds.name = synthLib::getFilenameWithoutPath(file.toStdString()); + ds.name = baseLib::filesystem::getFilenameWithoutPath(file.toStdString()); ds.type = pluginLib::patchDB::SourceType::LocalStorage; ds.origin = pluginLib::patchDB::DataSourceOrigin::Manual; diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.cpp b/source/jucePluginEditorLib/patchmanager/patchmanager.cpp @@ -15,6 +15,8 @@ #include "../pluginEditor.h" #include "../pluginProcessor.h" +#include "baseLib/filesystem.h" + #include "jucePluginLib/types.h" #include "jucePluginLib/clipboard.h" @@ -22,8 +24,6 @@ #include "dsp56kEmu/logging.h" -#include "synthLib/os.h" - #if JUCE_MAJOR_VERSION < 8 // they forgot this include but fixed it in version 8+ #include "juce_gui_extra/misc/juce_ColourSelector.h" #endif @@ -762,7 +762,7 @@ namespace jucePluginEditorLib::patchManager if(!loadFile(results, file) || results.empty()) continue; - const auto defaultName = results.size() == 1 ? synthLib::stripExtension(synthLib::getFilenameWithoutPath(file)) : ""; + const auto defaultName = results.size() == 1 ? baseLib::filesystem::stripExtension(baseLib::filesystem::getFilenameWithoutPath(file)) : ""; for (auto& result : results) { diff --git a/source/jucePluginEditorLib/pluginEditor.cpp b/source/jucePluginEditorLib/pluginEditor.cpp @@ -4,6 +4,8 @@ #include "pluginProcessor.h" #include "skin.h" +#include "baseLib/filesystem.h" + #include "jucePluginLib/clipboard.h" #include "jucePluginLib/parameterbinding.h" #include "jucePluginLib/tools.h" @@ -624,7 +626,7 @@ namespace jucePluginEditorLib const auto modulePath = synthLib::getModulePath(); const auto publicDataPath = m_processor.getDataFolder(); - const auto folder = synthLib::validatePath(m_skin.folder.find(modulePath) == 0 || m_skin.folder.find(publicDataPath) == 0 ? m_skin.folder : modulePath + m_skin.folder); + const auto folder = baseLib::filesystem::validatePath(m_skin.folder.find(modulePath) == 0 || m_skin.folder.find(publicDataPath) == 0 ? m_skin.folder : modulePath + m_skin.folder); // try to load from disk first FILE* hFile = fopen((folder + _name).c_str(), "rb"); diff --git a/source/jucePluginEditorLib/pluginEditorState.cpp b/source/jucePluginEditorLib/pluginEditorState.cpp @@ -3,13 +3,16 @@ #include "pluginEditor.h" #include "pluginProcessor.h" +#include "baseLib/filesystem.h" + #include "patchmanager/patchmanager.h" -#include "synthLib/os.h" #include "juceUiLib/editor.h" #include "dsp56kEmu/logging.h" +#include "synthLib/os.h" + namespace jucePluginEditorLib { @@ -30,7 +33,7 @@ PluginEditorState::PluginEditorState(Processor& _processor, pluginLib::Controlle for (auto& skin : m_includedSkins) { if(skin.folder.empty() && !m_processor.findResource(skin.jsonFilename)) - skin.folder = synthLib::validatePath(getSkinFolder() + skin.displayName); + skin.folder = baseLib::filesystem::validatePath(getSkinFolder() + skin.displayName); } } @@ -98,7 +101,7 @@ void PluginEditorState::getPerInstanceConfig(std::vector<uint8_t>& _data) std::string PluginEditorState::getSkinFolder() const { - return synthLib::validatePath(m_processor.getDataFolder() + "skins/"); + return baseLib::filesystem::validatePath(m_processor.getDataFolder() + "skins/"); } bool PluginEditorState::loadSkin(const Skin& _skin, const uint32_t _fallbackIndex/* = 0*/) @@ -126,7 +129,7 @@ bool PluginEditorState::loadSkin(const Skin& _skin, const uint32_t _fallbackInde // if the embedded skin cannot be found, use skin folder as fallback if(_skin.folder.empty() && !m_processor.findResource(_skin.jsonFilename)) { - skin.folder = synthLib::validatePath(getSkinFolder() + _skin.displayName); + skin.folder = baseLib::filesystem::validatePath(getSkinFolder() + _skin.displayName); } auto* editor = createEditor(skin); @@ -222,21 +225,21 @@ void PluginEditorState::openMenu(const juce::MouseEvent* _event) // new: user documents folder std::vector<std::string> entries; - synthLib::getDirectoryEntries(entries, getSkinFolder()); + baseLib::filesystem::getDirectoryEntries(entries, getSkinFolder()); // old: next to plugin, kept for backwards compatibility std::vector<std::string> entriesModulePath; - synthLib::getDirectoryEntries(entriesModulePath, modulePath + "skins_" + m_processor.getProperties().name); + baseLib::filesystem::getDirectoryEntries(entriesModulePath, modulePath + "skins_" + m_processor.getProperties().name); entries.insert(entries.end(), entriesModulePath.begin(), entriesModulePath.end()); for (const auto& entry : entries) { std::vector<std::string> files; - synthLib::getDirectoryEntries(files, entry); + baseLib::filesystem::getDirectoryEntries(files, entry); for (const auto& file : files) { - if(synthLib::hasExtension(file, ".json")) + if(baseLib::filesystem::hasExtension(file, ".json")) { if(!haveSkinsOnDisk) { @@ -247,7 +250,7 @@ void PluginEditorState::openMenu(const juce::MouseEvent* _event) std::string skinPath = entry; if(entry.find(modulePath) == 0) skinPath = entry.substr(modulePath.size()); - skinPath = synthLib::validatePath(skinPath); + skinPath = baseLib::filesystem::validatePath(skinPath); auto jsonName = file; const auto pathEndPos = jsonName.find_last_of("/\\"); @@ -277,7 +280,7 @@ void PluginEditorState::openMenu(const juce::MouseEvent* _event) skinMenu.addItem("Open folder '" + getSkinFolder() + "' in File Browser", true, false, [this] { const auto dir = getSkinFolder(); - synthLib::createDirectory(dir); + baseLib::filesystem::createDirectory(dir); juce::File(dir).revealToUser(); }); diff --git a/source/jucePluginLib/clipboard.cpp b/source/jucePluginLib/clipboard.cpp @@ -1,12 +1,14 @@ #include "clipboard.h" #include "synthLib/midiToSysex.h" -#include "synthLib/os.h" #include <sstream> #include "pluginVersion.h" #include "processor.h" + +#include "baseLib/filesystem.h" + #include "dsp56kEmu/logging.h" #include "juce_core/juce_core.h" @@ -40,7 +42,7 @@ namespace pluginLib if(_text.empty()) return {}; - auto text = synthLib::lowercase(_text); + auto text = baseLib::filesystem::lowercase(_text); while(true) { diff --git a/source/jucePluginLib/patchdb/db.cpp b/source/jucePluginLib/patchdb/db.cpp @@ -6,11 +6,11 @@ #include "patch.h" #include "patchmodifications.h" -#include "synthLib/os.h" #include "synthLib/midiToSysex.h" #include "baseLib/hybridcontainer.h" #include "baseLib/binarystream.h" +#include "baseLib/filesystem.h" #include "dsp56kEmu/logging.h" @@ -756,14 +756,14 @@ namespace pluginLib::patchDB bool DB::loadFile(DataList& _results, const std::string& _file) { - const auto size = synthLib::getFileSize(_file); + const auto size = baseLib::filesystem::getFileSize(_file); // unlikely that a 8mb file has useful data for us, skip if (!size || size >= static_cast<size_t>(8 * 1024 * 1024)) return false; Data data; - if (!synthLib::readFile(data, _file) || data.empty()) + if (!baseLib::filesystem::readFile(data, _file) || data.empty()) return false; return parseFileData(_results, data); @@ -774,7 +774,7 @@ namespace pluginLib::patchDB const auto file = getLocalStorageFile(_ds); std::vector<uint8_t> data; - if (!synthLib::readFile(data, file.getFullPathName().toStdString())) + if (!baseLib::filesystem::readFile(data, file.getFullPathName().toStdString())) return false; synthLib::MidiToSysex::splitMultipleSysex(_results, data); @@ -786,7 +786,7 @@ namespace pluginLib::patchDB assert(_folder->type == SourceType::Folder); std::vector<std::string> files; - synthLib::findFiles(files, _folder->name, {}, 0, 0); + baseLib::filesystem::findFiles(files, _folder->name, {}, 0, 0); for (const auto& file : files) { @@ -795,7 +795,7 @@ namespace pluginLib::patchDB child->name = file; child->origin = DataSourceOrigin::Autogenerated; - if(synthLib::isDirectory(file)) + if(baseLib::filesystem::isDirectory(file)) child->type = SourceType::Folder; else child->type = SourceType::File; @@ -826,20 +826,20 @@ namespace pluginLib::patchDB m_settingsDir.createDirectory(); std::vector<std::string> files; - synthLib::getDirectoryEntries(files, _migrateFromDir.getFullPathName().toStdString()); + baseLib::filesystem::getDirectoryEntries(files, _migrateFromDir.getFullPathName().toStdString()); std::vector<juce::File> toBeDeleted; for (const auto& file : files) { - if(synthLib::hasExtension(file, ".cache")) + if(baseLib::filesystem::hasExtension(file, ".cache")) { juce::File f(file); f.deleteFile(); continue; } - if(!synthLib::hasExtension(file, ".json") && !synthLib::hasExtension(file, ".syx")) + if(!baseLib::filesystem::hasExtension(file, ".json") && !baseLib::filesystem::hasExtension(file, ".syx")) continue; juce::File fileFrom(file); @@ -959,7 +959,7 @@ namespace pluginLib::patchDB std::vector<PatchPtr> patches; patches.reserve(data.size()); - const std::string defaultName = data.size() == 1 ? synthLib::stripExtension(synthLib::getFilenameWithoutPath(ds->name)) : ""; + const std::string defaultName = data.size() == 1 ? baseLib::filesystem::stripExtension(baseLib::filesystem::getFilenameWithoutPath(ds->name)) : ""; for (uint32_t p = 0; p < data.size(); ++p) { @@ -1803,7 +1803,7 @@ namespace pluginLib::patchDB return false; std::vector<uint8_t> data; - if(!synthLib::readFile(data, cacheFile.getFullPathName().toStdString())) + if(!baseLib::filesystem::readFile(data, cacheFile.getFullPathName().toStdString())) return false; try diff --git a/source/jucePluginLib/processor.cpp b/source/jucePluginLib/processor.cpp @@ -5,6 +5,7 @@ #include "types.h" #include "baseLib/binarystream.h" +#include "baseLib/filesystem.h" #include "bridgeLib/commands.h" @@ -13,10 +14,10 @@ #include "synthLib/deviceException.h" #include "synthLib/os.h" #include "synthLib/midiBufferParser.h" +#include "synthLib/romLoader.h" #include "dsp56kEmu/fastmath.h" #include "dsp56kEmu/logging.h" -#include "synthLib/romLoader.h" namespace synthLib { @@ -136,7 +137,7 @@ namespace pluginLib { msg += "\n\n"; msg += "The firmware file needs to be copied to\n"; - msg += synthLib::validatePath(getPublicRomFolder()) + "\n"; + msg += baseLib::filesystem::validatePath(getPublicRomFolder()) + "\n"; msg += "\n"; msg += "The target folder will be opened once you click OK. Copy the firmware to this folder and reload the plugin."; #ifdef _DEBUG @@ -398,17 +399,17 @@ namespace pluginLib std::string Processor::getPublicRomFolder() const { - return synthLib::validatePath(getDataFolder() + "roms/"); + return baseLib::filesystem::validatePath(getDataFolder() + "roms/"); } std::string Processor::getConfigFolder(const bool _useFxFolder) const { - return synthLib::validatePath(getDataFolder(_useFxFolder) + "config/"); + return baseLib::filesystem::validatePath(getDataFolder(_useFxFolder) + "config/"); } std::string Processor::getPatchManagerDataFolder(bool _useFxFolder) const { - return synthLib::validatePath(getDataFolder(_useFxFolder) + "patchmanager/"); + return baseLib::filesystem::validatePath(getDataFolder(_useFxFolder) + "patchmanager/"); } std::string Processor::getConfigFile(const bool _useFxFolder) const diff --git a/source/jucePluginLib/tools.cpp b/source/jucePluginLib/tools.cpp @@ -1,10 +1,10 @@ #include "tools.h" +#include "baseLib/filesystem.h" + #include "juce_audio_processors/juce_audio_processors.h" #include "juce_gui_basics/juce_gui_basics.h" -#include "synthLib/os.h" - namespace pluginLib { bool Tools::isHeadless() @@ -23,6 +23,6 @@ namespace pluginLib std::string Tools::getPublicDataFolder(const std::string& _vendorName, const std::string& _productName) { - return synthLib::validatePath(synthLib::getSpecialFolderPath(synthLib::SpecialFolderType::UserDocuments) + _vendorName + '/' + _productName + '/'); + return baseLib::filesystem::validatePath(baseLib::filesystem::getSpecialFolderPath(baseLib::filesystem::SpecialFolderType::UserDocuments) + _vendorName + '/' + _productName + '/'); } } diff --git a/source/juceUiLib/editor.cpp b/source/juceUiLib/editor.cpp @@ -2,7 +2,7 @@ #include "uiObject.h" -#include "synthLib/os.h" +#include "baseLib/filesystem.h" namespace genericUI { @@ -71,7 +71,7 @@ namespace genericUI if(!m_rootObject) return "Nothing to export"; - synthLib::createDirectory(_folder); + baseLib::filesystem::createDirectory(_folder); std::string subfolder = m_jsonFilename; const auto dotIndex = m_jsonFilename.rfind('.'); @@ -83,7 +83,7 @@ namespace genericUI const auto folder = _folder + subfolder + '/'; - synthLib::createDirectory(folder); + baseLib::filesystem::createDirectory(folder); std::stringstream errors; diff --git a/source/mqJucePlugin/PluginEditorState.cpp b/source/mqJucePlugin/PluginEditorState.cpp @@ -5,8 +5,6 @@ #include "jucePluginEditorLib/midiPorts.h" -#include "synthLib/os.h" - #include "skins.h" namespace mqJucePlugin diff --git a/source/mqJucePlugin/mqController.cpp b/source/mqJucePlugin/mqController.cpp @@ -8,8 +8,6 @@ #include "mqLib/mqstate.h" -#include "synthLib/os.h" - #include "dsp56kEmu/logging.h" namespace mqJucePlugin diff --git a/source/mqLib/microq.cpp b/source/mqLib/microq.cpp @@ -1,7 +1,6 @@ #include "microq.h" #include "synthLib/midiTypes.h" -#include "synthLib/os.h" #include "synthLib/deviceException.h" #include "dsp56kEmu/threadtools.h" diff --git a/source/mqLib/mqstate.cpp b/source/mqLib/mqstate.cpp @@ -6,7 +6,6 @@ #include "mqmiditypes.h" #include "microq.h" -#include "synthLib/os.h" #include "synthLib/midiToSysex.h" #include "synthLib/midiBufferParser.h" #include "dsp56kEmu/logging.h" diff --git a/source/mqLib/romloader.cpp b/source/mqLib/romloader.cpp @@ -1,7 +1,5 @@ #include "romloader.h" -#include "synthLib/os.h" - namespace mqLib { ROM RomLoader::findROM() diff --git a/source/nord/n2x/n2xJucePlugin/n2xController.cpp b/source/nord/n2x/n2xJucePlugin/n2xController.cpp @@ -5,10 +5,10 @@ #include "n2xPatchManager.h" #include "n2xPluginProcessor.h" -#include "synthLib/os.h" - #include "dsp56kEmu/logging.h" + #include "n2xLib/n2xmiditypes.h" + #include "synthLib/midiTranslator.h" namespace diff --git a/source/nord/n2x/n2xJucePlugin/n2xPluginEditorState.cpp b/source/nord/n2x/n2xJucePlugin/n2xPluginEditorState.cpp @@ -5,8 +5,6 @@ #include "jucePluginEditorLib/midiPorts.h" -#include "synthLib/os.h" - #include "skins.h" namespace n2xJucePlugin diff --git a/source/nord/n2x/n2xLib/n2xflash.cpp b/source/nord/n2x/n2xLib/n2xflash.cpp @@ -2,6 +2,9 @@ #include "n2xhardware.h" #include "n2xtypes.h" + +#include "baseLib/filesystem.h" + #include "synthLib/os.h" namespace n2x @@ -13,7 +16,7 @@ namespace n2x if(!filename.empty()) { std::vector<uint8_t> d; - if(synthLib::readFile(d, filename)) + if(baseLib::filesystem::readFile(d, filename)) { setData(d); } diff --git a/source/nord/n2x/n2xLib/n2xmc.cpp b/source/nord/n2x/n2xLib/n2xmc.cpp @@ -5,7 +5,7 @@ #include "n2xdsp.h" #include "n2xrom.h" -#include "synthLib/os.h" +#include "baseLib/filesystem.h" namespace n2x { @@ -319,7 +319,7 @@ namespace n2x if(writeRam) { writeRam = false; - synthLib::writeFile("romRam_runtime.bin", m_romRam); + baseLib::filesystem::writeFile("romRam_runtime.bin", m_romRam); } #endif const auto cycles = Mc68k::exec(); diff --git a/source/nord/n2x/n2xLib/n2xrom.cpp b/source/nord/n2x/n2xLib/n2xrom.cpp @@ -2,8 +2,6 @@ #include <algorithm> -#include "synthLib/os.h" - namespace n2x { Rom::Rom() diff --git a/source/nord/n2x/n2xLib/n2xromdata.cpp b/source/nord/n2x/n2xLib/n2xromdata.cpp @@ -2,6 +2,8 @@ #include "n2xtypes.h" +#include "baseLib/filesystem.h" + #include "synthLib/os.h" namespace n2x @@ -14,7 +16,7 @@ namespace n2x { if(_filename.empty()) return; - if(!synthLib::readFile(m_data, _filename)) + if(!baseLib::filesystem::readFile(m_data, _filename)) return; if(m_data.size() != MySize) return; @@ -31,7 +33,7 @@ namespace n2x template <uint32_t Size> void RomData<Size>::saveAs(const std::string& _filename) const { - synthLib::writeFile(_filename, m_data); + baseLib::filesystem::writeFile(_filename, m_data); } template class RomData<g_flashSize>; diff --git a/source/synthLib/lv2PresetExport.cpp b/source/synthLib/lv2PresetExport.cpp @@ -3,7 +3,7 @@ #include <fstream> #include <map> -#include "os.h" +#include "baseLib/filesystem.h" namespace synthLib { @@ -150,8 +150,8 @@ namespace synthLib bool Lv2PresetExport::exportPresets(const std::string& _outputPath, const std::string& _pluginId, const std::vector<Bank>& _banks) { - const auto path = validatePath(_outputPath); - createDirectory(path); + const auto path = baseLib::filesystem::validatePath(_outputPath); + baseLib::filesystem::createDirectory(path); for (const auto& bank : _banks) { @@ -163,8 +163,8 @@ namespace synthLib bool Lv2PresetExport::exportPresets(const std::string& _outputPath, const std::string& _pluginId, const Bank& _bank) { - const auto path = validatePath(_outputPath); - createDirectory(path); + const auto path = baseLib::filesystem::validatePath(_outputPath); + baseLib::filesystem::createDirectory(path); std::ofstream manifest(getManifestFilename(path)); if(!manifest.is_open()) return false; @@ -205,12 +205,12 @@ namespace synthLib std::string Lv2PresetExport::getBankPath(const std::string& _outputPath, const std::string& _bankName) { - return validatePath(_outputPath) + getBankFilename(_bankName) + ".lv2/"; + return baseLib::filesystem::validatePath(_outputPath) + getBankFilename(_bankName) + ".lv2/"; } std::string Lv2PresetExport::getManifestFilename(const std::string& _path) { - return validatePath(_path) + "manifest.ttl"; + return baseLib::filesystem::validatePath(_path) + "manifest.ttl"; } std::string Lv2PresetExport::getBankFilename(const std::string& _bankName) diff --git a/source/synthLib/midiToSysex.cpp b/source/synthLib/midiToSysex.cpp @@ -5,7 +5,7 @@ #include "dsp56kEmu/logging.h" -#include "os.h" +#include "baseLib/filesystem.h" #ifdef _MSC_VER #include <Windows.h> @@ -210,7 +210,7 @@ namespace synthLib { std::vector<uint8_t> data; - if(!synthLib::readFile(data, _filename)) + if(!baseLib::filesystem::readFile(data, _filename)) return false; return extractSysexFromData(_messages, data); diff --git a/source/synthLib/os.cpp b/source/synthLib/os.cpp @@ -1,5 +1,7 @@ #include "os.h" +#include "baseLib/filesystem.h" + #include "dsp56kEmu/logging.h" #ifndef _WIN32 @@ -39,15 +41,10 @@ #include <sys/sysctl.h> #endif +using namespace baseLib::filesystem; + namespace synthLib { -#ifdef _WIN32 - constexpr char g_nativePathSeparator = '\\'; -#else - constexpr char g_nativePathSeparator = '/'; -#endif - constexpr char g_otherPathSeparator = g_nativePathSeparator == '\\' ? '/' : '\\'; - std::string getModulePath(bool _stripPluginComponentFolders/* = true*/) { std::string path; @@ -113,184 +110,18 @@ namespace synthLib return validatePath(path); } - std::string getCurrentDirectory() - { -#ifdef USE_DIRENT - char temp[1024]; - getcwd(temp, sizeof(temp)); - return temp; -#else - return std::filesystem::current_path().string(); -#endif - } + namespace + { + std::string findFile(const std::string& _extension, const size_t _minSize, const size_t _maxSize, const bool _stripPluginComponentFolders) + { + std::string path = getModulePath(_stripPluginComponentFolders); - bool createDirectory(const std::string& _dir) - { -#ifdef USE_DIRENT - constexpr auto dirAttribs = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH; - for(size_t i=0; i<_dir.size(); ++i) - { - if(_dir[i] == '/' || _dir[i] == '\\') - { - const auto d = _dir.substr(0,i); - mkdir(d.c_str(), dirAttribs); - } - } - return mkdir(_dir.c_str(), dirAttribs) == 0; -#else - return std::filesystem::create_directories(_dir); -#endif - } + if(path.empty()) + path = getCurrentDirectory(); - std::string validatePath(std::string _path) - { - if(_path.empty()) - return _path; - - for (char& ch : _path) - { - if(ch == g_otherPathSeparator) - ch = g_nativePathSeparator; - } - - if(_path.back() == g_nativePathSeparator) - return _path; - - _path += g_nativePathSeparator; - return _path; - } - - bool getDirectoryEntries(std::vector<std::string>& _files, const std::string& _folder) - { -#ifdef USE_DIRENT - DIR *dir; - struct dirent *ent; - if ((dir = opendir(_folder.c_str()))) - { - while ((ent = readdir(dir))) - { - std::string f = ent->d_name; - - if(f == "." || f == "..") - continue; - - std::string file = _folder; - - if(file.back() != '/' && file.back() != '\\') - file += '/'; - - file += f; - - _files.push_back(file); - } - closedir(dir); - } - else - { - LOG("Failed to open directory " << _folder << ", error " << errno); - return false; - } -#else - try - { - const auto u8Path = std::filesystem::u8path(_folder); - for (const std::filesystem::directory_entry &entry : std::filesystem::directory_iterator(u8Path)) - { - const auto &file = entry.path(); - - try - { - _files.push_back(file.u8string()); - } - catch(std::exception& e) - { - LOG(e.what()); - } - } - } - catch (std::exception& e) - { - LOG(e.what()); - return false; - } -#endif - return !_files.empty(); - } - - std::string lowercase(const std::string &_src) - { - std::string str(_src); - for (char& i : str) - i = static_cast<char>(tolower(i)); - return str; - } - - std::string getExtension(const std::string &_name) - { - const auto pos = _name.find_last_of('.'); - if (pos != std::string::npos) - return _name.substr(pos); - return {}; - } - - std::string stripExtension(const std::string& _name) - { - const auto pos = _name.find_last_of('.'); - if (pos != std::string::npos) - return _name.substr(0, pos); - return _name; - } - - std::string getFilenameWithoutPath(const std::string& _name) - { - const auto pos = _name.find_last_of("/\\"); - if (pos != std::string::npos) - return _name.substr(pos + 1); - return _name; - } - - std::string getPath(const std::string& _filename) - { - const auto pos = _filename.find_last_of("/\\"); - if (pos != std::string::npos) - return _filename.substr(0, pos); - return _filename; - } - - size_t getFileSize(const std::string& _file) - { - FILE* hFile = openFile(_file, "rb"); - if (!hFile) - return 0; - - fseek(hFile, 0, SEEK_END); - const auto size = static_cast<size_t>(ftell(hFile)); - fclose(hFile); - return size; - } - - bool isDirectory(const std::string& _path) - { -#ifdef USE_DIRENT - struct stat statbuf; - stat(_path.c_str(), &statbuf); - if (S_ISDIR(statbuf.st_mode)) - return true; - return false; -#else - return std::filesystem::is_directory(_path); -#endif - } - - std::string findFile(const std::string& _extension, const size_t _minSize, const size_t _maxSize, const bool _stripPluginComponentFolders) - { - std::string path = getModulePath(_stripPluginComponentFolders); - - if(path.empty()) - path = getCurrentDirectory(); - - return findFile(path, _extension, _minSize, _maxSize); - } + return baseLib::filesystem::findFile(path, _extension, _minSize, _maxSize); + } + } std::string findFile(const std::string& _extension, const size_t _minSize, const size_t _maxSize) { @@ -300,43 +131,6 @@ namespace synthLib return findFile(_extension, _minSize, _maxSize, false); } - std::string findFile(const std::string& _rootPath, const std::string& _extension, const size_t _minSize, const size_t _maxSize) - { - std::vector<std::string> files; - if(!findFiles(files, _rootPath, _extension, _minSize, _maxSize)) - return {}; - return files.front(); - } - - bool findFiles(std::vector<std::string>& _files, const std::string& _rootPath, const std::string& _extension, const size_t _minSize, const size_t _maxSize) - { - std::vector<std::string> files; - - getDirectoryEntries(files, _rootPath); - - for (const auto& file : files) - { - if(!hasExtension(file, _extension)) - continue; - - if (!_minSize && !_maxSize) - { - _files.push_back(file); - continue; - } - - const auto size = getFileSize(file); - - if (_minSize && size < _minSize) - continue; - if (_maxSize && size > _maxSize) - continue; - - _files.push_back(file); - } - return !_files.empty(); - } - std::string findROM(const size_t _minSize, const size_t _maxSize) { std::string path = getModulePath(); @@ -344,13 +138,13 @@ namespace synthLib if(path.empty()) path = getCurrentDirectory(); - auto f = findFile(path, ".bin", _minSize, _maxSize); + auto f = baseLib::filesystem::findFile(path, ".bin", _minSize, _maxSize); if(!f.empty()) return f; path = getModulePath(false); - return findFile(path, ".bin", _minSize, _maxSize); + return baseLib::filesystem::findFile(path, ".bin", _minSize, _maxSize); } std::string findROM(const size_t _expectedSize) @@ -358,14 +152,6 @@ namespace synthLib return findROM(_expectedSize, _expectedSize); } - bool hasExtension(const std::string& _filename, const std::string& _extension) - { - if (_extension.empty()) - return true; - - return lowercase(getExtension(_filename)) == lowercase(_extension); - } - void setFlushDenormalsToZero() { #if defined(_MSC_VER) @@ -375,64 +161,6 @@ namespace synthLib #endif } - bool writeFile(const std::string& _filename, const std::vector<uint8_t>& _data) - { - return writeFile(_filename, _data.data(), _data.size()); - } - - bool writeFile(const std::string& _filename, const uint8_t* _data, size_t _size) - { - auto* hFile = openFile(_filename, "wb"); - if(!hFile) - return false; - const auto written = fwrite(&_data[0], 1, _size, hFile); - fclose(hFile); - return written == _size; - } - - bool readFile(std::vector<uint8_t>& _data, const std::string& _filename) - { - auto* hFile = openFile(_filename, "rb"); - if(!hFile) - return false; - - fseek(hFile, 0, SEEK_END); - const auto size = ftell(hFile); - fseek(hFile, 0, SEEK_SET); - - if(!size) - { - fclose(hFile); - _data.clear(); - return true; - } - - if(_data.size() != static_cast<size_t>(size)) - _data.resize(size); - - const auto read = fread(_data.data(), 1, _data.size(), hFile); - fclose(hFile); - return read == _data.size(); - } - - FILE* openFile(const std::string& _name, const char* _mode) - { -#ifdef _WIN32 - // convert filename - std::wstring nameW; - nameW.resize(_name.size()); - const int newSize = MultiByteToWideChar(CP_UTF8, 0, _name.c_str(), static_cast<int>(_name.size()), const_cast<wchar_t *>(nameW.c_str()), static_cast<int>(_name.size())); - nameW.resize(newSize); - - // convert mode - wchar_t mode[32]{0}; - MultiByteToWideChar(CP_UTF8, 0, _mode, static_cast<int>(strlen(_mode)), mode, (int)std::size(mode)); - return _wfopen(nameW.c_str(), mode); -#else - return fopen(_name.c_str(), _mode); -#endif - } - bool isRunningUnderRosetta() { #ifdef __APPLE__ @@ -449,92 +177,4 @@ namespace synthLib return false; #endif } - - std::string getHomeDirectory() - { -#ifdef _WIN32 - std::array<char, MAX_PATH<<1> data; - if (SHGetSpecialFolderPathA (nullptr, data.data(), CSIDL_PROFILE, FALSE)) - return validatePath(data.data()); - - const auto* home = getenv("USERPROFILE"); - if (home) - return home; - - const auto* drive = getenv("HOMEDRIVE"); - const auto* path = getenv("HOMEPATH"); - - if (drive && path) - return std::string(drive) + std::string(path); - - return "C:\\Users\\Default"; // meh, what can we do? -#else - const char* home = getenv("HOME"); - if (home && strlen(home) > 0) - return home; - const auto* pw = getpwuid(getuid()); - if(pw) - return std::string(pw->pw_dir); - return "/tmp"; // better ideas welcome -#endif - } - - std::string getSpecialFolderPath(const SpecialFolderType _type) - { -#ifdef _WIN32 - std::array<char, MAX_PATH<<1> path; - - int csidl; - switch (_type) - { - case SpecialFolderType::UserDocuments: - csidl = CSIDL_PERSONAL; - break; - case SpecialFolderType::PrivateAppData: - csidl = CSIDL_APPDATA; - break; - default: - return {}; - } - if (SHGetSpecialFolderPathA (nullptr, path.data(), csidl, FALSE)) - return validatePath(path.data()); -#else - const auto h = std::getenv("HOME"); - const std::string home = validatePath(getHomeDirectory()); - -#if defined(__APPLE__) - switch (_type) - { - case SpecialFolderType::UserDocuments: - return home + "Documents/"; - case SpecialFolderType::PrivateAppData: - return home + "Library/Application Support/"; - default: - return {}; - } -#else - // https://specifications.freedesktop.org/basedir-spec/latest/ - switch (_type) - { - case SpecialFolderType::UserDocuments: - { - const auto* docDir = std::getenv("XDG_DATA_HOME"); - if(docDir && strlen(docDir) > 0) - return validatePath(docDir); - return home + ".local/share/"; - } - case SpecialFolderType::PrivateAppData: - { - const auto* confDir = std::getenv("XDG_CONFIG_HOME"); - if(confDir && strlen(confDir) > 0) - return validatePath(confDir); - return home + ".config/"; - } - default: - return {}; - } -#endif -#endif - return {}; - } } // namespace synthLib diff --git a/source/synthLib/os.h b/source/synthLib/os.h @@ -1,60 +1,17 @@ #pragma once -#include <array> -#include <cstdint> #include <string> -#include <vector> namespace synthLib { std::string getModulePath(bool _stripPluginComponentFolders = true); - std::string getCurrentDirectory(); - bool createDirectory(const std::string& _dir);; - std::string validatePath(std::string _path); - - bool getDirectoryEntries(std::vector<std::string>& _files, const std::string& _folder); - - std::string lowercase(const std::string &_src); - std::string findFile(const std::string& _extension, size_t _minSize, size_t _maxSize); - bool findFiles(std::vector<std::string>& _files, const std::string& _rootPath, const std::string& _extension, size_t _minSize, size_t _maxSize); - std::string findFile(const std::string& _rootPath, const std::string& _extension, size_t _minSize, size_t _maxSize); std::string findROM(size_t _minSize, size_t _maxSize); std::string findROM(size_t _expectedSize = 524288); - std::string getExtension(const std::string& _name); - std::string stripExtension(const std::string& _name); - std::string getFilenameWithoutPath(const std::string& _name); - std::string getPath(const std::string& _filename); - - bool hasExtension(const std::string& _filename, const std::string& _extension); - size_t getFileSize(const std::string& _file); - bool isDirectory(const std::string& _path); - void setFlushDenormalsToZero(); - bool writeFile(const std::string& _filename, const std::vector<uint8_t>& _data); - bool writeFile(const std::string& _filename, const uint8_t* _data, size_t _size); - - template<size_t Size> bool writeFile(const std::string& _filename, const std::array<uint8_t, Size>& _data) - { - return writeFile(_filename, &_data[0], _data.size()); - } - - bool readFile(std::vector<uint8_t>& _data, const std::string& _filename); - - FILE* openFile(const std::string& _name, const char* _mode); - bool isRunningUnderRosetta(); - - enum class SpecialFolderType - { - UserDocuments, - PrivateAppData - }; - - std::string getHomeDirectory(); - std::string getSpecialFolderPath(SpecialFolderType _type); -} // namespace synthLib +} diff --git a/source/synthLib/romLoader.cpp b/source/synthLib/romLoader.cpp @@ -2,6 +2,8 @@ #include "os.h" +#include "baseLib/filesystem.h" + namespace synthLib { namespace @@ -17,11 +19,11 @@ namespace synthLib { g_searchPaths.insert(getModulePath(true)); g_searchPaths.insert(getModulePath(false)); - g_searchPaths.insert(getCurrentDirectory()); + g_searchPaths.insert(baseLib::filesystem::getCurrentDirectory()); } for (const auto& path : g_searchPaths) - synthLib::findFiles(results, path, _extension, _minSize, _maxSize); + baseLib::filesystem::findFiles(results, path, _extension, _minSize, _maxSize); return results; } @@ -32,12 +34,12 @@ namespace synthLib return findFiles(_extension, _minSize, _maxSize); std::vector<std::string> results; - synthLib::findFiles(results, _path, _extension, _minSize, _maxSize); + baseLib::filesystem::findFiles(results, _path, _extension, _minSize, _maxSize); return results; } void RomLoader::addSearchPath(const std::string& _path) { - g_searchPaths.insert(validatePath(_path)); + g_searchPaths.insert(baseLib::filesystem::validatePath(_path)); } } diff --git a/source/virusIntegrationTest/integrationTest.cpp b/source/virusIntegrationTest/integrationTest.cpp @@ -10,9 +10,9 @@ #include "dsp56kEmu/jitunittests.h" #include "baseLib/commandline.h" +#include "baseLib/filesystem.h" #include "synthLib/wavReader.h" -#include "synthLib/os.h" #include "virusLib/romloader.h" @@ -61,13 +61,13 @@ int main(int _argc, char* _argv[]) const auto res = test.run(); if(0 == res) - std::cout << "test successful, ROM " << synthLib::getFilenameWithoutPath(romFile) << ", preset " << preset << '\n'; + std::cout << "test successful, ROM " << baseLib::filesystem::getFilenameWithoutPath(romFile) << ", preset " << preset << '\n'; return res; } if(cmd.contains("folder")) { std::vector<std::string> subfolders; - synthLib::getDirectoryEntries(subfolders, cmd.get("folder")); + baseLib::filesystem::getDirectoryEntries(subfolders, cmd.get("folder")); if(subfolders.empty()) { @@ -83,7 +83,7 @@ int main(int _argc, char* _argv[]) continue; std::vector<std::string> files; - synthLib::getDirectoryEntries(files, subfolder); + baseLib::filesystem::getDirectoryEntries(files, subfolder); std::string romFile; std::string presetsFile; @@ -96,11 +96,11 @@ int main(int _argc, char* _argv[]) for (auto& file : files) { - if(synthLib::hasExtension(file, ".txt")) + if(baseLib::filesystem::hasExtension(file, ".txt")) presetsFile = file; - else if(synthLib::hasExtension(file, ".bin")) + else if(baseLib::filesystem::hasExtension(file, ".bin")) romFile = file; - else if(synthLib::hasExtension(file, ".mid")) + else if(baseLib::filesystem::hasExtension(file, ".mid")) { const auto rom = virusLib::ROMLoader::findROM(file); if(rom.isValid()) @@ -161,7 +161,7 @@ int main(int _argc, char* _argv[]) { std::cout << "All " << finishedTests.size() << " tests finished successfully:" << '\n'; for (const auto& [rom,preset] : finishedTests) - std::cout << "ROM " << synthLib::getFilenameWithoutPath(rom) << ", preset " << preset << '\n'; + std::cout << "ROM " << baseLib::filesystem::getFilenameWithoutPath(rom) << ", preset " << preset << '\n'; return 0; } } diff --git a/source/virusJucePlugin/PatchManager.cpp b/source/virusJucePlugin/PatchManager.cpp @@ -11,7 +11,6 @@ #include "virusLib/midiFileToRomData.h" #include "synthLib/midiToSysex.h" -#include "synthLib/os.h" #include "juce_cryptography/hashing/juce_MD5.h" diff --git a/source/virusJucePlugin/VirusController.cpp b/source/virusJucePlugin/VirusController.cpp @@ -6,7 +6,6 @@ #include "VirusProcessor.h" #include "virusLib/microcontrollerTypes.h" -#include "synthLib/os.h" #include "VirusEditor.h" diff --git a/source/virusJucePlugin/VirusEditor.cpp b/source/virusJucePlugin/VirusEditor.cpp @@ -13,8 +13,6 @@ #include "jucePluginEditorLib/filetype.h" #include "jucePluginEditorLib/patchmanager/savepatchdesc.h" -#include "synthLib/os.h" - namespace genericVirusUI { VirusEditor::VirusEditor(pluginLib::ParameterBinding& _binding, virus::VirusProcessor& _processorRef, const jucePluginEditorLib::Skin& _skin) : diff --git a/source/virusJucePlugin/VirusEditorState.cpp b/source/virusJucePlugin/VirusEditorState.cpp @@ -4,8 +4,6 @@ #include "VirusEditor.h" -#include "synthLib/os.h" - namespace virus { VirusEditorState::VirusEditorState(VirusProcessor& _processor, pluginLib::Controller& _controller, const std::vector<jucePluginEditorLib::Skin>& _includedSkins) diff --git a/source/virusJucePlugin/VirusProcessor.cpp b/source/virusJucePlugin/VirusProcessor.cpp @@ -4,10 +4,10 @@ #include "VirusController.h" #include "baseLib/binarystream.h" +#include "baseLib/filesystem.h" #include "synthLib/deviceException.h" #include "synthLib/lv2PresetExport.h" -#include "synthLib/os.h" namespace virus { @@ -122,7 +122,7 @@ namespace virus if(rom) { baseLib::ChunkWriter cw(s, "ROM ", 2); - const auto romName = synthLib::getFilenameWithoutPath(rom->getFilename()); + const auto romName = baseLib::filesystem::getFilenameWithoutPath(rom->getFilename()); s.write<uint8_t>(static_cast<uint8_t>(rom->getModel())); s.write(romName); } @@ -144,7 +144,7 @@ namespace virus for(uint32_t i=0; i<static_cast<uint32_t>(roms.size()); ++i) { const auto& rom = roms[i]; - if(rom.getModel() == model && synthLib::getFilenameWithoutPath(rom.getFilename()) == romName) + if(rom.getModel() == model && baseLib::filesystem::getFilenameWithoutPath(rom.getFilename()) == romName) setSelectedRom(i); } }); @@ -186,7 +186,7 @@ namespace virus case virusLib::DeviceModel::Invalid: bank.name = std::string("Unknown " ) + static_cast<char>('A' + b); assert(false); break; } - const auto path = synthLib::validatePath(_rootPath) + getProperties().name + '_' + synthLib::Lv2PresetExport::getBankFilename(bank.name) + ".lv2/"; + const auto path = baseLib::filesystem::validatePath(_rootPath) + getProperties().name + '_' + synthLib::Lv2PresetExport::getBankFilename(bank.name) + ".lv2/"; if(synthLib::Lv2PresetExport::manifestFileExists(path)) continue; diff --git a/source/virusLib/demoplayback.cpp b/source/virusLib/demoplayback.cpp @@ -7,7 +7,6 @@ #include "synthLib/midiToSysex.h" #include "synthLib/midiTypes.h" -#include "synthLib/os.h" #include "dsp56kEmu/logging.h" @@ -15,6 +14,8 @@ #include "midiFileToRomData.h" +#include "baseLib/filesystem.h" + namespace virusLib { constexpr auto g_timeScale_A = 54.0f; // A OS 2.8 @@ -23,7 +24,7 @@ namespace virusLib bool DemoPlayback::loadFile(const std::string& _filename) { - if(synthLib::hasExtension(_filename, ".bin")) + if(baseLib::filesystem::hasExtension(_filename, ".bin")) { std::vector<uint8_t> data; auto* hFile = fopen(_filename.c_str(), "rb"); diff --git a/source/virusLib/midiFileToRomData.cpp b/source/virusLib/midiFileToRomData.cpp @@ -2,7 +2,6 @@ #include "dsp56kEmu/logging.h" -#include "synthLib/os.h" #include "synthLib/midiToSysex.h" namespace virusLib diff --git a/source/virusLib/romfile.cpp b/source/virusLib/romfile.cpp @@ -9,8 +9,6 @@ #include "dsp56kEmu/dsp.h" #include "dsp56kEmu/logging.h" -#include "synthLib/os.h" - #include <cstring> // memcpy #include "demoplaybackTI.h" diff --git a/source/virusLib/romloader.cpp b/source/virusLib/romloader.cpp @@ -4,7 +4,7 @@ #include "midiFileToRomData.h" -#include "synthLib/os.h" +#include "baseLib/filesystem.h" namespace virusLib { @@ -60,21 +60,21 @@ namespace virusLib if(_filename.empty()) return findROM(_model); - const auto path = synthLib::getPath(_filename); + const auto path = baseLib::filesystem::getPath(_filename); const std::vector<ROMFile> results = findROMs(path, _model); if(results.empty()) return ROMFile::invalid(); - const auto requestedName = synthLib::lowercase(_filename); + const auto requestedName = baseLib::filesystem::lowercase(_filename); for (const auto& result : results) { - const auto name = synthLib::lowercase(result.getFilename()); + const auto name = baseLib::filesystem::lowercase(result.getFilename()); if(name == requestedName) return result; - if(synthLib::getFilenameWithoutPath(name) == requestedName) + if(baseLib::filesystem::getFilenameWithoutPath(name) == requestedName) return result; } return ROMFile::invalid(); @@ -85,16 +85,16 @@ namespace virusLib FileData data; data.filename = _name; - if(!synthLib::readFile(data.data, _name)) + if(!baseLib::filesystem::readFile(data.data, _name)) return {}; - if(synthLib::hasExtension(_name, ".bin")) + if(baseLib::filesystem::hasExtension(_name, ".bin")) { data.type = BinaryRom; return data; } - if(!synthLib::hasExtension(_name, ".mid")) + if(!baseLib::filesystem::hasExtension(_name, ".mid")) return {}; MidiFileToRomData midiLoader; @@ -145,7 +145,7 @@ namespace virusLib if(bracketClose == _data.end()) return DeviceModel::Invalid; - const auto versionString = synthLib::lowercase(std::string(bracketOpen+1, bracketClose-1)); + const auto versionString = baseLib::filesystem::lowercase(std::string(bracketOpen+1, bracketClose-1)); const auto test = [&versionString](const char* _key) { diff --git a/source/virusTestConsole/virusTestConsole.cpp b/source/virusTestConsole/virusTestConsole.cpp @@ -1,12 +1,12 @@ #include <iostream> +#include "baseLib/filesystem.h" + #include "virusConsoleLib/consoleApp.h" #include "dsp56kEmu/jitunittests.h" #include "dsp56kEmu/interpreterunittests.h" -#include "synthLib/os.h" - constexpr bool g_createDebugger = false; constexpr bool g_dumpAssembly = false; @@ -46,7 +46,7 @@ int main(int _argc, char* _argv[]) if(_argc > 1) { const std::string name = _argv[1]; - if(hasExtension(name, ".mid") || hasExtension(name, ".bin")) + if(baseLib::filesystem::hasExtension(name, ".mid") || baseLib::filesystem::hasExtension(name, ".bin")) { if(!app->loadDemo(name)) { diff --git a/source/wLib/wRom.cpp b/source/wLib/wRom.cpp @@ -2,7 +2,8 @@ #include <cstdint> -#include "synthLib/os.h" +#include "baseLib/filesystem.h" + #include "synthLib/midiToSysex.h" namespace wLib @@ -14,7 +15,7 @@ namespace wLib if(_filename.empty()) return false; - if(!synthLib::readFile(m_buffer, _filename)) + if(!baseLib::filesystem::readFile(m_buffer, _filename)) return false; if(m_buffer.size() != _expectedSize) @@ -54,7 +55,7 @@ namespace wLib _buffer.clear(); std::vector<uint8_t> buf; - if (!synthLib::readFile(buf, _filename)) + if (!baseLib::filesystem::readFile(buf, _filename)) return false; return loadFromSysExBuffer(_buffer, buf); } diff --git a/source/xtJucePlugin/PluginEditorState.cpp b/source/xtJucePlugin/PluginEditorState.cpp @@ -3,8 +3,6 @@ #include "xtEditor.h" #include "PluginProcessor.h" -#include "synthLib/os.h" - #include "skins.h" namespace xtJucePlugin diff --git a/source/xtJucePlugin/weData.cpp b/source/xtJucePlugin/weData.cpp @@ -2,14 +2,15 @@ #include "xtController.h" +#include "baseLib/filesystem.h" + #include "synthLib/midiToSysex.h" -#include "synthLib/os.h" #include "xtLib/xtState.h" namespace xtJucePlugin { - WaveEditorData::WaveEditorData(Controller& _controller, const std::string& _cacheDir) : m_controller(_controller), m_cacheDir(synthLib::validatePath(_cacheDir)) + WaveEditorData::WaveEditorData(Controller& _controller, const std::string& _cacheDir) : m_controller(_controller), m_cacheDir(baseLib::filesystem::validatePath(_cacheDir)) { loadRomCache(); loadUserData(); @@ -404,14 +405,14 @@ namespace xtJucePlugin data.insert(data.end(), sysex.begin(), sysex.end()); } - synthLib::createDirectory(m_cacheDir); - synthLib::writeFile(romWaves, data); + baseLib::filesystem::createDirectory(m_cacheDir); + baseLib::filesystem::writeFile(romWaves, data); } void WaveEditorData::loadRomCache() { std::vector<uint8_t> data; - if(!synthLib::readFile(data, getRomCacheFilename())) + if(!baseLib::filesystem::readFile(data, getRomCacheFilename())) return; std::vector<std::vector<uint8_t>> sysexMessages; @@ -431,7 +432,7 @@ namespace xtJucePlugin const auto filename = toFilename(_id); const auto data = xt::State::createTableData(*table, _id.rawId(), true); - synthLib::writeFile(m_cacheDir + filename, data); + baseLib::filesystem::writeFile(m_cacheDir + filename, data); } void WaveEditorData::saveWave(const xt::WaveId _id) const @@ -445,7 +446,7 @@ namespace xtJucePlugin const auto filename = toFilename(_id); const auto data = xt::State::createWaveData(*wave, _id.rawId(), true); - synthLib::writeFile(m_cacheDir + filename, data); + baseLib::filesystem::writeFile(m_cacheDir + filename, data); } void WaveEditorData::loadUserData() @@ -455,7 +456,7 @@ namespace xtJucePlugin const auto id = xt::WaveId(i + xt::wave::g_firstRamWaveIndex); const auto filename = toFilename(id); std::vector<uint8_t> data; - if (!synthLib::readFile(data, m_cacheDir + filename)) + if (!baseLib::filesystem::readFile(data, m_cacheDir + filename)) continue; xt::WaveData wave; if (xt::State::parseWaveData(wave, data)) @@ -467,7 +468,7 @@ namespace xtJucePlugin const auto id = xt::TableId(i); const auto filename = toFilename(id); std::vector<uint8_t> data; - if (!synthLib::readFile(data, m_cacheDir + filename)) + if (!baseLib::filesystem::readFile(data, m_cacheDir + filename)) continue; xt::TableData table; if (xt::State::parseTableData(table, data)) diff --git a/source/xtJucePlugin/xtController.cpp b/source/xtJucePlugin/xtController.cpp @@ -6,8 +6,6 @@ #include "xtLib/xtState.h" -#include "synthLib/os.h" - #include "dsp56kEmu/logging.h" #include "xtFrontPanel.h" diff --git a/source/xtLib/xt.cpp b/source/xtLib/xt.cpp @@ -1,8 +1,6 @@ #include "xt.h" #include "synthLib/midiTypes.h" -#include "synthLib/os.h" -#include "synthLib/deviceException.h" #include "dsp56kEmu/threadtools.h" diff --git a/source/xtLib/xtRomLoader.cpp b/source/xtLib/xtRomLoader.cpp @@ -5,7 +5,8 @@ #include <algorithm> #include <cstring> -#include "synthLib/os.h" +#include "baseLib/filesystem.h" + #include "wLib/wRom.h" namespace xt @@ -165,10 +166,10 @@ namespace xt for (const auto& name : fileNames) { File f; - if(!synthLib::readFile(f.data, name)) + if(!baseLib::filesystem::readFile(f.data, name)) continue; - f.name = synthLib::getFilenameWithoutPath(name); + f.name = baseLib::filesystem::getFilenameWithoutPath(name); files.emplace_back(std::move(f)); } return files; diff --git a/source/xtLib/xtState.cpp b/source/xtLib/xtState.cpp @@ -9,7 +9,6 @@ #include "xt.h" #include "xtWavePreview.h" -#include "synthLib/os.h" #include "synthLib/midiToSysex.h" #include "synthLib/midiBufferParser.h" diff --git a/source/xtTestConsole/xtTestConsole.cpp b/source/xtTestConsole/xtTestConsole.cpp @@ -6,8 +6,6 @@ #include "dsp56kEmu/jitunittests.h" -//#include "synthLib/os.h" - int main() { // dsp56k::JitUnittests tests;