- /* handle window creation requests, destroy requests,
- and run idle callbacks
- */
-
- if (msg.message == WM_TIMER) {
- pthread_mutex_lock (&plugin_mutex);
-
-again:
- for (fst = fst_first; fst; fst = fst->next) {
-
- pthread_mutex_lock (&fst->lock);
-
- if (fst->destroy) {
- fprintf (stderr, "%s scheduled for destroy\n", fst->handle->name);
- if (fst->window) {
- fst->plugin->dispatcher( fst->plugin, effEditClose, 0, 0, NULL, 0.0 );
- CloseWindow (fst->window);
- fst->window = NULL;
- fst->destroy = FALSE;
- }
- fst_event_loop_remove_plugin (fst);
- fst->been_activated = FALSE;
- pthread_cond_signal (&fst->window_status_change);
- pthread_mutex_unlock (&fst->lock);
- goto again;
- }
-
- if (fst->window == NULL) {
- if (fst_create_editor (fst)) {
- fst_error ("cannot create editor for plugin %s", fst->handle->name);
- fst_event_loop_remove_plugin (fst);
- pthread_cond_signal (&fst->window_status_change);
- pthread_mutex_unlock (&fst->lock);
- goto again;
- } else {
- /* condition/unlock: it was signalled & unlocked in fst_create_editor() */
- }
- }
-
- if (fst->want_program != -1 ) {
- if (fst->vst_version >= 2) {
- fst->plugin->dispatcher (fst->plugin, 67 /* effBeginSetProgram */, 0, 0, NULL, 0);
- }
-
- fst->plugin->dispatcher (fst->plugin, effSetProgram, 0, fst->want_program, NULL, 0);
-
- if (fst->vst_version >= 2) {
- fst->plugin->dispatcher (fst->plugin, 68 /* effEndSetProgram */, 0, 0, NULL, 0);
- }
- /* did it work? */
- fst->current_program = fst->plugin->dispatcher (fst->plugin, 3, /* effGetProgram */ 0, 0, NULL, 0);
- fst->want_program = -1;
- }
-
- if (fst->want_chunk == 1) {
- fst->plugin->dispatcher (fst->plugin, 24 /* effSetChunk */, 1, fst->wanted_chunk_size, fst->wanted_chunk, 0);
- fst->want_chunk = 0;
- }
-
- if(fst->dispatcher_wantcall) {
- fst->dispatcher_retval = fst->plugin->dispatcher( fst->plugin,
- fst->dispatcher_opcode,
- fst->dispatcher_index,
- fst->dispatcher_val,
- fst->dispatcher_ptr,
- fst->dispatcher_opt );
- fst->dispatcher_wantcall = 0;
- pthread_cond_signal (&fst->plugin_dispatcher_called);
- }
-
- fst->plugin->dispatcher (fst->plugin, effEditIdle, 0, 0, NULL, 0);
-
- if( fst->wantIdle ) {
- fst->plugin->dispatcher (fst->plugin, 53, 0, 0, NULL, 0);
- }
-
- pthread_mutex_unlock (&fst->lock);
-
- }
- pthread_mutex_unlock (&plugin_mutex);
+ /* See comment for maybe_set_program call below */
+ maybe_set_program (fst);
+ fst->want_program = -1;
+ fst->want_chunk = 0;
+ /* If we don't have an editor window yet, we still need to
+ * set up the program, otherwise when we load a plugin without
+ * opening its window it will sound wrong. However, it seems
+ * that if you don't also load the program after opening the GUI,
+ * the GUI does not reflect the program properly. So we'll not
+ * mark that we've done this (ie we won't set want_program to -1)
+ * and so it will be done again if and when the GUI arrives.
+ */
+ if (fst->program_set_without_editor == 0) {
+ maybe_set_program (fst);
+ fst->program_set_without_editor = 1;
+ }
+
+ pthread_mutex_unlock (&fst->lock);
+ }