diff --git a/premake5.lua b/premake5.lua index 76f84f430c7..ea9863ef147 100644 --- a/premake5.lua +++ b/premake5.lua @@ -58,6 +58,36 @@ if (os.istarget("macosx")) then platforms { "x64" } +elseif (os.istarget("linux")) then + + flags { "StaticRuntime" } + vectorextensions "SSE2" + + defines + { + "_MM_ALIGN16=__attribute__((aligned(16)))", + "__forceinline=inline", + "forceinline=inline", + "_aligned_malloc(x,a)=malloc(x)", + "_aligned_free(x)=free(x)", + "stricmp=strcasecmp", + "SSE_VERSION=3", + "__cdecl=" + } + + links + { + } + + defines { "WINDOWS=0" } + + buildoptions { "-std=c++17", "-I/home/kjetil/SDKs/VST_SDK/VST2_SDK" } + links { } + buildoptions { } + linkoptions { } + + platforms { "x64" } + elseif (os.istarget("windows")) then toolset "v141" @@ -167,6 +197,47 @@ function plugincommon() "QuartzCore.framework", } + elseif (os.istarget("linux")) then + + -- pchheader "src/common/precompiled.h" -- + -- pchsource "src/common/precompiled.cpp" -- + + buildoptions { + "-Wno-unused-variable", + "`pkg-config gtkmm-3.0 --cflags`", + "-std=c++14" + } + + files + { + "src/linux/*.mm", + "src/linux/**.cpp", + "src/linux/**.h", +-- "libs/vst/*.mm", -- + VSTGUI .. "vstgui_linux.cpp", +-- VSTGUI .. "vstgui_uidescription_linux.cpp", -- + } + + excludes { + VSTGUI .. "winfileselector.cpp", + VSTGUI .. "vstgui_ios.mm", + VSTGUI .. "vstgui_uidescription_ios.mm", + } + + includedirs + { + + } + + links { + "pthread", + "stdc++fs" + + } + + linkoptions { + "`pkg-config gtkmm-3.0 --libs`", + } elseif (os.istarget("windows")) then pchheader "precompiled.h" @@ -400,4 +471,4 @@ if (os.istarget("macosx")) then postbuildcommands { "./package-au.sh" } -end \ No newline at end of file +end diff --git a/src/common/AbstractSynthesizer.cpp b/src/common/AbstractSynthesizer.cpp index 8f784e98e8e..95f147b6bc5 100644 --- a/src/common/AbstractSynthesizer.cpp +++ b/src/common/AbstractSynthesizer.cpp @@ -5,7 +5,7 @@ #define SSE_STATE_FLAG 0x8040 -#if !MAC +#if !MAC && !__linux__ #include int SSE_VERSION; @@ -15,7 +15,7 @@ int SSE_VERSION; void initDllGlobals() { -#if !MAC // intel macs always support SSE2 +#if !MAC && !__linux__ // intel macs always support SSE2 unsigned int arch = determine_support(); // detect if (arch & ca_SSE3) @@ -39,4 +39,4 @@ void initDllGlobals() "Surge: System requirements not met", MB_OK | MB_ICONERROR); } #endif -} \ No newline at end of file +} diff --git a/src/common/MemoryFile.h b/src/common/MemoryFile.h index 438619bb3cb..315b5da52d0 100644 --- a/src/common/MemoryFile.h +++ b/src/common/MemoryFile.h @@ -1,5 +1,5 @@ #pragma once -#include +#include struct riffheader { @@ -306,7 +306,7 @@ class MemoryFile void invalid() { -#if !MAC +#if !MAC && !__linux__ char txt[1024]; sprintf(txt, "Invalid RIFF-structure.\n\nOffset: 0x%X", loc); MessageBox(::GetActiveWindow(), txt, "File I/O Error", MB_OK | MB_ICONERROR); diff --git a/src/common/Sample.h b/src/common/Sample.h index f528b027381..06be54dcfc1 100644 --- a/src/common/Sample.h +++ b/src/common/Sample.h @@ -7,7 +7,7 @@ //------------------------------------------------------------------------------------------------------- #pragma once -#ifdef MAC +#if MAC || __linux__ #else #include #include @@ -89,4 +89,4 @@ class Sample unsigned int refcount; }; -#endif \ No newline at end of file +#endif diff --git a/src/common/SurgePatch.cpp b/src/common/SurgePatch.cpp index d7c838ece7f..81ff0891ef6 100644 --- a/src/common/SurgePatch.cpp +++ b/src/common/SurgePatch.cpp @@ -7,7 +7,7 @@ #include "effect/Effect.h" #include #include "MemoryFile.h" -#include +#include const int hmargin = 6; // const int gui_topbar = 44; diff --git a/src/common/SurgeStorage.cpp b/src/common/SurgeStorage.cpp index cf544d07493..c8700f3fa2a 100644 --- a/src/common/SurgeStorage.cpp +++ b/src/common/SurgeStorage.cpp @@ -4,12 +4,13 @@ #include "SurgeStorage.h" #include "DspUtilities.h" #include -#include +#include #if MAC //#include //#include #include #include +#elif __linux__ #else #include #include @@ -128,6 +129,10 @@ SurgeStorage::SurgeStorage() userDataPath = "~/Documents/Surge"; +#elif __linux__ + + printf("Implement me, probably\n"); + #else PWSTR localAppData; @@ -151,7 +156,7 @@ SurgeStorage::SurgeStorage() if (!snapshotloader.LoadFile(snapshotmenupath.c_str())) // load snapshots (& config-stuff) { -#if !MAC +#if !MAC && !__linux__ MessageBox(::GetActiveWindow(), "Surge is not properly installed. Please reinstall.", "Configuration not found", MB_OK | MB_ICONERROR); #endif diff --git a/src/common/SurgeStorage.h b/src/common/SurgeStorage.h index 443ceb4958d..7c8c9ed0506 100644 --- a/src/common/SurgeStorage.h +++ b/src/common/SurgeStorage.h @@ -17,7 +17,12 @@ using namespace std; #endif #include +#if __linux +#include +#else #include +#endif + #include #include @@ -521,4 +526,4 @@ float db_to_linear(float); float lookup_waveshape(int, float); float lookup_waveshape_warp(int, float); float envelope_rate_lpf(float); -float envelope_rate_linear(float); \ No newline at end of file +float envelope_rate_linear(float); diff --git a/src/common/SurgeSynthesizer.cpp b/src/common/SurgeSynthesizer.cpp index 6fc94a09694..06cb06ae157 100644 --- a/src/common/SurgeSynthesizer.cpp +++ b/src/common/SurgeSynthesizer.cpp @@ -4,7 +4,7 @@ #include "SurgeSynthesizer.h" #include "DspUtilities.h" #include -#if MAC +#if MAC || __linux__ #include #else #include @@ -726,8 +726,8 @@ void SurgeSynthesizer::channelController(char channel, int cc, int value) int channelmask = ((channel == 0) ? 3 : 0) | ((channel == 1) ? 1 : 0) | ((channel == 2) ? 2 : 0); float fval = (float)value * (1.f / 127.f); - // spara all möjliga NRPN & RPN's i ett short-array.. blir endast 128kb eller nåt av av det - // ändå.. + // spara all m�jliga NRPN & RPN's i ett short-array.. blir endast 128kb eller n�t av av det + // �nd�.. switch (cc) { case 0: @@ -928,7 +928,7 @@ void SurgeSynthesizer::purgeHoldbuffer(int scene) iter++; } - // note: måste remova entries när noter dödar sig själv auch + // note: m�ste remova entries n�r noter d�dar sig sj�lv auch } void SurgeSynthesizer::allNotesOff() @@ -1903,7 +1903,7 @@ void SurgeSynthesizer::getParameterMeta(long index, parametermeta& pm) pm.fdefault = 0.5f; pm.hide = false; pm.meta = - false; // ironiskt eftersom det Šr metaparameters, men dom pŒverkar inga andra sliders + false; // ironiskt eftersom det �r metaparameters, men dom p�verkar inga andra sliders pm.expert = false; pm.clump = 1; } @@ -1949,7 +1949,7 @@ float SurgeSynthesizer::valueToNormalized(long index, float value) return 0.f; } -#if MAC +#if MAC || __linux__ void* loadPatchInBackgroundThread(void* sy) { #else @@ -2140,7 +2140,7 @@ void SurgeSynthesizer::process() // spawn patch-loading thread halt_engine = true; -#if MAC +#if MAC || __linux__ pthread_t thread; pthread_attr_t attributes; int ret; diff --git a/src/common/SurgeSynthesizerIO.cpp b/src/common/SurgeSynthesizerIO.cpp index ae701457e23..0158647bbae 100644 --- a/src/common/SurgeSynthesizerIO.cpp +++ b/src/common/SurgeSynthesizerIO.cpp @@ -4,8 +4,12 @@ #include "SurgeSynthesizer.h" #include "DspUtilities.h" #include -#include +#include +#ifdef __linux__ +#include +#else #include +#endif #include #include @@ -153,7 +157,7 @@ void SurgeSynthesizer::loadRaw(const void* data, int size, bool preset) refresh_editor = true; } -#if MAC +#if MAC || __linux__ #include #include #endif @@ -164,7 +168,7 @@ string SurgeSynthesizer::getUserPatchDirectory() } string SurgeSynthesizer::getLegacyUserPatchDirectory() { -#if MAC +#if MAC || __linux__ return storage.datapath + "patches_user/"; #else return storage.datapath + "patches_user\\"; @@ -181,6 +185,8 @@ bool askIfShouldOverwrite() CFSTR("Yes"), CFSTR("No"), 0, &responseFlags); if ((responseFlags & 0x3) != kCFUserNotificationDefaultResponse) return false; +#elif __linux__ + printf("Implement me\n"); #else if (MessageBox(::GetActiveWindow(), "The file already exist, do you wish to overwrite it?", "Overwrite?", MB_YESNO | MB_ICONQUESTION) != IDYES) diff --git a/src/common/dsp/DspUtilities.h b/src/common/dsp/DspUtilities.h index 79c839545a0..5dd1320e3e6 100644 --- a/src/common/dsp/DspUtilities.h +++ b/src/common/dsp/DspUtilities.h @@ -2,6 +2,9 @@ // Copyright 2005 Claes Johanson & Vember Audio //------------------------------------------------------------------------------------------------------- #pragma once + +#include + #include "globals.h" #include #include @@ -393,4 +396,4 @@ inline bool is_yes(const char* str) return 1; #endif return 0; -} \ No newline at end of file +} diff --git a/src/common/dsp/QuadFilterChain.cpp b/src/common/dsp/QuadFilterChain.cpp index 7b7bfd241c8..b7830258320 100644 --- a/src/common/dsp/QuadFilterChain.cpp +++ b/src/common/dsp/QuadFilterChain.cpp @@ -428,4 +428,4 @@ FBQFPtr GetFBQPointer(int config, bool A, bool WS, bool B) return GetFBQPointer2(A, WS, B); } return 0; -} \ No newline at end of file +} diff --git a/src/common/dsp/QuadFilterChain.h b/src/common/dsp/QuadFilterChain.h index f811b5a6a1d..e9f431573d0 100644 --- a/src/common/dsp/QuadFilterChain.h +++ b/src/common/dsp/QuadFilterChain.h @@ -24,4 +24,4 @@ struct fbq_global typedef void (*FBQFPtr)(QuadFilterChainState&, fbq_global&, float*, float*); -FBQFPtr GetFBQPointer(int config, bool A, bool WS, bool B); \ No newline at end of file +FBQFPtr GetFBQPointer(int config, bool A, bool WS, bool B); diff --git a/src/common/dsp/QuadFilterUnit.h b/src/common/dsp/QuadFilterUnit.h index e289636e20c..62b390359ae 100644 --- a/src/common/dsp/QuadFilterUnit.h +++ b/src/common/dsp/QuadFilterUnit.h @@ -1,5 +1,7 @@ #include "FilterCoefficientMaker.h" #pragma once +#include "globals.h" + const int n_filter_registers = 5; @@ -16,4 +18,4 @@ typedef __m128 (*FilterUnitQFPtr)(QuadFilterUnitState* __restrict, __m128 in); typedef __m128 (*WaveshaperQFPtr)(__m128 in, __m128 drive); FilterUnitQFPtr GetQFPtrFilterUnit(int type, int subtype); -WaveshaperQFPtr GetQFPtrWaveshaper(int type); \ No newline at end of file +WaveshaperQFPtr GetQFPtrWaveshaper(int type); diff --git a/src/common/dsp/VectorizedSvfFilter.cpp b/src/common/dsp/VectorizedSvfFilter.cpp index c600013c621..fbfe026343c 100644 --- a/src/common/dsp/VectorizedSvfFilter.cpp +++ b/src/common/dsp/VectorizedSvfFilter.cpp @@ -1,5 +1,8 @@ +#include + #include "VectorizedSvfFilter.h" + //================================================================================================ //------------------------------------------------------------------------------------------------ @@ -67,4 +70,4 @@ float VectorizedSvfFilter::CalcQ(float Quality) return 1.f / Quality; } -//------------------------------------------------------------------------------------------------ \ No newline at end of file +//------------------------------------------------------------------------------------------------ diff --git a/src/common/dsp/Wavetable.cpp b/src/common/dsp/Wavetable.cpp index 7207e0aa87e..5e5ce4646a9 100644 --- a/src/common/dsp/Wavetable.cpp +++ b/src/common/dsp/Wavetable.cpp @@ -2,7 +2,7 @@ #include #include "DspUtilities.h" #include -#include +#include #include "SurgeStorage.h" #if WINDOWS @@ -36,7 +36,7 @@ const int HRFilterI16[64] = { int min_F32_tables = 3; -#if MAC +#if MAC || __linux__ bool _BitScanReverse(unsigned int* result, unsigned int bits) { *result = __builtin_ctz(bits); @@ -305,4 +305,4 @@ void Wavetable::MipMapWT() // knäppen kommer antagligen från att det inte är någon padding i början så att det blir ur fas // vid mipmapbyte makes sense eftersom den skilde en hel sample vid bytet, vilket inte kan // förklaras av halfratefiltret -} \ No newline at end of file +} diff --git a/src/common/dsp/WindowOscillator.cpp b/src/common/dsp/WindowOscillator.cpp index 1ac2b0a46fd..95633fd904c 100644 --- a/src/common/dsp/WindowOscillator.cpp +++ b/src/common/dsp/WindowOscillator.cpp @@ -2,9 +2,12 @@ // Copyright 2006 Claes Johanson & Vember Audio //------------------------------------------------------------------------------------------------------- #include "Oscillator.h" -#if !MAC +#if !MAC && !__linux__ #include #endif +#ifdef __linux__ +#include +#endif /* wt2 osc */ @@ -96,6 +99,9 @@ __forceinline unsigned int BigMULr16(unsigned int a, unsigned int b) #elif _M_X64 unsigned __int64 c = __emulu(a, b); return c >> 16; +#elif __linux__ + uint64_t c = (uint64_t)a * (uint64_t)b; + return c >> 16; #else unsigned int result; __asm @@ -113,7 +119,7 @@ __forceinline unsigned int BigMULr16(unsigned int a, unsigned int b) #endif } -#if MAC +#if MAC || __linux__ __forceinline bool _BitScanReverse(unsigned long* result, unsigned long bits) { *result = __builtin_ctz(bits); diff --git a/src/common/globals.h b/src/common/globals.h index 4cd2eee56ba..8c2e868b282 100644 --- a/src/common/globals.h +++ b/src/common/globals.h @@ -16,6 +16,10 @@ #include #endif +#ifdef __linux__ +#include +#endif + using namespace std; const int namechars = 64; @@ -30,6 +34,6 @@ const int ob_length_quad = ob_length >> 2; const float block_size_inv = (1.f / block_size); const float block_size_os_inv = (1.f / block_size_os); const int max_fb_comb = 2048; // m�ste vara 2^n -#if !MAC +#if !MAC && !__linux__ extern int SSE_VERSION; -#endif \ No newline at end of file +#endif diff --git a/src/common/gui/SurgeGUIEditor.cpp b/src/common/gui/SurgeGUIEditor.cpp index d382b918049..e51f4c82e5f 100644 --- a/src/common/gui/SurgeGUIEditor.cpp +++ b/src/common/gui/SurgeGUIEditor.cpp @@ -176,7 +176,7 @@ void SurgeGUIEditor::idle() } synth->storage.CS_ModRouting.leave(); } -#if MAC +#if MAC || __linux__ idleinc++; if (idleinc > 15) { @@ -1904,6 +1904,8 @@ void SurgeGUIEditor::valueChanged(CControl* control) CFSTR("Saving patches isn't supported in the demo version of " "Surge. (including sequencer recall)"), CFSTR("Ok"), 0, 0, &responseFlags); +#elif __linux__ + printf("Implement me\n"); #else MessageBox(::GetActiveWindow(), L"Saving patches isn't supported in the demo version of Surge. (including " diff --git a/src/common/gui/SurgeGUIEditor.h b/src/common/gui/SurgeGUIEditor.h index 13911840d1c..9b222d7358e 100644 --- a/src/common/gui/SurgeGUIEditor.h +++ b/src/common/gui/SurgeGUIEditor.h @@ -103,7 +103,7 @@ class SurgeGUIEditor : public EditorType, public IControlListener, public IKeybo CControl* metaparam[n_customcontrollers] = {}; CControl* lfodisplay = nullptr; CControl* filtersubtype[2] = {}; -#if MAC +#if MAC || __linux__ #else HWND ToolTipWnd; #endif diff --git a/src/common/thread/CriticalSection.cpp b/src/common/thread/CriticalSection.cpp index 61e326f5d9d..be53856b3c8 100644 --- a/src/common/thread/CriticalSection.cpp +++ b/src/common/thread/CriticalSection.cpp @@ -1,4 +1,7 @@ #include "CriticalSection.h" + +#if !__linux__ + #include "assert.h" CriticalSection::CriticalSection() @@ -45,4 +48,6 @@ void CriticalSection::leave() #else LeaveCriticalSection(&cs); #endif -} \ No newline at end of file +} + +#endif diff --git a/src/common/thread/CriticalSection.h b/src/common/thread/CriticalSection.h index 8704c668502..b7fe901b36a 100644 --- a/src/common/thread/CriticalSection.h +++ b/src/common/thread/CriticalSection.h @@ -2,10 +2,49 @@ #if MAC #include +#elif __linux #else #include "windows.h" #endif +#if __linux__ + +#include +#include +#include + +class CriticalSection +{ +public: + CriticalSection(){ + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&mutex, &attr); + } + + ~CriticalSection(){ + } + + void enter(){ + pthread_mutex_lock(&mutex); + refcount++; + assert(refcount > 0); + assert(!(refcount > 5)); // if its >5 there's some crazy *§%* going on ^^ + } + void leave(){ + refcount--; + assert(refcount >= 0); + pthread_mutex_unlock(&mutex); + } + +protected: + pthread_mutex_t mutex; + int refcount = 0; +}; + +#else + class CriticalSection { public: @@ -21,4 +60,7 @@ class CriticalSection CRITICAL_SECTION cs; #endif int refcount; -}; \ No newline at end of file +}; + +#endif + diff --git a/src/common/vt_dsp/basic_dsp.cpp b/src/common/vt_dsp/basic_dsp.cpp index c4c13d0aca3..77e9ce9be8f 100644 --- a/src/common/vt_dsp/basic_dsp.cpp +++ b/src/common/vt_dsp/basic_dsp.cpp @@ -1,12 +1,17 @@ #include "basic_dsp.h" #include -#if MAC +#include +#if MAC || __linux__ #include #endif +#if __linux__ +using namespace std; +#endif + int Min(int a, int b) { -#if _M_X64 || PPC +#if _M_X64 || PPC || __linux__ return min(a, b); #else __asm @@ -20,7 +25,7 @@ int Min(int a, int b) } int Max(int a, int b) { -#if _M_X64 || PPC +#if _M_X64 || PPC || __linux__ return max(a, b); #else __asm @@ -47,7 +52,7 @@ double Max(double a, double b) unsigned int Min(unsigned int a, unsigned int b) { -#if _M_X64 || PPC +#if _M_X64 || PPC || __linux__ return min(a, b); #else __asm @@ -61,7 +66,7 @@ unsigned int Min(unsigned int a, unsigned int b) } unsigned int Max(unsigned int a, unsigned int b) { -#if _M_X64 || PPC +#if _M_X64 || PPC || __linux__ return max(a, b); #else __asm @@ -76,7 +81,7 @@ unsigned int Max(unsigned int a, unsigned int b) int limit_range(int x, int l, int h) { -#if _M_X64 || PPC +#if _M_X64 || PPC || __linux__ return max(min(x, h), l); #else __asm @@ -94,7 +99,7 @@ int limit_range(int x, int l, int h) int Wrap(int x, int L, int H) { -#if _M_X64 || PPC +#if _M_X64 || PPC || __linux__ // fattar inte vad den gör längre.. // int diff = H - L; // if(x > H) x = x-H; @@ -126,7 +131,7 @@ int Wrap(int x, int L, int H) int Sign(int x) { -#if _M_X64 || PPC +#if _M_X64 || PPC || __linux__ return (x < 0) ? -1 : 1; #else __asm @@ -142,7 +147,7 @@ int Sign(int x) unsigned int limit_range(unsigned int x, unsigned int l, unsigned int h) { -#if _M_X64 || PPC +#if _M_X64 || PPC || __linux__ return max(min(x, h), l); #else __asm diff --git a/src/common/vt_dsp/portable_intrinsics.h b/src/common/vt_dsp/portable_intrinsics.h index d4a669ff035..3977d936d79 100644 --- a/src/common/vt_dsp/portable_intrinsics.h +++ b/src/common/vt_dsp/portable_intrinsics.h @@ -45,6 +45,10 @@ forceinline float vSum(vFloat x) #else +#ifdef __linux__ +#include +#endif + #define vFloat __m128 #define vZero _mm_setzero_ps() diff --git a/src/common/vt_dsp/shared.h b/src/common/vt_dsp/shared.h index 713d67d2cf7..5135170766a 100644 --- a/src/common/vt_dsp/shared.h +++ b/src/common/vt_dsp/shared.h @@ -3,6 +3,11 @@ #include "macspecific.h" #endif +#ifdef __linux__ +#include +#endif + + #if !PPC inline float i2f_binary_cast(int i) diff --git a/src/common/vt_dsp/endian.h b/src/common/vt_dsp/vt_dsp_endian.h similarity index 97% rename from src/common/vt_dsp/endian.h rename to src/common/vt_dsp/vt_dsp_endian.h index 3ebd9840867..c013c80a28f 100644 --- a/src/common/vt_dsp/endian.h +++ b/src/common/vt_dsp/vt_dsp_endian.h @@ -8,7 +8,7 @@ __forceinline int swap_endian(int t) { -#if (MAC || _M_X64) +#if (__linux__ || MAC || _M_X64) return ((t << 24) & 0xff000000) | ((t << 8) & 0x00ff0000) | ((t >> 8) & 0x0000ff00) | ((t >> 24) & 0x000000ff); #else @@ -90,4 +90,4 @@ __forceinline void vt_copyblock_DW_LE(int* dst, const int* src, size_t count) #else memcpy(dst, src, count * sizeof(int)); #endif -} \ No newline at end of file +} diff --git a/src/vst2/Vst2PluginInstance.cpp b/src/vst2/Vst2PluginInstance.cpp index 80a466e22e9..b28231d131b 100644 --- a/src/vst2/Vst2PluginInstance.cpp +++ b/src/vst2/Vst2PluginInstance.cpp @@ -37,7 +37,7 @@ Vst2PluginInstance::Vst2PluginInstance(audioMasterCallback audioMaster) setNumInputs(2); // stereo in setNumOutputs(2); // stereo out -#if MAC +#if MAC || __linux__ isSynth(); plug_is_synth = true; setUniqueID('cjs3'); // identify