CARLA_BACKEND_USE_NAMESPACE // -------------------------------------------------------------------------------------------------------------------- //extern void (*jack_error_callback)(const char *msg) JACK_OPTIONAL_WEAK_EXPORT; CARLA_EXPORT void jack_set_error_function(void (*func)(const char *)) { carla_stderr2("%s(%p)", __FUNCTION__, func); }
bool CarlaBridgeUI::init(const int argc, const char* argv[]) { CARLA_SAFE_ASSERT_RETURN(fToolkit != nullptr, false); if (argc == 7) { if (! initPipeClient(argv)) return false; fLastMsgTimer = 0; // wait for ui options for (; ++fLastMsgTimer < 50 && ! fGotOptions;) { idlePipe(true); carla_msleep(20); } if (! fGotOptions) { carla_stderr2("CarlaBridgeUI::init() - did not get options on time, quitting..."); { const CarlaMutexLocker cml(getPipeLock()); writeMessage("exiting\n", 8); flushMessages(); } closePipeClient(); return false; } } if (! fToolkit->init(argc, argv)) { if (argc == 7) closePipeClient(); return false; } return true; }
static void test_CarlaUtils() { // ---------------------------------------------------------------------------------------------------------------- // misc functions { bool2str(false); bool2str(true); pass(); char strBuf[2]; nullStrBuf(strBuf); char* const strBuf2(strBuf+1); nullStrBuf(strBuf2); } // ---------------------------------------------------------------------------------------------------------------- // string print functions { carla_debug("DEBUG"); carla_stdout("STDOUT %s", bool2str(true)); carla_stderr("STDERR %s", bool2str(false)); carla_stderr2("STDERR2 " P_UINT64, 0xffffffff); // 4294967295 } // ---------------------------------------------------------------------------------------------------------------- // carla_*sleep { carla_sleep(1); 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("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("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* strNull; const char* strNormal; const char* strFree; const char* strSafe; TestStruct() : strNull(nullptr), strNormal(carla_strdup("strNormal")), strFree(carla_strdup_free(strdup("strFree"))), strSafe(carla_strdup_safe("strSafe")) {} ~TestStruct() noexcept { if (strNull != nullptr) { delete[] strNull; strNull = nullptr; } if (strNormal != nullptr) { delete[] strNormal; strNormal = nullptr; } if (strFree != nullptr) { delete[] strFree; strFree = nullptr; } if (strSafe != nullptr) { delete[] strSafe; strSafe = nullptr; } } CARLA_DECLARE_NON_COPY_STRUCT(TestStruct) }; TestStruct a, b, c; } // ---------------------------------------------------------------------------------------------------------------- // memory functions { 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_add(&d, &d, 1); assert(d == 1527*2); carla_add(&d, &d, 1); assert(d == 1527*4); carla_add(&d, &e, 1); assert(d == 1527*4); assert(e == 0); 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 a[501]; for (int i=500; --i>=0;) a[i] = 'a'; carla_zeroChars(a, 501); for (int i=501; --i>=0;) assert(a[i] == '\0'); for (int i=500; --i>=0;) a[i] = 'a'; assert(std::strlen(a) == 500); carla_fill(a+200, '\0', 1); assert(std::strlen(a) == 200); } { void* a[33]; carla_zeroPointers(a, 33); 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); } }
bool CarlaBridgeUI::msgReceived(const char* const msg) noexcept { carla_debug("CarlaBridgeUI::msgReceived(\"%s\")", msg); if (! fGotOptions && std::strcmp(msg, "urid") != 0 && std::strcmp(msg, "uiOptions") != 0) { carla_stderr2("CarlaBridgeUI::msgReceived(\"%s\") - invalid message while waiting for options", msg); return true; } if (fLastMsgTimer > 0) --fLastMsgTimer; if (std::strcmp(msg, "control") == 0) { uint32_t index; float value; CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(index), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true); dspParameterChanged(index, value); return true; } if (std::strcmp(msg, "program") == 0) { uint32_t index; CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(index), true); dspProgramChanged(index); return true; } if (std::strcmp(msg, "midiprogram") == 0) { uint32_t bank, program; CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(bank), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(program), true); dspMidiProgramChanged(bank, program); return true; } if (std::strcmp(msg, "configure") == 0) { const char* key; const char* value; CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value), true); dspStateChanged(key, value); delete[] key; delete[] value; return true; } if (std::strcmp(msg, "note") == 0) { bool onOff; uint8_t channel, note, velocity; CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(onOff), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsByte(channel), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsByte(note), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsByte(velocity), true); dspNoteReceived(onOff, channel, note, velocity); return true; } if (std::strcmp(msg, "atom") == 0) { uint32_t index, atomTotalSize; const char* base64atom; CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(index), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(atomTotalSize), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(base64atom), true); std::vector<uint8_t> chunk(carla_getChunkFromBase64String(base64atom)); delete[] base64atom; CARLA_SAFE_ASSERT_RETURN(chunk.size() >= sizeof(LV2_Atom), true); const LV2_Atom* const atom((const LV2_Atom*)chunk.data()); const uint32_t atomTotalSizeCheck(lv2_atom_total_size(atom)); CARLA_SAFE_ASSERT_RETURN(atomTotalSizeCheck == atomTotalSize, true); CARLA_SAFE_ASSERT_RETURN(atomTotalSizeCheck == chunk.size(), true); dspAtomReceived(index, atom); return true; } if (std::strcmp(msg, "urid") == 0) { uint32_t urid; const char* uri; CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(urid), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(uri), true); if (urid != 0) dspURIDReceived(urid, uri); delete[] uri; return true; } if (std::strcmp(msg, "uiOptions") == 0) { double sampleRate; bool useTheme, useThemeColors; const char* windowTitle; uint64_t transientWindowId; CARLA_SAFE_ASSERT_RETURN(readNextLineAsDouble(sampleRate), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(useTheme), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(useThemeColors), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(windowTitle), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsULong(transientWindowId), true); fGotOptions = true; uiOptionsChanged(sampleRate, useTheme, useThemeColors, windowTitle, static_cast<uintptr_t>(transientWindowId)); delete[] windowTitle; return true; } CARLA_SAFE_ASSERT_RETURN(fToolkit != nullptr, true); if (std::strcmp(msg, "show") == 0) { fToolkit->show(); return true; } if (std::strcmp(msg, "focus") == 0) { fToolkit->focus(); return true; } if (std::strcmp(msg, "hide") == 0) { fToolkit->hide(); return true; } if (std::strcmp(msg, "quit") == 0) { fQuitReceived = true; fToolkit->quit(); delete fToolkit; fToolkit = nullptr; return true; } if (std::strcmp(msg, "uiTitle") == 0) { const char* title; CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(title), true); fToolkit->setTitle(title); delete[] title; return true; } carla_stderr("CarlaBridgeUI::msgReceived : %s", msg); return false; }
CARLA_EXPORT void jack_set_info_function(void (*func)(const char *)) { carla_stderr2("%s(%p)", __FUNCTION__, func); }