Initial release
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Project : SDK Core
|
||||
// Version : 1.0
|
||||
//
|
||||
// Category : Common Base Classes
|
||||
// Filename : public.sdk/source/common/commoniids.cpp
|
||||
// Created by : Steinberg, 01/2019
|
||||
// Description : Define some IIDs
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "pluginterfaces/gui/iplugview.h"
|
||||
#include "pluginterfaces/gui/iplugviewcontentscalesupport.h"
|
||||
|
||||
namespace Steinberg
|
||||
{
|
||||
//----VST 3.0--------------------------------
|
||||
DEF_CLASS_IID (IPlugView)
|
||||
DEF_CLASS_IID (IPlugFrame)
|
||||
|
||||
//----VST 3.6.0--------------------------------
|
||||
DEF_CLASS_IID (IPlugViewContentScaleSupport)
|
||||
|
||||
#if SMTG_OS_LINUX
|
||||
DEF_CLASS_IID (Linux::IEventHandler)
|
||||
DEF_CLASS_IID (Linux::ITimerHandler)
|
||||
DEF_CLASS_IID (Linux::IRunLoop)
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace Steinberg
|
||||
@@ -0,0 +1,101 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Flags : clang-format SMTGSequencer
|
||||
// Project : VST SDK
|
||||
//
|
||||
// Category : Helpers
|
||||
// Filename : public.sdk/source/common/commonstringconvert.cpp
|
||||
// Created by : Steinberg, 07/2024
|
||||
// Description : c++11 unicode string convert functions
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "commonstringconvert.h"
|
||||
|
||||
#include <codecvt>
|
||||
#include <istream>
|
||||
#include <locale>
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4996)
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace Steinberg {
|
||||
namespace StringConvert {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace {
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1900
|
||||
#define USE_WCHAR_AS_UTF16TYPE
|
||||
using UTF16Type = wchar_t;
|
||||
#else
|
||||
using UTF16Type = char16_t;
|
||||
#endif
|
||||
|
||||
using Converter = std::wstring_convert<std::codecvt_utf8_utf16<UTF16Type>, UTF16Type>;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
Converter& converter ()
|
||||
{
|
||||
static Converter conv;
|
||||
return conv;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // anonymous
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
std::u16string convert (const std::string& utf8Str)
|
||||
{
|
||||
#if defined(USE_WCHAR_AS_UTF16TYPE)
|
||||
auto wstr = converter ().from_bytes (utf8Str);
|
||||
return {wstr.data (), wstr.data () + wstr.size ()};
|
||||
#else
|
||||
return converter ().from_bytes (utf8Str);
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
std::string convert (const std::u16string& str)
|
||||
{
|
||||
return converter ().to_bytes (reinterpret_cast<const UTF16Type*> (str.data ()),
|
||||
reinterpret_cast<const UTF16Type*> (str.data () + str.size ()));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
std::string convert (const char* str, uint32_t max)
|
||||
{
|
||||
std::string result;
|
||||
if (str)
|
||||
{
|
||||
result.reserve (max);
|
||||
for (uint32_t i = 0; i < max; ++i, ++str)
|
||||
{
|
||||
if (*str == 0)
|
||||
break;
|
||||
result += *str;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // StringConvert
|
||||
} // Steinberg
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
@@ -0,0 +1,74 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Flags : clang-format SMTGSequencer
|
||||
// Project : VST SDK
|
||||
//
|
||||
// Category : stringconvert
|
||||
// Filename : public.sdk/source/common/commonstringconvert.h
|
||||
// Created by : Steinberg, 07/2024
|
||||
// Description : read file routine
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace Steinberg {
|
||||
namespace StringConvert {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/**
|
||||
* convert an UTF-8 string to an UTF-16 string
|
||||
*
|
||||
* @param utf8Str UTF-8 string
|
||||
*
|
||||
* @return UTF-16 string
|
||||
*/
|
||||
std::u16string convert (const std::string& utf8Str);
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/**
|
||||
* convert an UTF-16 string to an UTF-8 string
|
||||
*
|
||||
* @param str UTF-16 string
|
||||
*
|
||||
* @return UTF-8 string
|
||||
*/
|
||||
std::string convert (const std::u16string& str);
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/**
|
||||
* convert a ASCII string buffer to an UTF-8 string
|
||||
*
|
||||
* @param str ASCII string buffer
|
||||
* @param max maximum characters in str
|
||||
*
|
||||
* @return UTF-8 string
|
||||
*/
|
||||
std::string convert (const char* str, uint32_t max);
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/**
|
||||
* convert a number to an UTF-16 string
|
||||
*
|
||||
* @param value number
|
||||
*
|
||||
* @return UTF-16 string
|
||||
*/
|
||||
template <typename NumberT>
|
||||
std::u16string toString (NumberT value)
|
||||
{
|
||||
auto u8str = std::to_string (value);
|
||||
return StringConvert::convert (u8str);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace StringConvert
|
||||
} // namespace Steinberg
|
||||
@@ -0,0 +1,299 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Project : SDK Core
|
||||
//
|
||||
// Category : Common Classes
|
||||
// Filename : public.sdk/source/common/memorystream.cpp
|
||||
// Created by : Steinberg, 03/2008
|
||||
// Description : IBStream Implementation for memory blocks
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "memorystream.h"
|
||||
#include "pluginterfaces/base/futils.h"
|
||||
#include <cstdlib>
|
||||
|
||||
namespace Steinberg {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_FUNKNOWN_METHODS (MemoryStream, IBStream, IBStream::iid)
|
||||
static const TSize kMemGrowAmount = 4096;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
MemoryStream::MemoryStream (void* data, TSize length)
|
||||
: memory ((char*)data)
|
||||
, memorySize (length)
|
||||
, size (length)
|
||||
, cursor (0)
|
||||
, ownMemory (false)
|
||||
, allocationError (false)
|
||||
{
|
||||
FUNKNOWN_CTOR
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
MemoryStream::MemoryStream ()
|
||||
: memory (nullptr)
|
||||
, memorySize (0)
|
||||
, size (0)
|
||||
, cursor (0)
|
||||
, ownMemory (true)
|
||||
, allocationError (false)
|
||||
{
|
||||
FUNKNOWN_CTOR
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
MemoryStream::~MemoryStream ()
|
||||
{
|
||||
if (ownMemory && memory)
|
||||
::free (memory);
|
||||
|
||||
FUNKNOWN_DTOR
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
tresult PLUGIN_API MemoryStream::read (void* data, int32 numBytes, int32* numBytesRead)
|
||||
{
|
||||
if (memory == nullptr)
|
||||
{
|
||||
if (allocationError)
|
||||
return kOutOfMemory;
|
||||
numBytes = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Does read exceed size ?
|
||||
if (cursor + numBytes > size)
|
||||
{
|
||||
int32 maxBytes = int32 (size - cursor);
|
||||
|
||||
// Has length become zero or negative ?
|
||||
if (maxBytes <= 0)
|
||||
{
|
||||
cursor = size;
|
||||
numBytes = 0;
|
||||
}
|
||||
else
|
||||
numBytes = maxBytes;
|
||||
}
|
||||
|
||||
if (numBytes)
|
||||
{
|
||||
memcpy (data, &memory[cursor], static_cast<size_t> (numBytes));
|
||||
cursor += numBytes;
|
||||
}
|
||||
}
|
||||
|
||||
if (numBytesRead)
|
||||
*numBytesRead = numBytes;
|
||||
|
||||
return kResultTrue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
tresult PLUGIN_API MemoryStream::write (void* buffer, int32 numBytes, int32* numBytesWritten)
|
||||
{
|
||||
if (allocationError)
|
||||
return kOutOfMemory;
|
||||
if (buffer == nullptr)
|
||||
return kInvalidArgument;
|
||||
|
||||
// Does write exceed size ?
|
||||
TSize requiredSize = cursor + numBytes;
|
||||
if (requiredSize > size)
|
||||
{
|
||||
if (requiredSize > memorySize)
|
||||
setSize (requiredSize);
|
||||
else
|
||||
size = requiredSize;
|
||||
}
|
||||
|
||||
// Copy data
|
||||
if (memory && cursor >= 0 && numBytes > 0)
|
||||
{
|
||||
memcpy (&memory[cursor], buffer, static_cast<size_t> (numBytes));
|
||||
// Update cursor
|
||||
cursor += numBytes;
|
||||
}
|
||||
else
|
||||
numBytes = 0;
|
||||
|
||||
if (numBytesWritten)
|
||||
*numBytesWritten = numBytes;
|
||||
|
||||
return kResultTrue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
tresult PLUGIN_API MemoryStream::seek (int64 pos, int32 mode, int64* result)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case kIBSeekSet:
|
||||
cursor = pos;
|
||||
break;
|
||||
case kIBSeekCur:
|
||||
cursor = cursor + pos;
|
||||
break;
|
||||
case kIBSeekEnd:
|
||||
cursor = size + pos;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ownMemory == false)
|
||||
if (cursor > memorySize)
|
||||
cursor = memorySize;
|
||||
|
||||
if (result)
|
||||
*result = cursor;
|
||||
|
||||
return kResultTrue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
tresult PLUGIN_API MemoryStream::tell (int64* pos)
|
||||
{
|
||||
if (!pos)
|
||||
return kInvalidArgument;
|
||||
|
||||
*pos = cursor;
|
||||
return kResultTrue;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
TSize MemoryStream::getSize () const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void MemoryStream::setSize (TSize s)
|
||||
{
|
||||
if (s <= 0)
|
||||
{
|
||||
if (ownMemory && memory)
|
||||
free (memory);
|
||||
|
||||
memory = nullptr;
|
||||
memorySize = 0;
|
||||
size = 0;
|
||||
cursor = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
TSize newMemorySize = (((Max (memorySize, s) - 1) / kMemGrowAmount) + 1) * kMemGrowAmount;
|
||||
if (newMemorySize == memorySize)
|
||||
{
|
||||
size = s;
|
||||
return;
|
||||
}
|
||||
|
||||
if (memory && ownMemory == false)
|
||||
{
|
||||
allocationError = true;
|
||||
return;
|
||||
}
|
||||
|
||||
ownMemory = true;
|
||||
char* newMemory = nullptr;
|
||||
|
||||
if (memory)
|
||||
{
|
||||
newMemory = (char*)realloc (memory, (size_t)newMemorySize);
|
||||
if (newMemory == nullptr && newMemorySize > 0)
|
||||
{
|
||||
newMemory = (char*)malloc ((size_t)newMemorySize);
|
||||
if (newMemory)
|
||||
{
|
||||
memcpy (newMemory, memory, (size_t)Min (newMemorySize, memorySize));
|
||||
free (memory);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
newMemory = (char*)malloc ((size_t)newMemorySize);
|
||||
|
||||
if (newMemory == nullptr)
|
||||
{
|
||||
if (newMemorySize > 0)
|
||||
allocationError = true;
|
||||
|
||||
memory = nullptr;
|
||||
memorySize = 0;
|
||||
size = 0;
|
||||
cursor = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
memory = newMemory;
|
||||
memorySize = newMemorySize;
|
||||
size = s;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
char* MemoryStream::getData () const
|
||||
{
|
||||
return memory;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
char* MemoryStream::detachData ()
|
||||
{
|
||||
if (ownMemory)
|
||||
{
|
||||
char* result = memory;
|
||||
memory = nullptr;
|
||||
memorySize = 0;
|
||||
size = 0;
|
||||
cursor = 0;
|
||||
return result;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
bool MemoryStream::truncate ()
|
||||
{
|
||||
if (ownMemory == false)
|
||||
return false;
|
||||
|
||||
if (memorySize == size)
|
||||
return true;
|
||||
|
||||
memorySize = size;
|
||||
|
||||
if (memorySize == 0)
|
||||
{
|
||||
if (memory)
|
||||
{
|
||||
free (memory);
|
||||
memory = nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (memory)
|
||||
{
|
||||
char* newMemory = (char*)realloc (memory, (size_t)memorySize);
|
||||
if (newMemory)
|
||||
memory = newMemory;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
bool MemoryStream::truncateToCursor ()
|
||||
{
|
||||
size = cursor;
|
||||
return truncate ();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -0,0 +1,59 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Project : SDK Core
|
||||
//
|
||||
// Category : Common Classes
|
||||
// Filename : public.sdk/source/common/memorystream.h
|
||||
// Created by : Steinberg, 03/2008
|
||||
// Description : IBStream Implementation for memory blocks
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pluginterfaces/base/ibstream.h"
|
||||
|
||||
namespace Steinberg {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/** Memory based Stream for IBStream implementation (using malloc).
|
||||
\ingroup sdkBase
|
||||
*/
|
||||
class MemoryStream : public IBStream
|
||||
{
|
||||
public:
|
||||
//------------------------------------------------------------------------
|
||||
MemoryStream ();
|
||||
MemoryStream (void* memory, TSize memorySize); ///< reuse a given memory without getting ownership
|
||||
virtual ~MemoryStream ();
|
||||
|
||||
//---IBStream---------------------------------------
|
||||
tresult PLUGIN_API read (void* buffer, int32 numBytes, int32* numBytesRead) SMTG_OVERRIDE;
|
||||
tresult PLUGIN_API write (void* buffer, int32 numBytes, int32* numBytesWritten) SMTG_OVERRIDE;
|
||||
tresult PLUGIN_API seek (int64 pos, int32 mode, int64* result) SMTG_OVERRIDE;
|
||||
tresult PLUGIN_API tell (int64* pos) SMTG_OVERRIDE;
|
||||
|
||||
TSize getSize () const; ///< returns the current memory size
|
||||
void setSize (TSize size); ///< set the memory size, a realloc will occur if memory already used
|
||||
char* getData () const; ///< returns the memory pointer
|
||||
char* detachData (); ///< returns the memory pointer and give up ownership
|
||||
bool truncate (); ///< realloc to the current use memory size if needed
|
||||
bool truncateToCursor (); ///< truncate memory at current cursor position
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
DECLARE_FUNKNOWN_METHODS
|
||||
protected:
|
||||
char* memory; // memory block
|
||||
TSize memorySize; // size of the memory block
|
||||
TSize size; // size of the stream
|
||||
int64 cursor; // stream pointer
|
||||
bool ownMemory; // stream has allocated memory itself
|
||||
bool allocationError; // stream invalid
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -0,0 +1,58 @@
|
||||
//------------------------------------------------------------------------
|
||||
// Flags : clang-format SMTGSequencer
|
||||
//
|
||||
// Category : Helpers
|
||||
// Project : Steinberg Plug-In SDK
|
||||
// Filename : public.sdk/source/common/openurl.cpp
|
||||
// Created by : Steinberg 04.2020
|
||||
// Description : Simple helper allowing to open a URL in the default associated application
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "openurl.h"
|
||||
#include "pluginterfaces/base/ftypes.h"
|
||||
|
||||
#if SMTG_OS_WINDOWS
|
||||
// keep this order
|
||||
#include <windows.h>
|
||||
|
||||
#include <shellapi.h>
|
||||
#else
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace Steinberg {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool openURLInDefaultApplication (const String& address)
|
||||
{
|
||||
bool res = false;
|
||||
|
||||
#if SMTG_OS_WINDOWS
|
||||
auto r = ShellExecuteA (nullptr, "open", address.text8 (), nullptr, nullptr, SW_SHOWNORMAL);
|
||||
res = (r != nullptr);
|
||||
#elif SMTG_OS_OSX
|
||||
String cmd;
|
||||
cmd += "open \"";
|
||||
cmd += address.text8 ();
|
||||
cmd += "\"";
|
||||
res = (system (cmd) == 0);
|
||||
#elif SMTG_OS_LINUX
|
||||
String cmd;
|
||||
cmd += "xdg-open \"";
|
||||
cmd += address.text8 ();
|
||||
cmd += "\"";
|
||||
res = (system (cmd) == 0);
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace Steinberg
|
||||
@@ -0,0 +1,39 @@
|
||||
//------------------------------------------------------------------------
|
||||
// Flags : clang-format SMTGSequencer
|
||||
//
|
||||
// Category : Helpers
|
||||
// Project : Steinberg Plug-In SDK
|
||||
// Filename : public.sdk/source/common/openurl.h
|
||||
// Created by : Steinberg 04.2020
|
||||
// Description : Simple helper allowing to open a URL in the default associated application
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/source/fstring.h"
|
||||
|
||||
namespace Steinberg {
|
||||
|
||||
/** Open the given URL into the default web browser.
|
||||
\ingroup sdkBase
|
||||
|
||||
It returns true if a default application is found and opened else false.
|
||||
Example:
|
||||
\code{.cpp}
|
||||
if (openURLInDefaultApplication ("https://www.steinberg.net/"))
|
||||
{
|
||||
// everything seems to be ok
|
||||
}
|
||||
\endcode
|
||||
*/
|
||||
bool openURLInDefaultApplication (const String& address);
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace Steinberg
|
||||
@@ -0,0 +1,80 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Project : SDK Core
|
||||
//
|
||||
// Category : Common Base Classes
|
||||
// Filename : public.sdk/source/common/pluginview.cpp
|
||||
// Created by : Steinberg, 01/2004
|
||||
// Description : Plug-In View Implementation
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "pluginview.h"
|
||||
|
||||
namespace Steinberg {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// CPluginView implementation
|
||||
//------------------------------------------------------------------------
|
||||
CPluginView::CPluginView (const ViewRect* _rect)
|
||||
: rect (0, 0, 0, 0)
|
||||
{
|
||||
if (_rect)
|
||||
rect = *_rect;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
CPluginView::~CPluginView ()
|
||||
{
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
tresult PLUGIN_API CPluginView::isPlatformTypeSupported (FIDString /*type*/)
|
||||
{
|
||||
return kNotImplemented;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
tresult PLUGIN_API CPluginView::attached (void* parent, FIDString /*type*/)
|
||||
{
|
||||
systemWindow = parent;
|
||||
|
||||
attachedToParent ();
|
||||
return kResultOk;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
tresult PLUGIN_API CPluginView::removed ()
|
||||
{
|
||||
systemWindow = nullptr;
|
||||
|
||||
removedFromParent ();
|
||||
return kResultOk;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
tresult PLUGIN_API CPluginView::onSize (ViewRect* newSize)
|
||||
{
|
||||
if (newSize)
|
||||
rect = *newSize;
|
||||
return kResultTrue;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
tresult PLUGIN_API CPluginView::getSize (ViewRect* size)
|
||||
{
|
||||
if (size)
|
||||
{
|
||||
*size = rect;
|
||||
return kResultTrue;
|
||||
}
|
||||
return kInvalidArgument;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace Steinberg
|
||||
@@ -0,0 +1,96 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Project : SDK Core
|
||||
//
|
||||
// Category : Common Base Classes
|
||||
// Filename : public.sdk/source/common/pluginview.h
|
||||
// Created by : Steinberg, 01/2004
|
||||
// Description : Plug-In View Implementation
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pluginterfaces/gui/iplugview.h"
|
||||
#include "base/source/fobject.h"
|
||||
|
||||
namespace Steinberg {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/** Plug-In view default implementation.
|
||||
\ingroup sdkBase
|
||||
Can be used as base class for an IPlugView implementation.
|
||||
*/
|
||||
class CPluginView : public FObject, public IPlugView
|
||||
{
|
||||
public:
|
||||
//------------------------------------------------------------------------
|
||||
CPluginView (const ViewRect* rect = nullptr);
|
||||
~CPluginView () SMTG_OVERRIDE;
|
||||
|
||||
/** Returns its current frame rectangle. */
|
||||
const ViewRect& getRect () const { return rect; }
|
||||
|
||||
/** Sets a new frame rectangle. */
|
||||
void setRect (const ViewRect& r) { rect = r; }
|
||||
|
||||
/** Checks if this view is attached to its parent view. */
|
||||
bool isAttached () const { return systemWindow != nullptr; }
|
||||
|
||||
/** Calls when this view will be attached to its parent view. */
|
||||
virtual void attachedToParent () {}
|
||||
|
||||
/** Calls when this view will be removed from its parent view. */
|
||||
virtual void removedFromParent () {}
|
||||
|
||||
//---from IPlugView-------
|
||||
tresult PLUGIN_API isPlatformTypeSupported (FIDString type) SMTG_OVERRIDE;
|
||||
tresult PLUGIN_API attached (void* parent, FIDString type) SMTG_OVERRIDE;
|
||||
tresult PLUGIN_API removed () SMTG_OVERRIDE;
|
||||
|
||||
tresult PLUGIN_API onWheel (float /*distance*/) SMTG_OVERRIDE { return kResultFalse; }
|
||||
tresult PLUGIN_API onKeyDown (char16 /*key*/, int16 /*keyMsg*/,
|
||||
int16 /*modifiers*/) SMTG_OVERRIDE
|
||||
{
|
||||
return kResultFalse;
|
||||
}
|
||||
tresult PLUGIN_API onKeyUp (char16 /*key*/, int16 /*keyMsg*/, int16 /*modifiers*/) SMTG_OVERRIDE
|
||||
{
|
||||
return kResultFalse;
|
||||
}
|
||||
tresult PLUGIN_API getSize (ViewRect* size) SMTG_OVERRIDE;
|
||||
tresult PLUGIN_API onSize (ViewRect* newSize) SMTG_OVERRIDE;
|
||||
|
||||
tresult PLUGIN_API onFocus (TBool /*state*/) SMTG_OVERRIDE { return kResultFalse; }
|
||||
tresult PLUGIN_API setFrame (IPlugFrame* frame) SMTG_OVERRIDE
|
||||
{
|
||||
plugFrame = frame;
|
||||
return kResultTrue;
|
||||
}
|
||||
|
||||
tresult PLUGIN_API canResize () SMTG_OVERRIDE { return kResultFalse; }
|
||||
tresult PLUGIN_API checkSizeConstraint (ViewRect* /*rect*/) SMTG_OVERRIDE
|
||||
{
|
||||
return kResultFalse;
|
||||
}
|
||||
|
||||
//---Interface------
|
||||
OBJ_METHODS (CPluginView, FObject)
|
||||
DEFINE_INTERFACES
|
||||
DEF_INTERFACE (IPlugView)
|
||||
END_DEFINE_INTERFACES (FObject)
|
||||
REFCOUNT_METHODS (FObject)
|
||||
//------------------------------------------------------------------------
|
||||
protected:
|
||||
ViewRect rect;
|
||||
void* systemWindow {nullptr};
|
||||
IPtr<IPlugFrame> plugFrame;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace Steinberg
|
||||
@@ -0,0 +1,64 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Project : VST SDK
|
||||
// Flags : clang-format SMTGSequencer
|
||||
//
|
||||
// Category : readfile
|
||||
// Filename : public.sdk/source/common/readfile.cpp
|
||||
// Created by : Steinberg, 3/2023
|
||||
// Description : read file routine
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "readfile.h"
|
||||
|
||||
#include "pluginterfaces/base/fplatform.h"
|
||||
|
||||
#if SMTG_OS_WINDOWS
|
||||
#include "commonstringconvert.h"
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#if !SMTG_CPP17
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
namespace Steinberg {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
std::string readFile (const std::string& path)
|
||||
{
|
||||
#if SMTG_OS_WINDOWS
|
||||
auto u16Path = StringConvert::convert (path);
|
||||
std::ifstream file (reinterpret_cast<const wchar_t*> (u16Path.data ()),
|
||||
std::ios_base::in | std::ios_base::binary);
|
||||
#else
|
||||
std::ifstream file (path, std::ios_base::in | std::ios_base::binary);
|
||||
#endif
|
||||
if (!file.is_open ())
|
||||
return {};
|
||||
|
||||
#if SMTG_CPP17
|
||||
auto size = file.seekg (0, std::ios_base::end).tellg ();
|
||||
file.seekg (0, std::ios_base::beg);
|
||||
std::string data;
|
||||
data.resize (size);
|
||||
file.read (data.data (), data.size ());
|
||||
if (file.bad ())
|
||||
return {};
|
||||
return data;
|
||||
#else
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf ();
|
||||
return buffer.str ();
|
||||
#endif // SMTG_CPP17
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace Steinberg
|
||||
@@ -0,0 +1,34 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Flags : clang-format SMTGSequencer
|
||||
// Project : VST SDK
|
||||
//
|
||||
// Category : readfile
|
||||
// Filename : public.sdk/source/common/readfile.h
|
||||
// Created by : Steinberg, 3/2023
|
||||
// Description : read file routine
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Steinberg {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/** Reads entire file content
|
||||
\ingroup sdkBase
|
||||
|
||||
Returns entire file content at the given path
|
||||
\endcode
|
||||
*/
|
||||
std::string readFile (const std::string& path);
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace Steinberg
|
||||
@@ -0,0 +1,45 @@
|
||||
//------------------------------------------------------------------------
|
||||
// Flags : clang-format SMTGSequencer
|
||||
//
|
||||
// Project : Steinberg Plug-In SDK
|
||||
// Filename : public.sdk/source/common/systemclipboard.h
|
||||
// Created by : Steinberg 04.2020
|
||||
// Description : Simple helper allowing to copy/retrieve text to/from the system clipboard
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace Steinberg {
|
||||
namespace SystemClipboard {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Copies the given text into the system clipboard
|
||||
\ingroup sdkBase
|
||||
|
||||
\param text UTF-8 encoded text
|
||||
\return true on success
|
||||
*/
|
||||
bool copyTextToClipboard (const std::string& text);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Retrieves the current text from the system clipboard
|
||||
\ingroup sdkBase
|
||||
|
||||
\param text UTF-8 encoded text
|
||||
\return true on success
|
||||
*/
|
||||
bool getTextFromClipboard (std::string& text);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
} // namespace SystemClipboard
|
||||
} // namespace Steinberg
|
||||
@@ -0,0 +1,44 @@
|
||||
//------------------------------------------------------------------------
|
||||
// Flags : clang-format SMTGSequencer
|
||||
//
|
||||
// Project : Steinberg Plug-In SDK
|
||||
// Filename : public.sdk/source/common/systemclipboard_linux.cpp
|
||||
// Created by : Steinberg 04.2023
|
||||
// Description : Simple helper allowing to copy/retrieve text to/from the system clipboard
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "systemclipboard.h"
|
||||
#include "pluginterfaces/base/fplatform.h"
|
||||
|
||||
#if SMTG_OS_LINUX
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace Steinberg {
|
||||
namespace SystemClipboard {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool copyTextToClipboard (const std::string& text)
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool getTextFromClipboard (std::string& text)
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace SystemClipboard
|
||||
} // namespace Steinberg
|
||||
|
||||
#endif // SMTG_OS_LINUX
|
||||
@@ -0,0 +1,71 @@
|
||||
//------------------------------------------------------------------------
|
||||
// Flags : clang-format SMTGSequencer
|
||||
//
|
||||
// Project : Steinberg Plug-In SDK
|
||||
// Filename : public.sdk/source/common/systemclipboard_mac.mm
|
||||
// Created by : Steinberg 04.2020
|
||||
// Description : Simple helper allowing to copy/retrieve text to/from the system clipboard
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "systemclipboard.h"
|
||||
#include "pluginterfaces/base/fplatform.h"
|
||||
|
||||
#if SMTG_OS_OSX
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace Steinberg {
|
||||
namespace SystemClipboard {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool copyTextToClipboard (const std::string& text)
|
||||
{
|
||||
auto pb = [NSPasteboard generalPasteboard];
|
||||
[pb clearContents];
|
||||
auto nsString = [NSString stringWithUTF8String:text.data ()];
|
||||
return [pb setString:nsString forType:NSPasteboardTypeString];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool getTextFromClipboard (std::string& text)
|
||||
{
|
||||
auto pb = [NSPasteboard generalPasteboard];
|
||||
if ([pb canReadItemWithDataConformingToTypes:@[NSPasteboardTypeString]])
|
||||
{
|
||||
if (auto items = [pb readObjectsForClasses:@[[NSString class]] options:nil])
|
||||
{
|
||||
if (items.count > 0)
|
||||
{
|
||||
text = [items[0] UTF8String];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace SystemClipboard
|
||||
} // namespace Steinberg
|
||||
|
||||
#elif SMTG_OS_IOS
|
||||
//------------------------------------------------------------------------
|
||||
bool copyTextToClipboard (const std::string& text)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
bool getTextFromClipboard (std::string& text)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // SMTG_OS_MACOS
|
||||
@@ -0,0 +1,148 @@
|
||||
//------------------------------------------------------------------------
|
||||
// Flags : clang-format SMTGSequencer
|
||||
//
|
||||
// Project : Steinberg Plug-In SDK
|
||||
// Filename : public.sdk/source/common/systemclipboard_win32.cpp
|
||||
// Created by : Steinberg 04.2020
|
||||
// Description : Simple helper allowing to copy/retrieve text to/from the system clipboard
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "systemclipboard.h"
|
||||
#include "pluginterfaces/base/fplatform.h"
|
||||
|
||||
#if SMTG_OS_WINDOWS
|
||||
#include <vector>
|
||||
#include <windows.h>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace Steinberg {
|
||||
namespace SystemClipboard {
|
||||
namespace {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
struct Clipboard
|
||||
{
|
||||
Clipboard () { open = OpenClipboard (nullptr); }
|
||||
~Clipboard ()
|
||||
{
|
||||
if (open)
|
||||
CloseClipboard ();
|
||||
}
|
||||
|
||||
bool open {false};
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
std::vector<WCHAR> convertToWide (const std::string& text)
|
||||
{
|
||||
std::vector<WCHAR> wideStr;
|
||||
|
||||
auto numChars =
|
||||
MultiByteToWideChar (CP_UTF8, 0, text.data (), static_cast<int> (text.size ()), nullptr, 0);
|
||||
if (numChars)
|
||||
{
|
||||
wideStr.resize (static_cast<size_t> (numChars) + 1);
|
||||
numChars = MultiByteToWideChar (CP_UTF8, 0, text.data (), static_cast<int> (text.size ()),
|
||||
wideStr.data (), static_cast<int> (wideStr.size ()));
|
||||
}
|
||||
wideStr[numChars] = 0;
|
||||
wideStr.resize (static_cast<size_t> (numChars) + 1);
|
||||
return wideStr;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
std::string convertToUTF8 (const WCHAR* data, const SIZE_T& dataSize)
|
||||
{
|
||||
std::string text;
|
||||
auto numChars =
|
||||
WideCharToMultiByte (CP_UTF8, 0, data, static_cast<int> (dataSize / sizeof (WCHAR)),
|
||||
nullptr, 0, nullptr, nullptr);
|
||||
text.resize (static_cast<size_t> (numChars) + 1);
|
||||
numChars = WideCharToMultiByte (CP_UTF8, 0, data, static_cast<int> (dataSize / sizeof (WCHAR)),
|
||||
const_cast<char*> (text.data ()),
|
||||
static_cast<int> (text.size ()), nullptr, nullptr);
|
||||
text.resize (numChars);
|
||||
return text;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // anonymous
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool copyTextToClipboard (const std::string& text)
|
||||
{
|
||||
Clipboard cb;
|
||||
if (text.empty () || !cb.open)
|
||||
return false;
|
||||
|
||||
if (!EmptyClipboard ())
|
||||
return false;
|
||||
|
||||
bool result = false;
|
||||
|
||||
auto wideStr = convertToWide (text);
|
||||
|
||||
auto byteSize = wideStr.size () * sizeof (WCHAR);
|
||||
|
||||
if (auto memory = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, byteSize))
|
||||
{
|
||||
if (auto* data = static_cast<WCHAR*> (GlobalLock (memory)))
|
||||
{
|
||||
#if defined(__MINGW32__)
|
||||
memcpy (data, wideStr.data (), byteSize);
|
||||
#else
|
||||
memcpy_s (data, byteSize, wideStr.data (), byteSize);
|
||||
#endif
|
||||
GlobalUnlock (memory);
|
||||
|
||||
auto handle = SetClipboardData (CF_UNICODETEXT, memory);
|
||||
result = handle != nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool getTextFromClipboard (std::string& text)
|
||||
{
|
||||
Clipboard cb;
|
||||
if (!cb.open)
|
||||
return false;
|
||||
|
||||
if (!IsClipboardFormatAvailable (CF_UNICODETEXT))
|
||||
return false;
|
||||
|
||||
bool result = false;
|
||||
|
||||
// Get handle of clipboard object for unicode text
|
||||
if (auto hData = GetClipboardData (CF_UNICODETEXT))
|
||||
{
|
||||
// Lock the handle to get the actual text pointer
|
||||
if (auto* data = (const WCHAR*)GlobalLock (hData))
|
||||
{
|
||||
auto dataSize = GlobalSize (hData);
|
||||
text = convertToUTF8 (data, dataSize);
|
||||
|
||||
// Release the lock
|
||||
GlobalUnlock (hData);
|
||||
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace SystemClipboard
|
||||
} // namespace Steinberg
|
||||
|
||||
#endif // SMTG_OS_WINDOWS
|
||||
@@ -0,0 +1,39 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Project : VST SDK
|
||||
//
|
||||
// Category : Examples
|
||||
// Filename : public.sdk/source/common/threadchecker.h
|
||||
// Created by : Steinberg, 01/2019
|
||||
// Description : thread checker
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pluginterfaces/base/ftypes.h"
|
||||
#include <memory>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace Steinberg {
|
||||
namespace Vst {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class ThreadChecker
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<ThreadChecker> create ();
|
||||
|
||||
virtual bool test (const char* failmessage = nullptr, bool exit = false) = 0;
|
||||
|
||||
virtual ~ThreadChecker () noexcept = default;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace Vst
|
||||
} // namespace Steinberg
|
||||
@@ -0,0 +1,56 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Project : VST SDK
|
||||
//
|
||||
// Category : Examples
|
||||
// Filename : public.sdk/source/common/threadchecker_linux.cpp
|
||||
// Created by : Steinberg, 01/2019
|
||||
// Description : linux thread checker
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "threadchecker.h"
|
||||
|
||||
#if SMTG_OS_LINUX
|
||||
|
||||
#include <cstdio>
|
||||
#include <pthread.h>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace Steinberg {
|
||||
namespace Vst {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class LinuxThreadChecker : public ThreadChecker
|
||||
{
|
||||
public:
|
||||
bool test (const char* failmessage = nullptr, bool exit = false) override
|
||||
{
|
||||
if (threadID == pthread_self ())
|
||||
return true;
|
||||
if (failmessage)
|
||||
fprintf (stderr, "%s", failmessage);
|
||||
if (exit)
|
||||
std::terminate ();
|
||||
return false;
|
||||
}
|
||||
|
||||
pthread_t threadID {pthread_self ()};
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
std::unique_ptr<ThreadChecker> ThreadChecker::create ()
|
||||
{
|
||||
return std::unique_ptr<ThreadChecker> (new LinuxThreadChecker);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace Vst
|
||||
} // namespace Steinberg
|
||||
|
||||
#endif // SMTG_OS_LINUX
|
||||
@@ -0,0 +1,56 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Project : VST SDK
|
||||
//
|
||||
// Category : Examples
|
||||
// Filename : public.sdk/source/common/threadchecker_mac.mm
|
||||
// Created by : Steinberg, 01/2019
|
||||
// Description : macOS thread checker
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "threadchecker.h"
|
||||
|
||||
#if SMTG_OS_MACOS
|
||||
|
||||
#include <pthread.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace Steinberg {
|
||||
namespace Vst {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class MacThreadChecker : public ThreadChecker
|
||||
{
|
||||
public:
|
||||
bool test (const char* failmessage = nullptr, bool exit = false) override
|
||||
{
|
||||
if (threadID == pthread_self ())
|
||||
return true;
|
||||
if (failmessage)
|
||||
NSLog (@"%s", failmessage);
|
||||
if (exit)
|
||||
std::terminate ();
|
||||
return false;
|
||||
}
|
||||
|
||||
pthread_t threadID {pthread_self ()};
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
std::unique_ptr<ThreadChecker> ThreadChecker::create ()
|
||||
{
|
||||
return std::unique_ptr<ThreadChecker> (new MacThreadChecker);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // Vst
|
||||
} // Steinberg
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Project : VST SDK
|
||||
//
|
||||
// Category : Examples
|
||||
// Filename : public.sdk/source/common/threadchecker_win32.cpp
|
||||
// Created by : Steinberg, 01/2019
|
||||
// Description : win32 thread checker
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "threadchecker.h"
|
||||
|
||||
#if SMTG_OS_WINDOWS
|
||||
#include <windows.h>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace Steinberg {
|
||||
namespace Vst {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class Win32ThreadChecker : public ThreadChecker
|
||||
{
|
||||
public:
|
||||
bool test (const char* failmessage = nullptr, bool exit = false) override
|
||||
{
|
||||
if (threadID == GetCurrentThreadId ())
|
||||
return true;
|
||||
if (failmessage)
|
||||
OutputDebugStringA (failmessage);
|
||||
if (exit)
|
||||
std::terminate ();
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD threadID {GetCurrentThreadId ()};
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
std::unique_ptr<ThreadChecker> ThreadChecker::create ()
|
||||
{
|
||||
return std::unique_ptr<ThreadChecker> (new Win32ThreadChecker);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace Vst
|
||||
} // namespace Steinberg
|
||||
|
||||
#endif // SMTG_OS_WINDOWS
|
||||
Reference in New Issue
Block a user