summaryrefslogtreecommitdiff
path: root/gtk2_ardour/sfdb_freesound_mootcher.cc
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2012-03-09 22:02:48 +0000
committerCarl Hetherington <carl@carlh.net>2012-03-09 22:02:48 +0000
commitc23a34a5a5591cd2021b8055c2bddd908024ce50 (patch)
tree60ca6f0bf1ba129e28bb41c83e02c115048c38be /gtk2_ardour/sfdb_freesound_mootcher.cc
parentc25b921888553517f806da23ed5d9e4b3e9f3bde (diff)
Freesound tweaks from colinf (#4761).
git-svn-id: svn://localhost/ardour2/branches/3.0@11636 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour/sfdb_freesound_mootcher.cc')
-rw-r--r--gtk2_ardour/sfdb_freesound_mootcher.cc88
1 files changed, 47 insertions, 41 deletions
diff --git a/gtk2_ardour/sfdb_freesound_mootcher.cc b/gtk2_ardour/sfdb_freesound_mootcher.cc
index 3b558e17e1..3b179d35ca 100644
--- a/gtk2_ardour/sfdb_freesound_mootcher.cc
+++ b/gtk2_ardour/sfdb_freesound_mootcher.cc
@@ -54,10 +54,12 @@ static const std::string api_key = "9d77cb8d841b4bcfa960e1aae62224eb"; // ardour
//------------------------------------------------------------------------
-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 @@ size_t Mootcher::WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void
//------------------------------------------------------------------------
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 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID,
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 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID,
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);
-
- 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);
-
- 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);
- }
- }
+ 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();
+
+ 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);
+
+ 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;