diff --git a/source/tests/CarlaUtils.cpp b/source/tests/CarlaUtils.cpp index e0f89206c..1015fab36 100644 --- a/source/tests/CarlaUtils.cpp +++ b/source/tests/CarlaUtils.cpp @@ -28,11 +28,16 @@ #include "CarlaEngineUtils.hpp" #include "CarlaLadspaUtils.hpp" +#include "CarlaDssiUtils.hpp" + +// used in dssi utils +#include "juce_core.h" +#include +#include +#include // #include "CarlaBridgeUtils.hpp" -// #include "CarlaDssiUtils.hpp" // #include "CarlaJuceUtils.hpp" -// #include "CarlaLadspaUtils.hpp" // #include "CarlaLibUtils.hpp" // #include "CarlaLv2Utils.hpp" // #include "CarlaOscUtils.hpp" @@ -488,6 +493,58 @@ static void test_CarlaEngineUtils() noexcept carla_stdout(EngineControlEventType2Str(kEngineControlEventTypeNull)); } +// ----------------------------------------------------------------------- + +static void test_CarlaLadspaUtils() noexcept +{ + LADSPA_Descriptor desc; + carla_zeroStruct(desc); + + LADSPA_RDF_Descriptor rdfDesc; + delete ladspa_rdf_dup(&rdfDesc); + + is_ladspa_port_good(0x0, 0x0); + is_ladspa_rdf_descriptor_valid(&rdfDesc, &desc); + get_default_ladspa_port_value(0x0, -1.0f, 1.0f); +} + +// ----------------------------------------------------------------------- + +namespace dssi_juce { +const char* find_dssi_ui(const char* const filename, const char* const label) noexcept; +#define HAVE_JUCE +#include "CarlaDssiUtils.cpp" +} + +namespace dssi_qt { +const char* find_dssi_ui(const char* const filename, const char* const label) noexcept; +#undef HAVE_JUCE +#include "CarlaDssiUtils.cpp" +} + +static void test_CarlaDssiUtils() noexcept +{ + const char* const ui_juce = dssi_juce::find_dssi_ui("/usr/lib/dssi/trivial_sampler.so", "aa"); + const char* const ui_qt = dssi_qt::find_dssi_ui("/usr/lib/dssi/trivial_sampler.so", "aa"); + + CARLA_SAFE_ASSERT(ui_juce != nullptr); + CARLA_SAFE_ASSERT(ui_qt != nullptr); + + if (ui_juce != nullptr) + { + carla_stdout("%s", ui_juce); + assert(std::strcmp(ui_juce, "/usr/lib/dssi/trivial_sampler/trivial_sampler_qt") == 0); + delete[] ui_juce; + } + + if (ui_qt != nullptr) + { + carla_stdout("%s", ui_qt); + assert(std::strcmp(ui_qt, "/usr/lib/dssi/trivial_sampler/trivial_sampler_qt") == 0); + delete[] ui_qt; + } +} + // ----------------------------------------------------------------------- // main @@ -499,6 +556,9 @@ int main() test_CarlaBackendUtils(); test_CarlaEngineUtils(); + test_CarlaLadspaUtils(); + test_CarlaDssiUtils(); + return 0; } diff --git a/source/tests/Makefile b/source/tests/Makefile index 2fd9d1e57..249d8f356 100644 --- a/source/tests/Makefile +++ b/source/tests/Makefile @@ -68,7 +68,9 @@ CarlaString: CarlaString.cpp ../utils/CarlaString.hpp valgrind --leak-check=full ./$@ CarlaUtils: CarlaUtils.cpp ../utils/*.hpp - $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ + $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ \ + ../modules/juce_core.a -ldl -lpthread -lrt \ + $(shell pkg-config --cflags --libs QtCore) -isystem /usr/include/qt4 valgrind --leak-check=full ./$@ RDF: RDF.cpp ../modules/ladspa_rdf.hpp ../modules/lv2_rdf.hpp diff --git a/source/utils/CarlaDssiUtils.cpp b/source/utils/CarlaDssiUtils.cpp index 1697e07b2..d0e72cc98 100644 --- a/source/utils/CarlaDssiUtils.cpp +++ b/source/utils/CarlaDssiUtils.cpp @@ -17,9 +17,13 @@ #include "CarlaDssiUtils.hpp" -#include -#include -#include +#ifdef HAVE_JUCE +# include "juce_core.h" +#else +# include +# include +# include +#endif // ----------------------------------------------------------------------- @@ -30,6 +34,37 @@ const char* find_dssi_ui(const char* const filename, const char* const label) no carla_debug("find_dssi_ui(\"%s\", \"%s\")", filename, label); try { +#ifdef HAVE_JUCE + using namespace juce; + + String guiFilename; + String pluginDir(String(filename).upToLastOccurrenceOf(".", false, false)); + + String checkLabel(label); + String checkSName(File(pluginDir).getFileName()); + + if (! checkLabel.endsWith("_")) checkLabel += "_"; + if (! checkSName.endsWith("_")) checkSName += "_"; + + Array results; + + for (int i=0, count=File(pluginDir).findChildFiles(results, File::findFiles|File::ignoreHiddenFiles, false); i < count; ++i) + { + const File& gui(results[i]); + const String& guiShortName(gui.getFileName()); + + if (guiShortName.startsWith(checkLabel) || guiShortName.startsWith(checkSName)) + { + guiFilename = gui.getFullPathName(); + break; + } + } + + if (guiFilename.isEmpty()) + return nullptr; + + return carla_strdup(guiFilename.toRawUTF8()); +#else QString guiFilename; QString pluginDir(filename); pluginDir.resize(pluginDir.lastIndexOf(".")); @@ -56,7 +91,7 @@ const char* find_dssi_ui(const char* const filename, const char* const label) no return nullptr; return carla_strdup(guiFilename.toUtf8().constData()); - +#endif } CARLA_SAFE_EXCEPTION_RETURN("find_dssi_ui", nullptr); } diff --git a/source/utils/CarlaLadspaUtils.hpp b/source/utils/CarlaLadspaUtils.hpp index dfbf0baf2..dd4062053 100644 --- a/source/utils/CarlaLadspaUtils.hpp +++ b/source/utils/CarlaLadspaUtils.hpp @@ -196,8 +196,8 @@ LADSPA_Data get_default_ladspa_port_value(const LADSPA_PortRangeHintDescriptor h // no default value if (min < 0.0f && max > 0.0f) return 0.0f; - else - return min; + + return min; } // ----------------------------------------------------------------------- diff --git a/source/utils/CarlaMathUtils.hpp b/source/utils/CarlaMathUtils.hpp index 499ef66e2..dee82b721 100644 --- a/source/utils/CarlaMathUtils.hpp +++ b/source/utils/CarlaMathUtils.hpp @@ -121,13 +121,13 @@ uint32_t carla_nextPowerOf2(uint32_t size) noexcept * Add float array values to another float array. */ static inline -void carla_addFloat(float* dataDst, const float* dataSrc, const size_t numSamples) noexcept +void carla_addFloat(float* dataDst, const float* dataSrc, const std::size_t numSamples) noexcept { CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,); CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,); CARLA_SAFE_ASSERT_RETURN(numSamples > 0,); - for (size_t i=0; i < numSamples; ++i) + for (std::size_t i=0; i < numSamples; ++i) *dataDst++ += *dataSrc++; } @@ -135,7 +135,7 @@ void carla_addFloat(float* dataDst, const float* dataSrc, const size_t numSample * Copy float array values to another float array. */ static inline -void carla_copyFloat(float* const dataDst, const float* const dataSrc, const size_t numSamples) noexcept +void carla_copyFloat(float* const dataDst, const float* const dataSrc, const std::size_t numSamples) noexcept { CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,); CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,); @@ -148,7 +148,7 @@ void carla_copyFloat(float* const dataDst, const float* const dataSrc, const siz * Clear a float array. */ static inline -void carla_zeroFloat(float* const data, const size_t numSamples) noexcept +void carla_zeroFloat(float* const data, const std::size_t numSamples) noexcept { CARLA_SAFE_ASSERT_RETURN(data != nullptr,); CARLA_SAFE_ASSERT_RETURN(numSamples > 0,); diff --git a/source/utils/CarlaUtils.hpp b/source/utils/CarlaUtils.hpp index 6d313fe65..26cbb7b98 100644 --- a/source/utils/CarlaUtils.hpp +++ b/source/utils/CarlaUtils.hpp @@ -259,8 +259,8 @@ const char* carla_strdup(const char* const strBuf) { CARLA_SAFE_ASSERT(strBuf != nullptr); - const size_t bufferLen = (strBuf != nullptr) ? std::strlen(strBuf) : 0; - char* const buffer = new char[bufferLen+1]; + const std::size_t bufferLen = (strBuf != nullptr) ? std::strlen(strBuf) : 0; + char* const buffer = new char[bufferLen+1]; if (strBuf != nullptr && bufferLen > 0) std::strncpy(buffer, strBuf, bufferLen); @@ -292,13 +292,13 @@ const char* carla_strdup_free(char* const strBuf) */ template static inline -void carla_add(T* dataDst, const T* dataSrc, const size_t size) noexcept +void carla_add(T* dataDst, const T* dataSrc, const std::size_t size) noexcept { CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,); CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,); CARLA_SAFE_ASSERT_RETURN(size > 0,); - for (size_t i=0; i < size; ++i) + for (std::size_t i=0; i < size; ++i) *dataDst++ += *dataSrc++; } @@ -307,7 +307,7 @@ void carla_add(T* dataDst, const T* dataSrc, const size_t size) noexcept */ template static inline -void carla_copy(T* const dataDst, const T* const dataSrc, const size_t size) noexcept +void carla_copy(T* const dataDst, const T* const dataSrc, const std::size_t size) noexcept { CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,); CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,); @@ -321,7 +321,7 @@ void carla_copy(T* const dataDst, const T* const dataSrc, const size_t size) noe */ template static inline -void carla_fill(T* data, const T v, const size_t size) noexcept +void carla_fill(T* data, const T v, const std::size_t size) noexcept { CARLA_SAFE_ASSERT_RETURN(data != nullptr,); CARLA_SAFE_ASSERT_RETURN(size > 0,); @@ -332,7 +332,7 @@ void carla_fill(T* data, const T v, const size_t size) noexcept } else { - for (size_t i=0; i < size; ++i) + for (std::size_t i=0; i < size; ++i) *data++ = v; } } @@ -341,7 +341,7 @@ void carla_fill(T* data, const T v, const size_t size) noexcept * Clear a byte array. */ static inline -void carla_zeroBytes(void* const memory, const size_t numBytes) noexcept +void carla_zeroBytes(void* const memory, const std::size_t numBytes) noexcept { CARLA_SAFE_ASSERT_RETURN(memory != nullptr,); CARLA_SAFE_ASSERT_RETURN(numBytes > 0,); @@ -353,7 +353,7 @@ void carla_zeroBytes(void* const memory, const size_t numBytes) noexcept * Clear a char array. */ static inline -void carla_zeroChar(char* const data, const size_t numChars) noexcept +void carla_zeroChar(char* const data, const std::size_t numChars) noexcept { CARLA_SAFE_ASSERT_RETURN(data != nullptr,); CARLA_SAFE_ASSERT_RETURN(numChars > 0,); @@ -376,7 +376,7 @@ void carla_zeroStruct(T& structure) noexcept */ template static inline -void carla_zeroStruct(T* const structure, const size_t count) noexcept +void carla_zeroStruct(T* const structure, const std::size_t count) noexcept { CARLA_SAFE_ASSERT_RETURN(structure != nullptr,); CARLA_SAFE_ASSERT_RETURN(count > 0,); @@ -399,7 +399,7 @@ void carla_copyStruct(T& struct1, const T& struct2) noexcept */ template static inline -void carla_copyStruct(T* const struct1, const T* const struct2, const size_t count) noexcept +void carla_copyStruct(T* const struct1, const T* const struct2, const std::size_t count) noexcept { CARLA_SAFE_ASSERT_RETURN(struct1 != nullptr,); CARLA_SAFE_ASSERT_RETURN(struct2 != nullptr,);