lv2 fixes, dcraw upgrade, arch/libdv
[goodguy/history.git] / cinelerra-5.1 / cinelerra / pluginlv2ui.C
index 03e656d7cb39d4523c9d4c949a8aad9c6e4e45ae..24faecf1bbf9708361b7b18c5d52ef4e6f9da90a 100644 (file)
@@ -160,13 +160,38 @@ void PluginLV2UI::run_lilv(int samples)
 
 void PluginLV2ChildUI::start_gui()
 {
-       gui->start_gui();
+       if( gui ) gui->start_gui();
        update_lv2_input(config.ctls, 1);
        connect_ports(config, PORTS_CONTROL | PORTS_ATOM);
+       int n = 0;
+#if 1
+// some plugins must have pointers, or they crash
+       float inp[nb_inputs], out[nb_outputs];
+       memset(&inp, 0, nb_inputs*sizeof(float));
+       memset(&out, 0, nb_outputs*sizeof(float));
+       int ich = 0, och = 0;
+       for( int i=0; i<config.nb_ports; ++i ) {
+               const LilvPort *lp = lilv_plugin_get_port_by_index(lilv, i);
+               if( !lp ) continue;
+               int port = config.ports[i];
+               if( !(port & PORTS_AUDIO) ) continue;
+               if( (port & PORTS_INPUT) ) {
+                       lilv_instance_connect_port(inst, i, &inp[ich++]);
+                       continue;
+               }
+               if( (port & PORTS_OUTPUT) ) {
+                       lilv_instance_connect_port(inst, i, &out[och++]);
+                       continue;
+               }
+       }
+       n = 1;
+#endif
        updates = 0;
-       run_lilv(0);
-       send_host(LV2_SHOW, 0, 0);
-       hidden = 0;
+       run_lilv(n);
+       if( gui ) {
+               send_host(LV2_SHOW, 0, 0);
+               hidden = 0;
+       }
 }
 
 void PluginLV2UI::update_host()
@@ -183,19 +208,14 @@ static void lv2ui_extui_host_ui_closed(void *p)
        ui->hidden = -1;
 }
 
-int PluginLV2ChildUI::init_ui(const char *path, int sample_rate)
+int PluginLV2ChildUI::init_ui(const char *path, int sample_rate, int bfrsz)
 {
        char *title = PluginLV2UI::title;
        if( load_lv2(path, title) ) return 1;
-       if( init_lv2(config, sample_rate) ) return 1;
+       if( init_lv2(config, sample_rate, bfrsz) ) return 1;
 
        lilv_uis = lilv_plugin_get_uis(lilv);
-       if( !lilv_uis ) {
-               printf("lv2: lilv_plugin_get_uis(%s) failed\n", path);
-               return 1;
-       }
-
-       if( !gui && wgt_type ) {
+       if( !gui && lilv_uis && wgt_type ) {
                LilvNode *gui_type = lilv_new_uri(world, wgt_type);
                LILV_FOREACH(uis, i, lilv_uis) {
                        const LilvUI *ui = lilv_uis_get(lilv_uis, i);
@@ -209,7 +229,7 @@ int PluginLV2ChildUI::init_ui(const char *path, int sample_rate)
                }
                lilv_node_free(gui_type);
        }
-       if( !gui && gtk_type ) {
+       if( !gui && lilv_uis && gtk_type ) {
                LilvNode *gui_type = lilv_new_uri(world, gtk_type);
                LILV_FOREACH(uis, i, lilv_uis) {
                        const LilvUI *ui = lilv_uis_get(lilv_uis, i);
@@ -224,18 +244,13 @@ int PluginLV2ChildUI::init_ui(const char *path, int sample_rate)
                ui_type = gtk_type;
        }
 
-       if( !gui ) {
-               printf("lv2_gui: init_ui failed: %s\n", title);
-               return 1;
-       }
-
        lilv_instance_activate(inst);
        return 0;
 }
 
 void PluginLV2ChildUI::reset_gui()
 {
-       gui->reset_gui();
+       if( gui ) gui->reset_gui();
        if( sinst )     { suil_instance_free(sinst);  sinst = 0; }
        if( ui_host )   { suil_host_free(ui_host);    ui_host = 0; }
 
@@ -254,7 +269,7 @@ int PluginLV2ChildUI::run_ui()
        done = 0;
        while( !done ) {
                if( hidden < 0 ) {
-                       gui->top_level = 0;
+                       if( gui ) gui->top_level = 0;
                        reset_gui();
                        if( !is_forked() ) {
                                done = -1;
@@ -295,13 +310,16 @@ int PluginLV2ChildUI::child_iteration(int64_t usec)
        int ret = 0;
        if( is_forked() )
                ret = read_child(usec);
-       else
+       else if( gui )
                usleep(usec);
+       else
+               ret = -1;
+
        if( ret > 0 ) {
                switch( child_token ) {
                case LV2_OPEN: {
                        open_bfr_t *open_bfr = (open_bfr_t *)child_data;
-                       if( init_ui(open_bfr->path, open_bfr->sample_rate) ) {
+                       if( init_ui(open_bfr->path, open_bfr->sample_rate, open_bfr->bfrsz) ) {
                                printf("lv2ui: unable to init: %s\n", open_bfr->path);
                                exit(1);
                        }