1,399 changes: 1,399 additions & 0 deletions jackbridge/JackBridge.cpp

Large diffs are not rendered by default.

341 changes: 341 additions & 0 deletions jackbridge/JackBridge.hpp

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions jackbridge/JackBridgeDefines.hpp
@@ -0,0 +1,70 @@
/*
* JackBridge common defines
* Copyright (C) 2013 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 JACKBRIDGE_DEFINES_HPP_INCLUDED
#define JACKBRIDGE_DEFINES_HPP_INCLUDED

// Check OS
#if defined(__linux__) || defined(__linux)
# define JACKBRIDGE_OS_LINUX
#elif defined(__APPLE__)
# define JACKBRIDGE_OS_MAC
#elif defined(__HAIKU__)
# define JACKBRIDGE_OS_HAIKU
#elif defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
# define JACKBRIDGE_OS_WIN64
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# define JACKBRIDGE_OS_WIN32
#else
# warning Unsupported platform!
#endif

#if defined(JACKBRIDGE_OS_WIN32) || defined(JACKBRIDGE_OS_WIN64)
# define JACKBRIDGE_OS_WIN
#elif ! defined(JACKBRIDGE_OS_HAIKU)
# define JACKBRIDGE_OS_UNIX
#endif

// Check for C++11 support
#if defined(HAVE_CPP11_SUPPORT)
# define JACKBRIDGE_PROPER_CPP11_SUPPORT
#elif defined(__GNUC__) && (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__))
# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405
# define JACKBRIDGE_PROPER_CPP11_SUPPORT
# if (__GNUC__ * 100 + __GNUC_MINOR__) < 407
# define override // gcc4.7+ only
# endif
# endif
#endif

#ifndef JACKBRIDGE_PROPER_CPP11_SUPPORT
# ifndef __clang__
# define noexcept throw()
# else
# define noexcept
# endif
# define override
# define nullptr (0)
#endif

// Define JACKBRIDGE_EXPORT
#if defined(JACKBRIDGE_OS_WIN) && ! defined(__WINE__)
# define JACKBRIDGE_EXPORT extern "C" __declspec (dllexport)
#else
# define JACKBRIDGE_EXPORT extern "C" __attribute__ ((visibility("default")))
#endif

#endif // JACKBRIDGE_DEFINES_HPP_INCLUDED
99 changes: 99 additions & 0 deletions jackbridge/JackBridgeLibUtils.hpp
@@ -0,0 +1,99 @@
/*
* JackBridge library utils
* Copyright (C) 2013 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 JACKBRIDGE_LIB_UTILS_HPP_INCLUDED
#define JACKBRIDGE_LIB_UTILS_HPP_INCLUDED

#include "JackBridgeDefines.hpp"

#ifdef JACKBRIDGE_OS_WIN
# include <cstdio>
# include <cstring>
# include <winsock2.h>
# include <windows.h>
#else
# include <dlfcn.h>
#endif

// -------------------------------------------------
// library related calls

static inline
void* lib_open(const char* const filename)
{
#ifdef JACKBRIDGE_OS_WIN
return (void*)LoadLibraryA(filename);
#else
return dlopen(filename, RTLD_NOW|RTLD_LOCAL);
#endif
}

static inline
bool lib_close(void* const lib)
{
if (lib == nullptr)
return false;

#ifdef JACKBRIDGE_OS_WIN
return FreeLibrary((HMODULE)lib);
#else
return (dlclose(lib) == 0);
#endif
}

static inline
void* lib_symbol(void* const lib, const char* const symbol)
{
if (lib == nullptr && symbol == nullptr)
return nullptr;

#ifdef JACKBRIDGE_OS_WIN
return (void*)GetProcAddress((HMODULE)lib, symbol);
#else
return dlsym(lib, symbol);
#endif
}

static inline
const char* lib_error(const char* const filename)
{
#ifdef JACKBRIDGE_OS_WIN
static char libError[2048+1];
std::memset(libError, 0, 2048*sizeof(char));

LPVOID winErrorString;
DWORD winErrorCode = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, winErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&winErrorString, 0, nullptr);

#if defined(__WINE__)
std::snprintf(libError, 2048, "%s: error code %i: %s", filename, winErrorCode, (const char*)winErrorString);
#else
std::snprintf(libError, 2048, "%s: error code %li: %s", filename, winErrorCode, (const char*)winErrorString);
#endif
LocalFree(winErrorString);

return libError;
#else
return dlerror();

// unused
(void)filename;
#endif
}

// -------------------------------------------------

#endif // JACKBRIDGE_LIB_UTILS_HPP_INCLUDED
4 changes: 4 additions & 0 deletions windows.def
@@ -0,0 +1,4 @@
LIBRARY JackAss
DESCRIPTION 'JackAss VST Plugin'
EXPORTS VSTPluginMain
main=VSTPluginMain