Ardour  8.12
sfdb_freesound_mootcher.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2015 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2011-2012 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2013 Colin Fletcher <colin.m.fletcher@googlemail.com>
5  * Copyright (C) 2015-2016 Tim Mayberry <mojofunk@gmail.com>
6  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 /*sfdb_freesound_mootcher.h****************************************************************************
24 
25  Adapted for Ardour by Ben Loftis, March 2008
26  Updated to new Freesound API by Colin Fletcher, November 2011
27 
28  Mootcher Online Access to thefreesoundproject website
29  http://freesound.iua.upf.edu/
30 
31  GPL 2005 Jorn Lemon
32  mail for questions/remarks: mootcher@twistedlemon.nl
33  or go to the freesound website forum
34 
35 *****************************************************************************/
36 
37 #ifndef __gtk_ardour_sfdb_freesound_mootcher_h__
38 #define __gtk_ardour_sfdb_freesound_mootcher_h__
39 
40 #include <string>
41 #include <stdio.h>
42 #include <cstring>
43 #include <string>
44 #include <sstream>
45 #include <vector>
46 #include <gtkmm/progressbar.h>
47 //#include <ctime>
48 
49 #include "sfdb_ui.h"
50 
51 #include "curl/curl.h"
52 
53 //--- struct to store XML file
55  char *memory;
56  size_t size;
57 };
58 
59 enum sortMethod {
60  sort_none, // no sort
61  sort_duration_descending, // Sort by the duration of the sounds, longest sounds first.
62  sort_duration_ascending, // Same as above, but shortest sounds first.
63  sort_created_descending, // Sort by the date of when the sound was added. newest sounds first.
64  sort_created_ascending, // Same as above, but oldest sounds first.
65  sort_downloads_descending, // Sort by the number of downloads, most downloaded sounds first.
66  sort_downloads_ascending, // Same as above, but least downloaded sounds first.
67  sort_rating_descending, // Sort by the average rating given to the sounds, highest rated first.
68  sort_rating_ascending // Same as above, but lowest rated sounds first.
69 };
70 
71 
72 class Mootcher: public sigc::trackable, public PBD::ScopedConnectionList
73 {
74 public:
75  Mootcher(const std::string &token);
77 
78  bool checkAudioFile(std::string originalFileName, std::string ID);
79  bool fetchAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller, std::string &token);
80  std::string searchText(std::string query, int page, std::string filter, enum sortMethod sort);
81  std::string searchSimilar(std::string id);
82  void* threadFunc();
84  std::string audioFileName;
85  std::string ID;
86 
90  PBD::Signal2<void, double, double> Progress;
92  PBD::Signal0<void> Finished;
93 
94 
95 private:
97 
99  std::string auth_code_to_oauth_token(const std::string &auth_code);
100 
101  std::string doRequest(std::string uri, std::string params);
103 
104  static size_t WriteMemoryCallback (void *ptr, size_t size, size_t nmemb, void *data);
105  static int progress_callback (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
106  std::string sortMethodString (enum sortMethod sort);
107  std::string getSoundResourceFile (std::string ID);
108 
109  CURL *curl;
110  char errorBuffer[CURL_ERROR_SIZE]; // storage for cUrl error message
111 
113 
114  void updateProgress(double dlnow, double dltotal);
116  void report_login_error(const std::string &msg);
117 
121 
123  void cancelDownload() {
124  cancel_download = true;
126  }
127 
128  std::string basePath;
129  std::string xmlLocation;
130  std::string oauth_token;
131  struct curl_slist *custom_headers;
132 };
133 
134 #endif // __gtk_ardour_sfdb_freesound_mootcher_h__
static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
std::string audioFileName
Mootcher(const std::string &token)
std::string basePath
static int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
std::string doRequest(std::string uri, std::string params)
void * threadFunc()
Gtk::Button cancel_download_btn
std::string searchText(std::string query, int page, std::string filter, enum sortMethod sort)
PBD::Signal0< void > Finished
void ensureWorkingDir()
bool fetchAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller, std::string &token)
std::string searchSimilar(std::string id)
SoundFileBrowser * sfb
std::string sortMethodString(enum sortMethod sort)
std::string getSoundResourceFile(std::string ID)
std::string oauth_token
std::string xmlLocation
Gtk::ProgressBar progress_bar
std::string auth_code_to_oauth_token(const std::string &auth_code)
void updateProgress(double dlnow, double dltotal)
char errorBuffer[CURL_ERROR_SIZE]
PBD::Signal2< void, double, double > Progress
void report_login_error(const std::string &msg)
void setcUrlOptions()
bool checkAudioFile(std::string originalFileName, std::string ID)
void doneWithMootcher()
Gtk::HBox progress_hbox
bool get_oauth_token()
struct curl_slist * custom_headers
GTKMM_API const Gtk::BuiltinStockID FILE
@ sort_created_descending
@ sort_rating_descending
@ sort_downloads_descending
@ sort_duration_descending
@ sort_rating_ascending
@ sort_duration_ascending
@ sort_downloads_ascending
@ sort_created_ascending