Skip to content

Commit

Permalink
Proper fix for slow-loading plugins, for instance Reaktor.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmatheussen committed Nov 14, 2017
1 parent c62e914 commit 86656fe
Show file tree
Hide file tree
Showing 18 changed files with 175 additions and 77 deletions.
5 changes: 5 additions & 0 deletions GTK/GTK_visual.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

#if 0


#include "../common/nsmtracker.h"


Expand Down Expand Up @@ -1252,3 +1255,5 @@ void GTK_Init(int argc, char **argv){

#endif // GTK_IS_USED


#endif
145 changes: 107 additions & 38 deletions Qt/Qt_Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,30 @@


/*
g++ Qt_Error.cpp `pkg-config --cflags --libs QtGui` -DCOMPILE_EXECUTABLE -o ../bin/radium_error_message && ../bin/radium_error_message gakkgakk1
g++ Qt_Error.cpp `pkg-config --cflags --libs QtGui` -DTEST_MAIN -o test_radium_error_message && ./test_radium_error_message gakkgakk2
g++ Qt_Error.cpp `pkg-config --cflags --libs Qt5Gui Qt5Widgets` -DCOMPILE_EXECUTABLE -o ../bin/radium_error_message `cat ../buildtype.opt` `cat ../flagopts.opt` -DFOR_LINUX -I. -fPIC -std=gnu++11 && ../bin/radium_error_message gakkgakk1
g++ Qt_Error.cpp `pkg-config --cflags --libs Qt5Gui Qt5Widgets` -DTEST_MAIN -o test_radium_error_message `cat ../buildtype.opt` `cat ../flagopts.opt` -DFOR_LINUX -I. -fPIC -std=gnu++11 && ./test_radium_error_message gakkgakk2
both:
g++ Qt_Error.cpp `pkg-config --cflags --libs Qt5Gui Qt5Widgets` -DCOMPILE_EXECUTABLE -o ../bin/radium_error_message `cat ../buildtype.opt` `cat ../flagopts.opt` -DFOR_LINUX -I. -fPIC -std=gnu++11 && g++ Qt_Error.cpp `pkg-config --cflags --libs Qt5Gui Qt5Widgets` -DTEST_MAIN -o test_radium_error_message `cat ../buildtype.opt` `cat ../flagopts.opt` -DFOR_LINUX -I. -fPIC -std=gnu++11 && ./test_radium_error_message gakkgakk2
*/


#ifdef COMPILE_EXECUTABLE


static int show_message(const char *message){
static int show_message(QString message, const QVector<QString> &menu_strings){

//QPointer<MyQMessageBox> msgBox = MyQMessageBox::create();
ScopedQPointer<MyQMessageBox> msgBox(MyQMessageBox::create(true));

msgBox->setText(QString(message));
msgBox->setText(message);

QPushButton *continue_button = msgBox->addButton("continue", QMessageBox::AcceptRole);
QPushButton *quit_button = msgBox->addButton("quit", QMessageBox::AcceptRole);
QPushButton *ignore1_button = msgBox->addButton("ignore warnings and errors for two seconds", QMessageBox::AcceptRole);
QPushButton *ignore2_button = msgBox->addButton("ignore warnings and errors for the rest of the program", QMessageBox::AcceptRole);
QVector<QPushButton*> buttons;
for(QString menu_string : menu_strings){
QPushButton *button = msgBox->addButton(menu_string, QMessageBox::AcceptRole);
buttons.push_back(button);
}

msgBox->show();
msgBox->raise();
Expand All @@ -53,15 +58,13 @@ static int show_message(const char *message){

QAbstractButton *clicked_button = msgBox->clickedButton();

if(clicked_button->text()==continue_button->text())
return 0;
if(clicked_button==quit_button)
return 1;
if(clicked_button==ignore1_button)
return 2;
if(clicked_button==ignore2_button)
return 3;

int i = 0;
for(QString menu_string : menu_strings){
if(clicked_button->text()==menu_string)
return i;
i++;
}

fprintf(stderr,"what?\n");
return -1;
}
Expand Down Expand Up @@ -94,6 +97,12 @@ int main(int argc, char **argv){
QCoreApplication::setLibraryPaths(QStringList());
#endif

QString message = QByteArray::fromBase64(argv[1]);

QVector<QString> menu_strings;
for(int i=2 ; i<argc;i++)
menu_strings.push_back(QByteArray::fromBase64(argv[i]));

argv = getQApplicationConstructorArgs(argc, argv);
QApplication app(argc, argv);

Expand All @@ -107,7 +116,7 @@ int main(int argc, char **argv){
}
#endif

int ret = show_message(argv[1]);
int ret = show_message(message, menu_strings);
printf("ret: %d\n",ret);
return ret;
}
Expand All @@ -121,15 +130,8 @@ int main(int argc, char **argv){
extern bool g_qt_is_running;

extern "C" {
int SYSTEM_show_message(const char *message){

static bool ignore_forever = false;
static double ignore_until = -1;
static double last_time = -1;
double time_now = TIME_get_ms();

if (time_now <= ignore_until || ignore_forever)
return 0;
int SYSTEM_show_message_menu(const struct vector_t_ *options, const char *message){

if (g_qt_is_running==false){
fprintf(stderr,"\n\n\n === %s ===\n\n\n", message);
Expand All @@ -141,13 +143,16 @@ int SYSTEM_show_message(const char *message){


#if FOR_WINDOWS
QString program = OS_get_full_program_file_path("radium_error_message.exe");
QString program = QString::fromWCharArray(OS_get_full_program_file_path(L"radium_error_message.exe"));
#else
QString program = OS_get_full_program_file_path("radium_error_message");
QString program = QString::fromWCharArray(OS_get_full_program_file_path(L"radium_error_message"));
#endif

QStringList arguments;
arguments << message;
arguments << QString(QString(message).toUtf8().toBase64().constData());
VECTOR_FOR_EACH(const char*, menu_string, options){
arguments << QString(QString(menu_string).toUtf8().toBase64().constData());
}END_VECTOR_FOR_EACH;

QProcess *myProcess = new QProcess();
myProcess->connect(myProcess, SIGNAL(finished(int)), myProcess, SLOT(deleteLater()));
Expand All @@ -168,7 +173,7 @@ int SYSTEM_show_message(const char *message){
//abort();

GL_unlock();
return 0;
return -1;
}

GL_unlock();
Expand All @@ -184,33 +189,97 @@ int SYSTEM_show_message(const char *message){
return -1;
}

last_time = TIME_get_ms();

R_ASSERT_RETURN_IF_FALSE2(myProcess->exitStatus()==QProcess::NormalExit, -1);


int status = myProcess->exitCode();
return myProcess->exitCode();
}

int SYSTEM_show_error_message(const char *message){
static bool ignore_forever = false;
static double ignore_until = -1;
static double last_time = -1;
double time_now = TIME_get_ms();

if (time_now <= ignore_until || ignore_forever)
return 0;

if (status==1){
last_time = TIME_get_ms();

vector_t v = {};
int continue_ = VECTOR_push_back(&v, "continue"); (void)continue_;
int quit = VECTOR_push_back(&v, "quit");
int ignore1 = VECTOR_push_back(&v, "ignore warnings and errors for two seconds");
int ignore2 = VECTOR_push_back(&v, "ignore warnings and errors for the rest of the program");

int ret = SYSTEM_show_message_menu(&v, message);

if (ret==quit){
exit(-1);
abort();
}

if (status==2)
if (ret==ignore1)
ignore_until = last_time + 2000;
else if (status==3)
else if (ret==ignore2)
ignore_forever = true;

return status;
return ret;
}
}



#ifdef TEST_MAIN

double TIME_get_ms(void){
return 0;
}

bool g_qt_is_running = true;
extern "C"{
wchar_t *OS_get_full_program_file_path(const wchar_t *w){
QString ret = QString("../bin/") + QString::fromWCharArray(w);
wchar_t * ch = (wchar_t*)calloc(sizeof(wchar_t), ret.size()+1);
ret.toWCharArray(ch);
return ch;
}
}

void GL_lock(void){
}
void GL_unlock(void){
}

void GFX_ShowProgress(void){
}
void GFX_HideProgress(void){
}

void *talloc__(int size, const char *filename, int linenumber){
return calloc(1, size);
}

void *talloc_realloc__(void *v, int new_size, const char *filename, int linenumber){
return realloc(v, new_size);
}

extern "C"{
void CRASHREPORTER_send_assert_message(Crash_Type tye, const char *message, ...){
abort();
}
}

int main(int argc, char **argv){
QApplication app(argc,argv);
int ret = SYSTEM_show_message(argv[1]);
int ret = SYSTEM_show_error_message(argv[1]);
printf("ret: %d\n",ret);

vector_t menu = {};
VECTOR_push_back(&menu, "Option 1/3 øæå ååå");
VECTOR_push_back(&menu, "Option 2/3 øæå ååå");
VECTOR_push_back(&menu, "Option 3/3 øæå ååå");
ret = SYSTEM_show_message_menu(&menu, "HELLO!");
printf("ret: %d\n",ret);
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions Qt/Qt_Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2903,21 +2903,21 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QS
snprintf(temp, 1000, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
fprintf(stderr, "%s", temp);
#ifndef RELEASE
SYSTEM_show_message(temp);
SYSTEM_show_error_message(temp);
#endif
break;
case QtCriticalMsg:
snprintf(temp, 1000, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
fprintf(stderr, "%s", temp);
#ifndef RELEASE
SYSTEM_show_message(temp);
SYSTEM_show_error_message(temp);
#endif
break;
case QtFatalMsg:
snprintf(temp, 1000, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
fprintf(stderr, "%s", temp);
#ifndef RELEASE
SYSTEM_show_message(temp);
SYSTEM_show_error_message(temp);
#endif
break;
//abort();
Expand Down
5 changes: 2 additions & 3 deletions Qt/Qt_MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,8 @@ int GFX_Message2_internal(vector_t *buttons, bool program_state_is_valid, const

if (g_qt_is_painting || g_is_loading || g_qtgui_has_stopped==true || !THREADING_is_main_thread() || g_radium_runs_custom_exec){

SYSTEM_show_message(message);
return -1; // TODO: FIX: This is really really really horrible.

return SYSTEM_show_message_menu(buttons, message);

} else {

return show_gfx_message(buttons, program_state_is_valid, QString(message));
Expand Down
3 changes: 1 addition & 2 deletions Qt/Qt_sample_requester_widget_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,12 @@ class Sample_requester_widget : public QWidget
remove = VECTOR_push_back(&v, "Remove bookmark");

int ok = VECTOR_push_back(&v, "Ok");
(void)ok;

int ret = GFX_Message(&v, "Bookmarked sample directory \"%s\" doesn't exist anymore",name.toUtf8().constData());

if (ret==remove){
SETTINGS_remove(settings_key.toUtf8().constData());
} else {
} else if(ret==ok){
already_warned_about.insert(name);
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/api_various.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2437,7 +2437,7 @@ void testCrashreporterInAudioThread(void){
}

void testErrorMessage(void){
SYSTEM_show_message("Error message seems to work");
SYSTEM_show_error_message("Error message seems to work");
}

void startAutotestingMode(void){
Expand Down
26 changes: 16 additions & 10 deletions audio/Juce_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1358,12 +1358,12 @@ static void *create_plugin_data(const SoundPluginType *plugin_type, SoundPlugin
if (String(plugin_type->name)=="Moody Sampler" && (type_data->description.version=="V5.0" || type_data->description.version=="0.5.0")){
vector_t v = {};

VECTOR_push_back(&v, "Yes");
int no = VECTOR_push_back(&v, "No");
int yes = VECTOR_push_back(&v, "Yes");
int no = VECTOR_push_back(&v, "No");(void)no;

int ret = GFX_Message(&v,
"Warning, this plugin (\"Moody Sampler\") has been marked as unstable.<p>Reason: Crashes program when deleted.<p>Load it anyway?");
if (ret==no)
if (ret!=yes)
return NULL;
}
}
Expand Down Expand Up @@ -1700,24 +1700,30 @@ static enum PopulateContainerResult launch_program_calling_write_container_descr

while(process.waitForProcessToFinish(s*1000)==false){
vector_t v = {};

int w3 = VECTOR_push_back(&v, "Wait 3 seconds more");
int w20 = VECTOR_push_back(&v, "Wait 20 seconds more");
VECTOR_push_back(&v, "Cancel");
int cancel = VECTOR_push_back(&v, "Cancel");

int blacklist = VECTOR_push_back(&v, "Cancel, and add to blacklist");
fprintf(stderr, "Openinig requester\n");

int ret = GFX_Message2(&v, true, "Waited more than %d seconds for \"%s\" to load\n", s, STRING_get_chars(container_filename));
fprintf(stderr, "Got answer from requester\n");

if (ret==w3)
s = 3;
else if (ret==w20 || ret==-1) // ret==-1 is a quick hack to fix loading of slow-loading plugins when loading song. The real fix is to fix SYSTEM_show_message (which really must be done).
else if (ret==w20)
s = 20;
else {
else if (ret==cancel){
process.kill();
if(ret==blacklist)
return POPULATE_RESULT_PLUGIN_MUST_BE_BLACKLISTED;
else
return POPULATE_RESULT_OTHER_ERROR;
return POPULATE_RESULT_OTHER_ERROR;
}
else if (ret==blacklist){
process.kill();
return POPULATE_RESULT_PLUGIN_MUST_BE_BLACKLISTED;
} else
s = 3; // timeout, for instance.
}

return POPULATE_RESULT_IS_OKAY; // as far as we know. (ChildProcess doesn't have an hasCrashed() function).
Expand Down
4 changes: 2 additions & 2 deletions audio/KillJackd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ bool KILLJACKD_kill_jackd_if_unresponsive(void){

int ignore = VECTOR_push_back(&v, "Try to run anyway");
int kill = VECTOR_push_back(&v, "Stop the jack process! (Strongly recommended)");
(void)kill;

message = "There is a problem with the jack server: " + message;
int hmmm = GFX_Message(&v, "%s", message.toUtf8().constData());
(void)ignore;

if (hmmm==kill){
if (hmmm!=ignore){
kill_jackd();
GFX_Message(NULL, "We have now run several commands that should have stopped the jack process.<p>Now you need to start Jack one more time, and after that start Radium again.");
return true;
Expand Down
4 changes: 2 additions & 2 deletions audio/Ladspa_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ static void add_ladspa_plugin_type(const QFileInfo &file_info){

vector_t v = {}; // c++ way of zero-initialization without getting missing-field-initializers warning.

VECTOR_push_back(&v,"Init LADSPA plugins first");
int init_ladspa_first = VECTOR_push_back(&v,"Init LADSPA plugins first");
VECTOR_push_back(&v,"Continue without loading this plugin library.");

int result = GFX_Message(&v,
Expand All @@ -571,7 +571,7 @@ static void add_ladspa_plugin_type(const QFileInfo &file_info){
"In case you want to try this, press the \"Init LADSPA plugins first\" button below and start radium again.\n",
qlibrary->fileName().toUtf8().constData()
);
if (result==0)
if (result==init_ladspa_first)
PR_set_init_ladspa_first();

} else {
Expand Down
Loading

0 comments on commit 86656fe

Please sign in to comment.