From 8318b64a23f1d5db157aa9c0c66ecc8675ea9fe3 Mon Sep 17 00:00:00 2001 From: Paul W Date: Sun, 16 Jun 2019 22:13:49 -0400 Subject: [PATCH] Surge UserInteractions stubbed with Zenity Surge UserInteractions on Linux should really use the vst event loop and vstgui and be hand written because otherwise you have to popen zenity which can cause audio pauses and pops. But audio pauses and pops on anciliary actions are better than nothing, so stick in a crudy zenity implementation which is a start, and someone inspired to remove it at least has a spec in the future. Addresses #562 Closes #637 and #917 --- doc/Developer Guide.md | 4 +-- src/common/gui/PopupEditorDialog.cpp | 18 ++++++++++++- src/linux/UserInteractionsLinux.cpp | 40 ++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/doc/Developer Guide.md b/doc/Developer Guide.md index ad6af79b1ea..baecd0af95b 100644 --- a/doc/Developer Guide.md +++ b/doc/Developer Guide.md @@ -210,8 +210,8 @@ sudo apt-get install ajmidid The run jac and ajmidid in separate terminals ``` -jack -d alsa -X alsa_midi -ajmidid -e +jackd -d alsa -X alsa_midi +a2jmidid -e ``` Now start surge with carla-single diff --git a/src/common/gui/PopupEditorDialog.cpp b/src/common/gui/PopupEditorDialog.cpp index 89f9cac94ad..c4172e27aab 100644 --- a/src/common/gui/PopupEditorDialog.cpp +++ b/src/common/gui/PopupEditorDialog.cpp @@ -147,11 +147,27 @@ void spawn_miniedit_text(char* c, int maxchars) #elif LINUX #include "UserInteractions.h" +#include void spawn_miniedit_text(char* c, int maxchars) { // FIXME: Implement text edit popup on Linux. - Surge::UserInteractions::promptError( "miniedit_text is not implemented on linux", "Unimplemented Feature" ); + char cmd[1024]; + snprintf(cmd, 1024, "zenity --entry --entry-text \"%s\"", c ); + FILE *z = popen( cmd, "r" ); + if( ! z ) + { + return; + } + char buffer[ 1024 ]; + if (!fscanf(z, "%1024s", buffer)) + { + return; + } + pclose(z); + + strncpy( c, buffer, maxchars); + } #endif diff --git a/src/linux/UserInteractionsLinux.cpp b/src/linux/UserInteractionsLinux.cpp index 5fb8c0819b6..4097eafb966 100644 --- a/src/linux/UserInteractionsLinux.cpp +++ b/src/linux/UserInteractionsLinux.cpp @@ -3,7 +3,18 @@ #include #include #include +#include +/* +** In June 2019, @baconpaul chose to implement these with an attempt +** to fork/exec a zenity. (He also did this for mini edit). This is not +** ideal. Properly you would somehow asynchronously interact with +** vstgui and so on, which @jjs started. But we kinda gotta do something. +** +** If you want to come along and rip out these zenity calls and replace them +** with vstgui, please do so! This is purely tactical stuff to get us +** not silently failing. +*/ namespace Surge { @@ -13,6 +24,17 @@ namespace UserInteractions void promptError(const std::string &message, const std::string &title, SurgeGUIEditor *guiEditor) { + if (vfork()==0) + { + if (execlp("zenity", "zenity", + "--error", + "--text", message.c_str(), + "--title", title.c_str(), + (char*)nullptr) < 0) + { + exit(0); + } + } std::cerr << "Surge Error\n" << title << "\n" << message << "\n" << std::flush; @@ -55,8 +77,22 @@ void promptFileOpenDialog(const std::string& initialDirectory, std::function callbackOnOpen, SurgeGUIEditor* guiEditor) { - UserInteractions::promptError("OpenFileDialog is unimplemented in this version of Surge. Sorry!", - "Unimplemented Function", guiEditor); + /* + ** This is a blocking model which will cause us problems I am sure + */ + FILE *z = popen( "zenity --file-selection", "r" ); + if( ! z ) + { + return; + } + char buffer[ 1024 ]; + if (!fscanf(z, "%1024s", buffer)) + { + return; + } + pclose(z); + + callbackOnOpen(buffer); } };