Delay jack init on startup when not configured as audio device, fix some tX_widget...
authorAlexander Koenig <alex@lisas.de>
Thu, 23 Jan 2014 20:43:28 +0000 (21:43 +0100)
committerAlexander Koenig <alex@lisas.de>
Thu, 23 Jan 2014 20:43:28 +0000 (21:43 +0100)
src/main.cc
src/tX_audiodevice.cc
src/tX_audiodevice.h
src/tX_flash.c
src/tX_prelis.cc
src/tX_widget.c
src/tX_widget.h

index 685b09d2755432bfe76cff9f242a5de56d8cc67e..c59089a70ebac5cbc100d0cca90e3c99406d7240 100644 (file)
@@ -239,7 +239,11 @@ int main(int argc, char **argv)
        LADSPA_Plugin::init();
 
 #ifdef USE_JACK        
-       tX_jack_client::init();
+       if (globals.audiodevice_type == JACK) {
+               // only init jack interface when chosen via configuration
+               // to allow wiring of jack in-/outputs
+               tX_jack_client::get_instance()->init();
+       }
 #endif 
 
 #ifdef USE_SCHEDULER
@@ -283,11 +287,6 @@ int main(int argc, char **argv)
        store_globals();
 
        delete engine;
-#ifdef USE_JACK        
-       if (tX_jack_client::get_instance()) {
-               delete tX_jack_client::get_instance();
-       }
-#endif // USE_JACK
        
        fprintf(stderr, "Have a nice life.\n");
 #else // CREATE_BENCHMARK
index 5c44d27dcfd3b6118f76ed63219fba8099f9f2db..5d0512ce8a36b49ff2704d9f0648d0cff6d56a97 100644 (file)
@@ -354,58 +354,54 @@ void tX_audiodevice_alsa :: play(int16_t *buffer)
 
 #ifdef USE_JACK
 
-tX_jack_client* tX_jack_client::instance=NULL;
+tX_jack_client tX_jack_client::instance;
 
-void tX_jack_client::init()
+bool tX_jack_client::init()
 {
-               tX_jack_client *test=new tX_jack_client();
+       if (!client_initialized) {
+               if ((client=jack_client_open("terminatorX", (jack_options_t) NULL, NULL))==0) {
+                       tX_error("tX_jack_client() -> failed to connect to jackd.");
+               } else {
+                       client_initialized = true;
+                       const char **ports;
+                       
+                       /* Setting up jack callbacks... */              
+                       jack_set_process_callback(client, tX_jack_client::process, NULL);
+                       jack_set_sample_rate_callback(client, tX_jack_client::srate, NULL);             
+                       jack_on_shutdown (client, tX_jack_client::shutdown, NULL);
+                       
+                       /* Creating the port... */
+                       left_port = jack_port_register (client, "output_1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
+                       right_port = jack_port_register (client, "output_2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
                
-               if (!instance) {
-                       delete test;
-               }       
+                       /* Action... */
+                       jack_activate(client);
+                       
+                       /* Connect some ports... */
+                       if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) {
+                               tX_error("tX_jack_client() no ports to connect to found. Connect manually.");
+                       } else if (ports[0] && ports[1]) {
+                               if (jack_connect (client, jack_port_name(left_port), ports[0])) {
+                                       tX_error("tX_jack_client() failed to connect left port.");
+                               }
+                               if (jack_connect (client, jack_port_name(right_port), ports[1])) {
+                                       tX_error("tX_jack_client() failed to connect right port.");
+                               }
+                               free (ports);
+                       }
+               }
+       }
+       
+       return client_initialized;
 }
 
-tX_jack_client::tX_jack_client():device(NULL),jack_shutdown(false)
+tX_jack_client::tX_jack_client():device(NULL),jack_shutdown(false),client_initialized(false)
 {
        jack_set_error_function(tX_jack_client::error);
-       
-       if ((client=jack_client_open("terminatorX", (jack_options_t) NULL, NULL))==0) {
-               tX_error("tX_jack_client() -> failed to connect to jackd.");
-               instance=NULL;
-       } else {
-               instance=this;
-               const char **ports;
-               
-               /* Setting up jack callbacks... */              
-               jack_set_process_callback(client, tX_jack_client::process, NULL);
-               jack_set_sample_rate_callback(client, tX_jack_client::srate, NULL);             
-               jack_on_shutdown (client, tX_jack_client::shutdown, NULL);
-               
-               /* Creating the port... */
-               left_port = jack_port_register (client, "output_1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
-               right_port = jack_port_register (client, "output_2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
-       
-               /* Action... */
-               jack_activate(client);
-               
-               /* Connect some ports... */
-               if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) {
-                       tX_error("tX_jack_client() no ports to connect to found. Connect manually.");
-               } else if (ports[0] && ports[1]) {
-                       if (jack_connect (client, jack_port_name(left_port), ports[0])) {
-                               tX_error("tX_jack_client() failed to connect left port.");
-                       }
-                       if (jack_connect (client, jack_port_name(right_port), ports[1])) {
-                               tX_error("tX_jack_client() failed to connect right port.");
-                       }
-                       free (ports);
-               }
-       }
 }
 
 tX_jack_client::~tX_jack_client()
 {
-       instance=NULL;
        if (client) jack_client_close(client);
 }
 
@@ -423,14 +419,12 @@ int tX_jack_client::srate(jack_nframes_t nframes, void *arg)
 void tX_jack_client::shutdown(void *arg)
 {
        tX_error("tX_jack_client::shutdown() jack daemon has shut down. Bad!");
-       if (instance) instance->jack_shutdown=true;
+       instance.jack_shutdown=true;
 }
 
 int tX_jack_client::process(jack_nframes_t nframes, void *arg)
 {
-       if (instance) {
-               return instance->play(nframes);
-       }
+       return instance.play(nframes);
        
        /* Hmm, what to do in such a case? */
        return 0;
@@ -468,11 +462,13 @@ int tX_audiodevice_jack::open()
        tX_jack_client *jack_client=tX_jack_client::get_instance();
        
        if (jack_client) {
-               sample_rate=jack_client->get_sample_rate();
-               client=jack_client;
-               is_open=true;
-               
-               return 0;
+               if (jack_client->init()) {
+                       sample_rate=jack_client->get_sample_rate();
+                       client=jack_client;
+                       is_open=true;
+                       
+                       return 0;
+               }
        }
        
        return 1;
index 3c6d0c8777a94c4389acf11ff1ca34e9d8a3f48a..d22c11afb030caba7fafddb13efacaf302ad95e0 100644 (file)
@@ -132,23 +132,24 @@ class tX_audiodevice_jack : public tX_audiodevice
 class tX_jack_client
 {
        public:
-       static void init();
-       static tX_jack_client *get_instance() { return instance; };
+       static tX_jack_client *get_instance() { return &instance; };
+       bool init();
        ~tX_jack_client();
        
        private:
        tX_jack_client();       
-       static tX_jack_client *instance;
+       static tX_jack_client instance;
        static void error(const char *desc);
        static int srate(jack_nframes_t nframes, void *arg);
        static void shutdown(void *arg);
        static int process(jack_nframes_t nframes, void *arg);
        
-       jack_client_t *client;
+       jack_client_t *client;  
        tX_audiodevice_jack *device;
        jack_port_t *left_port;
        jack_port_t *right_port;
        bool jack_shutdown;
+       bool client_initialized;
        int play(jack_nframes_t nframes);
        
        public:
index e7ab5654a6ce7fbf310998d8fa92c7ef04bbff83..c1c77a15e6ae19ca0f8d53b6da8e4ae201052964 100644 (file)
@@ -393,6 +393,7 @@ static void gtk_tx_flash_set_channel_level(GtkTxFlash *tx_flash, f_prec new_valu
        
        cr = gdk_cairo_create (gtk_widget_get_window(widget));
        cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
+       cairo_set_line_width(cr,1);
        cairo_set_source_surface (cr, tx_flash->surface, 0, 0);
 
        gdk_cairo_set_source_color (cr, &tx_flash->colors[COL_BG]);
index 7f03ff7deeabc5e88efb26314e80419ebf89cbb5..3134c75126c9ad04a6035e9b8eaeb314495a482a 100644 (file)
@@ -118,7 +118,7 @@ void prelis_start(char *name) {
                else
 #endif
 #ifdef USE_SOX_INPUT           
-                       execlp("sox", "sox", nm, "-t", "oss", "-b", "16", "-e", "signed-integer", dev, NULL);
+                       execlp("play", "play", "-q", nm, NULL);
 #else
                        exit(0);
 #endif                 
index 3185ff6f2b03e1bb2945e64c00a6dfd259e15feb..22af87542c64fd71a0d2bed3ead24553d83ada9e 100644 (file)
@@ -151,9 +151,12 @@ static void gtk_tx_init(GtkTx * tx) {
        
        gtk_tx_update_colors(tx);
        
-       tx->current_fg=&tx->colors[COL_FG_NO_FOCUS];
+       tx->current_fg=tx->audio_colors_focus;
        tx->current_bg=&tx->colors[COL_BG_NO_FOCUS];
        
+       tx->audio_colors_focus = NULL;
+       tx->audio_colors_nofocus = NULL;
+       
        tx->spp=1;
        tx->lastmute=-1;
        tx->zoom=0;
@@ -254,7 +257,8 @@ static void gtk_tx_prepare(GtkWidget * widget) {
        int16_t *ptr;
        f_prec value;
        GtkTx *tx;
-       int avg_pos;
+       int avg_pos, color;
+       gboolean *success;
 
        g_return_if_fail(widget != NULL);
        g_return_if_fail(GTK_IS_TX(widget));
@@ -262,8 +266,73 @@ static void gtk_tx_prepare(GtkWidget * widget) {
        tx = GTK_TX(widget);
        
        GtkAllocation allocation;
+       GdkColor midColor;
+       gboolean fg = (tx->current_fg == tx->audio_colors_focus);
+       
+       if (tx->audio_colors_focus) { 
+               // deallocate colors with old tx->yc value
+               gdk_colormap_free_colors(gtk_widget_get_colormap(GTK_WIDGET(tx)), tx->audio_colors_focus, tx->yc);
+               gdk_colormap_free_colors(gtk_widget_get_colormap(GTK_WIDGET(tx)), tx->audio_colors_nofocus, tx->yc);
+               
+               free(tx->audio_colors_focus); 
+               free(tx->audio_colors_nofocus); 
+               
+               tx->audio_colors_focus = NULL; 
+               tx->audio_colors_nofocus = NULL; 
+       } else {
+               fg = FALSE;
+       }
+       
+       // update tx->yc
+       
        gtk_widget_get_allocation(widget, &allocation);
        tx->yc = allocation.height / 2;
+       
+       // allocate colors
+       
+       tx->audio_colors_focus = (GdkColor *) malloc(tx->yc * sizeof(GdkColor));
+       tx->audio_colors_nofocus = (GdkColor *) malloc(tx->yc * sizeof(GdkColor));
+       
+       success = (gboolean *) malloc(tx->yc * sizeof(gboolean));
+
+       // no focus colors
+
+       midColor.red = tx->colors[COL_BG_NO_FOCUS].red + (tx->colors[COL_FG_NO_FOCUS].red - tx->colors[COL_BG_NO_FOCUS].red) / 4;
+       midColor.green = tx->colors[COL_BG_NO_FOCUS].green + (tx->colors[COL_FG_NO_FOCUS].green - tx->colors[COL_BG_NO_FOCUS].green) / 4;
+       midColor.blue = tx->colors[COL_BG_NO_FOCUS].blue + (tx->colors[COL_FG_NO_FOCUS].blue - tx->colors[COL_BG_NO_FOCUS].blue) / 4;
+       
+       for (color=0 ; color < tx->yc; color++) {
+               float dist = (float) color / (float) tx->yc;
+               
+               tx->audio_colors_nofocus[color].red = midColor.red + dist*(tx->colors[COL_FG_NO_FOCUS].red - midColor.red);
+               tx->audio_colors_nofocus[color].green = midColor.green + dist*(tx->colors[COL_FG_NO_FOCUS].green - midColor.green);
+               tx->audio_colors_nofocus[color].blue = midColor.blue + dist*(tx->colors[COL_FG_NO_FOCUS].blue - midColor.blue);         
+       }
+       gdk_colormap_alloc_colors(gtk_widget_get_colormap(GTK_WIDGET(tx)), tx->audio_colors_nofocus, tx->yc, 0, 1, success);
+       
+       // focus colors
+
+       midColor.red = tx->colors[COL_BG_FOCUS].red + (tx->colors[COL_FG_FOCUS].red - tx->colors[COL_BG_FOCUS].red) / 4;
+       midColor.green = tx->colors[COL_BG_FOCUS].green + (tx->colors[COL_FG_FOCUS].green - tx->colors[COL_BG_FOCUS].green) / 4;
+       midColor.blue = tx->colors[COL_BG_FOCUS].blue + (tx->colors[COL_FG_FOCUS].blue - tx->colors[COL_BG_FOCUS].blue) / 4;
+       
+       for (color=0 ; color < tx->yc; color++) {
+               float dist = (float) color / (float) tx->yc;
+               
+               tx->audio_colors_focus[color].red = midColor.red + dist*(tx->colors[COL_FG_FOCUS].red - midColor.red);
+               tx->audio_colors_focus[color].green = midColor.green + dist*(tx->colors[COL_FG_FOCUS].green - midColor.green);
+               tx->audio_colors_focus[color].blue = midColor.blue + dist*(tx->colors[COL_FG_FOCUS].blue - midColor.blue);              
+       }
+       gdk_colormap_alloc_colors(gtk_widget_get_colormap(GTK_WIDGET(tx)), tx->audio_colors_focus, tx->yc, 0, 1, success);
+       
+       if (fg) {
+               tx->current_fg = tx->audio_colors_focus;
+       } else {
+               tx->current_fg = tx->audio_colors_nofocus;
+       }
+       
+       // give up success
+       free(success);
 
        if (tx->disp_data) { free(tx->disp_data); tx->disp_data=NULL; }
 
@@ -376,6 +445,7 @@ static gint gtk_tx_expose(GtkWidget * widget, GdkEventExpose * event) {
        cr = gdk_cairo_create (gtk_widget_get_window(widget));
        cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
        cairo_set_source_surface (cr, tx->surface, 0, 0);
+       cairo_set_line_width(cr,1);
 
        gdk_cairo_set_source_color (cr, tx->current_bg);
 
@@ -383,25 +453,27 @@ static gint gtk_tx_expose(GtkWidget * widget, GdkEventExpose * event) {
 
        cairo_rectangle(cr, area->x, area->y, area->width, area->height);
        cairo_fill(cr);
-       
-       cairo_set_line_width(cr,1);
-       
-       gdk_cairo_set_source_color (cr, tx->current_fg);
 
        if (tx->disp_data) {
-               int max_x=area->x+area->width;
+               int max_x=area->x+area->width+1;
 
            for (x =area->x; x < max_x; x++) {
-                       cairo_move_to (cr, x, tx->yc - tx->disp_data[tx->display_x_offset+x]);
-                       cairo_line_to (cr, x, tx->yc + tx->disp_data[tx->display_x_offset+x]+1);
+                       int dy = tx->disp_data[tx->display_x_offset+x];
+                       gdk_cairo_set_source_color (cr, &tx->current_fg[dy]);
+                       cairo_move_to (cr, x, tx->yc - dy);
+                       cairo_line_to (cr, x, tx->yc + dy+1);
+                       cairo_stroke (cr);
            }
        } else {
                GtkAllocation allocation;
                gtk_widget_get_allocation(widget, &allocation);
+               
+               gdk_cairo_set_source_color (cr, tx->current_fg);
                cairo_move_to (cr, 0, tx->yc);
                cairo_line_to (cr, allocation.width, tx->yc);
+               cairo_stroke (cr);
        }
-       cairo_stroke (cr);
+       
        cairo_destroy (cr);
 
        return FALSE;
@@ -445,7 +517,6 @@ void gtk_tx_update_pos_display(GtkTx * tx, int sample, int mute) {
        widget = GTK_WIDGET(tx);
        window = gtk_widget_get_window(widget);
 
-
        yc = tx->yc;
        GtkAllocation allocation;
        gtk_widget_get_allocation(widget, &allocation);
@@ -458,6 +529,7 @@ void gtk_tx_update_pos_display(GtkTx * tx, int sample, int mute) {
        cr = gdk_cairo_create (gtk_widget_get_window(widget));
        cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
        cairo_set_source_surface (cr, tx->surface, 0, 0);
+       cairo_set_line_width(cr,1);
        
        if (x >= 0) {
                gdk_cairo_set_source_color (cr, tx->current_bg);
@@ -466,9 +538,9 @@ void gtk_tx_update_pos_display(GtkTx * tx, int sample, int mute) {
                cairo_line_to (cr, x, ymax);
                cairo_stroke (cr);
                
-               gdk_cairo_set_source_color (cr, tx->current_fg);
-               
            y = tx->disp_data[x+tx->display_x_offset];
+           gdk_cairo_set_source_color (cr, &tx->current_fg[y]);
+           
                cairo_move_to (cr, x, yc + y);
                cairo_line_to (cr, x, yc - y+1);
                cairo_stroke (cr);
@@ -548,10 +620,10 @@ void gtk_tx_cleanup_pos_display(GtkTx * tx) {
 
 void gtk_tx_show_frame(GtkTx *tx, int show) {
        if (show) {
-               tx->current_fg=&tx->colors[COL_FG_FOCUS];
+               tx->current_fg=tx->audio_colors_focus;
                tx->current_bg=&tx->colors[COL_BG_FOCUS];
        } else {
-               tx->current_fg=&tx->colors[COL_FG_NO_FOCUS];
+               tx->current_fg=tx->audio_colors_nofocus;
                tx->current_bg=&tx->colors[COL_BG_NO_FOCUS];
        }
        
index 03169c9117e398ee8e8499ee33f0d418868b94e1..76dacbfeb638724e9a68a81542c40f5bba8c054f 100644 (file)
@@ -59,6 +59,9 @@ struct _GtkTx {
        GdkColor *current_fg;
        GdkColor *current_bg;
        
+       GdkColor *audio_colors_focus;
+       GdkColor *audio_colors_nofocus;
+       
        int spp;
        int yc;
        
@@ -102,3 +105,4 @@ f_prec gtk_tx_get_zoom(GtkTx *tx);
 }
 #endif /* __cplusplus */
 #endif
+