narrow down multi-channel tracks
[ardour.git] / gtk2_ardour / sfdb_freesound_mootcher.cc
index 38d53aaa70b44bb9017f695a9d971553f443c815..8e57d9a0c44bab7b7702047202485b89ef5086a4 100644 (file)
@@ -55,6 +55,7 @@
 #include "ardour/audio_library.h"\r
 #include "ardour/rc_configuration.h"\r
 #include "pbd/pthread_utils.h"\r
+#include "gui_thread.h"\r
 \r
 using namespace PBD;\r
 \r
@@ -331,17 +332,15 @@ CURLcode res;
 \r
        return (void *) res;\r
 }\r
-\r
-static int \r
-donewithMootcher(void *arg) \r
\r
+void\r
+Mootcher::doneWithMootcher()\r
 {\r
-       Mootcher *thisMootcher = (Mootcher *) arg;\r
 \r
        // update the sound info pane if the selection in the list box is still us \r
-       thisMootcher->sfb->refresh_display(thisMootcher->ID, thisMootcher->audioFileName);\r
+       sfb->refresh_display(ID, audioFileName);\r
 \r
-       delete(thisMootcher);\r
-       return 0;\r
+       delete this; // this should be OK to do as long as Progress and Finished signals are always received in the order in which they are emitted\r
 }\r
 \r
 static void *\r
@@ -352,8 +351,8 @@ freesound_download_thread_func(void *arg)
 \r
        // std::cerr << "freesound_download_thread_func(" << arg << ")" << std::endl;\r
        res = thisMootcher->threadFunc();\r
-       g_idle_add(donewithMootcher, thisMootcher);\r
 \r
+       thisMootcher->Finished(); /* EMIT SIGNAL */\r
        return res;\r
 }\r
 \r
@@ -421,6 +420,8 @@ bool Mootcher::fetchAudioFile(std::string originalFileName, std::string theID, s
        curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, progress_callback);\r
        curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, this);\r
 \r
+       Progress.connect(*this, invalidator (*this), boost::bind(&Mootcher::updateProgress, this, _1, _2), gui_context());\r
+       Finished.connect(*this, invalidator (*this), boost::bind(&Mootcher::doneWithMootcher, this), gui_context());\r
        pthread_t freesound_download_thread;\r
        pthread_create_and_store("freesound_import", &freesound_download_thread, freesound_download_thread_func, this);\r
 \r
@@ -428,29 +429,20 @@ bool Mootcher::fetchAudioFile(std::string originalFileName, std::string theID, s
 }\r
 \r
 //---------\r
-struct progressInfo {\r
-       Gtk::ProgressBar *bar;\r
-       double dltotal;\r
-       double dlnow;\r
-};\r
 \r
-static int \r
-updateProgress(void *arg\r
+void \r
+Mootcher::updateProgress(double dlnow, double dltotal\r
 {\r
-       struct progressInfo *progress = (struct progressInfo *) arg;\r
-       if (progress->dltotal > 0) {\r
-               double fraction = progress->dlnow / progress->dltotal;\r
+       if (dltotal > 0) {\r
+               double fraction = dlnow / dltotal;\r
                // std::cerr << "progress idle: " << progress->bar->get_text() << ". " << progress->dlnow << " / " << progress->dltotal << " = " << fraction << std::endl;\r
                if (fraction > 1.0) {\r
                        fraction = 1.0;\r
                } else if (fraction < 0.0) {\r
                        fraction = 0.0;\r
                }\r
-               progress->bar->set_fraction(fraction);\r
+               progress_bar.set_fraction(fraction);\r
        }\r
-\r
-       delete progress;\r
-       return 0;\r
 }\r
 \r
 int \r
@@ -466,12 +458,7 @@ Mootcher::progress_callback(void *caller, double dltotal, double dlnow, double /
                return -1;\r
        }\r
 \r
-       struct progressInfo *progress = new struct progressInfo;\r
-       progress->bar = &thisMootcher->progress_bar;\r
-       progress->dltotal = dltotal;\r
-       progress->dlnow = dlnow;\r
-\r
-       g_idle_add(updateProgress, progress);\r
+       thisMootcher->Progress(dlnow, dltotal); /* EMIT SIGNAL */\r
        return 0;\r
 }\r
 \r