mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-11 09:06:33 +01:00
Freesound fixes for #5853, and a few other small improvements
Add a 'More' button to load the next page of results without clearing the already-found list. Don't allow cancellation of searches, and don't update progress bar around searches, since we only get one page at a time now. Show number of pages of results remaining to download in the tooltip of the 'More' button. Use a new Mootcher object for each request, to avoid bad things happening when clicking in the Freesound search results list while a search or file download is already in progress. Make the 'Stop' button insensitive except when it will actually stop the download of a sound file. Only retrieve one page worth of data per search, rather than looping to get all pages. Don't show an error in the log window if the user cancelled download. Request 100 items per page, rather than the default 30. Fix DOS line endings.
This commit is contained in:
parent
8cbb9727e9
commit
2233e91086
4 changed files with 253 additions and 244 deletions
|
|
@ -226,6 +226,7 @@ std::string Mootcher::searchText(std::string query, int page, std::string filter
|
||||||
params += "&s=" + sortMethodString(sort);
|
params += "&s=" + sortMethodString(sort);
|
||||||
|
|
||||||
params += "&fields=id,original_filename,duration,filesize,samplerate,license,serve";
|
params += "&fields=id,original_filename,duration,filesize,samplerate,license,serve";
|
||||||
|
params += "&sounds_per_page=100";
|
||||||
|
|
||||||
return doRequest("/sounds/search", params);
|
return doRequest("/sounds/search", params);
|
||||||
}
|
}
|
||||||
|
|
@ -318,7 +319,7 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID,
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
//if already canceling a previous download, bail out here ( this can happen b/c getAudioFile gets called by various UI update funcs )
|
// if already cancelling a previous download, bail out here ( this can happen b/c getAudioFile gets called by various UI update funcs )
|
||||||
if ( caller->freesound_download_cancel ) {
|
if ( caller->freesound_download_cancel ) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
@ -359,7 +360,10 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID,
|
||||||
caller->freesound_progress_bar.set_text("");
|
caller->freesound_progress_bar.set_text("");
|
||||||
|
|
||||||
if( res != 0 ) {
|
if( res != 0 ) {
|
||||||
|
/* it's not an error if the user pressed the stop button */
|
||||||
|
if (res != CURLE_ABORTED_BY_CALLBACK) {
|
||||||
error << string_compose (_("curl error %1 (%2)"), res, curl_easy_strerror(res)) << endmsg;
|
error << string_compose (_("curl error %1 (%2)"), res, curl_easy_strerror(res)) << endmsg;
|
||||||
|
}
|
||||||
remove( audioFileName.c_str() );
|
remove( audioFileName.c_str() );
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -520,8 +520,6 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s, bool persi
|
||||||
|
|
||||||
//add freesound search
|
//add freesound search
|
||||||
|
|
||||||
mootcher = new Mootcher();
|
|
||||||
|
|
||||||
HBox* passbox;
|
HBox* passbox;
|
||||||
Label* label;
|
Label* label;
|
||||||
|
|
||||||
|
|
@ -553,8 +551,13 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s, bool persi
|
||||||
freesound_sort.set_active(0);
|
freesound_sort.set_active(0);
|
||||||
|
|
||||||
passbox->pack_start (freesound_search_btn, false, false);
|
passbox->pack_start (freesound_search_btn, false, false);
|
||||||
|
passbox->pack_start (freesound_more_btn, false, false);
|
||||||
|
freesound_more_btn.set_label(_("More"));
|
||||||
|
freesound_more_btn.set_sensitive(false);
|
||||||
|
|
||||||
passbox->pack_end (freesound_stop_btn, false, false);
|
passbox->pack_end (freesound_stop_btn, false, false);
|
||||||
freesound_stop_btn.set_label(_("Stop"));
|
freesound_stop_btn.set_label(_("Stop"));
|
||||||
|
freesound_stop_btn.set_sensitive(false);
|
||||||
|
|
||||||
scroll = manage(new ScrolledWindow);
|
scroll = manage(new ScrolledWindow);
|
||||||
scroll->add(freesound_list_view);
|
scroll->add(freesound_list_view);
|
||||||
|
|
@ -586,6 +589,7 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s, bool persi
|
||||||
freesound_list_view.signal_row_activated().connect (sigc::mem_fun (*this, &SoundFileBrowser::freesound_list_view_activated));
|
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_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_entry.signal_activate().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_search_clicked));
|
||||||
|
freesound_more_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_more_clicked));
|
||||||
freesound_stop_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_stop_clicked));
|
freesound_stop_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_stop_clicked));
|
||||||
notebook.append_page (*vbox, _("Search Freesound"));
|
notebook.append_page (*vbox, _("Search Freesound"));
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -802,12 +806,13 @@ void
|
||||||
SoundFileBrowser::freesound_list_view_selected ()
|
SoundFileBrowser::freesound_list_view_selected ()
|
||||||
{
|
{
|
||||||
freesound_download_cancel = false;
|
freesound_download_cancel = false;
|
||||||
|
freesound_stop_btn.set_sensitive(true);
|
||||||
|
|
||||||
#ifdef FREESOUND
|
#ifdef FREESOUND
|
||||||
if (!reset_options ()) {
|
if (!reset_options ()) {
|
||||||
set_action_sensitive (false);
|
set_action_sensitive (false);
|
||||||
} else {
|
} else {
|
||||||
|
Mootcher mootcher;
|
||||||
string file;
|
string file;
|
||||||
|
|
||||||
TreeView::Selection::ListHandle_Path rows = freesound_list_view.get_selection()->get_selected_rows ();
|
TreeView::Selection::ListHandle_Path rows = freesound_list_view.get_selection()->get_selected_rows ();
|
||||||
|
|
@ -825,7 +830,7 @@ SoundFileBrowser::freesound_list_view_selected ()
|
||||||
gdk_window_set_cursor (get_window()->gobj(), gdk_cursor_new(GDK_WATCH));
|
gdk_window_set_cursor (get_window()->gobj(), gdk_cursor_new(GDK_WATCH));
|
||||||
gdk_flush();
|
gdk_flush();
|
||||||
|
|
||||||
file = mootcher->getAudioFile(ofn, id, uri, this);
|
file = mootcher.getAudioFile(ofn, id, uri, this);
|
||||||
|
|
||||||
gdk_window_set_cursor (get_window()->gobj(), prev_cursor);
|
gdk_window_set_cursor (get_window()->gobj(), prev_cursor);
|
||||||
|
|
||||||
|
|
@ -843,6 +848,7 @@ SoundFileBrowser::freesound_list_view_selected ()
|
||||||
preview.setup_labels (file);
|
preview.setup_labels (file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
freesound_stop_btn.set_sensitive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -872,15 +878,26 @@ SoundFileBrowser::found_search_clicked ()
|
||||||
void
|
void
|
||||||
SoundFileBrowser::freesound_search_clicked ()
|
SoundFileBrowser::freesound_search_clicked ()
|
||||||
{
|
{
|
||||||
freesound_search_cancel = false;
|
freesound_page = 1;
|
||||||
|
freesound_list->clear();
|
||||||
|
matches = 0;
|
||||||
freesound_search();
|
freesound_search();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SoundFileBrowser::freesound_more_clicked ()
|
||||||
|
{
|
||||||
|
char row_path[21];
|
||||||
|
freesound_page++;
|
||||||
|
freesound_search();
|
||||||
|
snprintf(row_path, 21, "%d", (freesound_page - 1) * 100);
|
||||||
|
freesound_list_view.scroll_to_row(Gtk::TreePath(row_path), 0);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SoundFileBrowser::freesound_stop_clicked ()
|
SoundFileBrowser::freesound_stop_clicked ()
|
||||||
{
|
{
|
||||||
freesound_download_cancel = true;
|
freesound_download_cancel = true;
|
||||||
freesound_search_cancel = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -888,9 +905,8 @@ void
|
||||||
SoundFileBrowser::freesound_search()
|
SoundFileBrowser::freesound_search()
|
||||||
{
|
{
|
||||||
#ifdef FREESOUND
|
#ifdef FREESOUND
|
||||||
freesound_list->clear();
|
Mootcher mootcher;
|
||||||
freesound_list_view.get_column(1)->set_sizing(TREE_VIEW_COLUMN_GROW_ONLY);
|
freesound_list_view.get_column(1)->set_sizing(TREE_VIEW_COLUMN_GROW_ONLY);
|
||||||
matches = 0;
|
|
||||||
|
|
||||||
string search_string = freesound_entry.get_text ();
|
string search_string = freesound_entry.get_text ();
|
||||||
enum sortMethod sort_method = (enum sortMethod) freesound_sort.get_active_row_number();
|
enum sortMethod sort_method = (enum sortMethod) freesound_sort.get_active_row_number();
|
||||||
|
|
@ -901,24 +917,9 @@ SoundFileBrowser::freesound_search()
|
||||||
freesound_progress_bar.set_fraction(0.0);
|
freesound_progress_bar.set_fraction(0.0);
|
||||||
gdk_flush();
|
gdk_flush();
|
||||||
|
|
||||||
int freesound_n_pages = 1;
|
std::string theString = mootcher.searchText(
|
||||||
for (int page = 1; page <= 99 && page <= freesound_n_pages; page++ ) {
|
|
||||||
|
|
||||||
std::string prog;
|
|
||||||
if (freesound_n_pages > 1) {
|
|
||||||
freesound_progress_bar.set_fraction(page/(float)freesound_n_pages);
|
|
||||||
prog = string_compose (_("Searching Page %1 of %2, click Stop to cancel"), page, freesound_n_pages);
|
|
||||||
} else {
|
|
||||||
prog = _("Searching, click Stop to cancel");
|
|
||||||
}
|
|
||||||
freesound_progress_bar.set_text(prog);
|
|
||||||
while (Glib::MainContext::get_default()->iteration (false)) {
|
|
||||||
/* do nothing */
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string theString = mootcher->searchText(
|
|
||||||
search_string,
|
search_string,
|
||||||
page,
|
freesound_page,
|
||||||
#ifdef GTKOSX
|
#ifdef GTKOSX
|
||||||
"", // OSX eats anything incl mp3
|
"", // OSX eats anything incl mp3
|
||||||
#else
|
#else
|
||||||
|
|
@ -927,38 +928,53 @@ SoundFileBrowser::freesound_search()
|
||||||
sort_method
|
sort_method
|
||||||
);
|
);
|
||||||
|
|
||||||
|
gdk_window_set_cursor (get_window()->gobj(), prev_cursor);
|
||||||
|
|
||||||
XMLTree doc;
|
XMLTree doc;
|
||||||
doc.read_buffer( theString );
|
doc.read_buffer( theString );
|
||||||
XMLNode *root = doc.root();
|
XMLNode *root = doc.root();
|
||||||
|
|
||||||
if (!root) {
|
if (!root) {
|
||||||
error << "no root XML node!" << endmsg;
|
error << "no root XML node!" << endmsg;
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( strcmp(root->name().c_str(), "response") != 0) {
|
if ( strcmp(root->name().c_str(), "response") != 0) {
|
||||||
error << string_compose ("root node name == %1 != \"response\"", root->name()) << endmsg;
|
error << string_compose ("root node name == %1 != \"response\"", root->name()) << endmsg;
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find out how many pages are available to search
|
// find out how many pages are available to search
|
||||||
|
int freesound_n_pages = 1;
|
||||||
XMLNode *res = root->child("num_pages");
|
XMLNode *res = root->child("num_pages");
|
||||||
if (res) {
|
if (res) {
|
||||||
string result = res->child("text")->content();
|
string result = res->child("text")->content();
|
||||||
freesound_n_pages = atoi(result.c_str());
|
freesound_n_pages = atoi(result.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
XMLNode *sounds_root = root->child("sounds");
|
int more_pages = freesound_n_pages - freesound_page;
|
||||||
|
|
||||||
|
if (more_pages > 0) {
|
||||||
|
freesound_more_btn.set_sensitive(true);
|
||||||
|
freesound_more_btn.set_tooltip_text(string_compose(P_(
|
||||||
|
"%1 more page of 100 results available",
|
||||||
|
"%1 more pages of 100 results available",
|
||||||
|
more_pages), more_pages));
|
||||||
|
} else {
|
||||||
|
freesound_more_btn.set_sensitive(false);
|
||||||
|
freesound_more_btn.set_tooltip_text(_("No more results available"));
|
||||||
|
}
|
||||||
|
|
||||||
|
XMLNode *sounds_root = root->child("sounds");
|
||||||
if (!sounds_root) {
|
if (!sounds_root) {
|
||||||
error << "no child node \"sounds\" found!" << endmsg;
|
error << "no child node \"sounds\" found!" << endmsg;
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
XMLNodeList sounds = sounds_root->children();
|
XMLNodeList sounds = sounds_root->children();
|
||||||
if (sounds.size() == 0) {
|
if (sounds.size() == 0) {
|
||||||
/* nothing found */
|
/* nothing found */
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
XMLNodeConstIterator niter;
|
XMLNodeConstIterator niter;
|
||||||
|
|
@ -967,12 +983,12 @@ SoundFileBrowser::freesound_search()
|
||||||
node = *niter;
|
node = *niter;
|
||||||
if( strcmp( node->name().c_str(), "resource") != 0 ) {
|
if( strcmp( node->name().c_str(), "resource") != 0 ) {
|
||||||
error << string_compose ("node->name()=%1 != \"resource\"", node->name()) << endmsg;
|
error << string_compose ("node->name()=%1 != \"resource\"", node->name()) << endmsg;
|
||||||
freesound_search_cancel = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// node->dump(cerr, "node:");
|
// node->dump(cerr, "node:");
|
||||||
|
|
||||||
|
|
||||||
XMLNode *id_node = node->child ("id");
|
XMLNode *id_node = node->child ("id");
|
||||||
XMLNode *uri_node = node->child ("serve");
|
XMLNode *uri_node = node->child ("serve");
|
||||||
XMLNode *ofn_node = node->child ("original_filename");
|
XMLNode *ofn_node = node->child ("original_filename");
|
||||||
|
|
@ -1047,18 +1063,9 @@ SoundFileBrowser::freesound_search()
|
||||||
row[freesound_list_columns.smplrate] = srt;
|
row[freesound_list_columns.smplrate] = srt;
|
||||||
row[freesound_list_columns.license ] = shortlicense;
|
row[freesound_list_columns.license ] = shortlicense;
|
||||||
matches++;
|
matches++;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (freesound_search_cancel)
|
|
||||||
break;
|
|
||||||
|
|
||||||
} //page "for" loop
|
|
||||||
|
|
||||||
gdk_window_set_cursor (get_window()->gobj(), prev_cursor);
|
|
||||||
|
|
||||||
freesound_progress_bar.set_fraction(0.0);
|
|
||||||
if (matches == 0) {
|
if (matches == 0) {
|
||||||
freesound_progress_bar.set_text(_("Search returned no results."));
|
freesound_progress_bar.set_text(_("Search returned no results."));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1100,6 +1107,7 @@ SoundFileBrowser::get_paths ()
|
||||||
} else {
|
} else {
|
||||||
#ifdef FREESOUND
|
#ifdef FREESOUND
|
||||||
typedef TreeView::Selection::ListHandle_Path ListPath;
|
typedef TreeView::Selection::ListHandle_Path ListPath;
|
||||||
|
Mootcher mootcher;
|
||||||
|
|
||||||
ListPath rows = freesound_list_view.get_selection()->get_selected_rows ();
|
ListPath rows = freesound_list_view.get_selection()->get_selected_rows ();
|
||||||
for (ListPath::iterator i = rows.begin() ; i != rows.end(); ++i) {
|
for (ListPath::iterator i = rows.begin() ; i != rows.end(); ++i) {
|
||||||
|
|
@ -1113,7 +1121,7 @@ SoundFileBrowser::get_paths ()
|
||||||
gdk_window_set_cursor (get_window()->gobj(), gdk_cursor_new(GDK_WATCH));
|
gdk_window_set_cursor (get_window()->gobj(), gdk_cursor_new(GDK_WATCH));
|
||||||
gdk_flush();
|
gdk_flush();
|
||||||
|
|
||||||
string str = mootcher->getAudioFile(ofn, id, uri, this);
|
string str = mootcher.getAudioFile(ofn, id, uri, this);
|
||||||
if (str != "") {
|
if (str != "") {
|
||||||
results.push_back (str);
|
results.push_back (str);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,7 @@ class SoundFileBrowser : public ArdourWindow
|
||||||
FreesoundColumns freesound_list_columns;
|
FreesoundColumns freesound_list_columns;
|
||||||
Glib::RefPtr<Gtk::ListStore> freesound_list;
|
Glib::RefPtr<Gtk::ListStore> freesound_list;
|
||||||
|
|
||||||
|
Gtk::Button freesound_more_btn;
|
||||||
Gtk::Button freesound_stop_btn;
|
Gtk::Button freesound_stop_btn;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -173,21 +174,15 @@ class SoundFileBrowser : public ArdourWindow
|
||||||
|
|
||||||
Gtk::Entry freesound_entry;
|
Gtk::Entry freesound_entry;
|
||||||
Gtk::ComboBoxText freesound_sort;
|
Gtk::ComboBoxText freesound_sort;
|
||||||
Gtk::SpinButton freesound_page;
|
|
||||||
|
|
||||||
Gtk::Button freesound_search_btn;
|
Gtk::Button freesound_search_btn;
|
||||||
Gtk::TreeView freesound_list_view;
|
Gtk::TreeView freesound_list_view;
|
||||||
Gtk::ProgressBar freesound_progress_bar;
|
Gtk::ProgressBar freesound_progress_bar;
|
||||||
|
|
||||||
bool freesound_search_cancel;
|
|
||||||
bool freesound_download_cancel;
|
bool freesound_download_cancel;
|
||||||
|
|
||||||
void freesound_search();
|
void freesound_search();
|
||||||
|
|
||||||
#ifdef FREESOUND
|
|
||||||
Mootcher *mootcher;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool resetting_ourselves;
|
bool resetting_ourselves;
|
||||||
int matches;
|
int matches;
|
||||||
|
|
@ -228,7 +223,9 @@ class SoundFileBrowser : public ArdourWindow
|
||||||
void freesound_list_view_selected ();
|
void freesound_list_view_selected ();
|
||||||
void freesound_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
|
void freesound_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
|
||||||
void freesound_search_clicked ();
|
void freesound_search_clicked ();
|
||||||
|
void freesound_more_clicked ();
|
||||||
void freesound_stop_clicked ();
|
void freesound_stop_clicked ();
|
||||||
|
int freesound_page;
|
||||||
|
|
||||||
void chooser_file_activated ();
|
void chooser_file_activated ();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue