colinf's 2011-12-08 patch for freesound mootcher (add stop, remove URI, clear barberpole, etc)
git-svn-id: svn://localhost/ardour2/branches/3.0@11265 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
759f1216af
commit
577469a06a
|
@ -139,7 +139,7 @@ void Mootcher::setcUrlOptions()
|
|||
|
||||
// Allow connections to time out (without using signals)
|
||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30);
|
||||
|
||||
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ int audioFileWrite(void *buffer, size_t size, size_t nmemb, void *file)
|
|||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, Gtk::ProgressBar *progress_bar)
|
||||
std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller)
|
||||
{
|
||||
ensureWorkingDir();
|
||||
std::string audioFileName = basePath + "snd/" + ID + "-" + originalFileName;
|
||||
|
@ -332,17 +332,20 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID,
|
|||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, theFile);
|
||||
|
||||
std::cerr << "downloading " << audioFileName << " from " << audioURL << "..." << std::endl;
|
||||
/* hack to get rid of the barber-pole stripes */
|
||||
caller->progress_bar.hide();
|
||||
caller->progress_bar.show();
|
||||
|
||||
curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 0); // turn on the progress bar
|
||||
curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
|
||||
curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, progress_bar);
|
||||
curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, caller);
|
||||
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
fclose(theFile);
|
||||
|
||||
curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 1); // turn off the progress bar
|
||||
progress_bar->set_fraction(0.0);
|
||||
|
||||
caller->progress_bar.set_fraction(0.0);
|
||||
|
||||
if( res != 0 ) {
|
||||
std::cerr << "curl error " << res << " (" << curl_easy_strerror(res) << ")" << std::endl;
|
||||
remove( audioFileName.c_str() );
|
||||
|
@ -359,14 +362,18 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID,
|
|||
}
|
||||
|
||||
//---------
|
||||
int Mootcher::progress_callback(void *bar, double dltotal, double dlnow, double ultotal, double ulnow)
|
||||
int Mootcher::progress_callback(void *caller, double dltotal, double dlnow, double ultotal, double ulnow)
|
||||
{
|
||||
|
||||
SoundFileBrowser *sfb = (SoundFileBrowser *) caller;
|
||||
//XXX I hope it's OK to do GTK things in this callback. Otherwise
|
||||
// I'll have to do stuff like in interthread_progress_window.
|
||||
if (sfb->freesound_stop) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Gtk::ProgressBar *progress_bar = (Gtk::ProgressBar *) bar;
|
||||
progress_bar->set_fraction(dlnow/dltotal);
|
||||
|
||||
sfb->progress_bar.set_fraction(dlnow/dltotal);
|
||||
/* Make sure the progress widget gets updated */
|
||||
while (Glib::MainContext::get_default()->iteration (false)) {
|
||||
/* do nothing */
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include <gtkmm/progressbar.h>
|
||||
//#include <ctime>
|
||||
|
||||
#include "sfdb_ui.h"
|
||||
|
||||
#include "curl/curl.h"
|
||||
|
||||
//--- struct to store XML file
|
||||
|
@ -50,7 +52,7 @@ public:
|
|||
Mootcher(const char *saveLocation);
|
||||
~Mootcher();
|
||||
|
||||
std::string getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, Gtk::ProgressBar *progress_bar);
|
||||
std::string getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller);
|
||||
std::string searchText(std::string query, int page, std::string filter, enum sortMethod sort);
|
||||
|
||||
private:
|
||||
|
|
|
@ -548,6 +548,8 @@ SoundFileBrowser::SoundFileBrowser (Gtk::Window& parent, string title, ARDOUR::S
|
|||
|
||||
passbox->pack_start (freesound_search_btn, false, false);
|
||||
passbox->pack_start (progress_bar);
|
||||
passbox->pack_end (freesound_stop_btn, false, false);
|
||||
freesound_stop_btn.set_label(_("Stop"));
|
||||
|
||||
Gtk::ScrolledWindow *scroll = manage(new ScrolledWindow);
|
||||
scroll->add(freesound_list_view);
|
||||
|
@ -559,13 +561,14 @@ SoundFileBrowser::SoundFileBrowser (Gtk::Window& parent, string title, ARDOUR::S
|
|||
|
||||
freesound_list_view.append_column(_("ID") , freesound_list_columns.id);
|
||||
freesound_list_view.append_column(_("Filename"), freesound_list_columns.filename);
|
||||
freesound_list_view.append_column(_("URI") , freesound_list_columns.uri);
|
||||
// freesound_list_view.append_column(_("URI") , freesound_list_columns.uri);
|
||||
freesound_list_view.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_list_view_selected));
|
||||
|
||||
freesound_list_view.get_selection()->set_mode (SELECTION_MULTIPLE);
|
||||
freesound_list_view.signal_row_activated().connect (sigc::mem_fun (*this, &SoundFileBrowser::freesound_list_view_activated));
|
||||
freesound_search_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_search_clicked));
|
||||
freesound_entry.signal_activate().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_search_clicked));
|
||||
freesound_stop_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_stop_clicked));
|
||||
notebook.append_page (*vbox, _("Search Freesound"));
|
||||
}
|
||||
#endif
|
||||
|
@ -756,12 +759,15 @@ SoundFileBrowser::freesound_list_view_selected ()
|
|||
gdk_window_set_cursor (get_window()->gobj(), gdk_cursor_new(GDK_WATCH));
|
||||
gdk_flush();
|
||||
|
||||
file = theMootcher.getAudioFile(ofn, id, uri, &progress_bar);
|
||||
freesound_stop = false;
|
||||
file = theMootcher.getAudioFile(ofn, id, uri, this);
|
||||
|
||||
gdk_window_set_cursor (get_window()->gobj(), prev_cursor);
|
||||
|
||||
chooser.set_filename (file);
|
||||
set_response_sensitive (RESPONSE_OK, true);
|
||||
if (file != "") {
|
||||
chooser.set_filename (file);
|
||||
set_response_sensitive (RESPONSE_OK, true);
|
||||
}
|
||||
} else {
|
||||
set_response_sensitive (RESPONSE_OK, false);
|
||||
}
|
||||
|
@ -801,6 +807,12 @@ SoundFileBrowser::freesound_search_clicked ()
|
|||
freesound_search();
|
||||
}
|
||||
|
||||
void
|
||||
SoundFileBrowser::freesound_stop_clicked ()
|
||||
{
|
||||
freesound_stop = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SoundFileBrowser::freesound_search()
|
||||
|
@ -940,8 +952,11 @@ SoundFileBrowser::get_paths ()
|
|||
gdk_window_set_cursor (get_window()->gobj(), gdk_cursor_new(GDK_WATCH));
|
||||
gdk_flush();
|
||||
|
||||
string str = theMootcher.getAudioFile(ofn, id, uri, &progress_bar);
|
||||
results.push_back (str);
|
||||
freesound_stop = false;
|
||||
string str = theMootcher.getAudioFile(ofn, id, uri, this);
|
||||
if (str != "") {
|
||||
results.push_back (str);
|
||||
}
|
||||
|
||||
gdk_window_set_cursor (get_window()->gobj(), prev_cursor);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <sigc++/signal.h>
|
||||
|
||||
#include <gtkmm/stock.h>
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/checkbutton.h>
|
||||
|
@ -36,6 +37,11 @@
|
|||
#include <gtkmm/frame.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <gtkmm/textview.h>
|
||||
#include <gtkmm/table.h>
|
||||
#include <gtkmm/liststore.h>
|
||||
#include <gtkmm/spinbutton.h>
|
||||
#include <gtkmm/notebook.h>
|
||||
|
||||
|
||||
#include "ardour/audiofilesource.h"
|
||||
#include "ardour/session_handle.h"
|
||||
|
@ -130,7 +136,7 @@ class SoundFileBrowser : public ArdourDialog
|
|||
FreesoundColumns freesound_list_columns;
|
||||
Glib::RefPtr<Gtk::ListStore> freesound_list;
|
||||
|
||||
Gtk::ProgressBar progress_bar;
|
||||
Gtk::Button freesound_stop_btn;
|
||||
|
||||
public:
|
||||
SoundFileBrowser (Gtk::Window& parent, std::string title, ARDOUR::Session* _s, bool persistent);
|
||||
|
@ -155,6 +161,9 @@ class SoundFileBrowser : public ArdourDialog
|
|||
|
||||
Gtk::Button freesound_search_btn;
|
||||
Gtk::TreeView freesound_list_view;
|
||||
Gtk::ProgressBar progress_bar;
|
||||
|
||||
bool freesound_stop;
|
||||
|
||||
void freesound_search();
|
||||
|
||||
|
@ -189,7 +198,8 @@ class SoundFileBrowser : public ArdourDialog
|
|||
void freesound_list_view_selected ();
|
||||
void freesound_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
|
||||
void freesound_search_clicked ();
|
||||
|
||||
void freesound_stop_clicked ();
|
||||
|
||||
void chooser_file_activated ();
|
||||
|
||||
bool on_audio_filter (const Gtk::FileFilter::Info& filter_info);
|
||||
|
|
Loading…
Reference in New Issue