[SCM] gxtuner/upstream: Imported Upstream version 1.4

alessio at users.alioth.debian.org alessio at users.alioth.debian.org
Sat Aug 20 09:12:12 UTC 2011


The following commit has been merged in the upstream branch:
commit 3f95bee8e2915d3d87572994ec5e7782728d7a92
Author: Alessio Treglia <alessio at debian.org>
Date:   Sat Aug 20 11:13:16 2011 +0200

    Imported Upstream version 1.4

diff --git a/Makefile b/Makefile
index a13c022..a392d18 100644
--- a/Makefile
+++ b/Makefile
@@ -7,10 +7,21 @@
 	SHARE_DIR = $(PREFIX)/share
 	DESKAPPS_DIR = $(SHARE_DIR)/applications
 	PIXMAPS_DIR = $(SHARE_DIR)/pixmaps
+## set to NO to disable jack_session support
+	JACK_SESSION  = YES
 
 all    :
 	@echo '#define PIXMAPS_DIR  "$(PIXMAPS_DIR)"' > config.h
+ifneq ($(JACK_SESSION), YES)
 	@echo "build . . gxtuner"
+	@echo ''
+	@echo '-->> to enable JACK SESSION SUPPORT,'
+	@echo '     please edit the Makefile'
+	@echo ''
+else
+	@echo "build gxtuner with jack_session support"
+	@echo '#define HAVE_JACK_SESSION 1' >> config.h 
+endif
 	$(CXX) -O2 -Wall -march=native  -ffast-math -lzita-resampler `pkg-config --cflags --libs jack gtk+-2.0 gthread-2.0 fftw3f` gxtuner.cpp  -o gxtuner
 	@echo "build finish, now run make install"
 
diff --git a/README b/README
index 27653fa..4ff8dcf 100644
--- a/README
+++ b/README
@@ -22,24 +22,30 @@ libfftw3-3-dev
 libgcc1-dev
 libglib2.0-0-dev
 libgtk2.0-0-dev
+libstdc++6-dev
+libzita-resampler0-dev
 libjack-jackd2-0-dev 
 or
 libjack-0.116-dev
-libstdc++6-dev
-libzita-resampler0-dev
+
 
 note that those packages could have different, but similar names 
 on different distributions. There is no configure script, 
-build will simply fail when one of those packages isn't found.
+make will simply fail when one of those packages isn't found.
+
+to disable jack_session support edit the Makefile, see comment in
+the Makefile.
 
-to build gxtuner simply run
+then, to build gxtuner simply run
 $ make
 in the source directory.
-If you wish to install gxtuner run
+If you wish to install[1] gxtuner run
 $ make install
 
 but you can run gxtuner from any location you choose.
 
+[1] to work propper with jack_session you need to install gxtuner
+
 gxtuner home is :
 http://sourceforge.net/projects/guitarix/files/gxtuner/
 
diff --git a/gxtuner.cpp b/gxtuner.cpp
index de6e3b1..49e8ce3 100644
--- a/gxtuner.cpp
+++ b/gxtuner.cpp
@@ -22,7 +22,6 @@
  */
 
 #include "./gxtuner.h"
-#include "./config.h"
 
 #define P_(s) (s)   // FIXME -> gettext
 
@@ -46,21 +45,25 @@ static const double rect_width = 100;
 static const double rect_height = 60;
 
 static const double dashes[] = {
-    0.0,                    /* ink  */
-    rect_height,            /* skip */
-    10.0,                    /* ink  */
-    10.0                    /* skip */
+    0.0,                      /* ink  */
+    rect_height,              /* skip */
+    10.0,                     /* ink  */
+    10.0                      /* skip */
 };
 
 static const double dash_ind[] = {
-    0,                        /* ink  */
-    5,                        /* skip */
+    0,                         /* ink  */
+    5,                         /* skip */
     rect_height-20,            /* ink  */
-    100.0                    /* skip */
+    100.0                      /* skip */
 };
 
-GType gx_tuner_get_type(void)
-{
+static const double dash[] = {
+    5,                        /* ink  */
+    0.25                       /* skip */
+};
+
+GType gx_tuner_get_type(void) {
     static GType tuner_type = 0;
 
     if (!tuner_type) {
@@ -82,8 +85,7 @@ GType gx_tuner_get_type(void)
     return tuner_type;
 }
 
-static void gx_tuner_class_init(GxTunerClass *klass)
-{
+static void gx_tuner_class_init(GxTunerClass *klass) {
     GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
     GTK_WIDGET_CLASS(klass)->expose_event = gtk_tuner_expose;
     gobject_class->set_property = gx_tuner_set_property;
@@ -99,36 +101,31 @@ static void gx_tuner_class_init(GxTunerClass *klass)
     draw_background(klass->surface_tuner);
 }
 
-static void gx_tuner_base_class_finalize(GxTunerClass *klass)
-{
+static void gx_tuner_base_class_finalize(GxTunerClass *klass) {
     if (klass->surface_tuner) {
         g_object_unref(klass->surface_tuner);
     }
 }
 
-static void gx_tuner_init (GxTuner *tuner)
-{
+static void gx_tuner_init (GxTuner *tuner) {
     GtkWidget *widget = GTK_WIDGET(tuner);
     widget->requisition.width = tuner_width;
     widget->requisition.height = tuner_height;
 }
 
-void gx_tuner_set_freq(GxTuner *tuner, double freq)
-{
+void gx_tuner_set_freq(GxTuner *tuner, double freq) {
     g_assert(GX_IS_TUNER(tuner));
     tuner->freq = freq;
     gtk_widget_queue_draw(GTK_WIDGET(tuner));
     g_object_notify(G_OBJECT(tuner), "freq");
 }
 
-GtkWidget *gx_tuner_new(void)
-{
+GtkWidget *gx_tuner_new(void) {
     return (GtkWidget*)g_object_new(GX_TYPE_TUNER, NULL);
 }
 
 static void gx_tuner_set_property(GObject *object, guint prop_id,
-                                      const GValue *value, GParamSpec *pspec)
-{
+                                      const GValue *value, GParamSpec *pspec) {
     GxTuner *tuner = GX_TUNER(object);
 
     switch(prop_id) {
@@ -142,8 +139,7 @@ static void gx_tuner_set_property(GObject *object, guint prop_id,
 }
 
 static void gx_tuner_get_property(GObject *object, guint prop_id,
-                                      GValue *value, GParamSpec *pspec)
-{
+                                      GValue *value, GParamSpec *pspec) {
     GxTuner *tuner = GX_TUNER(object);
 
     switch(prop_id) {
@@ -156,8 +152,7 @@ static void gx_tuner_get_property(GObject *object, guint prop_id,
     }
 }
 
-static gboolean gtk_tuner_expose (GtkWidget *widget, GdkEventExpose *event)
-{
+static gboolean gtk_tuner_expose (GtkWidget *widget, GdkEventExpose *event) {
     static const char* note[12] = {"A ","A#","B ","C ","C#","D ","D#","E ","F ","F#","G ","G#"};
     static const char* octave[9] = {"0","1","2","3","4","4","6","7"," "};
     static int indicate_oc = 0;
@@ -261,7 +256,15 @@ static gboolean gtk_tuner_expose (GtkWidget *widget, GdkEventExpose *event)
     cairo_line_to(cr, (scale*2*rect_width)+x0+47, y0+(scale*scale*30)+2);
     cairo_set_source_rgb(cr,  0.5, 0.1, 0.1);
     cairo_stroke(cr);
-    
+
+   /* if (scale > -0.5) {
+        int light = round(scale * (rect_width+80));
+        cairo_set_source_rgb(cr,  0.5, 0.5, 0.5);
+        cairo_rectangle (cr, x0+45.+light,y0+rect_height+8,5,18);
+        cairo_set_operator(cr,CAIRO_OPERATOR_COLOR_DODGE);
+        cairo_fill(cr);
+    } */
+   
     cairo_destroy(cr);
 
     return FALSE;
@@ -270,8 +273,7 @@ static gboolean gtk_tuner_expose (GtkWidget *widget, GdkEventExpose *event)
 /*
 ** paint tuner background picture (the non-changing parts)
 */
-static void draw_background(cairo_surface_t *surface)
-{
+static void draw_background(cairo_surface_t *surface) {
     cairo_t *cr;
 
     double x0      = 0;
@@ -337,6 +339,19 @@ static void draw_background(cairo_surface_t *surface)
     cairo_line_to(cr, x0+50, y0+2);
     cairo_stroke(cr);
 
+   /* pat = cairo_pattern_create_linear (x0+50, y0,x0, y0);
+    cairo_pattern_set_extend(pat, CAIRO_EXTEND_REFLECT);
+    cairo_pattern_add_color_stop_rgba (pat, 0, 0.1, 0.8, 0.1, 0.3);
+    cairo_pattern_add_color_stop_rgba (pat, 1, 1, 0.1, 0.1, 0.3);
+    cairo_set_source (cr, pat);
+    cairo_set_line_width(cr, 1.2);
+    cairo_set_dash (cr, dash, sizeof(dash_ind)/sizeof(dash_ind[0]), 0);
+    for (int i = -3; i < 6; i++) {
+        cairo_move_to(cr,x0+6, y0+rect_height+15+(2*i));
+        cairo_line_to(cr, x0+95, y0+rect_height+15+(2*i));
+    }
+    cairo_stroke(cr); */
+
     // indicator shaft (circle)
     cairo_set_dash (cr, dash_ind, sizeof(dash_ind)/sizeof(dash_ind[0]), 0);
     //cairo_set_dash (cr, 0, 0, 0); // (for full circle)
@@ -372,6 +387,7 @@ PitchTracker::PitchTracker()
     busy(false),
     tick(0),
     m_pthr(0),
+    resamp(new Resampler),
     m_buffer(new float[MAX_FFT_SIZE]),
     m_bufferIndex(0),
     m_audioLevel(false),
@@ -411,7 +427,7 @@ bool PitchTracker::setParameters(int sampleRate, int fftSize) {
         return false;
     }
     m_sampleRate = sampleRate / DOWNSAMPLE;
-    resamp.setup(sampleRate, m_sampleRate, 1, 16); // 16 == least quality
+    resamp->setup(sampleRate, m_sampleRate, 1, 16); // 16 == least quality
 
     if (m_fftSize != fftSize) {
         m_fftSize = fftSize;
@@ -436,8 +452,16 @@ bool PitchTracker::setParameters(int sampleRate, int fftSize) {
     return !error;
 }
 
+void PitchTracker::stop_thread() {
+    pthread_cancel (m_pthr);
+    pthread_join (m_pthr, NULL);
+    sem_post(&m_trig);
+    delete resamp;
+    resamp = 0;
+}
+
 void PitchTracker::start_thread() {
-    int                min, max;
+    int                min = 0, max = 0;
     pthread_attr_t     attr;
     struct sched_param  spar;
     int priority, policy;
@@ -450,7 +474,8 @@ void PitchTracker::start_thread() {
     if (priority < min) priority = min;
     spar.sched_priority = priority;
     pthread_attr_init(&attr);
-    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+    pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE );
+    pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
     pthread_attr_setschedpolicy(&attr, policy);
     pthread_attr_setschedparam(&attr, &spar);
     pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
@@ -507,19 +532,19 @@ void PitchTracker::add(int count, float* input) {
     if (error) {
         return;
     }
-    resamp.inp_count = count;
-    resamp.inp_data = input;
+    resamp->inp_count = count;
+    resamp->inp_data = input;
     for (;;) {
-        resamp.out_data = &m_buffer[m_bufferIndex];
+        resamp->out_data = &m_buffer[m_bufferIndex];
         int n = MAX_FFT_SIZE - m_bufferIndex;
-        resamp.out_count = n;
-        resamp.process();
-        n -= resamp.out_count; // n := number of output samples
+        resamp->out_count = n;
+        resamp->process();
+        n -= resamp->out_count; // n := number of output samples
         if (!n) { // all soaked up by filter
             return;
         }
         m_bufferIndex = (m_bufferIndex + n) % MAX_FFT_SIZE;
-        if (resamp.inp_count == 0) {
+        if (resamp->inp_count == 0) {
             break;
         }
     }
@@ -549,6 +574,7 @@ void PitchTracker::run() {
     for (;;) {
         busy = false;
         sem_wait(&m_trig);
+        pthread_testcancel();
         busy = true;
         if (error) {
             continue;
@@ -632,8 +658,13 @@ static bool gx_jack_init() {
     if (client) {
         jack_sr = jack_get_sample_rate(client); // jack sample rate
         jack_bs = jack_get_buffer_size(client); // jack buffer size
-        jack_set_process_callback(client, gx_jack_process, 0);
-        jack_on_shutdown (client, jack_shutdown, 0);
+        jack_set_process_callback(client, gx_jack_process, 0); // compute
+        jack_on_shutdown (client, jack_shutdown, 0);  // shutdown clean up
+#ifdef HAVE_JACK_SESSION
+        if (jack_set_session_callback) {
+            jack_set_session_callback(client, gx_jack_session_callback, 0);
+        }
+#endif
         input_port = jack_port_register(client, "in_0", JACK_DEFAULT_AUDIO_TYPE,
                      JackPortIsInput|JackPortIsTerminal, 0);
     } else {
@@ -641,14 +672,17 @@ static bool gx_jack_init() {
         exit(1);
     }
 
+    return true;
+}
+
+static void gx_jack_activate() {
     if (jack_activate (client)) {
         fprintf (stderr, "cannot activate client\n");
         exit (1);
     }
-    return true;
 }
 
-void jack_shutdown (void *arg) {exit (1);}
+void jack_shutdown (void *arg) {gtk_main_quit ();}
 
 static int gx_jack_process(jack_nframes_t nframes, void *arg) {
     float *input = static_cast<float *>
@@ -656,7 +690,37 @@ static int gx_jack_process(jack_nframes_t nframes, void *arg) {
     gx_engine::pitch_tracker.add(nframes, input);
     return 0;
 }
+
+#ifdef HAVE_JACK_SESSION
+static int gx_jack_session_callback_helper(gpointer data) {
+    jack_session_event_t *event = static_cast<jack_session_event_t *>(data);
+    std::string cmd("gxtuner -U ");
+    cmd += event->client_uuid;
+    event->command_line = strdup(cmd.c_str());
+
+    jack_session_reply(client, event);
+
+    if (event->type == JackSessionSaveAndQuit) {
+        jack_port_unregister(client, input_port);
+        jack_deactivate(client);
+        jack_client_close(client);
+        if (gx_gui::g_threads > 0) {
+            g_source_remove(gx_gui::g_threads);
+        }
+        gtk_main_quit ();
+        gx_engine::pitch_tracker.stop_thread();
+        jack_session_event_free(event);
+        exit(0);
+    }
+    jack_session_event_free(event);
+    return 0;
+}
+
+void gx_jack_session_callback(jack_session_event_t *event, void *arg) {
+    gtk_idle_add(gx_jack_session_callback_helper, static_cast<void *>(event));
 }
+#endif
+} // end namespace gx_jack
 
 static gboolean gx_update_all_gui(gpointer arg) {
     gx_tuner_set_freq(GX_TUNER(gx_gui::tuner),gx_gui::fConsta4);
@@ -667,25 +731,32 @@ int main(int argc, char *argv[]) {
     gx_gui::g_threads = 0;
     g_thread_init(NULL);
     gx_jack::gx_jack_init();
-    gx_engine::pitch_tracker.init();
     gtk_init (&argc, &argv);
+    gx_jack::gx_jack_activate();
+
     GError* err = NULL;
     GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
     gtk_window_set_default_size(GTK_WINDOW(window), 120,100);
     gtk_window_set_icon_from_file(GTK_WINDOW(window),
         (std::string(PIXMAPS_DIR) + "/gxtuner.png").c_str(),&err);
     if (err != NULL) g_error_free(err);
-    gx_gui::tuner = gx_tuner_new();
-    gtk_container_add (GTK_CONTAINER (window), gx_gui::tuner);
 
     g_signal_connect (window, "delete-event",
             G_CALLBACK (delete_event), NULL);
     g_signal_connect (window, "destroy",
             G_CALLBACK (destroy), NULL);
-    gx_tuner_set_freq(GX_TUNER(gx_gui::tuner),gx_gui::fConsta4);
+
+    gx_gui::tuner = gx_tuner_new();
+    gtk_container_add (GTK_CONTAINER (window), gx_gui::tuner);
     gtk_widget_show_all  (window);
+
     gx_gui::g_threads = g_timeout_add(100, gx_update_all_gui, 0);
+
+    gx_engine::pitch_tracker.init();
+
     gtk_main ();
 
+    gx_engine::pitch_tracker.stop_thread();
+
     return 0;
 }
diff --git a/gxtuner.h b/gxtuner.h
index 52a2d0d..129f395 100644
--- a/gxtuner.h
+++ b/gxtuner.h
@@ -26,6 +26,7 @@
 #ifndef SRC_HEADERS_TUNER_H_
 #define SRC_HEADERS_TUNER_H_
 
+#include "./config.h"
 #include <jack/jack.h>
 #include <gtk/gtk.h>
 #include <glib.h>
@@ -36,6 +37,10 @@
 #include <assert.h> 
 #include <pthread.h>
 
+#ifdef HAVE_JACK_SESSION
+#include <jack/session.h>
+#endif
+
 #include <cstring> 
 #include <string> 
 #include <cmath>
@@ -43,7 +48,6 @@
 
 #include <zita-resampler.h>
 
-
 G_BEGIN_DECLS
 
 #define GX_TYPE_TUNER          (gx_tuner_get_type())
@@ -78,8 +82,12 @@ G_END_DECLS
 
 namespace gx_jack {
 
-    static bool gx_jack_init();
-    static int gx_jack_process(jack_nframes_t nframes, void *arg);
+    static bool         gx_jack_init();
+    static int          gx_jack_process(jack_nframes_t nframes, void *arg);
+    static void         gx_jack_activate();
+#ifdef HAVE_JACK_SESSION
+    static void         gx_jack_session_callback(jack_session_event_t *event, void *arg);
+#endif
     void jack_shutdown (void *arg);
     std::string         client_name;
     jack_client_t*      client;
@@ -109,6 +117,7 @@ class PitchTracker {
                         {setParameters(static_cast<int>(gx_jack::jack_sr), MAX_FFT_SIZE);}
     void                add(int count, float *input);
     float               tuner_estimate();
+    void                stop_thread();
 
  private:
     void                run();
@@ -123,7 +132,7 @@ class PitchTracker {
     int                 tick;
     sem_t               m_trig;
     pthread_t           m_pthr;
-    Resampler           resamp;
+    Resampler           *resamp;
     int                 m_sampleRate;
     // Size of the FFT window.
     int                 m_fftSize;

-- 
gxtuner packaging



More information about the pkg-multimedia-commits mailing list