From 81a0ec3e4846a655f3cb5205a8dd63676d441499 Mon Sep 17 00:00:00 2001 From: Lukas W Date: Sun, 26 Nov 2017 14:07:08 +0100 Subject: [PATCH] MSVC: Port RemoteVstPlugin --- plugins/vst_base/RemoteVstPlugin.cpp | 55 +++++++--------------------- 1 file changed, 14 insertions(+), 41 deletions(-) diff --git a/plugins/vst_base/RemoteVstPlugin.cpp b/plugins/vst_base/RemoteVstPlugin.cpp index 71ebf74c0..b9193e67e 100644 --- a/plugins/vst_base/RemoteVstPlugin.cpp +++ b/plugins/vst_base/RemoteVstPlugin.cpp @@ -34,10 +34,6 @@ #include "RemotePlugin.h" -#ifdef LMMS_HAVE_PTHREAD_H -#include -#endif - #ifdef LMMS_HAVE_FCNTL_H #include #endif @@ -63,6 +59,7 @@ #define USE_WS_PREFIX #include +#include #include #include #include @@ -240,17 +237,17 @@ public: inline void lockShm() { - pthread_mutex_lock( &m_shmLock ); + m_shmLock.lock(); } inline bool tryLockShm() { - return pthread_mutex_trylock( &m_shmLock ) == 0; + return m_shmLock.try_lock(); } inline void unlockShm() { - pthread_mutex_unlock( &m_shmLock ); + m_shmLock.unlock(); } inline bool isShmValid() @@ -346,7 +343,7 @@ private: float * * m_inputs; float * * m_outputs; - pthread_mutex_t m_shmLock; + std::mutex m_shmLock; bool m_shmValid; typedef std::vector VstMidiEventList; @@ -392,7 +389,6 @@ RemoteVstPlugin::RemoteVstPlugin( const char * socketPath ) : m_shouldGiveIdle( false ), m_inputs( NULL ), m_outputs( NULL ), - m_shmLock(), m_shmValid( false ), m_midiEvents(), m_bpm( 0 ), @@ -402,8 +398,6 @@ RemoteVstPlugin::RemoteVstPlugin( const char * socketPath ) : m_shmID( -1 ), m_vstSyncData( NULL ) { - pthread_mutex_init( &m_shmLock, NULL ); - __plugin = this; #ifndef USE_QT_SHMEM @@ -493,8 +487,6 @@ RemoteVstPlugin::~RemoteVstPlugin() delete[] m_inputs; delete[] m_outputs; - - pthread_mutex_destroy( &m_shmLock ); } @@ -675,11 +667,11 @@ void RemoteVstPlugin::init( const std::string & _plugin_file ) -static void close_check( int fd ) +static void close_check( FILE* fd ) { - if( close( fd ) ) + if( fclose( fd ) ) { - perror( "close" ); + perror( "fclose" ); } } @@ -1047,8 +1039,9 @@ void RemoteVstPlugin::saveChunkToFile( const std::string & _file ) const int len = pluginDispatch( 23, 0, 0, &chunk ); if( len > 0 ) { - int fd = open( _file.c_str(), O_WRONLY | O_BINARY ); - if ( ::write( fd, chunk, len ) != len ) + + FILE* fd = fopen( _file.c_str(), "wb" ); + if ( fwrite( chunk, 1, len, fd ) != len ) { fprintf( stderr, "Error saving chunk to file.\n" ); @@ -1365,8 +1358,8 @@ void RemoteVstPlugin::loadChunkFromFile( const std::string & _file, int _len ) { char * chunk = new char[_len]; - const int fd = open( _file.c_str(), O_RDONLY | O_BINARY ); - if ( ::read( fd, chunk, _len ) != _len ) + FILE* fd = fopen( _file.c_str(), "rb" ); + if ( fread( chunk, 1, _len, fd ) != _len ) { fprintf( stderr, "Error loading chunk from file.\n" ); } @@ -1541,11 +1534,7 @@ intptr_t RemoteVstPlugin::hostCallback( AEffect * _effect, int32_t _opcode, _timeInfo.flags |= kVstBarsValid; -#ifdef LMMS_BUILD_WIN64 - return (long long) &_timeInfo; -#else - return (long) &_timeInfo; -#endif + return (intptr_t) &_timeInfo; case audioMasterProcessEvents: SHOW_CALLBACK( "amc: audioMasterProcessEvents\n" ); @@ -1971,14 +1960,6 @@ int main( int _argc, char * * _argv ) return -1; } -#ifdef LMMS_BUILD_WIN32 -#ifndef __WINPTHREADS_VERSION - // (non-portable) initialization of statically linked pthread library - pthread_win32_process_attach_np(); - pthread_win32_thread_attach_np(); -#endif -#endif - #ifdef LMMS_BUILD_LINUX #ifdef LMMS_HAVE_SCHED_H // try to set realtime-priority @@ -2086,14 +2067,6 @@ int main( int _argc, char * * _argv ) delete __plugin; - -#ifdef LMMS_BUILD_WIN32 -#ifndef __WINPTHREADS_VERSION - pthread_win32_thread_detach_np(); - pthread_win32_process_detach_np(); -#endif -#endif - return 0; }