diff --git a/source/backend/CarlaBackend.hpp b/source/backend/CarlaBackend.hpp index 9867f33ae..67eaedc78 100644 --- a/source/backend/CarlaBackend.hpp +++ b/source/backend/CarlaBackend.hpp @@ -144,16 +144,17 @@ enum BinaryType { * Some plugin classes might provide more than 1 plugin type. */ enum PluginType { - PLUGIN_NONE = 0, //!< Null plugin type. - PLUGIN_INTERNAL = 1, //!< Internal plugin. - PLUGIN_LADSPA = 2, //!< LADSPA plugin. - PLUGIN_DSSI = 3, //!< DSSI plugin. - PLUGIN_LV2 = 4, //!< LV2 plugin. - PLUGIN_VST = 5, //!< VST1/2 plugin. - PLUGIN_VST3 = 6, //!< VST3 plugin. - PLUGIN_GIG = 7, //!< GIG sound kit. - PLUGIN_SF2 = 8, //!< SF2 sound kit (aka SoundFont). - PLUGIN_SFZ = 9 //!< SFZ sound kit. + PLUGIN_NONE = 0, //!< Null plugin type. + PLUGIN_INTERNAL = 1, //!< Internal plugin. + PLUGIN_LADSPA = 2, //!< LADSPA plugin. + PLUGIN_DSSI = 3, //!< DSSI plugin. + PLUGIN_LV2 = 4, //!< LV2 plugin. + PLUGIN_VST = 5, //!< VST1/2 plugin. + PLUGIN_VST3 = 6, //!< VST3 plugin. + PLUGIN_AU = 7, //!< AU plugin. + PLUGIN_GIG = 8, //!< GIG sound kit. + PLUGIN_SF2 = 9, //!< SF2 sound kit (aka SoundFont). + PLUGIN_SFZ = 10 //!< SFZ sound kit. }; /*! diff --git a/source/includes/CarlaDefines.hpp b/source/includes/CarlaDefines.hpp index ce6b61f23..42fbfc9e7 100644 --- a/source/includes/CarlaDefines.hpp +++ b/source/includes/CarlaDefines.hpp @@ -160,4 +160,17 @@ # define OS_SEP '/' #endif +// Define PRE/POST_PACKED_STRUCTURE +#if defined(__GNUC__) +# define PRE_PACKED_STRUCTURE +# define POST_PACKED_STRUCTURE __attribute__((__packed__)) +#elif defined(_MSC_VER) +# define PRE_PACKED_STRUCTURE1 __pragma(pack(push,1)) +# define PRE_PACKED_STRUCTURE PRE_PACKED_STRUCTURE1 +# define POST_PACKED_STRUCTURE ;__pragma(pack(pop)) +#else +# define PRE_PACKED_STRUCTURE +# define POST_PACKED_STRUCTURE +#endif + #endif // CARLA_DEFINES_HPP_INCLUDED diff --git a/source/includes/lv2_rdf.hpp b/source/includes/lv2_rdf.hpp index f0e180433..7d8d8dd01 100644 --- a/source/includes/lv2_rdf.hpp +++ b/source/includes/lv2_rdf.hpp @@ -118,11 +118,13 @@ typedef uint32_t LV2_Property; #define LV2_PORT_ATOM_SEQUENCE (0x040 | LV2_PORT_ATOM) #define LV2_PORT_EVENT 0x080 #define LV2_PORT_MIDI_LL 0x100 +#define LV2_PORT_OSC 0x200 // Port Data Types #define LV2_PORT_DATA_MIDI_EVENT 0x1000 -#define LV2_PORT_DATA_PATCH_MESSAGE 0x2000 -#define LV2_PORT_DATA_TIME_POSITION 0x4000 +#define LV2_PORT_DATA_OSC 0x2000 +#define LV2_PORT_DATA_PATCH_MESSAGE 0x4000 +#define LV2_PORT_DATA_TIME_POSITION 0x8000 #define LV2_IS_PORT_INPUT(x) ((x) & LV2_PORT_INPUT) #define LV2_IS_PORT_OUTPUT(x) ((x) & LV2_PORT_OUTPUT) @@ -132,8 +134,10 @@ typedef uint32_t LV2_Property; #define LV2_IS_PORT_ATOM_SEQUENCE(x) ((x) & LV2_PORT_ATOM_SEQUENCE) #define LV2_IS_PORT_EVENT(x) ((x) & LV2_PORT_EVENT) #define LV2_IS_PORT_MIDI_LL(x) ((x) & LV2_PORT_MIDI_LL) +#define LV2_IS_PORT_OSC(x) ((x) & LV2_PORT_OSC) #define LV2_PORT_SUPPORTS_MIDI_EVENT(x) ((x) & LV2_PORT_DATA_MIDI_EVENT) +#define LV2_PORT_SUPPORTS_OSC(x) ((x) & LV2_PORT_DATA_OSC) #define LV2_PORT_SUPPORTS_PATCH_MESSAGE(x) ((x) & LV2_PORT_DATA_PATCH_MESSAGE) #define LV2_PORT_SUPPORTS_TIME_POSITION(x) ((x) & LV2_PORT_DATA_TIME_POSITION) @@ -210,16 +214,18 @@ typedef uint32_t LV2_Property; #define LV2_UI_GTK3 2 #define LV2_UI_QT4 3 #define LV2_UI_QT5 4 -#define LV2_UI_COCOA 5 -#define LV2_UI_WINDOWS 6 -#define LV2_UI_X11 7 -#define LV2_UI_EXTERNAL 8 -#define LV2_UI_OLD_EXTERNAL 9 +#define LV2_UI_NTK 5 +#define LV2_UI_COCOA 6 +#define LV2_UI_WINDOWS 7 +#define LV2_UI_X11 8 +#define LV2_UI_EXTERNAL 9 +#define LV2_UI_OLD_EXTERNAL 10 #define LV2_IS_UI_GTK2(x) ((x) == LV2_UI_GTK2) #define LV2_IS_UI_GTK3(x) ((x) == LV2_UI_GTK3) #define LV2_IS_UI_QT4(x) ((x) == LV2_UI_QT4) #define LV2_IS_UI_QT5(x) ((x) == LV2_UI_QT5) +#define LV2_IS_UI_NTK(x) ((x) == LV2_UI_NTK) #define LV2_IS_UI_COCOA(x) ((x) == LV2_UI_COCOA) #define LV2_IS_UI_WINDOWS(x) ((x) == LV2_UI_WINDOWS) #define LV2_IS_UI_X11(x) ((x) == LV2_UI_X11) diff --git a/source/modules/rtmempool/list.h b/source/modules/rtmempool/list.h index 90b4cdf9a..5c5795d26 100644 --- a/source/modules/rtmempool/list.h +++ b/source/modules/rtmempool/list.h @@ -38,7 +38,7 @@ # include #endif -#if !defined(offsetof) +#ifndef offsetof # define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #endif @@ -51,7 +51,7 @@ */ #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) + (type *)( (char *)__mptr - offsetof(type, member) );}) #define prefetch(x) (x = x) @@ -305,7 +305,7 @@ static inline void list_splice_tail_init(struct list_head *list, struct list_hea container_of(ptr, type, member) #else # define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) + ((type *)((char *)(ptr)-offsetof(type, member))) #endif /** diff --git a/source/modules/utils/CarlaBridgeUtils.hpp b/source/modules/utils/CarlaBridgeUtils.hpp index 67452e02d..589edb7fb 100644 --- a/source/modules/utils/CarlaBridgeUtils.hpp +++ b/source/modules/utils/CarlaBridgeUtils.hpp @@ -67,6 +67,7 @@ const char* const CARLA_BRIDGE_MSG_SET_CUSTOM = "CarlaBridgeSetCustom"; //!< Hos // ----------------------------------------------------------------------- +PRE_PACKED_STRUCTURE struct BridgeShmControl { union { void* runServer; @@ -77,7 +78,7 @@ struct BridgeShmControl { char _padClient[32]; }; RingBuffer ringBuffer; -} __attribute__((__packed__)); +} POST_PACKED_STRUCTURE; // ----------------------------------------------------------------------- diff --git a/source/modules/utils/CarlaMutex.hpp b/source/modules/utils/CarlaMutex.hpp index bf62242ce..aa23c3297 100644 --- a/source/modules/utils/CarlaMutex.hpp +++ b/source/modules/utils/CarlaMutex.hpp @@ -95,4 +95,6 @@ private: CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaMutex) }; +// ----------------------------------------------------------------------- + #endif // CARLA_MUTEX_HPP_INCLUDED diff --git a/source/modules/utils/CarlaRingBuffer.hpp b/source/modules/utils/CarlaRingBuffer.hpp index b5f21d5af..0d9644f91 100644 --- a/source/modules/utils/CarlaRingBuffer.hpp +++ b/source/modules/utils/CarlaRingBuffer.hpp @@ -19,7 +19,7 @@ #ifndef CARLA_RING_BUFFER_HPP_INCLUDED #define CARLA_RING_BUFFER_HPP_INCLUDED -#include "CarlaUtils.hpp" +#include "CarlaJuceUtils.hpp" #ifndef RING_BUFFER_SIZE # define RING_BUFFER_SIZE 2048 @@ -28,11 +28,12 @@ // ----------------------------------------------------------------------- // RingBuffer struct +PRE_PACKED_STRUCTURE struct RingBuffer { int32_t head, tail, written; bool invalidateCommit; char buf[RING_BUFFER_SIZE]; -} __attribute__((__packed__)); +} POST_PACKED_STRUCTURE; // ----------------------------------------------------------------------- // RingBufferControl class @@ -229,6 +230,11 @@ private: fRingBuf->written = static_cast(writeto); } + + CARLA_PREVENT_HEAP_ALLOCATION + CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(RingBufferControl) }; +// ----------------------------------------------------------------------- + #endif // CARLA_RING_BUFFER_HPP_INCLUDED diff --git a/source/modules/utils/CarlaString.hpp b/source/modules/utils/CarlaString.hpp index d780291e8..f67a05f23 100644 --- a/source/modules/utils/CarlaString.hpp +++ b/source/modules/utils/CarlaString.hpp @@ -467,8 +467,8 @@ private: } } - CARLA_LEAK_DETECTOR(CarlaString) CARLA_PREVENT_HEAP_ALLOCATION + CARLA_LEAK_DETECTOR(CarlaString) }; // ----------------------------------------------------------------------- @@ -499,4 +499,6 @@ CarlaString operator+(const char* const strBufBefore, const CarlaString& strAfte return CarlaString(newBuf); } +// ----------------------------------------------------------------------- + #endif // CARLA_STRING_HPP_INCLUDED diff --git a/source/modules/utils/RtList.hpp b/source/modules/utils/RtList.hpp index b08027b96..b8942a633 100644 --- a/source/modules/utils/RtList.hpp +++ b/source/modules/utils/RtList.hpp @@ -88,7 +88,7 @@ public: T& operator*() { fData = list_entry(fEntry, Data, siblings); - CARLA_SAFE_ASSERT_RETURN(fData != nullptr, nullptr); + CARLA_ASSERT(fData != nullptr); return fData->value; } @@ -116,7 +116,10 @@ public: list_for_each_safe(entry, entry2, &fQueue) { if (Data* data = list_entry(entry, Data, siblings)) + { + data->~Data(); _deallocate(data); + } } } @@ -137,6 +140,7 @@ public: { if (Data* const data = _allocate()) { + new(data)Data(); data->value = value; list_add_tail(&data->siblings, &fQueue); ++fCount; @@ -150,6 +154,7 @@ public: { if (Data* const data = _allocate()) { + new(data)Data(); data->value = value; list_add_tail(&data->siblings, it.fEntry->next); ++fCount; @@ -163,6 +168,7 @@ public: { if (Data* const data = _allocate()) { + new(data)Data(); data->value = value; list_add(&data->siblings, &fQueue); ++fCount; @@ -176,6 +182,7 @@ public: { if (Data* const data = _allocate()) { + new(data)Data(); data->value = value; list_add(&data->siblings, it.fEntry->prev); ++fCount; @@ -188,7 +195,7 @@ public: T& getAt(const size_t index, const bool remove = false) { if (fCount == 0 || index >= fCount) - return _getEmpty(); + return fFallbackValue; size_t i = 0; Data* data = nullptr; @@ -202,21 +209,25 @@ public: data = list_entry(entry, Data, siblings); + if (data != nullptr) + fRetValue = data->value; + if (remove) { --fCount; list_del(entry); if (data != nullptr) + { + data->~Data(); _deallocate(data); + } } break; } - CARLA_ASSERT(data != nullptr); - - return (data != nullptr) ? data->value : _getEmpty(); + return (data != nullptr) ? fRetValue : fFallbackValue; } T& getFirst(const bool remove = false) @@ -238,6 +249,8 @@ public: { --fCount; list_del(it.fEntry); + + it.fData->~Data(); _deallocate(it.fData); } } @@ -258,6 +271,8 @@ public: { --fCount; list_del(entry); + + data->~Data(); _deallocate(data); break; } @@ -266,27 +281,6 @@ public: return (data != nullptr); } - void removeAll(const T& value) - { - Data* data; - k_list_head* entry; - k_list_head* entry2; - - list_for_each_safe(entry, entry2, &fQueue) - { - data = list_entry(entry, Data, siblings); - - CARLA_ASSERT(data != nullptr); - - if (data != nullptr && data->value == value) - { - --fCount; - list_del(entry); - _deallocate(data); - } - } - } - void spliceAppend(List& list, const bool init = true) { if (init) @@ -323,9 +317,12 @@ protected: k_list_head fQueue; virtual Data* _allocate() = 0; - virtual void _deallocate(Data* const dataPtr) = 0; + virtual void _deallocate(Data*& dataPtr) = 0; private: + T fFallbackValue; + T fRetValue; + void _init() noexcept { fCount = 0; @@ -335,33 +332,29 @@ private: T& _getFirstOrLast(const bool first, const bool remove) { if (fCount == 0) - return _getEmpty(); + return fFallbackValue; k_list_head* const entry = first ? fQueue.next : fQueue.prev; - Data* const data = list_entry(entry, Data, siblings); - - CARLA_SAFE_ASSERT_RETURN(data != nullptr, _getEmpty()); + Data* data = list_entry(entry, Data, siblings); - T& ret = data->value; + if (data != nullptr) + fRetValue = data->value; if (remove) { --fCount; list_del(entry); - _deallocate(data); - } - return ret; - } + if (data != nullptr) + { + data->~Data(); + _deallocate(data); + } + } - T& _getEmpty() - { - carla_zeroStruct(fFallbackValue); - return fFallbackValue; + return (data != nullptr) ? fRetValue : fFallbackValue; } - T fFallbackValue; - LIST_DECLARATIONS(List) }; @@ -452,6 +445,7 @@ public: { if (typename List::Data* const data = _allocate_sleepy()) { + new(data)typename List::Data(); data->value = value; list_add_tail(&data->siblings, &this->fQueue); ++this->fCount; @@ -462,6 +456,7 @@ public: { if (typename List::Data* const data = _allocate_sleepy()) { + new(data)typename List::Data(); data->value = value; list_add(&data->siblings, &this->fQueue); ++this->fCount; @@ -518,7 +513,7 @@ private: }; // ----------------------------------------------------------------------- -// Non-Realtime list, using malloc/free methods +// Non-Realtime list template class NonRtList : public List @@ -549,34 +544,5 @@ private: }; // ----------------------------------------------------------------------- -// Non-Realtime list, using new/delete methods - -template -class NonRtListNew : public List -{ -public: - NonRtListNew() - { - } - - ~NonRtListNew() override - { - } - -private: - typename List::Data* _allocate() override - { - return new typename List::Data; - } - - void _deallocate(typename List::Data*& dataPtr) override - { - CARLA_ASSERT(dataPtr != nullptr); - delete dataPtr; - dataPtr = nullptr; - } - - LIST_DECLARATIONS(NonRtListNew) -}; #endif // RT_LIST_HPP_INCLUDED diff --git a/source/tests/ANSI.cpp b/source/tests/ANSI.cpp index 85898c0de..0a02430a6 100644 --- a/source/tests/ANSI.cpp +++ b/source/tests/ANSI.cpp @@ -40,8 +40,8 @@ #include "RtList.hpp" // Carla utils (part 3/4) -#include "CarlaBackendUtils.hpp" -#include "CarlaBridgeUtils.hpp" +// #include "CarlaBackendUtils.hpp" +// #include "CarlaBridgeUtils.hpp" // #include "CarlaLadspaUtils.hpp" // #include "CarlaLibUtils.hpp" // #include "CarlaLv2Utils.hpp" @@ -54,19 +54,19 @@ // #include "Lv2AtomQueue.hpp" // Carla Native Plugin API -#include "CarlaNative.h" +// #include "CarlaNative.h" // Carla Native Plugin API (C++) -#include "CarlaNative.hpp" +// #include "CarlaNative.hpp" // Carla Plugin API -#include "CarlaPlugin.hpp" +// #include "CarlaPlugin.hpp" // Carla Engine API -#include "CarlaEngine.hpp" +// #include "CarlaEngine.hpp" // Carla Standalone API -#include "CarlaStandalone.hpp" +// #include "CarlaStandalone.hpp" // // Carla Plugin // #include "plugin/CarlaPluginThread.hpp" @@ -84,7 +84,6 @@ int safe_assert_return_test(bool test) int main() { -#if 0 // ladspa rdf { LADSPA_RDF_ScalePoint a; @@ -125,6 +124,7 @@ int main() a=a;b=b;c=c;d=d;e=e;f=f;g=g;h=h;i=i;j=j;k=k;l=l;m=m;n=n;o=o; } +#if 0 // Carla Native Plugin API { HostHandle a = nullptr; @@ -158,6 +158,7 @@ int main() a=a;b=b;c=c;d=d;e=e;f=f;g=g;h=h;i=i;j=j;k=k;l=l;m=m;n=n;o=o;p=p; (void)q; } +#endif // Carla common utils { @@ -400,6 +401,7 @@ int main() ScopedPointer f(nullptr); } +#if 0 // Carla Native Plugin API (C++) { class PluginDescriptorClassTest : public PluginDescriptorClass @@ -456,6 +458,7 @@ int main() assert(b.i == 5); assert(c.i == 6); } +#endif // Carla Mutex { @@ -464,7 +467,6 @@ int main() m.unlock(); const CarlaMutex::ScopedLocker sl(m); } -#endif // RingBuffer { @@ -526,5 +528,12 @@ int main() printf("\nDUMP FINISHED"); } + // RtList + { + NonRtList list; + list.append(6); + list.clear(); + } + return 0; } diff --git a/source/tests/Makefile b/source/tests/Makefile index 2414e67fc..06072265f 100644 --- a/source/tests/Makefile +++ b/source/tests/Makefile @@ -42,7 +42,7 @@ all: $(TARGETS) RUN ANSI: ANSI.cpp $(CXX) $^ $(BUILD_CXX_FLAGS) $(ANSI_CXX_FLAGS) $(LINK_FLAGS) -lpthread -o $@ -CarlaString: CarlaString.cpp +CarlaString: CarlaString.cpp ../modules/utils/CarlaString.hpp $(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ DGL1: DGL1.cpp DGL1_Artwork.cpp ../libs/dgl.a @@ -54,8 +54,8 @@ DGL2: DGL2.cpp NekoArtwork.cpp ../libs/dgl.a MacTest: MacTest.cpp $(CXX) MacTest.cpp -o $@ -RtList: RtList.cpp ../utils/RtList.hpp ../libs/rtmempool.a - $(CXX) RtList.cpp ../libs/rtmempool.a $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -pthread -lpthread -o $@ +RtList: RtList.cpp ../modules/utils/RtList.hpp ../modules/rtmempool.a + $(CXX) RtList.cpp ../modules/rtmempool.a $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -pthread -lpthread -o $@ Print: Print.cpp $(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ diff --git a/source/tests/RtList.cpp b/source/tests/RtList.cpp index 748518837..4aa8c73a5 100644 --- a/source/tests/RtList.cpp +++ b/source/tests/RtList.cpp @@ -20,8 +20,8 @@ #include "CarlaString.hpp" #include "CarlaMutex.hpp" -const unsigned short MIN_RT_EVENTS = 152; -const unsigned short MAX_RT_EVENTS = 512; +const unsigned short MIN_RT_EVENTS = 5; +const unsigned short MAX_RT_EVENTS = 10; struct MyData { CarlaString str; @@ -33,11 +33,6 @@ struct MyData { MyData(int id) : str(id), idStr(id) {} - -#ifdef PROPER_CPP11_SUPPORT - MyData(MyData&) = delete; - MyData(const MyData&) = delete; -#endif }; struct PostRtEvents { @@ -78,11 +73,6 @@ struct PostRtEvents { } } - //void appendNonRT(const PluginPostRtEvent& event) - //{ - // data.append_sleepy(event); - //} - } postRtEvents; void run5Tests() @@ -95,9 +85,8 @@ void run5Tests() while (! postRtEvents.data.isEmpty()) { - MyData& my = postRtEvents.data.getFirst(true); + const MyData& my(postRtEvents.data.getFirst(true)); allMyData[k++] = my; - //std::memcpy(&allMyData[i++], &my, sizeof(MyData)); } postRtEvents.mutex.unlock(); @@ -114,7 +103,7 @@ void run5Tests() // Handle events now for (unsigned short i=0; i < k; ++i) { - const MyData& my = allMyData[i]; + const MyData& my(allMyData[i]); printf("Got data: %i %s\n", my.idStr, (const char*)my.str); }