Skip to content

Commit

Permalink
Add debug logs for plugin init, send midi out to keep active
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Mar 22, 2024
1 parent fd5d5fb commit 13e7437
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
34 changes: 32 additions & 2 deletions src/plugin/DesktopPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class DesktopPlugin : public Plugin,

if (availablePortNum == 0)
{
d_stderr("MOD Desktop: Failed to find available ports");
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorShmSetupFailed;
return;
}
Expand All @@ -73,19 +74,23 @@ class DesktopPlugin : public Plugin,

if (envp == nullptr)
{
d_stderr("MOD Desktop: Failed to init environment");
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorAppDirNotFound;
return;
}

if (! shm.init(availablePortNum))
{
d_stderr("MOD Desktop: Failed to init shared memory");
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorShmSetupFailed;
return;
}

portBaseNum = availablePortNum;

setupResampler(getSampleRate());

d_stderr("MOD Desktop: Initial init ok");
}

~DesktopPlugin()
Expand Down Expand Up @@ -130,6 +135,7 @@ class DesktopPlugin : public Plugin,

if (shm.data == nullptr && ! shm.init(portBaseNum))
{
d_stderr("MOD Desktop: Failed to init shared memory inside runner");
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorShmSetupFailed;
return false;
}
Expand All @@ -138,6 +144,7 @@ class DesktopPlugin : public Plugin,
{
if (startingJackd)
{
d_stderr("MOD Desktop: Failed to get jackd to run");
startingJackd = false;
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorJackdExecFailed;
return false;
Expand All @@ -164,8 +171,12 @@ class DesktopPlugin : public Plugin,

startingJackd = true;
if (jackd.start(jackd_args, envp))
{
d_stderr("MOD Desktop: jackd exec ok");
return true;

}

d_stderr("MOD Desktop: Failed to start jackd");
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorJackdExecFailed;
return false;
}
Expand All @@ -184,6 +195,7 @@ class DesktopPlugin : public Plugin,
{
if (startingModUI)
{
d_stderr("MOD Desktop: Failed to get mod-ui to run");
startingModUI = false;
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorModUiExecFailed;
return false;
Expand All @@ -199,13 +211,21 @@ class DesktopPlugin : public Plugin,

startingModUI = true;
if (mod_ui.start(mod_ui_args, envp))
{
d_stderr("MOD Desktop: mod-ui exec ok");
return true;
}

d_stderr("MOD Desktop: Failed to start jackd");
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorModUiExecFailed;
return false;
}

startingModUI = false;
if (startingModUI)
{
d_stderr("MOD Desktop: Runner setup ok");
startingModUI = false;
}

parameters[kParameterBasePortNumber] = portBaseNum;
return true;
Expand Down Expand Up @@ -492,6 +512,16 @@ class DesktopPlugin : public Plugin,

audioBufferOut.read(outputs, frames);

for (uint32_t i = 0; i < frames; i += 32)
{
MidiEvent midiEvent = {
i, 1, { 0xFE, 0, 0, 0 }, nullptr
};

if (! writeMidiEvent(midiEvent))
break;
}

#if 0
// FIXME not quite right, crashes
if (getBufferSize() != frames)
Expand Down
19 changes: 13 additions & 6 deletions src/plugin/SharedMemory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#ifdef DISTRHO_OS_WINDOWS
#else
# include <cerrno>
# include <fcntl.h>
# include <sys/mman.h>
# ifdef DISTRHO_OS_MAC
Expand All @@ -16,7 +17,6 @@
# include <mach/semaphore.h>
# include <servers/bootstrap.h>
# else
# include <cerrno>
# include <syscall.h>
# include <sys/time.h>
# include <linux/futex.h>
Expand Down Expand Up @@ -122,19 +122,26 @@ class SharedMemory
const HANDLE testshm = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, shmName);

if (testshm == nullptr)
{
d_stderr("SharedMemory::canInit(%u) - true", portBaseNum);
return true;
}

CloseHandle(testshm);
#else
std::snprintf(shmName, 31, "/mod-desktop-shm-%d", portBaseNum);
const int testshmfd = shm_open(shmName, O_RDONLY, 0);

if (testshmfd < 0)
{
d_stderr("SharedMemory::canInit(%u) - true", portBaseNum);
return true;
}

close(testshmfd);
#endif

d_stderr("SharedMemory::canInit(%u) - false", portBaseNum);
return false;
}

Expand All @@ -160,10 +167,10 @@ class SharedMemory
#else
std::snprintf(shmName, 31, "/mod-desktop-shm-%d", portBaseNum);

shmfd = shm_open(shmName, O_CREAT|O_EXCL|O_RDWR, 0600);
DISTRHO_SAFE_ASSERT_RETURN(shmfd >= 0, false);
shmfd = shm_open(shmName, O_CREAT|O_EXCL|O_RDWR, 0666);
DISTRHO_CUSTOM_SAFE_ASSERT_RETURN(std::strerror(errno), shmfd >= 0, false);

DISTRHO_SAFE_ASSERT_RETURN(ftruncate(shmfd, static_cast<off_t>(kDataSize)) == 0, fail_deinit());
DISTRHO_CUSTOM_SAFE_ASSERT_RETURN(std::strerror(errno), ftruncate(shmfd, static_cast<off_t>(kDataSize)) == 0, fail_deinit());

#ifdef MAP_LOCKED
ptr = mmap(nullptr, kDataSize, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, shmfd, 0);
Expand All @@ -172,8 +179,8 @@ class SharedMemory
{
ptr = mmap(nullptr, kDataSize, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
}
DISTRHO_SAFE_ASSERT_RETURN(ptr != nullptr, fail_deinit());
DISTRHO_SAFE_ASSERT_RETURN(ptr != MAP_FAILED, fail_deinit());
DISTRHO_CUSTOM_SAFE_ASSERT_RETURN(std::strerror(errno), ptr != nullptr, fail_deinit());
DISTRHO_CUSTOM_SAFE_ASSERT_RETURN(std::strerror(errno), ptr != MAP_FAILED, fail_deinit());

#ifndef MAP_LOCKED
mlock(ptr, kDataSize);
Expand Down

0 comments on commit 13e7437

Please sign in to comment.