@@ -1,6 +1,6 @@ | |||
/* | |||
* Carla DSSI Plugin | |||
* Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com> | |||
* Carla Plugin, DSSI implementation | |||
* Copyright (C) 2011-2015 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License as | |||
@@ -15,8 +15,6 @@ | |||
* For a full copy of the GNU General Public License see the doc/GPL.txt file. | |||
*/ | |||
// TODO: set fUsesCustomData and latency index before init finishes | |||
#include "CarlaPluginInternal.hpp" | |||
#include "CarlaEngineUtils.hpp" | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* Carla LADSPA Plugin | |||
* Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com> | |||
* Carla Plugin, LADSPA implementation | |||
* Copyright (C) 2011-2015 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License as | |||
@@ -1426,7 +1426,7 @@ static void do_juce_check(const char* const filename_, const char* const stype, | |||
} | |||
else | |||
#endif | |||
filename = File(filename_).getFullPathName(); | |||
filename = File(filename_).getFullPathName(); | |||
juce::ScopedPointer<AudioPluginFormat> pluginFormat; | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* Carla Utility Tests | |||
* Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com> | |||
* Copyright (C) 2013-2015 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License as | |||
@@ -22,15 +22,15 @@ | |||
#include "CarlaUtils.hpp" | |||
#include "CarlaMathUtils.hpp" | |||
#include "CarlaBackendUtils.hpp" | |||
#include "CarlaBridgeUtils.hpp" | |||
#include "CarlaEngineUtils.hpp" | |||
// #include "CarlaBackendUtils.hpp" | |||
// #include "CarlaBridgeUtils.hpp" | |||
// #include "CarlaEngineUtils.hpp" | |||
// ----------------------------------------------------------------------- | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
static void test_CarlaUtils() | |||
{ | |||
// ------------------------------------------------------------------- | |||
// ---------------------------------------------------------------------------------------------------------------- | |||
// misc functions | |||
{ | |||
@@ -38,11 +38,14 @@ static void test_CarlaUtils() | |||
bool2str(true); | |||
pass(); | |||
char strBuf[1]; | |||
char strBuf[2]; | |||
nullStrBuf(strBuf); | |||
char* const strBuf2(strBuf+1); | |||
nullStrBuf(strBuf2); | |||
} | |||
// ------------------------------------------------------------------- | |||
// ---------------------------------------------------------------------------------------------------------------- | |||
// string print functions | |||
{ | |||
@@ -52,7 +55,7 @@ static void test_CarlaUtils() | |||
carla_stderr2("STDERR2 " P_UINT64, 0xffffffff); // 4294967295 | |||
} | |||
// ------------------------------------------------------------------- | |||
// ---------------------------------------------------------------------------------------------------------------- | |||
// carla_*sleep | |||
{ | |||
@@ -60,65 +63,73 @@ static void test_CarlaUtils() | |||
carla_msleep(1); | |||
} | |||
// ------------------------------------------------------------------- | |||
// ---------------------------------------------------------------------------------------------------------------- | |||
// carla_setenv | |||
{ | |||
carla_setenv("THIS", "THAT"); | |||
assert(std::strcmp(std::getenv("THIS"), "THAT") == 0); | |||
carla_unsetenv("THIS"); | |||
assert(std::getenv("THIS") == nullptr); | |||
} | |||
// ------------------------------------------------------------------- | |||
// ---------------------------------------------------------------------------------------------------------------- | |||
// carla_strdup | |||
{ | |||
// with variables | |||
const char* const str1(carla_strdup("string1")); | |||
const char* const strF(carla_strdup_free(strdup("string2"))); | |||
const char* const str1(carla_strdup("stringN")); | |||
const char* const strF(carla_strdup_free(strdup("stringF"))); | |||
const char* const str2(carla_strdup_safe("stringS")); | |||
delete[] str1; | |||
delete[] str2; | |||
delete[] strF; | |||
// without variables | |||
delete[] carla_strdup("string3"); | |||
delete[] carla_strdup_free(strdup("string4")); | |||
delete[] carla_strdup("string_normal"); | |||
delete[] carla_strdup_free(strdup("string_free")); | |||
delete[] carla_strdup_safe("string_safe"); | |||
} | |||
{ | |||
// common use case in Carla code | |||
struct TestStruct { | |||
const char* str1; | |||
const char* str2; | |||
const char* str3; | |||
const char* str4; | |||
const char* strNull; | |||
const char* strNormal; | |||
const char* strFree; | |||
const char* strSafe; | |||
TestStruct() | |||
: str1(carla_strdup("str1")), | |||
str2(carla_strdup("str2")), | |||
str3(nullptr), | |||
str4(carla_strdup("str4")) {} | |||
: strNull(nullptr), | |||
strNormal(carla_strdup("strNormal")), | |||
strFree(carla_strdup_free(strdup("strFree"))), | |||
strSafe(carla_strdup_safe("strSafe")) {} | |||
~TestStruct() noexcept | |||
{ | |||
if (str1 != nullptr) | |||
if (strNull != nullptr) | |||
{ | |||
delete[] str1; | |||
str1 = nullptr; | |||
delete[] strNull; | |||
strNull = nullptr; | |||
} | |||
if (str2 != nullptr) | |||
if (strNormal != nullptr) | |||
{ | |||
delete[] str2; | |||
str2 = nullptr; | |||
delete[] strNormal; | |||
strNormal = nullptr; | |||
} | |||
if (str3 != nullptr) | |||
if (strFree != nullptr) | |||
{ | |||
delete[] str3; | |||
str3 = nullptr; | |||
delete[] strFree; | |||
strFree = nullptr; | |||
} | |||
if (str4 != nullptr) | |||
if (strSafe != nullptr) | |||
{ | |||
delete[] str4; | |||
str4 = nullptr; | |||
delete[] strSafe; | |||
strSafe = nullptr; | |||
} | |||
} | |||
@@ -128,167 +139,244 @@ static void test_CarlaUtils() | |||
TestStruct a, b, c; | |||
} | |||
// ------------------------------------------------------------------- | |||
// ---------------------------------------------------------------------------------------------------------------- | |||
// memory functions | |||
{ | |||
int a[] = { 4, 3, 2, 1 }; | |||
int b[] = { 1, 2, 3, 4 }; | |||
carla_add(a, b, 4); | |||
assert(a[0] == 5); | |||
assert(a[1] == 5); | |||
assert(a[2] == 5); | |||
assert(a[3] == 5); | |||
int c[] = { 4, 3, 2, 1 }; | |||
carla_add(b, c, 4); | |||
assert(a[0] == b[0]); | |||
assert(a[1] == b[1]); | |||
assert(a[2] == b[2]); | |||
assert(a[3] == b[3]); | |||
carla_copy(a, c, 2); | |||
carla_copy(b+2, c+2, 2); | |||
assert(a[0] == c[0]); | |||
assert(a[1] == c[1]); | |||
assert(b[2] == c[2]); | |||
assert(b[3] == c[3]); | |||
carla_copy(c, a, 4); | |||
assert(a[0] == c[0]); | |||
assert(a[1] == c[1]); | |||
assert(a[2] == c[2]); | |||
assert(a[3] == c[3]); | |||
carla_fill(a, 0, 4); | |||
assert(a[0] == 0); | |||
assert(a[1] == 0); | |||
assert(a[2] == 0); | |||
assert(a[3] == 0); | |||
int a1[] = { 4, 3, 2, 1 }; | |||
int a2[] = { 4, 3, 2, 1 }; | |||
int b1[] = { 1, 2, 3, 4 }; | |||
int b2[] = { 1, 2, 3, 4 }; | |||
carla_add(a1, b1, 4); | |||
assert(a1[0] == 5); | |||
assert(a1[1] == 5); | |||
assert(a1[2] == 5); | |||
assert(a1[3] == 5); | |||
carla_add(b1, a2, 4); | |||
assert(b1[0] == 5); | |||
assert(b1[1] == 5); | |||
assert(b1[2] == 5); | |||
assert(b1[3] == 5); | |||
assert(a1[0] == b1[0]); | |||
assert(a1[1] == b1[1]); | |||
assert(a1[2] == b1[2]); | |||
assert(a1[3] == b1[3]); | |||
carla_copy(a1, b2, 4); | |||
assert(a1[0] != b1[0]); | |||
assert(a1[1] != b1[1]); | |||
assert(a1[2] != b1[2]); | |||
assert(a1[3] != b1[3]); | |||
assert(a1[0] == b2[0]); | |||
assert(a1[1] == b2[1]); | |||
assert(a1[2] == b2[2]); | |||
assert(a1[3] == b2[3]); | |||
carla_copy(a1, b1, 4); | |||
assert(a1[0] == b1[0]); | |||
assert(a1[1] == b1[1]); | |||
assert(a1[2] == b1[2]); | |||
assert(a1[3] == b1[3]); | |||
carla_copy(a1, b2, 2); | |||
assert(a1[0] != b1[0]); | |||
assert(a1[1] != b1[1]); | |||
assert(a1[2] == b1[2]); | |||
assert(a1[3] == b1[3]); | |||
carla_copy(a1+2, b2+2, 2); | |||
assert(a1[0] != b1[0]); | |||
assert(a1[1] != b1[1]); | |||
assert(a1[2] != b1[2]); | |||
assert(a1[3] != b1[3]); | |||
carla_copy(a1, b1, 2); | |||
assert(a1[0] == b1[0]); | |||
assert(a1[1] == b1[1]); | |||
assert(a1[2] != b1[2]); | |||
assert(a1[3] != b1[3]); | |||
carla_copy(a1+2, b1+2, 2); | |||
assert(a1[0] == b1[0]); | |||
assert(a1[1] == b1[1]); | |||
assert(a1[2] == b1[2]); | |||
assert(a1[3] == b1[3]); | |||
carla_fill(a1, 0, 4); | |||
assert(a1[0] == 0); | |||
assert(a1[1] == 0); | |||
assert(a1[2] == 0); | |||
assert(a1[3] == 0); | |||
carla_fill(a1, -11, 4); | |||
assert(a1[0] == -11); | |||
assert(a1[1] == -11); | |||
assert(a1[2] == -11); | |||
assert(a1[3] == -11); | |||
carla_fill(a1, 1791, 2); | |||
assert(a1[0] == 1791); | |||
assert(a1[1] == 1791); | |||
assert(a1[2] == -11); | |||
assert(a1[3] == -11); | |||
carla_fill(a1+2, 1791, 2); | |||
assert(a1[0] == 1791); | |||
assert(a1[1] == 1791); | |||
assert(a1[2] == 1791); | |||
assert(a1[3] == 1791); | |||
int16_t d = 1527, e = 0; | |||
carla_fill(a, -11, 4); | |||
assert(a[0] == -11); | |||
assert(a[1] == -11); | |||
assert(a[2] == -11); | |||
assert(a[3] == -11); | |||
carla_add(&d, &d, 1); | |||
assert(d == 1527*2); | |||
carla_fill(a+0, 17, 2); | |||
carla_fill(a+2, 23, 2); | |||
assert(a[0] == 17); | |||
assert(a[1] == 17); | |||
assert(a[2] == 23); | |||
assert(a[3] == 23); | |||
carla_add(&d, &d, 1); | |||
assert(d == 1527*4); | |||
carla_add(&d, &e, 1); | |||
assert(d == 1527*4); | |||
assert(e == 0); | |||
carla_zeroBytes(a, sizeof(int)*4); | |||
carla_add(&e, &d, 1); | |||
assert(d == e); | |||
carla_add(&e, &d, 1); | |||
assert(e == d*2); | |||
d = -e; | |||
carla_add(&d, &e, 1); | |||
assert(d == 0); | |||
} | |||
{ | |||
bool x; | |||
const bool f = false, t = true; | |||
carla_copy(&x, &t, 1); | |||
assert(x); | |||
carla_copy(&x, &f, 1); | |||
assert(! x); | |||
carla_fill(&x, true, 1); | |||
assert(x); | |||
carla_fill(&x, false, 1); | |||
assert(! x); | |||
} | |||
{ | |||
uint8_t a[] = { 3, 2, 1, 0 }; | |||
carla_zeroBytes(a, 1); | |||
assert(a[0] == 0); | |||
assert(a[1] == 2); | |||
assert(a[2] == 1); | |||
assert(a[3] == 0); | |||
carla_zeroBytes(a+1, 2); | |||
assert(a[0] == 0); | |||
assert(a[1] == 0); | |||
assert(a[2] == 0); | |||
assert(a[3] == 0); | |||
} | |||
char strBuf[501]; | |||
strBuf[0] = strBuf[499] = strBuf[500] = '!'; | |||
carla_zeroChar(strBuf, 501); | |||
{ | |||
char a[501]; | |||
for (int i=0; i<501; ++i) | |||
assert(strBuf[i] == '\0'); | |||
for (int i=500; --i>=0;) | |||
a[i] = 'a'; | |||
int d = 1527, e = 0; | |||
carla_add(&d, &d, 1); | |||
carla_add(&d, &e, 1); | |||
carla_add(&e, &d, 1); | |||
assert(d == 1527*2); | |||
assert(d == e); | |||
carla_zeroChars(a, 501); | |||
e = -e; | |||
carla_add(&d, &e, 1); | |||
assert(d == 0); | |||
for (int i=501; --i>=0;) | |||
assert(a[i] == '\0'); | |||
carla_copy(&d, &e, 1); | |||
assert(d == -1527*2); | |||
assert(d == e); | |||
for (int i=500; --i>=0;) | |||
a[i] = 'a'; | |||
carla_fill(&d, 9999, 1); | |||
carla_fill(&e, 123, 1); | |||
assert(d == 9999); | |||
assert(e == 123); | |||
assert(std::strlen(a) == 500); | |||
carla_zeroStruct(d); | |||
assert(d == 0); | |||
carla_fill(a+200, '\0', 1); | |||
assert(std::strlen(a) == 200); | |||
} | |||
carla_copyStruct(d, e); | |||
assert(d != 0); | |||
assert(d == e); | |||
{ | |||
void* a[33]; | |||
carla_zeroPointers(a, 33); | |||
carla_fill(a+0, 1, 1); | |||
carla_fill(a+1, 2, 1); | |||
carla_fill(a+2, 3, 1); | |||
carla_fill(a+3, 4, 1); | |||
assert(a[0] == 1); | |||
assert(a[1] == 2); | |||
assert(a[2] == 3); | |||
assert(a[3] == 4); | |||
carla_copyStruct(c, a, 4); | |||
assert(c[0] == a[0]); | |||
assert(c[1] == a[1]); | |||
assert(c[2] == a[2]); | |||
assert(c[3] == a[3]); | |||
carla_zeroStruct(c, 4); | |||
assert(c[0] == 0); | |||
assert(c[1] == 0); | |||
assert(c[2] == 0); | |||
assert(c[3] == 0); | |||
float fl[5]; | |||
carla_fill(fl, 1.11f, 5); | |||
assert(fl[0] == 1.11f); | |||
assert(fl[1] == 1.11f); | |||
assert(fl[2] == 1.11f); | |||
assert(fl[3] == 1.11f); | |||
assert(fl[4] == 1.11f); | |||
carla_add(fl, fl, 5); | |||
assert(fl[0] == 1.11f*2); | |||
assert(fl[1] == 1.11f*2); | |||
assert(fl[2] == 1.11f*2); | |||
assert(fl[3] == 1.11f*2); | |||
assert(fl[4] == 1.11f*2); | |||
carla_add(fl, fl, 4); | |||
assert(fl[0] == 1.11f*4); | |||
assert(fl[1] == 1.11f*4); | |||
assert(fl[2] == 1.11f*4); | |||
assert(fl[3] == 1.11f*4); | |||
assert(fl[4] == 1.11f*2); | |||
carla_add(fl, fl, 3); | |||
assert(fl[0] == 1.11f*8); | |||
assert(fl[1] == 1.11f*8); | |||
assert(fl[2] == 1.11f*8); | |||
assert(fl[3] == 1.11f*4); | |||
assert(fl[4] == 1.11f*2); | |||
carla_add(fl, fl, 2); | |||
assert(fl[0] == 1.11f*16); | |||
assert(fl[1] == 1.11f*16); | |||
assert(fl[2] == 1.11f*8); | |||
assert(fl[3] == 1.11f*4); | |||
assert(fl[4] == 1.11f*2); | |||
carla_add(fl, fl, 1); | |||
assert(fl[0] == 1.11f*32); | |||
assert(fl[1] == 1.11f*16); | |||
assert(fl[2] == 1.11f*8); | |||
assert(fl[3] == 1.11f*4); | |||
assert(fl[4] == 1.11f*2); | |||
for (int i=33; --i>=0;) | |||
assert(a[i] == nullptr); | |||
} | |||
{ | |||
struct Thing { | |||
char c; | |||
int i; | |||
int64_t h; | |||
bool operator==(const Thing& t) const noexcept | |||
{ | |||
return (t.c == c && t.i == i && t.h == h); | |||
} | |||
bool operator!=(const Thing& t) const noexcept | |||
{ | |||
return !operator==(t); | |||
} | |||
}; | |||
Thing a, b, c; | |||
a.c = 0; | |||
a.i = 0; | |||
a.h = 0; | |||
b.c = 64; | |||
b.i = 64; | |||
b.h = 64; | |||
c = a; | |||
carla_copyStruct(a, b); | |||
assert(a == b); | |||
carla_zeroStruct(a); | |||
assert(a == c); | |||
carla_copyStruct(c, b); | |||
assert(a != c); | |||
// make it non-zero | |||
a.c = 1; | |||
Thing d[3]; | |||
carla_zeroStructs(d, 3); | |||
assert(d[0] != a); | |||
assert(d[1] != b); | |||
assert(d[2] != c); | |||
carla_copyStructs(d, &a, 1); | |||
assert(d[0] == a); | |||
assert(d[1] != b); | |||
assert(d[2] != c); | |||
carla_copyStructs(&c, d+2, 1); | |||
assert(d[0] == a); | |||
assert(d[1] != b); | |||
assert(d[2] == c); | |||
} | |||
} | |||
// ----------------------------------------------------------------------- | |||
#if 0 | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
static void test_CarlaMathUtils() noexcept | |||
{ | |||
// ------------------------------------------------------------------- | |||
// ---------------------------------------------------------------------------------------------------------------- | |||
// math functions (base) | |||
// Return the lower of 2 values, with 'min' as the minimum possible value. | |||
@@ -428,14 +516,16 @@ static void test_CarlaMathUtils() noexcept | |||
assert((power = carla_nextPowerOf2(power+1)) == 65536); | |||
assert((power = carla_nextPowerOf2(power+1)) == 131072); | |||
// ------------------------------------------------------------------- | |||
// ---------------------------------------------------------------------------------------------------------------- | |||
// math functions (extended) | |||
// carla_addFloat, carla_copyFloat & carla_zeroFloat tests skipped | |||
// mostly unused due to juce::FloatVectorOperations | |||
} | |||
#endif | |||
// ----------------------------------------------------------------------- | |||
#if 0 | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
static void test_CarlaBackendUtils() noexcept | |||
{ | |||
@@ -457,7 +547,7 @@ static void test_CarlaBackendUtils() noexcept | |||
getPluginCategoryFromName("cat"); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
static void test_CarlaBridgeUtils() noexcept | |||
{ | |||
@@ -466,7 +556,7 @@ static void test_CarlaBridgeUtils() noexcept | |||
carla_stdout(PluginBridgeNonRtOpcode2str(kPluginBridgeNonRtNull)); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
static void test_CarlaEngineUtils() noexcept | |||
{ | |||
@@ -476,21 +566,21 @@ static void test_CarlaEngineUtils() noexcept | |||
carla_stdout(EngineEventType2Str(kEngineEventTypeNull)); | |||
carla_stdout(EngineControlEventType2Str(kEngineControlEventTypeNull)); | |||
} | |||
#endif | |||
// ----------------------------------------------------------------------- | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
// main | |||
int main() | |||
{ | |||
// already tested, skip for now | |||
test_CarlaUtils(); | |||
test_CarlaMathUtils(); | |||
//test_CarlaMathUtils(); | |||
test_CarlaBackendUtils(); | |||
test_CarlaBridgeUtils(); | |||
test_CarlaEngineUtils(); | |||
//test_CarlaBackendUtils(); | |||
//test_CarlaBridgeUtils(); | |||
//test_CarlaEngineUtils(); | |||
return 0; | |||
} | |||
// ----------------------------------------------------------------------- | |||
// -------------------------------------------------------------------------------------------------------------------- |
@@ -53,27 +53,27 @@ endif | |||
# -------------------------------------------------------------- | |||
TARGETS = ansi-pedantic-test_c_ansi | |||
TARGETS += ansi-pedantic-test_c89 | |||
TARGETS += ansi-pedantic-test_c99 | |||
TARGETS += ansi-pedantic-test_c11 | |||
TARGETS += ansi-pedantic-test_clang | |||
TARGETS += ansi-pedantic-test_cxx_ansi | |||
TARGETS += ansi-pedantic-test_cxx03 | |||
TARGETS += ansi-pedantic-test_cxx11 | |||
TARGETS += ansi-pedantic-test_cxxlang | |||
TARGETS += CarlaPipeUtils | |||
TARGETS += CarlaRingBuffer | |||
TARGETS += CarlaString | |||
# TARGETS += CarlaUtils1 | |||
# TARGETS = ansi-pedantic-test_c_ansi | |||
# TARGETS += ansi-pedantic-test_c89 | |||
# TARGETS += ansi-pedantic-test_c99 | |||
# TARGETS += ansi-pedantic-test_c11 | |||
# TARGETS += ansi-pedantic-test_clang | |||
# TARGETS += ansi-pedantic-test_cxx_ansi | |||
# TARGETS += ansi-pedantic-test_cxx03 | |||
# TARGETS += ansi-pedantic-test_cxx11 | |||
# TARGETS += ansi-pedantic-test_cxxlang | |||
# TARGETS += CarlaPipeUtils | |||
# TARGETS += CarlaRingBuffer | |||
# TARGETS += CarlaString | |||
TARGETS += CarlaUtils1 | |||
# ifneq ($(WIN32),true) | |||
# TARGETS += CarlaUtils2 | |||
# endif | |||
TARGETS += CarlaUtils3 | |||
# TARGETS += CarlaUtils3 | |||
# TARGETS += CarlaUtils4 | |||
TARGETS += Exceptions | |||
TARGETS += Print | |||
TARGETS += RDF | |||
# TARGETS += Exceptions | |||
# TARGETS += Print | |||
# TARGETS += RDF | |||
all: $(TARGETS) | |||
@@ -1,7 +1,7 @@ | |||
/* | |||
* Carla misc utils based on Juce | |||
* Copyright (C) 2013 Raw Material Software Ltd. | |||
* Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com> | |||
* Copyright (C) 2013-2015 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* Permission to use, copy, modify, and/or distribute this software for any purpose with | |||
* or without fee is hereby granted, provided that the above copyright notice and this | |||
@@ -21,16 +21,16 @@ | |||
#include "CarlaUtils.hpp" | |||
/** A good old-fashioned C macro concatenation helper. | |||
This combines two items (which may themselves be macros) into a single string, | |||
avoiding the pitfalls of the ## macro operator. | |||
This combines two items (which may themselves be macros) into a single string, | |||
avoiding the pitfalls of the ## macro operator. | |||
*/ | |||
#define CARLA_JOIN_MACRO_HELPER(a, b) a ## b | |||
#define CARLA_JOIN_MACRO(item1, item2) CARLA_JOIN_MACRO_HELPER(item1, item2) | |||
/** This macro lets you embed a leak-detecting object inside a class.\n | |||
/** This macro lets you embed a leak-detecting object inside a class. | |||
To use it, simply declare a CARLA_LEAK_DETECTOR(YourClassName) inside a private section | |||
of the class declaration. E.g. | |||
\code | |||
@code | |||
class MyClass | |||
{ | |||
public: | |||
@@ -40,7 +40,7 @@ | |||
private: | |||
CARLA_LEAK_DETECTOR(MyClass) | |||
}; | |||
\endcode | |||
@endcode | |||
*/ | |||
#define CARLA_LEAK_DETECTOR(ClassName) \ | |||
friend class ::LeakedObjectDetector<ClassName>; \ | |||
@@ -51,7 +51,7 @@ | |||
CARLA_DECLARE_NON_COPY_CLASS(ClassName) \ | |||
CARLA_LEAK_DETECTOR(ClassName) | |||
//============================================================================== | |||
//===================================================================================================================== | |||
/** | |||
Embedding an instance of this class inside another class can be used as a low-overhead | |||
way of detecting leaked instances. | |||
@@ -67,7 +67,7 @@ template <class OwnerClass> | |||
class LeakedObjectDetector | |||
{ | |||
public: | |||
//============================================================================== | |||
//================================================================================================================= | |||
LeakedObjectDetector() noexcept { ++(getCounter().numObjects); } | |||
LeakedObjectDetector(const LeakedObjectDetector&) noexcept { ++(getCounter().numObjects); } | |||
@@ -86,12 +86,13 @@ public: | |||
your object management. Tut, tut. Always, always use ScopedPointers, OwnedArrays, | |||
ReferenceCountedObjects, etc, and avoid the 'delete' operator at all costs! | |||
*/ | |||
carla_stderr2("*** Dangling pointer deletion! Class: '%s', Count: %i", getLeakedObjectClassName(), getCounter().numObjects); | |||
carla_stderr2("*** Dangling pointer deletion! Class: '%s', Count: %i", getLeakedObjectClassName(), | |||
getCounter().numObjects); | |||
} | |||
} | |||
private: | |||
//============================================================================== | |||
//================================================================================================================= | |||
class LeakCounter | |||
{ | |||
public: | |||
@@ -109,7 +110,8 @@ private: | |||
your object management. Tut, tut. Always, always use ScopedPointers, OwnedArrays, | |||
ReferenceCountedObjects, etc, and avoid the 'delete' operator at all costs! | |||
*/ | |||
carla_stderr2("*** Leaked objects detected: %i instance(s) of class '%s'", numObjects, getLeakedObjectClassName()); | |||
carla_stderr2("*** Leaked objects detected: %i instance(s) of class '%s'", numObjects, | |||
getLeakedObjectClassName()); | |||
} | |||
} | |||
@@ -129,7 +131,7 @@ private: | |||
} | |||
}; | |||
//============================================================================== | |||
//===================================================================================================================== | |||
/** | |||
Helper class providing an RAII-based mechanism for temporarily setting and | |||
then re-setting a value. | |||
@@ -185,7 +187,7 @@ public: | |||
} | |||
private: | |||
//============================================================================== | |||
//================================================================================================================= | |||
ValueType& value; | |||
const ValueType originalValue; | |||
@@ -199,4 +201,6 @@ extern bool juce_isRunningInWine(); | |||
} | |||
#endif | |||
//===================================================================================================================== | |||
#endif // CARLA_JUCE_UTILS_HPP_INCLUDED |
@@ -1,6 +1,6 @@ | |||
/* | |||
* Carla math utils | |||
* Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com> | |||
* Copyright (C) 2011-2015 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License as | |||
@@ -23,17 +23,17 @@ | |||
#include <cmath> | |||
#include <limits> | |||
// ----------------------------------------------------------------------- | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
// math functions (base) | |||
/* | |||
* Return the lower of 2 values, with 'min' as the minimum possible value (ie, base). | |||
* Return the lower of 2 values, with 'min' as the minimum possible value (ie, constrain). | |||
*/ | |||
template<typename T> | |||
static inline | |||
const T& carla_minWithBase(const T& v1, const T& v2, const T& min) noexcept | |||
const T& carla_minConstrained(const T& v1, const T& v2, const T& min) noexcept | |||
{ | |||
return ((v1 <= min || v2 <= min) ? min : (v1 < v2 ? v1 : v2)); | |||
return (v1 <= min || v2 <= min) ? min : (v1 < v2 ? v1 : v2); | |||
} | |||
/* | |||
@@ -62,7 +62,7 @@ template<typename T> | |||
static inline | |||
const T& carla_maxLimited(const T& v1, const T& v2, const T& max) noexcept | |||
{ | |||
return ((v1 >= max || v2 >= max) ? max : (v1 > v2 ? v1 : v2)); | |||
return (v1 >= max || v2 >= max) ? max : (v1 > v2 ? v1 : v2); | |||
} | |||
/* | |||
@@ -89,7 +89,7 @@ T carla_maxNegative(const T& v1, const T& v2) noexcept | |||
*/ | |||
template<typename T> | |||
static inline | |||
const T& carla_fixValue(const T& min, const T& max, const T& value) noexcept | |||
const T& carla_fixedValue(const T& min, const T& max, const T& value) noexcept | |||
{ | |||
CARLA_SAFE_ASSERT_RETURN(max > min, max); | |||
@@ -118,22 +118,28 @@ uint32_t carla_nextPowerOf2(uint32_t size) noexcept | |||
return ++size; | |||
} | |||
// ----------------------------------------------------------------------- | |||
// math functions (floating numbers) | |||
/* | |||
* Safely compare two floating point numbers. | |||
* Returns true if they match. | |||
* Safely check if 2 numbers are equal. | |||
*/ | |||
template<typename T> | |||
static inline | |||
bool carla_compareFloats(const T& v1, const T& v2) | |||
bool carla_isEqual(const T& v1, const T& v2) | |||
{ | |||
return std::abs(v1-v2) < std::numeric_limits<T>::epsilon(); | |||
} | |||
/* | |||
* Safely check if a floating point number is zero. | |||
* Safely check if 2 numbers are not equal. | |||
*/ | |||
template<typename T> | |||
static inline | |||
bool carla_isNotEqual(const T& v1, const T& v2) | |||
{ | |||
return std::abs(v1-v2) >= std::numeric_limits<T>::epsilon(); | |||
} | |||
/* | |||
* Safely check if a number is zero. | |||
*/ | |||
template<typename T> | |||
static inline | |||
@@ -143,7 +149,7 @@ bool carla_isZero(const T& value) | |||
} | |||
/* | |||
* Safely check if a floating point number is not zero. | |||
* Safely check if a number is not zero. | |||
*/ | |||
template<typename T> | |||
static inline | |||
@@ -152,52 +158,52 @@ bool carla_isNotZero(const T& value) | |||
return std::abs(value) >= std::numeric_limits<T>::epsilon(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
// math functions (extended) | |||
/* | |||
* Add float array values to another float array. | |||
*/ | |||
static inline | |||
void carla_addFloat(float* dataDst, const float* dataSrc, const std::size_t numSamples) noexcept | |||
void carla_addFloats(float dest[], const float src[], const std::size_t count) noexcept | |||
{ | |||
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(numSamples > 0,); | |||
CARLA_SAFE_ASSERT_RETURN(dest != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(src != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(count > 0,); | |||
for (std::size_t i=0; i < numSamples; ++i) | |||
*dataDst++ += *dataSrc++; | |||
for (std::size_t i=0; i<count; ++i) | |||
*dest++ += *src++; | |||
} | |||
/* | |||
* Copy float array values to another float array. | |||
*/ | |||
static inline | |||
void carla_copyFloat(float* const dataDst, const float* const dataSrc, const std::size_t numSamples) noexcept | |||
void carla_copyFloats(float dest[], const float src[], const std::size_t count) noexcept | |||
{ | |||
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(numSamples > 0,); | |||
CARLA_SAFE_ASSERT_RETURN(dest != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(src != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(count > 0,); | |||
std::memcpy(dataDst, dataSrc, numSamples*sizeof(float)); | |||
std::memcpy(dest, src, count*sizeof(float)); | |||
} | |||
/* | |||
* Clear a float array. | |||
*/ | |||
static inline | |||
void carla_zeroFloat(float* const data, const std::size_t numSamples) noexcept | |||
void carla_zeroFloats(float floats[], const std::size_t count) noexcept | |||
{ | |||
CARLA_SAFE_ASSERT_RETURN(data != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(numSamples > 0,); | |||
CARLA_SAFE_ASSERT_RETURN(floats != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(count > 0,); | |||
std::memset(data, 0, numSamples*sizeof(float)); | |||
std::memset(floats, 0, count*sizeof(float)); | |||
} | |||
#if defined(CARLA_OS_MAC) && ! defined(DISTRHO_OS_MAC) | |||
// ----------------------------------------------------------------------- | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
// Missing functions in OSX. | |||
#if defined(CARLA_OS_MAC) && ! defined(DISTRHO_OS_MAC) | |||
namespace std { | |||
inline float fmin(float __x, float __y) | |||
{ return __builtin_fminf(__x, __y); } | |||
@@ -210,6 +216,6 @@ inline float round(float __x) | |||
} | |||
#endif | |||
// ----------------------------------------------------------------------- | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
#endif // CARLA_MATH_UTILS_HPP_INCLUDED |
@@ -1,6 +1,6 @@ | |||
/* | |||
* Carla String | |||
* Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com> | |||
* Copyright (C) 2013-2015 Filipe Coelho <falktx@falktx.com> | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU General Public License as | |||
@@ -21,13 +21,6 @@ | |||
#include "CarlaJuceUtils.hpp" | |||
#include "CarlaMathUtils.hpp" | |||
namespace std { | |||
#ifdef CARLA_OS_HAIKU | |||
using ::snprintf; | |||
#endif | |||
using ::ssize_t; // FIXME? | |||
} | |||
// ----------------------------------------------------------------------- | |||
// CarlaString class | |||
@@ -379,7 +372,7 @@ public: | |||
if (char* const subStrBuf = std::strstr(fBuffer, strBuf)) | |||
{ | |||
const std::ssize_t ret(subStrBuf - fBuffer); | |||
const ssize_t ret(subStrBuf - fBuffer); | |||
if (ret < 0) | |||
{ | |||
@@ -592,7 +585,7 @@ public: | |||
"abcdefghijklmnopqrstuvwxyz" | |||
"0123456789+/"; | |||
const std::size_t kTmpBufSize = carla_nextPowerOf2(dataSize/3); | |||
const std::size_t kTmpBufSize = carla_nextPowerOf2(static_cast<uint32_t>(dataSize/3)); | |||
const uchar* bytesToEncode((const uchar*)data); | |||
@@ -296,7 +296,7 @@ const char* carla_strdup(const char* const strBuf) | |||
char* const buffer = new char[bufferLen+1]; | |||
if (strBuf != nullptr && bufferLen > 0) | |||
std::strncpy(buffer, strBuf, bufferLen); | |||
std::memcpy(buffer, strBuf, bufferLen); | |||
buffer[bufferLen] = '\0'; | |||
@@ -334,7 +334,7 @@ const char* carla_strdup_safe(const char* const strBuf) noexcept | |||
} CARLA_SAFE_EXCEPTION_RETURN("carla_strdup_safe", nullptr); | |||
if (strBuf != nullptr && bufferLen > 0) | |||
std::strncpy(buffer, strBuf, bufferLen); | |||
std::memcpy(buffer, strBuf, bufferLen); | |||
buffer[bufferLen] = '\0'; | |||
@@ -349,14 +349,14 @@ const char* carla_strdup_safe(const char* const strBuf) noexcept | |||
*/ | |||
template<typename T> | |||
static inline | |||
void carla_add(T* dataDst, const T* dataSrc, const std::size_t size) noexcept | |||
void carla_add(T dest[], const T src[], const std::size_t count) noexcept | |||
{ | |||
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(size > 0,); | |||
CARLA_SAFE_ASSERT_RETURN(dest != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(src != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(count > 0,); | |||
for (std::size_t i=0; i < size; ++i) | |||
*dataDst++ += *dataSrc++; | |||
for (std::size_t i=0; i<count; ++i) | |||
*dest++ += *src++; | |||
} | |||
/* | |||
@@ -364,13 +364,13 @@ void carla_add(T* dataDst, const T* dataSrc, const std::size_t size) noexcept | |||
*/ | |||
template<typename T> | |||
static inline | |||
void carla_copy(T* const dataDst, const T* const dataSrc, const std::size_t size) noexcept | |||
void carla_copy(T dest[], const T src[], const std::size_t count) noexcept | |||
{ | |||
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(size > 0,); | |||
CARLA_SAFE_ASSERT_RETURN(dest != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(src != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(count > 0,); | |||
std::memcpy(dataDst, dataSrc, size*sizeof(T)); | |||
std::memcpy(dest, src, count*sizeof(T)); | |||
} | |||
/* | |||
@@ -378,19 +378,19 @@ void carla_copy(T* const dataDst, const T* const dataSrc, const std::size_t size | |||
*/ | |||
template<typename T> | |||
static inline | |||
void carla_fill(T* data, const T v, const std::size_t size) noexcept | |||
void carla_fill(T data[], const T& value, const std::size_t count) noexcept | |||
{ | |||
CARLA_SAFE_ASSERT_RETURN(data != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(size > 0,); | |||
CARLA_SAFE_ASSERT_RETURN(count > 0,); | |||
if (v == 0) | |||
if (value == 0) | |||
{ | |||
std::memset(data, 0, size*sizeof(T)); | |||
std::memset(data, 0, count*sizeof(T)); | |||
} | |||
else | |||
{ | |||
for (std::size_t i=0; i < size; ++i) | |||
*data++ = v; | |||
for (std::size_t i=0; i<count; ++i) | |||
*data++ = value; | |||
} | |||
} | |||
@@ -398,24 +398,24 @@ void carla_fill(T* data, const T v, const std::size_t size) noexcept | |||
* Clear a byte array. | |||
*/ | |||
static inline | |||
void carla_zeroBytes(void* const memory, const std::size_t numBytes) noexcept | |||
void carla_zeroBytes(uint8_t bytes[], const std::size_t count) noexcept | |||
{ | |||
CARLA_SAFE_ASSERT_RETURN(memory != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(numBytes > 0,); | |||
CARLA_SAFE_ASSERT_RETURN(bytes != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(count > 0,); | |||
std::memset(memory, 0, numBytes); | |||
std::memset(bytes, 0, count*sizeof(uint8_t)); | |||
} | |||
/* | |||
* Clear a char array. | |||
*/ | |||
static inline | |||
void carla_zeroChar(char* const data, const std::size_t numChars) noexcept | |||
void carla_zeroChars(char chars[], const std::size_t count) noexcept | |||
{ | |||
CARLA_SAFE_ASSERT_RETURN(data != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(numChars > 0,); | |||
CARLA_SAFE_ASSERT_RETURN(chars != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(count > 0,); | |||
std::memset(data, 0, numChars*sizeof(char)); | |||
std::memset(chars, 0, count*sizeof(char)); | |||
} | |||
/* | |||
@@ -423,59 +423,59 @@ void carla_zeroChar(char* const data, const std::size_t numChars) noexcept | |||
*/ | |||
template<typename T> | |||
static inline | |||
void carla_zeroPointers(T* pointers[], const std::size_t numPointers) noexcept | |||
void carla_zeroPointers(T* ptrs[], const std::size_t count) noexcept | |||
{ | |||
CARLA_SAFE_ASSERT_RETURN(pointers != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(numPointers > 0,); | |||
CARLA_SAFE_ASSERT_RETURN(ptrs != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(count > 0,); | |||
std::memset(pointers, 0, numPointers*sizeof(T*)); | |||
std::memset(ptrs, 0, count*sizeof(T*)); | |||
} | |||
/* | |||
* Clear a single struct/class. | |||
* Clear a single struct. | |||
*/ | |||
template <typename T> | |||
static inline | |||
void carla_zeroStruct(T& structure) noexcept | |||
void carla_zeroStruct(T& s) noexcept | |||
{ | |||
std::memset(&structure, 0, sizeof(T)); | |||
std::memset(&s, 0, sizeof(T)); | |||
} | |||
/* | |||
* Clear an array of struct/classes. | |||
* Clear a struct array. | |||
*/ | |||
template <typename T> | |||
static inline | |||
void carla_zeroStruct(T* const structure, const std::size_t count) noexcept | |||
void carla_zeroStructs(T structs[], const std::size_t count) noexcept | |||
{ | |||
CARLA_SAFE_ASSERT_RETURN(structure != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(structs != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(count > 0,); | |||
std::memset(structure, 0, count*sizeof(T)); | |||
std::memset(structs, 0, count*sizeof(T)); | |||
} | |||
/* | |||
* Copy a single struct/class. | |||
* Copy a single struct. | |||
*/ | |||
template <typename T> | |||
static inline | |||
void carla_copyStruct(T& struct1, const T& struct2) noexcept | |||
void carla_copyStruct(T& dest, const T& src) noexcept | |||
{ | |||
std::memcpy(&struct1, &struct2, sizeof(T)); | |||
std::memcpy(&dest, &src, sizeof(T)); | |||
} | |||
/* | |||
* Copy an array of struct/classes. | |||
* Copy a struct array. | |||
*/ | |||
template <typename T> | |||
static inline | |||
void carla_copyStruct(T* const struct1, const T* const struct2, const std::size_t count) noexcept | |||
void carla_copyStructs(T dest[], const T src[], const std::size_t count) noexcept | |||
{ | |||
CARLA_SAFE_ASSERT_RETURN(struct1 != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(struct2 != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(dest != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(src != nullptr,); | |||
CARLA_SAFE_ASSERT_RETURN(count > 0,); | |||
std::memcpy(struct1, struct2, count*sizeof(T)); | |||
std::memcpy(dest, src, count*sizeof(T)); | |||
} | |||
// -------------------------------------------------------------------------------------------------------------------- | |||