summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfalkTX <falktx@gmail.com>2014-10-11 16:17:00 +0100
committerfalkTX <falktx@gmail.com>2014-10-11 16:17:00 +0100
commitae8e42e6a773da0ce62d070256fc849f112177d5 (patch)
tree05b3259e2d787105ee01f31c5890bd85f1af1cb0
parent064c511ac7da355bff202f66329ef6d3bd22c909 (diff)
Add new files
-rw-r--r--libs/distrho/extra/d_thread.hpp291
-rwxr-xr-xlibs/generate-vst-bundles.sh33
2 files changed, 324 insertions, 0 deletions
diff --git a/libs/distrho/extra/d_thread.hpp b/libs/distrho/extra/d_thread.hpp
new file mode 100644
index 0000000..9a7b2a9
--- /dev/null
+++ b/libs/distrho/extra/d_thread.hpp
@@ -0,0 +1,291 @@
+/*
+ * DISTRHO Plugin Framework (DPF)
+ * Copyright (C) 2012-2014 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
+ * permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef DISTRHO_THREAD_HPP_INCLUDED
+#define DISTRHO_THREAD_HPP_INCLUDED
+
+#include "d_mutex.hpp"
+#include "d_sleep.hpp"
+#include "d_string.hpp"
+
+#if defined(__GLIBC__) && (__GLIBC__ * 1000 + __GLIBC_MINOR__) >= 2012
+// has pthread_setname_np
+#elif defined(DISTRHO_OS_LINUX)
+# include <sys/prctl.h>
+#endif
+
+START_NAMESPACE_DISTRHO
+
+// -----------------------------------------------------------------------
+// Thread class
+
+class Thread
+{
+protected:
+ /*
+ * Constructor.
+ */
+ Thread(const char* const threadName = nullptr) noexcept
+ : fLock(),
+ fName(threadName),
+#ifdef PTW32_DLLPORT
+ fHandle({nullptr, 0}),
+#else
+ fHandle(0),
+#endif
+ fShouldExit(false) {}
+
+ /*
+ * Destructor.
+ */
+ virtual ~Thread() /*noexcept*/
+ {
+ DISTRHO_SAFE_ASSERT(! isThreadRunning());
+
+ stopThread(-1);
+ }
+
+ /*
+ * Virtual function to be implemented by the subclass.
+ */
+ virtual void run() = 0;
+
+ // -------------------------------------------------------------------
+
+public:
+ /*
+ * Check if the thread is running.
+ */
+ bool isThreadRunning() const noexcept
+ {
+#ifdef PTW32_DLLPORT
+ return (fHandle.p != nullptr);
+#else
+ return (fHandle != 0);
+#endif
+ }
+
+ /*
+ * Check if the thread should exit.
+ */
+ bool shouldThreadExit() const noexcept
+ {
+ return fShouldExit;
+ }
+
+ /*
+ * Start the thread.
+ */
+ bool startThread() noexcept
+ {
+ // check if already running
+ DISTRHO_SAFE_ASSERT_RETURN(! isThreadRunning(), true);
+
+ const MutexLocker cml(fLock);
+
+ fShouldExit = false;
+
+ pthread_t handle;
+
+ if (pthread_create(&handle, nullptr, _entryPoint, this) == 0)
+ {
+#ifdef PTW32_DLLPORT
+ DISTRHO_SAFE_ASSERT_RETURN(handle.p != nullptr, false);
+#else
+ DISTRHO_SAFE_ASSERT_RETURN(handle != 0, false);
+#endif
+ pthread_detach(handle);
+ _copyFrom(handle);
+
+ // wait for thread to start
+ fLock.lock();
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /*
+ * Stop the thread.
+ * In the 'timeOutMilliseconds':
+ * = 0 -> no wait
+ * > 0 -> wait timeout value
+ * < 0 -> wait forever
+ */
+ bool stopThread(const int timeOutMilliseconds) noexcept
+ {
+ const MutexLocker cml(fLock);
+
+ if (isThreadRunning())
+ {
+ signalThreadShouldExit();
+
+ if (timeOutMilliseconds != 0)
+ {
+ // Wait for the thread to stop
+ int timeOutCheck = (timeOutMilliseconds == 1 || timeOutMilliseconds == -1) ? timeOutMilliseconds : timeOutMilliseconds/2;
+
+ for (; isThreadRunning();)
+ {
+ d_msleep(2);
+
+ if (timeOutCheck < 0)
+ continue;
+
+ if (timeOutCheck > 0)
+ timeOutCheck -= 1;
+ else
+ break;
+ }
+ }
+
+ if (isThreadRunning())
+ {
+ // should never happen!
+ d_stderr2("Carla assertion failure: \"! isThreadRunning()\" in file %s, line %i", __FILE__, __LINE__);
+
+ // copy thread id so we can clear our one
+ pthread_t threadId;
+ _copyTo(threadId);
+ _init();
+
+ try {
+ pthread_cancel(threadId);
+ } DISTRHO_SAFE_EXCEPTION("pthread_cancel");
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /*
+ * Tell the thread to stop as soon as possible.
+ */
+ void signalThreadShouldExit() noexcept
+ {
+ fShouldExit = true;
+ }
+
+ // -------------------------------------------------------------------
+
+ /*
+ * Returns the name of the thread.
+ * This is the name that gets set in the constructor.
+ */
+ const d_string& getThreadName() const noexcept
+ {
+ return fName;
+ }
+
+ /*
+ * Changes the name of the caller thread.
+ */
+ static void setCurrentThreadName(const char* const name) noexcept
+ {
+ DISTRHO_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
+
+#if defined(__GLIBC__) && (__GLIBC__ * 1000 + __GLIBC_MINOR__) >= 2012
+ pthread_setname_np(pthread_self(), name);
+#elif defined(DISTRHO_OS_LINUX)
+ prctl(PR_SET_NAME, name, 0, 0, 0);
+#endif
+ }
+
+ // -------------------------------------------------------------------
+
+private:
+ Mutex fLock; // Thread lock
+ const d_string fName; // Thread name
+ volatile pthread_t fHandle; // Handle for this thread
+ volatile bool fShouldExit; // true if thread should exit
+
+ /*
+ * Init pthread type.
+ */
+ void _init() noexcept
+ {
+#ifdef PTW32_DLLPORT
+ fHandle.p = nullptr;
+ fHandle.x = 0;
+#else
+ fHandle = 0;
+#endif
+ }
+
+ /*
+ * Copy our pthread type from another var.
+ */
+ void _copyFrom(const pthread_t& handle) noexcept
+ {
+#ifdef PTW32_DLLPORT
+ fHandle.p = handle.p;
+ fHandle.x = handle.x;
+#else
+ fHandle = handle;
+#endif
+ }
+
+ /*
+ * Copy our pthread type to another var.
+ */
+ void _copyTo(volatile pthread_t& handle) const noexcept
+ {
+#ifdef PTW32_DLLPORT
+ handle.p = fHandle.p;
+ handle.x = fHandle.x;
+#else
+ handle = fHandle;
+#endif
+ }
+
+ /*
+ * Thread entry point.
+ */
+ void _runEntryPoint() noexcept
+ {
+ // report ready
+ fLock.unlock();
+
+ setCurrentThreadName(fName);
+
+ try {
+ run();
+ } catch(...) {}
+
+ // done
+ _init();
+ }
+
+ /*
+ * Thread entry point.
+ */
+ static void* _entryPoint(void* userData) noexcept
+ {
+ static_cast<Thread*>(userData)->_runEntryPoint();
+ return nullptr;
+ }
+
+ DISTRHO_DECLARE_NON_COPY_CLASS(Thread)
+};
+
+// -----------------------------------------------------------------------
+
+END_NAMESPACE_DISTRHO
+
+#endif // DISTRHO_THREAD_HPP_INCLUDED
diff --git a/libs/generate-vst-bundles.sh b/libs/generate-vst-bundles.sh
new file mode 100755
index 0000000..4ff14b6
--- /dev/null
+++ b/libs/generate-vst-bundles.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+set -e
+
+if [ -d bin ]; then
+ cd bin
+else
+ echo "Please run this script from the root folder"
+ exit
+fi
+
+PWD=`pwd`
+
+if [ ! -d /System/Library ]; then
+ echo "This doesn't seem to be OSX, please stop!"
+ exit 0
+fi
+
+rm -rf *.vst/
+
+PLUGINS=`ls | grep vst.dylib`
+
+for i in $PLUGINS; do
+ FILE=`echo $i | awk 'sub("-vst.dylib","")'`
+ cp -r ../dpf/utils/plugin.vst/ $FILE.vst
+ mv $i $FILE.vst/Contents/MacOS/$FILE
+ rm -f $FILE.vst/Contents/MacOS/deleteme
+ sed -i -e "s/X-PROJECTNAME-X/$FILE/" $FILE.vst/Contents/Info.plist
+ rm -f $FILE.vst/Contents/Info.plist-e
+ SetFile -a B $FILE.vst
+done
+
+cd ..