Skip to content

Commit

Permalink
Linux VST3 Shutdown; and include in DEB
Browse files Browse the repository at this point in the history
The LInux VST3 now cleanly shuts down its runloop, meaning
it works completely in reaper linux. I have included it in the
deb file for installation as a result.

Addresses surge-synthesizer#514
  • Loading branch information
baconpaul committed Aug 20, 2019
1 parent 593620a commit c25c137
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
2 changes: 1 addition & 1 deletion installer_linux/make_deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ cp -r ../resources/data/* ${PACKAGE_NAME}/usr/share/${SURGE_NAME}/
cp ../target/vst2/Release/Surge.so ${PACKAGE_NAME}/usr/lib/vst/${SURGE_NAME}.so

# Once VST3 works, this will be ../products/vst3
# cp ../target/vst3/Release/Surge.so ${PACKAGE_NAME}/usr/lib/vst3/${SURGE_NAME}.so
cp -r ../products/Surge.vst3 ${PACKAGE_NAME}/usr/lib/vst3/

#build package

Expand Down
35 changes: 13 additions & 22 deletions src/linux/LinuxVST3Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class RunLoop : public X11::IRunLoop, public AtomicReferenceCounted

bool registerEventHandler(int fd, X11::IEventHandler* handler) final
{
std::cout << __func__ << " " << fd << " " << handler << std::endl;
if (!runLoop)
return false;

Expand All @@ -70,8 +69,7 @@ class RunLoop : public X11::IRunLoop, public AtomicReferenceCounted

bool unregisterEventHandler(X11::IEventHandler* handler) final
{
std::cout << __func__ << " " << handler << std::endl;
if (!runLoop)
if (!runLoop)
return false;

for (auto it = eventHandlers.begin(), end = eventHandlers.end(); it != end; ++it)
Expand All @@ -87,10 +85,9 @@ class RunLoop : public X11::IRunLoop, public AtomicReferenceCounted
}
bool registerTimer(uint64_t interval, X11::ITimerHandler* handler) final
{
std::cout << __func__ << " " << interval << " " << handler << std::endl;
if (!runLoop)
return false;
std::cout << "Have a runloop" << std::endl;
// std::cout << "Have a runloop" << std::endl;

auto smtgHandler = Steinberg::owned(new TimerHandler());
smtgHandler->handler = handler;
Expand All @@ -103,7 +100,6 @@ class RunLoop : public X11::IRunLoop, public AtomicReferenceCounted
}
bool unregisterTimer(X11::ITimerHandler* handler) final
{
std::cout << __func__ << " " << handler << std::endl;
if (!runLoop)
return false;

Expand All @@ -121,7 +117,7 @@ class RunLoop : public X11::IRunLoop, public AtomicReferenceCounted

RunLoop(Steinberg::Linux::IRunLoop* _runLoop) : runLoop(_runLoop)
{
std::cout << "RunLoop is " << runLoop << " " << _runLoop << std::endl;
// std::cout << "RunLoop is " << runLoop << " " << _runLoop << std::endl;
}

private:
Expand Down Expand Up @@ -153,27 +149,21 @@ static UpdateHandlerInit gUpdateHandlerInit;
class IdleUpdateHandler
{
public:
std::atomic<bool> running;
pthread_t t;
static void start()
{
auto& instance = get();
if (++instance.users == 1)
{
/*
instance.timer = VSTGUI::makeOwned<VSTGUI::CVSTGUITimer>
(
[] (VSTGUI::CVSTGUITimer*) {
std::cout << "DEFUP" << std::endl;
gUpdateHandlerInit.get ()->triggerDeferedUpdates (); },
1000 / 30);
*/
pthread_t t;
pthread_create(&t, NULL, IdleUpdateHandler::doDefUp, NULL);
instance.running = true;
pthread_create(&instance.t, NULL, IdleUpdateHandler::doDefUp, NULL);
}
}

static void* doDefUp(void* x)
{
while (true)
while (get().running)
{
// std::cout << "GUpdate" << std::endl;
gUpdateHandlerInit.get()->triggerDeferedUpdates();
Expand All @@ -186,7 +176,8 @@ class IdleUpdateHandler
auto& instance = get();
if (--instance.users == 0)
{
instance.timer = nullptr;
instance.running = false;
pthread_join(instance.t, NULL);
}
}

Expand All @@ -203,7 +194,7 @@ class IdleUpdateHandler

void LinuxVST3Init(Steinberg::Linux::IRunLoop* rl)
{
std::cout << "irl is " << rl << std::endl;
// std::cout << "irl is " << rl << std::endl;
VSTGUI::X11::RunLoop::init(owned(new RunLoop(rl)));
}

Expand All @@ -214,14 +205,14 @@ void LinuxVST3FrameOpen(VSTGUI::CFrame* that, void* parent, const VSTGUI::Platfo
x11config.runLoop = VSTGUI::X11::RunLoop::get();
config = &x11config;

std::cout << "Special Magical VST3 Open" << std::endl;
// std::cout << "Special Magical VST3 Open" << std::endl;
that->open(parent, pt, config);

IdleUpdateHandler::start();
}

void LinuxVST3Detatch()
{
std::cout << "Would detatch here. FIXME" << std::endl;
IdleUpdateHandler::stop();
}
#endif

0 comments on commit c25c137

Please sign in to comment.