commit fe96a100e4ca925076b341414295b71f1a88f591
parent 5ac2c9bcef19e2a72a587bacc0efd235e7b633d6
Author: Tal Aviram <me@talaviram.com>
Date: Fri, 23 Jul 2021 13:17:18 +0300
clang-format synthLib/os.{h,cpp}
Diffstat:
2 files changed, 158 insertions(+), 158 deletions(-)
diff --git a/source/synthLib/os.cpp b/source/synthLib/os.cpp
@@ -1,7 +1,7 @@
#include "os.h"
-#include "../dsp56300/source/dsp56kEmu/logging.h"
#include "../dsp56300/source/dsp56kEmu/buildconfig.h"
+#include "../dsp56300/source/dsp56kEmu/logging.h"
#ifndef _WIN32
// filesystem is only available on Mac OS Catalina 10.15+
@@ -10,190 +10,190 @@
#endif
#ifdef USE_DIRENT
-# include <dirent.h>
-# include <unistd.h>
+#include <dirent.h>
+#include <unistd.h>
#else
-# include <filesystem>
+#include <filesystem>
#endif
#ifdef _WIN32
-# define NOMINMAX
-# define NOSERVICE
-# include <Windows.h>
+#define NOMINMAX
+#define NOSERVICE
+#include <Windows.h>
#else
-# include <dlfcn.h>
+#include <dlfcn.h>
#endif
#ifdef _MSC_VER
-# include <cfloat>
+#include <cfloat>
#elif defined(HAVE_SSE)
-# include <immintrin.h>
+#include <immintrin.h>
#endif
namespace synthLib
{
- std::string getModulePath()
- {
- std::string path;
+ std::string getModulePath()
+ {
+ std::string path;
#ifdef _WIN32
- char buffer[MAX_PATH];
- HMODULE hm = nullptr;
-
- if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast<LPCSTR>(&getModulePath), &hm) == 0)
- {
- LOG("GetModuleHandle failed, error = " << GetLastError());
- return std::string();
- }
- if (GetModuleFileName(hm, buffer, sizeof(buffer)) == 0)
- {
- LOG("GetModuleFileName failed, error = " << GetLastError());
- return std::string();
- }
-
- path = buffer;
+ char buffer[MAX_PATH];
+ HMODULE hm = nullptr;
+
+ if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ reinterpret_cast<LPCSTR>(&getModulePath), &hm) == 0)
+ {
+ LOG("GetModuleHandle failed, error = " << GetLastError());
+ return std::string();
+ }
+ if (GetModuleFileName(hm, buffer, sizeof(buffer)) == 0)
+ {
+ LOG("GetModuleFileName failed, error = " << GetLastError());
+ return std::string();
+ }
+
+ path = buffer;
#else
- Dl_info info;
- if (!dladdr(reinterpret_cast<const void*>(&getModulePath), &info))
- {
- LOG("Failed to get module path");
- return std::string();
- }
- else
- {
- const auto end = path.find_last_of("/\\");
- path = info.dli_fname;
- }
+ Dl_info info;
+ if (!dladdr(reinterpret_cast<const void *>(&getModulePath), &info))
+ {
+ LOG("Failed to get module path");
+ return std::string();
+ }
+ else
+ {
+ const auto end = path.find_last_of("/\\");
+ path = info.dli_fname;
+ }
#endif
- auto fixPath = [&](std::string key)
- {
- const auto end = path.find(key);
+ auto fixPath = [&](std::string key) {
+ const auto end = path.find(key);
- if(end != std::string::npos)
- path = path.substr(0, end);
- };
+ if (end != std::string::npos)
+ path = path.substr(0, end);
+ };
- fixPath(".vst/");
- fixPath(".vst3/");
- fixPath(".component/");
+ fixPath(".vst/");
+ fixPath(".vst3/");
+ fixPath(".component/");
- fixPath(".vst\\");
- fixPath(".vst3\\");
- fixPath(".component\\");
+ fixPath(".vst\\");
+ fixPath(".vst3\\");
+ fixPath(".component\\");
- const auto end = path.find_last_of("/\\");
+ const auto end = path.find_last_of("/\\");
- if(end != std::string::npos)
- path = path.substr(0, end + 1);
+ if (end != std::string::npos)
+ path = path.substr(0, end + 1);
- return path;
- }
+ return path;
+ }
- static std::string lowercase(const std::string& _src)
- {
- std::string str(_src);
- for(size_t i=0; i<str.size(); ++i)
- str[i] = tolower(str[i]);
- return str;
- }
+ static std::string lowercase(const std::string &_src)
+ {
+ std::string str(_src);
+ for (size_t i = 0; i < str.size(); ++i)
+ str[i] = tolower(str[i]);
+ return str;
+ }
- static 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();
- }
+ static 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();
+ }
- std::string findROM(const size_t _expectedSize)
- {
- std::string path = getModulePath();
+ std::string findROM(const size_t _expectedSize)
+ {
+ std::string path = getModulePath();
#ifdef USE_DIRENT
- if(path.empty())
- {
- char temp[1024];
- getcwd(temp, sizeof(temp));
- path = temp;
- }
-
- DIR *dir;
- struct dirent *ent;
- if ((dir = opendir (path.c_str())))
- {
- /* print all the files and directories within directory */
- while ((ent = readdir (dir)))
- {
- const std::string file = path + ent->d_name;
-
- const std::string ext = lowercase(getExtension(file));
-
- if(ext != ".bin")
- continue;
-
- if(_expectedSize)
- {
- FILE* hFile = fopen(file.c_str(), "rb");
- if(!hFile)
- continue;
-
- fseek(hFile, 0, SEEK_END);
- const auto size = ftell(hFile);
- fclose(hFile);
- if(size != _expectedSize)
- continue;
-
- LOG("Found ROM at path " << file);
-
- return file;
- }
- }
- closedir (dir);
- }
- else
- {
- return std::string();
- }
-#else
- if(path.empty())
- path = std::filesystem::current_path().string();
-
- try
- {
- for (const std::filesystem::directory_entry& entry : std::filesystem::directory_iterator(path))
- {
- const auto& file = entry.path();
-
- if(!file.has_extension())
- continue;
-
- if(_expectedSize && entry.file_size() != _expectedSize)
- continue;
-
- std::string ext = lowercase(file.extension().string());
-
- if(ext != ".bin")
- continue;
-
- LOG("Found ROM at path " << file);
-
- return file.string();
- }
- }
- catch(...)
- {
- }
+ if (path.empty())
+ {
+ char temp[1024];
+ getcwd(temp, sizeof(temp));
+ path = temp;
+ }
+
+ DIR *dir;
+ struct dirent *ent;
+ if ((dir = opendir(path.c_str())))
+ {
+ /* print all the files and directories within directory */
+ while ((ent = readdir(dir)))
+ {
+ const std::string file = path + ent->d_name;
+
+ const std::string ext = lowercase(getExtension(file));
+
+ if (ext != ".bin")
+ continue;
+
+ if (_expectedSize)
+ {
+ FILE *hFile = fopen(file.c_str(), "rb");
+ if (!hFile)
+ continue;
+
+ fseek(hFile, 0, SEEK_END);
+ const auto size = ftell(hFile);
+ fclose(hFile);
+ if (size != _expectedSize)
+ continue;
+
+ LOG("Found ROM at path " << file);
+
+ return file;
+ }
+ }
+ closedir(dir);
+ }
+ else
+ {
+ return std::string();
+ }
+#else
+ if (path.empty())
+ path = std::filesystem::current_path().string();
+
+ try
+ {
+ for (const std::filesystem::directory_entry &entry : std::filesystem::directory_iterator(path))
+ {
+ const auto &file = entry.path();
+
+ if (!file.has_extension())
+ continue;
+
+ if (_expectedSize && entry.file_size() != _expectedSize)
+ continue;
+
+ std::string ext = lowercase(file.extension().string());
+
+ if (ext != ".bin")
+ continue;
+
+ LOG("Found ROM at path " << file);
+
+ return file.string();
+ }
+ }
+ catch (...)
+ {
+ }
#endif
- return std::string();
- }
+ return std::string();
+ }
- void setFlushDenormalsToZero()
- {
+ void setFlushDenormalsToZero()
+ {
#if defined(_MSC_VER)
- _controlfp(_DN_FLUSH, _MCW_DN);
+ _controlfp(_DN_FLUSH, _MCW_DN);
#elif defined(HAVE_SSE)
- _MM_SET_FLUSH_ZERO_MODE (_MM_FLUSH_ZERO_ON);
+ _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
#endif
- }
-}
+ }
+} // namespace synthLib
diff --git a/source/synthLib/os.h b/source/synthLib/os.h
@@ -3,7 +3,7 @@
namespace synthLib
{
- std::string getModulePath();
- std::string findROM(size_t _expectedSize = 524288);
- void setFlushDenormalsToZero();
-}
+ std::string getModulePath();
+ std::string findROM(size_t _expectedSize = 524288);
+ void setFlushDenormalsToZero();
+} // namespace synthLib