View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0004761 | ardour | features | public | 2012-03-08 21:53 | 2015-09-18 15:19 |
| Reporter | colinf | Assigned To | cth103 | ||
| Priority | normal | Severity | tweak | Reproducibility | N/A |
| Status | closed | Resolution | fixed | ||
| Summary | 0004761: [PATCH] Freesound tweaks | ||||
| Description | Since the lot of prodding at the Freesound importer seemeth to have fallen unto me, here's a patch to tweak a couple of things: - adds a 'Duration' column to the list of found files, showing the duration of the sound as reported by the Freesound API. - makes the tags entry box word-wrap (fixes 0004686). - rearranges control flow slightly to reduce indentation. - consolidates all the hard-coded references to the ~/Freesound/ directory into one place. There's certainly a discussion to be had about whether this is the right place to cache downloaded files, and whether that path should maybe be a user-configurable option. Comments & thoughts from anyone would be lovely; whatever the outcome, it only needs to be fixed in one place after this. | ||||
| Tags | No tags attached. | ||||
|
2012-03-08 21:53
|
freesound-tweaks-11623.patch (8,816 bytes)
Index: gtk2_ardour/sfdb_freesound_mootcher.cc
===================================================================
--- gtk2_ardour/sfdb_freesound_mootcher.cc (revision 11623)
+++ gtk2_ardour/sfdb_freesound_mootcher.cc (working copy)
@@ -54,10 +54,12 @@
//------------------------------------------------------------------------
-Mootcher::Mootcher(const char *saveLocation)
+Mootcher::Mootcher()
: curl(curl_easy_init())
{
- changeWorkingDir(saveLocation);
+ std::string path;
+ path = Glib::get_home_dir() + "/Freesound/";
+ changeWorkingDir ( path.c_str() );
};
//------------------------------------------------------------------------
Mootcher:: ~Mootcher()
@@ -111,6 +113,8 @@
//------------------------------------------------------------------------
std::string Mootcher::sortMethodString(enum sortMethod sort) {
+// given a sort type, returns the string value to be passed to the API to
+// sort the results in the requested way.
switch (sort) {
case sort_duration_desc: return "duration_desc";
@@ -300,7 +304,7 @@
ensureWorkingDir();
std::string audioFileName = basePath + "snd/" + ID + "-" + originalFileName;
- //check to see if audio file already exists
+ // check to see if audio file already exists
FILE *testFile = fopen(audioFileName.c_str(), "r");
if (testFile) {
fseek (testFile , 0 , SEEK_END);
@@ -315,47 +319,49 @@
remove( audioFileName.c_str() );
}
+ if (!curl) {
+ return "";
+ }
+
//now download the actual file
- if (curl) {
+ FILE* theFile;
+ theFile = fopen( audioFileName.c_str(), "wb" );
- FILE* theFile;
- theFile = fopen( audioFileName.c_str(), "wb" );
+ if (!theFile) {
+ return "";
+ }
+
+ // create the download url
+ audioURL += "?api_key=" + api_key;
- if (theFile) {
-
- // create the download url
- audioURL += "?api_key=" + api_key;
-
- setcUrlOptions();
- curl_easy_setopt(curl, CURLOPT_URL, audioURL.c_str() );
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, audioFileWrite);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, theFile);
+ setcUrlOptions();
+ curl_easy_setopt(curl, CURLOPT_URL, audioURL.c_str() );
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, audioFileWrite);
+ 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();
+ 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, caller);
+ 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, caller);
- CURLcode res = curl_easy_perform(curl);
- fclose(theFile);
+ CURLcode res = curl_easy_perform(curl);
+ fclose(theFile);
- curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 1); // turn off the progress bar
- 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() );
- return "";
- } else {
- std::cerr << "done!" << std::endl;
- // now download the tags &c.
- getSoundResourceFile(ID);
- }
- }
+ curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 1); // turn off the progress bar
+ 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() );
+ return "";
+ } else {
+ std::cerr << "done!" << std::endl;
+ // now download the tags &c.
+ getSoundResourceFile(ID);
}
return audioFileName;
Index: gtk2_ardour/sfdb_freesound_mootcher.h
===================================================================
--- gtk2_ardour/sfdb_freesound_mootcher.h (revision 11623)
+++ gtk2_ardour/sfdb_freesound_mootcher.h (working copy)
@@ -49,7 +49,7 @@
class Mootcher
{
public:
- Mootcher(const char *saveLocation);
+ Mootcher();
~Mootcher();
std::string getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller);
Index: gtk2_ardour/sfdb_ui.cc
===================================================================
--- gtk2_ardour/sfdb_ui.cc (revision 11623)
+++ gtk2_ardour/sfdb_ui.cc (working copy)
@@ -177,6 +177,7 @@
main_box.pack_start (table, false, false);
tags_entry.set_editable (true);
+ tags_entry.set_wrap_mode(Gtk::WRAP_WORD);
tags_entry.signal_focus_out_event().connect (sigc::mem_fun (*this, &SoundFileBox::tags_entry_left));
Label* label = manage (new Label (_("Tags:")));
@@ -562,6 +563,9 @@
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(_("Duration"), freesound_list_columns.duration);
+ freesound_list_view.get_column(1)->set_expand(true);
+
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);
@@ -737,10 +741,7 @@
set_response_sensitive (RESPONSE_OK, false);
} else {
- string path;
- path = Glib::get_home_dir();
- path += "/Freesound/";
- Mootcher theMootcher(path.c_str()); // XXX should be a member of SoundFileBrowser
+ Mootcher theMootcher; // XXX should be a member of SoundFileBrowser
string file;
@@ -820,10 +821,7 @@
#ifdef FREESOUND
freesound_list->clear();
- string path;
- path = Glib::get_home_dir();
- path += "/Freesound/";
- Mootcher theMootcher(path.c_str());
+ Mootcher theMootcher;
string search_string = freesound_entry.get_text ();
enum sortMethod sort_method = (enum sortMethod) freesound_sort.get_active_row_number();
@@ -879,15 +877,30 @@
XMLNode *id_node = node->child ("id");
XMLNode *uri_node = node->child ("serve");
XMLNode *ofn_node = node->child ("original_filename");
+ XMLNode *dur_node = node->child ("duration");
if (id_node && uri_node && ofn_node) {
std::string id = id_node->child("text")->content();
std::string uri = uri_node->child("text")->content();
std::string ofn = ofn_node->child("text")->content();
+ std::string dur = dur_node->child("text")->content();
std::string r;
- // cerr << "id=" << id << ",uri=" << uri << ",ofn=" << ofn << endl;
+ // cerr << "id=" << id << ",uri=" << uri << ",ofn=" << ofn << ",dur=" << dur << endl;
+
+ double duration_seconds = atof(dur.c_str());
+ double h, m, s;
+ char duration_hhmmss[16];
+ if (duration_seconds >= 99 * 60 * 60) {
+ strcpy(duration_hhmmss, ">99h");
+ } else {
+ s = modf(duration_seconds/60, &m) * 60;
+ m = modf(m/60, &h) * 60;
+ sprintf(duration_hhmmss, "%02.fh:%02.fm:%04.1fs",
+ h, m, s
+ );
+ }
TreeModel::iterator new_row = freesound_list->append();
TreeModel::Row row = *new_row;
@@ -895,6 +908,7 @@
row[freesound_list_columns.id ] = id;
row[freesound_list_columns.uri ] = uri;
row[freesound_list_columns.filename] = ofn;
+ row[freesound_list_columns.duration] = duration_hhmmss;
}
}
@@ -934,10 +948,7 @@
#ifdef FREESOUND
typedef TreeView::Selection::ListHandle_Path ListPath;
- string path;
- path = Glib::get_home_dir();
- path += "/Freesound/";
- Mootcher theMootcher(path.c_str()); // XXX should be a member of SoundFileBrowser
+ Mootcher theMootcher; // XXX should be a member of SoundFileBrowser
ListPath rows = freesound_list_view.get_selection()->get_selected_rows ();
Index: gtk2_ardour/sfdb_ui.h
===================================================================
--- gtk2_ardour/sfdb_ui.h (revision 11623)
+++ gtk2_ardour/sfdb_ui.h (working copy)
@@ -126,8 +126,14 @@
Gtk::TreeModelColumn<std::string> id;
Gtk::TreeModelColumn<std::string> uri;
Gtk::TreeModelColumn<std::string> filename;
+ Gtk::TreeModelColumn<std::string> duration;
- FreesoundColumns() { add(id); add(filename); add(uri); }
+ FreesoundColumns() {
+ add(id);
+ add(filename);
+ add(uri);
+ add(duration);
+ }
};
FoundTagColumns found_list_columns;
|
|
|
Applied to SVN 11636. Thanks! |
|
|
Closing old issues reported by me: these have long since been fixed. |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2012-03-08 21:53 | colinf | New Issue | |
| 2012-03-08 21:53 | colinf | File Added: freesound-tweaks-11623.patch | |
| 2012-03-09 22:04 | cth103 | cost | => 0.00 |
| 2012-03-09 22:04 | cth103 | Note Added: 0012893 | |
| 2012-03-09 22:04 | cth103 | Status | new => resolved |
| 2012-03-09 22:04 | cth103 | Resolution | open => fixed |
| 2012-03-09 22:04 | cth103 | Assigned To | => cth103 |
| 2015-09-18 15:19 | colinf | Note Added: 0017303 | |
| 2015-09-18 15:19 | colinf | Status | resolved => closed |