freesound fixes from a3 and mixbus: allow multi-valued keyword searching. put files directly in Freesound folder. show more feedback and make canceling easier, plus other workflow fixes
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@12979 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
a8bd6d1883
commit
1275817417
|
@ -63,7 +63,12 @@ Mootcher::Mootcher()
|
|||
: curl(curl_easy_init())
|
||||
{
|
||||
std::string path;
|
||||
path = Glib::get_home_dir() + "/Freesound/";
|
||||
#ifdef __WIN32__
|
||||
path = Glib::build_filename (Glib::get_user_special_dir( G_USER_DIRECTORY_DOCUMENTS ), "Freesound");
|
||||
#else
|
||||
path = Glib::build_filename (Glib::get_home_dir(), "Freesound");
|
||||
#endif
|
||||
path = Glib::build_filename ( path, G_DIR_SEPARATOR_S );
|
||||
changeWorkingDir ( path.c_str() );
|
||||
};
|
||||
//------------------------------------------------------------------------
|
||||
|
@ -76,25 +81,11 @@ Mootcher:: ~Mootcher()
|
|||
void Mootcher::changeWorkingDir(const char *saveLocation)
|
||||
{
|
||||
basePath = saveLocation;
|
||||
#ifdef __WIN32__
|
||||
std::string replace = "/";
|
||||
size_t pos = basePath.find("\\");
|
||||
while( pos != std::string::npos ){
|
||||
basePath.replace(pos, 1, replace);
|
||||
pos = basePath.find("\\");
|
||||
}
|
||||
#endif
|
||||
//
|
||||
size_t pos2 = basePath.find_last_of("/");
|
||||
if(basePath.length() != (pos2+1)) basePath += "/";
|
||||
}
|
||||
|
||||
void Mootcher::ensureWorkingDir ()
|
||||
{
|
||||
std::string sndLocation = basePath;
|
||||
g_mkdir(sndLocation.c_str(), 0777);
|
||||
sndLocation += "snd";
|
||||
g_mkdir(sndLocation.c_str(), 0777);
|
||||
g_mkdir(basePath.c_str(), 0777);
|
||||
}
|
||||
|
||||
|
||||
|
@ -210,7 +201,11 @@ std::string Mootcher::searchText(std::string query, int page, std::string filter
|
|||
params += buf;
|
||||
}
|
||||
|
||||
params += "q=" + query;
|
||||
//replace spaces with %20 so multiple-tag search will work
|
||||
while (query.find(" ") != std::string::npos)
|
||||
query.replace(query.find(" "), 1, "%20");
|
||||
|
||||
params += "q=\"" + query + "\";";
|
||||
|
||||
if (filter != "")
|
||||
params += "&f=" + filter;
|
||||
|
@ -253,12 +248,11 @@ std::string Mootcher::getSoundResourceFile(std::string ID)
|
|||
return "";
|
||||
}
|
||||
|
||||
XMLNode *name = freesound->child("original_filename");
|
||||
|
||||
// get the file name and size from xml file
|
||||
XMLNode *name = freesound->child("original_filename");
|
||||
if (name) {
|
||||
|
||||
audioFileName = basePath + "snd/" + ID + "-" + name->child("text")->content();
|
||||
audioFileName = basePath + ID + "-" + name->child("text")->content();
|
||||
|
||||
//store all the tags in the database
|
||||
XMLNode *tags = freesound->child("tags");
|
||||
|
@ -292,8 +286,9 @@ 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, SoundFileBrowser *caller)
|
||||
{
|
||||
caller->dlFileName = originalFileName;
|
||||
ensureWorkingDir();
|
||||
std::string audioFileName = basePath + "snd/" + ID + "-" + originalFileName;
|
||||
std::string audioFileName = basePath + ID + "-" + originalFileName;
|
||||
|
||||
// check to see if audio file already exists
|
||||
FILE *testFile = g_fopen(audioFileName.c_str(), "r");
|
||||
|
@ -336,9 +331,8 @@ 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->freesound_progress_bar.hide();
|
||||
caller->freesound_progress_bar.show();
|
||||
caller->freesound_entry_box.hide();
|
||||
caller->freesound_progress_box.show();
|
||||
|
||||
string prog;
|
||||
prog = string_compose (_("%1: click Stop to cancel -->"), originalFileName);
|
||||
|
@ -351,6 +345,9 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID,
|
|||
CURLcode res = curl_easy_perform(curl);
|
||||
fclose(theFile);
|
||||
|
||||
caller->freesound_progress_box.hide();
|
||||
caller->freesound_entry_box.show();
|
||||
|
||||
curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 1); // turn off the progress bar
|
||||
caller->freesound_progress_bar.set_fraction(0.0);
|
||||
caller->freesound_progress_bar.set_text("");
|
||||
|
@ -379,6 +376,9 @@ int Mootcher::progress_callback(void *caller, double dltotal, double dlnow, doub
|
|||
}
|
||||
|
||||
sfb->freesound_progress_bar.set_fraction(dlnow/dltotal);
|
||||
string prog;
|
||||
prog = string_compose (_("%1: %2 of %3 bytes downloaded, click Stop to cancel -->"), sfb->dlFileName, dlnow, dltotal);
|
||||
sfb->freesound_progress_bar.set_text( prog );
|
||||
|
||||
/* Make sure the progress widget gets updated */
|
||||
while (Glib::MainContext::get_default()->iteration (false)) {
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
#include "curl/curl.h"
|
||||
|
||||
#define NUM_RESULTS_PER_PAGE 30 //as defined in Freesound docs, May 2012
|
||||
|
||||
//--- struct to store XML file
|
||||
struct MemoryStruct {
|
||||
char *memory;
|
||||
|
|
|
@ -226,7 +226,11 @@ SoundFileBox::setup_labels (const string& filename)
|
|||
}
|
||||
|
||||
path = filename;
|
||||
|
||||
|
||||
if (filename.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
string error_msg;
|
||||
|
||||
if(!AudioFileSource::get_soundfile_info (filename, sf_info, error_msg)) {
|
||||
|
@ -484,21 +488,19 @@ SoundFileBrowser::SoundFileBrowser (Gtk::Window& parent, string title, ARDOUR::S
|
|||
#ifdef FREESOUND
|
||||
{
|
||||
VBox* vbox;
|
||||
HBox* passbox;
|
||||
Label* label;
|
||||
|
||||
passbox = manage(new HBox);
|
||||
passbox->set_border_width (12);
|
||||
passbox->set_spacing (6);
|
||||
freesound_entry_box.set_border_width (12);
|
||||
freesound_entry_box.set_spacing (6);
|
||||
label = manage (new Label);
|
||||
label->set_text (_("Tags:"));
|
||||
passbox->pack_start (*label, false, false);
|
||||
passbox->pack_start (freesound_entry, false, false);
|
||||
freesound_entry_box.pack_start (*label, false, false);
|
||||
freesound_entry_box.pack_start (freesound_entry, false, false);
|
||||
|
||||
label = manage (new Label);
|
||||
label->set_text (_("Sort:"));
|
||||
passbox->pack_start (*label, false, false);
|
||||
passbox->pack_start (freesound_sort, false, false);
|
||||
freesound_entry_box.pack_start (*label, false, false);
|
||||
freesound_entry_box.pack_start (freesound_sort, false, false);
|
||||
// freesound_sort.clear_items();
|
||||
|
||||
// Order of the following must correspond with enum sortMethod
|
||||
|
@ -514,10 +516,7 @@ SoundFileBrowser::SoundFileBrowser (Gtk::Window& parent, string title, ARDOUR::S
|
|||
freesound_sort.append_text(_("Lowest rated"));
|
||||
freesound_sort.set_active(0);
|
||||
|
||||
passbox->pack_start (freesound_search_btn, false, false);
|
||||
|
||||
passbox->pack_start (freesound_progress_bar);
|
||||
passbox->pack_end (freesound_stop_btn, false, false);
|
||||
freesound_entry_box.pack_start (freesound_search_btn, false, false);
|
||||
freesound_stop_btn.set_label(_("Stop"));
|
||||
|
||||
Gtk::ScrolledWindow *scroll = manage(new ScrolledWindow);
|
||||
|
@ -525,7 +524,15 @@ SoundFileBrowser::SoundFileBrowser (Gtk::Window& parent, string title, ARDOUR::S
|
|||
scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
|
||||
|
||||
vbox = manage(new VBox);
|
||||
vbox->pack_start (*passbox, PACK_SHRINK);
|
||||
vbox->pack_start (freesound_entry_box, PACK_SHRINK);
|
||||
|
||||
freesound_progress_box.set_border_width (12);
|
||||
freesound_progress_box.set_spacing (4);
|
||||
|
||||
freesound_progress_box.pack_start (freesound_progress_bar);
|
||||
freesound_progress_box.pack_end (freesound_stop_btn, false, false);
|
||||
|
||||
vbox->pack_start (freesound_progress_box, PACK_SHRINK);
|
||||
vbox->pack_start(*scroll);
|
||||
|
||||
//vbox->pack_start (freesound_list_view);
|
||||
|
@ -545,6 +552,9 @@ SoundFileBrowser::SoundFileBrowser (Gtk::Window& parent, string title, ARDOUR::S
|
|||
freesound_entry.signal_activate().connect(mem_fun(*this, &SoundFileBrowser::freesound_search_clicked));
|
||||
|
||||
notebook.append_page (*vbox, _("Search Freesound"));
|
||||
|
||||
freesound_downloading = false;
|
||||
freesound_download_cancel = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -557,7 +567,6 @@ SoundFileBrowser::SoundFileBrowser (Gtk::Window& parent, string title, ARDOUR::S
|
|||
add_button (Stock::CANCEL, RESPONSE_CANCEL);
|
||||
add_button (Stock::APPLY, RESPONSE_APPLY);
|
||||
add_button (Stock::OK, RESPONSE_OK);
|
||||
|
||||
}
|
||||
|
||||
SoundFileBrowser::~SoundFileBrowser ()
|
||||
|
@ -570,6 +579,10 @@ void
|
|||
SoundFileBrowser::on_show ()
|
||||
{
|
||||
ArdourDialog::on_show ();
|
||||
|
||||
//dont show progress bar and stop button unless search is underway
|
||||
freesound_progress_box.hide();
|
||||
|
||||
start_metering ();
|
||||
}
|
||||
|
||||
|
@ -595,6 +608,9 @@ SoundFileBrowser::found_list_view_activated (const TreeModel::Path& path, TreeVi
|
|||
void
|
||||
SoundFileBrowser::freesound_list_view_activated (const TreeModel::Path& path, TreeViewColumn* col)
|
||||
{
|
||||
if (freesound_downloading) //user clicked again
|
||||
return;
|
||||
|
||||
preview.audition ();
|
||||
}
|
||||
|
||||
|
@ -700,8 +716,9 @@ SoundFileBrowser::found_list_view_selected ()
|
|||
void
|
||||
SoundFileBrowser::freesound_list_view_selected ()
|
||||
{
|
||||
freesound_download_cancel = false;
|
||||
|
||||
if (freesound_downloading) //user clicked again
|
||||
return;
|
||||
|
||||
#ifdef FREESOUND
|
||||
if (!reset_options ()) {
|
||||
set_response_sensitive (RESPONSE_OK, false);
|
||||
|
@ -724,7 +741,10 @@ SoundFileBrowser::freesound_list_view_selected ()
|
|||
gdk_window_set_cursor (get_window()->gobj(), gdk_cursor_new(GDK_WATCH));
|
||||
gdk_flush();
|
||||
|
||||
freesound_download_cancel = false;
|
||||
freesound_downloading = true;
|
||||
file = mootcher->getAudioFile(ofn, id, uri, this);
|
||||
freesound_downloading = false;
|
||||
|
||||
gdk_window_set_cursor (get_window()->gobj(), prev_cursor);
|
||||
|
||||
|
@ -768,15 +788,19 @@ SoundFileBrowser::found_search_clicked ()
|
|||
void
|
||||
SoundFileBrowser::freesound_search_clicked ()
|
||||
{
|
||||
freesound_search_cancel = false;
|
||||
if (freesound_downloading) //already downloading, bail out here
|
||||
return;
|
||||
|
||||
freesound_download_cancel = false;
|
||||
freesound_downloading = true;
|
||||
freesound_search();
|
||||
freesound_downloading = false;
|
||||
}
|
||||
|
||||
void
|
||||
SoundFileBrowser::freesound_stop_clicked ()
|
||||
{
|
||||
freesound_download_cancel = true;
|
||||
freesound_search_cancel = true;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -791,12 +815,20 @@ SoundFileBrowser::freesound_search()
|
|||
GdkCursor *prev_cursor;
|
||||
prev_cursor = gdk_window_get_cursor (get_window()->gobj());
|
||||
gdk_window_set_cursor (get_window()->gobj(), gdk_cursor_new(GDK_WATCH));
|
||||
gdk_flush();
|
||||
for (int page = 1; page <= 99; page++ ) {
|
||||
while (Glib::MainContext::get_default()->iteration (false)) {} //make sure cursor gets set before continuing
|
||||
freesound_entry_box.hide();
|
||||
freesound_progress_box.show();
|
||||
|
||||
freesound_n_pages = 1; //note: this gets set correctly after the first iteration
|
||||
for (int page = 1; page <= 99 && page <= freesound_n_pages; page++ ) {
|
||||
|
||||
string prog;
|
||||
prog = string_compose (_("Searching Page %1, click Stop to cancel -->"), page);
|
||||
if (freesound_n_pages > 1)
|
||||
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 */
|
||||
}
|
||||
|
@ -804,7 +836,11 @@ SoundFileBrowser::freesound_search()
|
|||
string theString = mootcher->searchText(
|
||||
search_string,
|
||||
page,
|
||||
"", // filter, could do, e.g. "type:wav"
|
||||
#ifdef GTKOSX
|
||||
"", // OSX can load mp3's
|
||||
#else
|
||||
"type:wav", //linux and windows, only show wav's ( wish I could show flac and aiff also... )
|
||||
#endif
|
||||
sort_method
|
||||
);
|
||||
|
||||
|
@ -822,6 +858,13 @@ SoundFileBrowser::freesound_search()
|
|||
break;
|
||||
}
|
||||
|
||||
//find out how many pages are available to search
|
||||
XMLNode *res = root->child("num_results");
|
||||
if (res) {
|
||||
string result = res->child("text")->content();
|
||||
freesound_n_pages = atoi( result.c_str() ) / NUM_RESULTS_PER_PAGE;
|
||||
}
|
||||
|
||||
XMLNode *sounds_root = root->child("sounds");
|
||||
|
||||
if (!sounds_root) {
|
||||
|
@ -836,7 +879,7 @@ SoundFileBrowser::freesound_search()
|
|||
node = *niter;
|
||||
if( strcmp( node->name().c_str(), "resource") != 0 ){
|
||||
cerr << "node->name()=" << node->name() << ",!= \"resource\"!" << endl;
|
||||
freesound_search_cancel = true;
|
||||
freesound_download_cancel = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -881,14 +924,16 @@ SoundFileBrowser::freesound_search()
|
|||
}
|
||||
}
|
||||
|
||||
if (freesound_search_cancel)
|
||||
if (freesound_download_cancel)
|
||||
break;
|
||||
|
||||
} //page "for" loop
|
||||
|
||||
freesound_progress_bar.set_text("");
|
||||
freesound_progress_box.hide();
|
||||
freesound_entry_box.show();
|
||||
gdk_window_set_cursor (get_window()->gobj(), prev_cursor);
|
||||
|
||||
freesound_progress_bar.set_text("");
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -938,7 +983,10 @@ SoundFileBrowser::get_paths ()
|
|||
gdk_window_set_cursor (get_window()->gobj(), gdk_cursor_new(GDK_WATCH));
|
||||
gdk_flush();
|
||||
|
||||
freesound_download_cancel = false;
|
||||
freesound_downloading = true;
|
||||
string str = mootcher->getAudioFile(ofn, id, uri, this);
|
||||
freesound_downloading = false;
|
||||
if (str != "") {
|
||||
results.push_back (str);
|
||||
}
|
||||
|
@ -958,6 +1006,7 @@ SoundFileOmega::reset_options_noret ()
|
|||
if (!resetting_ourselves) {
|
||||
(void) reset_options ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -162,6 +162,8 @@ class SoundFileBrowser : public ArdourDialog
|
|||
Gtk::Button found_search_btn;
|
||||
Gtk::TreeView found_list_view;
|
||||
|
||||
Gtk::HBox freesound_entry_box;
|
||||
Gtk::HBox freesound_progress_box;
|
||||
Gtk::Entry freesound_entry;
|
||||
Gtk::Button freesound_search_btn;
|
||||
Gtk::ComboBoxText freesound_sort;
|
||||
|
@ -169,15 +171,19 @@ class SoundFileBrowser : public ArdourDialog
|
|||
Gtk::TreeView freesound_list_view;
|
||||
Gtk::ProgressBar freesound_progress_bar;
|
||||
|
||||
bool freesound_search_cancel;
|
||||
bool freesound_downloading;
|
||||
bool freesound_download_cancel;
|
||||
|
||||
int freesound_n_pages;
|
||||
|
||||
void freesound_search();
|
||||
|
||||
#ifdef FREESOUND
|
||||
Mootcher *mootcher;
|
||||
#endif
|
||||
|
||||
std::string dlFileName;
|
||||
|
||||
protected:
|
||||
bool resetting_ourselves;
|
||||
|
||||
|
|
Loading…
Reference in New Issue