mirror of
https://github.com/LMMS/lmms.git
synced 2026-03-13 03:27:06 -04:00
Refactor shared memory (#6404)
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "VstSyncController.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "AudioEngine.h"
|
||||
@@ -32,53 +34,23 @@
|
||||
#include "Engine.h"
|
||||
#include "RemotePlugin.h"
|
||||
|
||||
#ifndef USE_QT_SHMEM
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#endif
|
||||
|
||||
|
||||
VstSyncController::VstSyncController() :
|
||||
m_syncData( nullptr ),
|
||||
m_shmID( -1 ),
|
||||
m_shm( "/usr/bin/lmms" )
|
||||
m_syncData( nullptr )
|
||||
{
|
||||
if( ConfigManager::inst()->value( "ui", "syncvstplugins" ).toInt() )
|
||||
{
|
||||
connect( Engine::audioEngine(), SIGNAL( sampleRateChanged() ), this, SLOT( updateSampleRate() ) );
|
||||
|
||||
#ifdef USE_QT_SHMEM
|
||||
if ( m_shm.create( sizeof( VstSyncData ) ) )
|
||||
try
|
||||
{
|
||||
m_syncData = (VstSyncData*) m_shm.data();
|
||||
m_shm.create("usr_bin_lmms");
|
||||
m_syncData = m_shm.get();
|
||||
}
|
||||
else
|
||||
catch (const std::runtime_error& error)
|
||||
{
|
||||
qWarning() << QString( "Failed to allocate shared memory for VST sync: %1" ).arg( m_shm.errorString() );
|
||||
qWarning() << "Failed to allocate shared memory for VST sync:" << error.what();
|
||||
}
|
||||
#else
|
||||
key_t key; // make the key:
|
||||
if( ( key = ftok( VST_SNC_SHM_KEY_FILE, 'R' ) ) == -1 )
|
||||
{
|
||||
qWarning( "VstSyncController: ftok() failed" );
|
||||
}
|
||||
else
|
||||
{ // connect to shared memory segment
|
||||
if( ( m_shmID = shmget( key, sizeof( VstSyncData ), 0644 | IPC_CREAT ) ) == -1 )
|
||||
{
|
||||
qWarning( "VstSyncController: shmget() failed" );
|
||||
}
|
||||
else
|
||||
{ // attach segment
|
||||
m_syncData = (VstSyncData *)shmat( m_shmID, 0, 0 );
|
||||
if( m_syncData == (VstSyncData *)( -1 ) )
|
||||
{
|
||||
qWarning( "VstSyncController: shmat() failed" );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -111,25 +83,6 @@ VstSyncController::~VstSyncController()
|
||||
{
|
||||
delete m_syncData;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef USE_QT_SHMEM
|
||||
if( m_shm.data() )
|
||||
{
|
||||
// detach shared memory, delete it:
|
||||
m_shm.detach();
|
||||
}
|
||||
#else
|
||||
if( shmdt( m_syncData ) != -1 )
|
||||
{
|
||||
shmctl( m_shmID, IPC_RMID, nullptr );
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning( "VstSyncController: shmdt() failed" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user