Skip to content

Commit

Permalink
Add locks to make events/setProgram thread safe. Organize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
nidefawl committed Jun 5, 2016
1 parent dc27174 commit 01377b2
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 44 deletions.
12 changes: 10 additions & 2 deletions Debug.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@

#include "plugin.h"
#include <cmath>
#include "Debug.h"
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <io.h>
#include <conio.h>
#include <fcntl.h>
using namespace std;
#ifdef DEBUG

#ifdef DEBUG_CONSOLE
void FSM_VST_Plugin::startConsoleWin(int width, int height, char* fname)
{
Expand Down Expand Up @@ -42,7 +48,9 @@ void FSM_VST_Plugin::startConsoleWin(int width, int height, char* fname)
fprintf(stdout, "Test output to stdout\n");
fprintf(stderr, "Test output to stderr\n");
}

#endif // DEBUG_CONSOLE

#ifdef DISPATCHER_DEBUG_TRACE

//-----------------------------------------------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions Debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __DEBUG_H__
#define __DEBUG_H__

#if defined _WIN32 && defined DEBUG
#define DEBUG_CONSOLE
#define DISPATCHER_DEBUG_TRACE
#define dprintf(...) printf (__VA_ARGS__)
#else
#define dprintf(...) {}
#endif

#endif // __DEBUG_H__
89 changes: 87 additions & 2 deletions FSM_KickXP.vcxproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug_Ableton|Win32">
<Configuration>Debug_Ableton</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug_Ableton|x64">
<Configuration>Debug_Ableton</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug_UNIT|Win32">
<Configuration>Debug_UNIT</Configuration>
<Platform>Win32</Platform>
Expand Down Expand Up @@ -34,6 +42,8 @@
<ClCompile Include="plugin.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Debug.h" />
<ClInclude Include="lock.h" />
<ClInclude Include="plugin.h" />
</ItemGroup>
<ItemGroup>
Expand All @@ -57,6 +67,12 @@
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Ableton|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
Expand All @@ -69,6 +85,12 @@
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Ableton|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
Expand All @@ -92,12 +114,18 @@
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug_UNIT|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Ableton|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug_UNIT|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Ableton|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
Expand All @@ -111,6 +139,9 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_UNIT|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Ableton|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.dll</TargetExt>
Expand All @@ -123,13 +154,19 @@
<OutDir>C:\PluginManager\configs\default\hosts\Ableton\categories\dev\</OutDir>
<TargetName>$(ProjectName).$(Platform)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Ableton|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.dll</TargetExt>
<OutDir>C:\PluginManager\configs\default\hosts\Ableton\categories\dev\</OutDir>
<TargetName>$(ProjectName).$(Platform)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<SourcePath>$(VC_SourcePath);</SourcePath>
<IncludePath>C:\Program Files (x86)\AMD APP\include\;D:\boost_1_51_0;$(IncludePath)</IncludePath>
<OutDir>C:\PluginManager\configs\default\hosts\Ableton\categories\dev\</OutDir>
<TargetName>$(ProjectName).$(Platform)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -159,6 +196,20 @@
<OutputFile>C:\PluginManager\configs\default\hosts\Ableton\categories\dev\$(ProjectName).x64.dll</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Ableton|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>C:\PluginManager\configs\default\hosts\Ableton\categories\dev\$(ProjectName).x64.dll</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
Expand Down Expand Up @@ -227,6 +278,40 @@
<DataExecutionPrevention>false</DataExecutionPrevention>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Ableton|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Full</Optimization>
<PreprocessorDefinitions>WINDOWS;_WINDOWS;WIN32;_USRDLL;_USE_MATH_DEFINES;DEBUG;DEBUG=1;_DEBUG=1;_CRT_SECURE_NO_DEPRECATE;VST_64BIT_PLATFORM;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>C:\Users\Michael\Desktop\VSTDEV\INCLUDES\VST GUI\;C:\Users\Michael\Desktop\VSTDEV\INCLUDES\VST3 SDK\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<StructMemberAlignment>16Bytes</StructMemberAlignment>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FloatingPointModel>Fast</FloatingPointModel>
<ExpandAttributedSource>true</ExpandAttributedSource>
<AssemblerOutput>All</AssemblerOutput>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>C:\PluginManager\configs\default\hosts\Ableton\categories\dev\$(ProjectName).x64.dll</OutputFile>
<AdditionalDependencies>msvcrtd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>libcmtd.lib</IgnoreSpecificDefaultLibraries>
<ModuleDefinitionFile>vstplug.def</ModuleDefinitionFile>
<GenerateMapFile>true</GenerateMapFile>
<MapExports>true</MapExports>
<AssemblyDebug>true</AssemblyDebug>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>false</DataExecutionPrevention>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
Expand Down
2 changes: 2 additions & 0 deletions FSM_KickXP.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="plugin.h" />
<ClInclude Include="Debug.h" />
<ClInclude Include="lock.h" />
</ItemGroup>
<ItemGroup>
<None Include="vstplug.def" />
Expand Down
11 changes: 10 additions & 1 deletion FSM_KickXP.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
<LocalDebuggerCommand>C:\Users\Michael\Desktop\VSTDEV\VST-Plugin Unit Test (x64).exe</LocalDebuggerCommand>
<LocalDebuggerCommandArguments>C:\PluginManager\configs\default\hosts\Ableton\categories\dev\FSM_KickXP.x64.dll</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerAttach>false</LocalDebuggerAttach>
<LocalDebuggerAttach>true</LocalDebuggerAttach>
<LocalDebuggerMergeEnvironment>false</LocalDebuggerMergeEnvironment>
<LocalDebuggerDebuggerType>Auto</LocalDebuggerDebuggerType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Ableton|x64'">
<LocalDebuggerCommand>C:\ProgramData\Ableton\Live 9.5 Beta\Program\Ableton Live 9.6 Beta.exe</LocalDebuggerCommand>
<LocalDebuggerCommandArguments>
</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerAttach>true</LocalDebuggerAttach>
<LocalDebuggerMergeEnvironment>false</LocalDebuggerMergeEnvironment>
<LocalDebuggerDebuggerType>Auto</LocalDebuggerDebuggerType>
</PropertyGroup>
Expand Down
51 changes: 51 additions & 0 deletions lock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef __LOCK_H__
#define __LOCK_H__

#ifdef WIN32
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>


class WIN32_CriticalSection {
CRITICAL_SECTION g_critSec;
public:
~WIN32_CriticalSection() {
DeleteCriticalSection(&g_critSec);

}
WIN32_CriticalSection() {
InitializeCriticalSection(&g_critSec);
}
void lock() {
EnterCriticalSection(&g_critSec);
}
void unlock() {
LeaveCriticalSection(&g_critSec);
}
};

typedef WIN32_CriticalSection Lock;

#else

#include <mutex>


class STDMutex {
std::mutex g_mutex;
public:
void lock() {
g_mutex.lock();
}
void unlock() {
g_mutex.unlock();
}

};

typedef STDMutex Lock;

#endif

#endif // __LOCK_H__
Loading

0 comments on commit 01377b2

Please sign in to comment.