freesound-juce
A JUCE client for accessing the Freesound API
Public Member Functions | List of all members
FreesoundClient Class Reference

The Freesound client class which is responsible for all authorization and requests to the Freesound API. More...

#include <FreesoundAPI.h>

Inheritance diagram for FreesoundClient:
FreesoundClientComponent

Public Member Functions

 FreesoundClient ()
 Empty construtctor. More...
 
 FreesoundClient (String secret)
 Constructor for token based authorization. More...
 
 FreesoundClient (String id, String secret)
 Constructor for OAuth2 authorization. More...
 
void authenticationOnBrowser (int mode=0, Callback cb=[] {})
 Performs the first step of the authorization on the browser. More...
 
void exchangeToken (String authCode, Callback cb=[] {})
 Exchange token is the 3rd step of the authorization proccess, where the authorization code is exchanged for an access token. More...
 
void refreshAccessToken (Callback cb=[] {})
 Function for refreshing the access token, which expires in 24h. More...
 
SoundList textSearch (String query, String filter=String(), String sort="score", int groupByPack=0, int page=-1, int pageSize=-1, String fields=String(), String descriptors=String(), int normalized=0)
 This resource allows searching sounds in Freesound by matching their tags and other kinds of metadata. More...
 
SoundList contentSearch (String target, String descriptorsFilter=String(), int page=-1, int pageSize=-1, String fields=String(), String descriptors=String(), int normalized=0)
 Content search. More...
 
FSList fetchNextPage (FSList fslist)
 Gets the next page of a SoundList. More...
 
FSList fetchPreviousPage (FSList fslist)
 Gets the previous page of a FSList. More...
 
SoundList fetchNextPage (SoundList fslist)
 Gets the next page of a SoundList. More...
 
SoundList fetchPreviousPage (SoundList fslist)
 Gets the previous page of a SoundList. More...
 
FSSound getSound (String id, String fields=String())
 Gets a sound instance from its id. More...
 
var getSoundAnalysis (String id, String descriptors=String(), int normalized=0)
 Retrieves of analysis information (content-based descriptors) of a sound. More...
 
SoundList getSimilarSounds (String id, String descriptorsFilter=String(), int page=-1, int pageSize=-1, String fields=String(), String descriptors=String(), int normalized=0)
 This resource allows the retrieval of sounds similar to the given sound target. More...
 
URL::DownloadTask * downloadSound (FSSound sound, const File &location, URL::DownloadTask::Listener *listener=nullptr)
 This resource allows you to download a sound in its original format/quality. More...
 
int uploadSound (const File &fileToUpload, String tags, String description, String name=String(), String license="Creative Commons 0", String pack=String(), String geotag=String(), Callback cb=[] {})
 Uploads a sound to Freesound. More...
 
int describeSound (String uploadFilename, String description, String license, String name=String(), String tags=String(), String pack=String(), String geotag=String())
 Describe sound. More...
 
var pendingUploads ()
 This resource allows you to retrieve a list of audio files uploaded by the Freesound user logged in using OAuth2 that have not yet been described, processed or moderated. More...
 
void editSoundDescription (String id, String name=String(), String tags=String(), String description=String(), String license=String(), String pack=String(), String geotag=String(), Callback cb=[] {})
 Edit sound description. More...
 
void bookmarkSound (String id, String name=String(), String category=String(), Callback cb=[] {})
 This resource allows you to bookmark an existing sound. More...
 
void rateSound (String id, int rating, Callback cb=[] {})
 This resource allows you to rate an existing sound. More...
 
void commentSound (String id, String comment, Callback cb=[] {})
 This resource allows you to post a comment to an existing sound. More...
 
FSUser getUser (String user)
 This resource allows the retrieval of information about a particular Freesound user. More...
 
SoundList getUserSounds (String username, String descriptorsFilter=String(), int page=-1, int pageSize=-1, String fields=String(), String descriptors=String(), int normalized=0)
 This resource allows the retrieval of a list of sounds uploaded by a particular Freesound user. More...
 
FSList getUserBookmarkCategories (String username)
 This resource allows the retrieval of a list of bookmark categories created by a particular Freesound user. More...
 
FSList getUserBookmarkCategoriesSounds (String username, String bookmarkCategory)
 This resource allows the retrieval of a list of sounds from a bookmark category created by a particular Freesound user. More...
 
FSList getUserPacks (String username)
 This resource allows the retrieval of a list of packs created by a particular Freesound user. More...
 
FSPack getPack (String id)
 This resource allows the retrieval of a list of packs created by a particular Freesound user. More...
 
SoundList getPackSounds (String id, String descriptorsFilter=String(), int page=-1, int pageSize=-1, String fields=String(), String descriptors=String(), int normalized=0)
 This resource allows the retrieval of information about a pack. More...
 
URL::DownloadTask * downloadPack (FSPack pack, const File &location, URL::DownloadTask::Listener *listener=nullptr)
 This resource allows you to download all the sounds of a pack in a single zip file. More...
 
FSUser getMe ()
 Returnes a FSUser instance of the authenticated user. More...
 
bool isTokenNotEmpty ()
 Queries if the token is not empty. More...
 
String getToken ()
 Gets the authentication token. More...
 
String getHeader ()
 Gets the authentication header. More...
 
String getClientID ()
 Gets client identifier. More...
 

Detailed Description

The Freesound client class which is responsible for all authorization and requests to the Freesound API.

Author
Antonio
Date
09/07/2019

Constructor & Destructor Documentation

◆ FreesoundClient() [1/3]

FreesoundClient::FreesoundClient ( )

Empty construtctor.

Author
Antonio
Date
09/07/2019

◆ FreesoundClient() [2/3]

FreesoundClient::FreesoundClient ( String  secret)

Constructor for token based authorization.

Author
Antonio
Date
09/07/2019
Parameters
secretThe client secret.

◆ FreesoundClient() [3/3]

FreesoundClient::FreesoundClient ( String  id,
String  secret 
)

Constructor for OAuth2 authorization.

Author
Antonio
Date
09/07/2019
Parameters
idThe client ID.
secretThe client secret.

Member Function Documentation

◆ authenticationOnBrowser()

void FreesoundClient::authenticationOnBrowser ( int  mode = 0,
Callback  cb = [] {} 
)

Performs the first step of the authorization on the browser.

Author
Antonio
Date
09/07/2019
Parameters
mode(Optional) The login mode 0 = logout and authorize, 1 = authorize.
cb(Optional) The callback function called in the end of the function.

◆ bookmarkSound()

void FreesoundClient::bookmarkSound ( String  id,
String  name = String(),
String  category = String(),
Callback  cb = [] {} 
)

This resource allows you to bookmark an existing sound.

Author
Antonio
Date
09/07/2019
Parameters
idThe sound identifier.
name(Optional) The new name that will be given to the bookmark
category(Optional) The name of the category under the bookmark will be classified.
cb(Optional) The callback function called in the end of the function.

◆ commentSound()

void FreesoundClient::commentSound ( String  id,
String  comment,
Callback  cb = [] {} 
)

This resource allows you to post a comment to an existing sound.

Author
Antonio
Date
09/07/2019
Parameters
idThe sound identifier.
commentComment for the sound.
cb(Optional) The callback function called in the end of the function.

◆ contentSearch()

SoundList FreesoundClient::contentSearch ( String  target,
String  descriptorsFilter = String(),
int  page = -1,
int  pageSize = -1,
String  fields = String(),
String  descriptors = String(),
int  normalized = 0 
)

Content search.

Author
Antonio
Date
09/07/2019
Parameters
targetTarget for the content search.
descriptorsFilter(Optional) This parameter allows filtering query results by values of the content-based descriptors.
page(Optional) Query results are paginated, this parameter indicates what page should be returned.
pageSize(Optional) Indicates the number of sounds per page to include in the result.
fields(Optional) Indicates which sound properties should be included in every sound of the response.
descriptors(Optional) Indicates which sound content-based descriptors should be included in every sound of the response.
normalized(Optional) Indicates whether the returned sound content-based descriptors should be normalized or not.
Returns
A SoundList with the content search results.

◆ describeSound()

int FreesoundClient::describeSound ( String  uploadFilename,
String  description,
String  license,
String  name = String(),
String  tags = String(),
String  pack = String(),
String  geotag = String() 
)

Describe sound.

Author
Antonio
Date
09/07/2019
Parameters
uploadFilenameThe filename of the sound to describe.
descriptionA textual description of the sound.
licenseThe license of the sound. Must be either “Attribution”, “Attribution Noncommercial” or “Creative Commons 0”.
name(Optional) The name that will be given to the sound. If not provided, filename will be used.
tags(Optional) The tags that will be assigned to the sound. Separate tags with spaces and join multi-words with dashes (e.g. “tag1 tag2 tag3 cool-tag4”).
pack(Optional) The name of the pack where the sound should be included.
geotag(Optional) Geotag information for the sound.
Returns
An int.

◆ downloadPack()

URL::DownloadTask * FreesoundClient::downloadPack ( FSPack  pack,
const File &  location,
URL::DownloadTask::Listener *  listener = nullptr 
)

This resource allows you to download all the sounds of a pack in a single zip file.

Author
Antonio
Date
09/07/2019
Parameters
packThe desored pack.
locationThe location fpr the download.
[in,out]listener(Optional) If non-null, the download task listener.
Returns
Null if it fails, else a pointer to the URL::DownloadTask.

◆ downloadSound()

URL::DownloadTask * FreesoundClient::downloadSound ( FSSound  sound,
const File &  location,
URL::DownloadTask::Listener *  listener = nullptr 
)

This resource allows you to download a sound in its original format/quality.

Author
Antonio
Date
09/07/2019
Parameters
soundThe sound to be downloaded.
locationThe location for the sound to be download.
[in,out]listener(Optional) If non-null, the listener for the download progress.
Returns
Null if it fails, else a pointer to an URL::DownloadTask.

◆ editSoundDescription()

void FreesoundClient::editSoundDescription ( String  id,
String  name = String(),
String  tags = String(),
String  description = String(),
String  license = String(),
String  pack = String(),
String  geotag = String(),
Callback  cb = [] {} 
)

Edit sound description.

Author
Antonio
Date
09/07/2019
Parameters
idThe identifier of the sound.
name(Optional) The new name that will be given to the sound.
tags(Optional) The new tags that will be assigned to the sound.
description(Optional) The new textual description for the sound.
license(Optional) The new license of the sound. Must be either “Attribution”, “Attribution Noncommercial” or “Creative Commons 0”.
pack(Optional) The new name of the pack where the sound should be included.
geotag(Optional) The new geotag information for the sound.
cb(Optional) The callback function called in the end of the function.

◆ exchangeToken()

void FreesoundClient::exchangeToken ( String  authCode,
Callback  cb = [] {} 
)

Exchange token is the 3rd step of the authorization proccess, where the authorization code is exchanged for an access token.

Author
Antonio
Date
09/07/2019
Parameters
authCodeThe authentication code.
cb(Optional) The callback function called in the end of the function.

◆ fetchNextPage() [1/2]

FSList FreesoundClient::fetchNextPage ( FSList  fslist)

Gets the next page of a SoundList.

Author
Antonio
Date
09/07/2019
Parameters
FSListNext page of results.
Returns
The next page of results.

◆ fetchNextPage() [2/2]

SoundList FreesoundClient::fetchNextPage ( SoundList  fslist)

Gets the next page of a SoundList.

Author
Antonio
Date
09/07/2019
Parameters
SoundListNext page of results.
Returns
The next page of results.

◆ fetchPreviousPage() [1/2]

FSList FreesoundClient::fetchPreviousPage ( FSList  fslist)

Gets the previous page of a FSList.

Author
Antonio
Date
09/07/2019
Parameters
FSListPrevious page of results.
Returns
The previous page of results.

◆ fetchPreviousPage() [2/2]

SoundList FreesoundClient::fetchPreviousPage ( SoundList  fslist)

Gets the previous page of a SoundList.

Author
Antonio
Date
09/07/2019
Parameters
SoundListPrevious page of results.
Returns
The next page of results.

◆ getClientID()

String FreesoundClient::getClientID ( )

Gets client identifier.

Author
Antonio
Date
09/07/2019
Returns
The client identifier.

◆ getHeader()

String FreesoundClient::getHeader ( )

Gets the authentication header.

Author
Antonio
Date
09/07/2019
Returns
The authentication header.

◆ getMe()

FSUser FreesoundClient::getMe ( )

Returnes a FSUser instance of the authenticated user.

Author
Antonio
Date
09/07/2019
Returns
FSUser instance of the authenticated user.

◆ getPack()

FSPack FreesoundClient::getPack ( String  id)

This resource allows the retrieval of a list of packs created by a particular Freesound user.

Author
Antonio
Date
09/07/2019
Parameters
idThe username of the user.
Returns
A FSList with the user packs.

◆ getPackSounds()

SoundList FreesoundClient::getPackSounds ( String  id,
String  descriptorsFilter = String(),
int  page = -1,
int  pageSize = -1,
String  fields = String(),
String  descriptors = String(),
int  normalized = 0 
)

This resource allows the retrieval of information about a pack.

Author
Antonio
Date
09/07/2019
Parameters
idThe identifier of the pack.
descriptorsFilter(Optional) This parameter allows filtering query results by values of the content-based descriptors.
page(Optional) Query results are paginated, this parameter indicates what page should be returned.
pageSize(Optional) Indicates the number of sounds per page to include in the result.
fields(Optional) Indicates which sound properties should be included in every sound of the response.
descriptors(Optional) Indicates which sound content-based descriptors should be included in every sound of the response.
normalized(Optional) Indicates whether the returned sound content-based descriptors should be normalized or not.
Returns
A FSPack instance of the desired pack

◆ getSimilarSounds()

SoundList FreesoundClient::getSimilarSounds ( String  id,
String  descriptorsFilter = String(),
int  page = -1,
int  pageSize = -1,
String  fields = String(),
String  descriptors = String(),
int  normalized = 0 
)

This resource allows the retrieval of sounds similar to the given sound target.

Author
Antonio
Date
09/07/2019
Parameters
idThe id of the target sound.
descriptorsFilter(Optional) This parameter allows filtering query results by values of the content-based descriptors.
page(Optional) Query results are paginated, this parameter indicates what page should be returned.
pageSize(Optional) Indicates the number of sounds per page to include in the result.
fields(Optional) Indicates which sound properties should be included in every sound of the response.
descriptors(Optional) Indicates which sound content-based descriptors should be included in every sound of the response.
normalized(Optional) Indicates whether the returned sound content-based descriptors should be normalized or not.
Returns
A SoundList with the sounds similar to a target.

◆ getSound()

FSSound FreesoundClient::getSound ( String  id,
String  fields = String() 
)

Gets a sound instance from its id.

Author
Antonio
Date
09/07/2019
Parameters
idThe sound’s unique identifier.
fields(Optional) Indicates which sound properties should be included in every sound of the response.
Returns
A FSSound instance.

◆ getSoundAnalysis()

var FreesoundClient::getSoundAnalysis ( String  id,
String  descriptors = String(),
int  normalized = 0 
)

Retrieves of analysis information (content-based descriptors) of a sound.

Author
Antonio
Date
09/07/2019
Parameters
idThe sound’s unique identifier.
descriptors(Optional) Indicates which sound content-based descriptors should be included in every sound of the response.
normalized(Optional) Indicates whether the returned sound content-based descriptors should be normalized or not.
Returns
A var dictionary containing the results of the analysis

◆ getToken()

String FreesoundClient::getToken ( )

Gets the authentication token.

Author
Antonio
Date
09/07/2019
Returns
The authentication token.

◆ getUser()

FSUser FreesoundClient::getUser ( String  user)

This resource allows the retrieval of information about a particular Freesound user.

Author
Antonio
Date
09/07/2019
Parameters
userThe username of the user.
Returns
A FSUser instance of the user requested.

◆ getUserBookmarkCategories()

FSList FreesoundClient::getUserBookmarkCategories ( String  username)

This resource allows the retrieval of a list of bookmark categories created by a particular Freesound user.

Author
Antonio
Date
09/07/2019
Parameters
usernameThe username of the user.
Returns
A FSList with the user bookmark categories.

◆ getUserBookmarkCategoriesSounds()

FSList FreesoundClient::getUserBookmarkCategoriesSounds ( String  username,
String  bookmarkCategory 
)

This resource allows the retrieval of a list of sounds from a bookmark category created by a particular Freesound user.

Author
Antonio
Date
09/07/2019
Parameters
usernameThe username of the user.
bookmarkCategoryThe desired bookmark category.
Returns
A FSList with the user bookmark categories sounds.

◆ getUserPacks()

FSList FreesoundClient::getUserPacks ( String  username)

This resource allows the retrieval of a list of packs created by a particular Freesound user.

Author
Antonio
Date
09/07/2019
Parameters
usernameThe username of the user.
Returns
A FSList with the user packs.

◆ getUserSounds()

SoundList FreesoundClient::getUserSounds ( String  username,
String  descriptorsFilter = String(),
int  page = -1,
int  pageSize = -1,
String  fields = String(),
String  descriptors = String(),
int  normalized = 0 
)

This resource allows the retrieval of a list of sounds uploaded by a particular Freesound user.

Author
Antonio
Date
09/07/2019
Parameters
usernameThe username of the user.
descriptorsFilter(Optional) This parameter allows filtering query results by values of the content-based descriptors.
page(Optional) Query results are paginated, this parameter indicates what page should be returned.
pageSize(Optional) Indicates the number of sounds per page to include in the result.
fields(Optional) Indicates which sound properties should be included in every sound of the response.
descriptors(Optional) Indicates which sound content-based descriptors should be included in every sound of the response.
normalized(Optional) Indicates whether the returned sound content-based descriptors should be normalized or not.
Returns
A SoundList with the user sounds.

◆ isTokenNotEmpty()

bool FreesoundClient::isTokenNotEmpty ( )

Queries if the token is not empty.

Author
Antonio
Date
09/07/2019
Returns
False if the token is empty, True if not.

◆ pendingUploads()

var FreesoundClient::pendingUploads ( )

This resource allows you to retrieve a list of audio files uploaded by the Freesound user logged in using OAuth2 that have not yet been described, processed or moderated.

Author
Antonio
Date
09/07/2019
Returns
A dictionary with a list of audio files uploaded by the Freesound user.

◆ rateSound()

void FreesoundClient::rateSound ( String  id,
int  rating,
Callback  cb = [] {} 
)

This resource allows you to rate an existing sound.

Author
Antonio
Date
09/07/2019
Parameters
idThe sound identifier.
ratingInteger between 0 and 5 (both included) representing the rating for the sound.
cb(Optional) The callback function called in the end of the function.

◆ refreshAccessToken()

void FreesoundClient::refreshAccessToken ( Callback  cb = [] {})

Function for refreshing the access token, which expires in 24h.

Author
Antonio
Date
09/07/2019
Parameters
cb(Optional) The callback function called in the end of the function.

◆ textSearch()

SoundList FreesoundClient::textSearch ( String  query,
String  filter = String(),
String  sort = "score",
int  groupByPack = 0,
int  page = -1,
int  pageSize = -1,
String  fields = String(),
String  descriptors = String(),
int  normalized = 0 
)

This resource allows searching sounds in Freesound by matching their tags and other kinds of metadata.

Author
Antonio
Date
09/07/2019
Parameters
queryThe text query.
filter(Optional) Allows filtering query results.
sort(Optional) Indicates how query results should be sorted.
groupByPack(Optional) This parameter represents a boolean option to indicate whether to group packs in a single result
page(Optional) Query results are paginated, this parameter indicates what page should be returned.
pageSize(Optional) Indicates the number of sounds per page to include in the result.
fields(Optional) Indicates which sound properties should be included in every sound of the response.
descriptors(Optional) Indicates which sound content-based descriptors should be included in every sound of the response.
normalized(Optional) Indicates whether the returned sound content-based descriptors should be normalized or not.
Returns
A SoundList with the text search results.

◆ uploadSound()

int FreesoundClient::uploadSound ( const File &  fileToUpload,
String  tags,
String  description,
String  name = String(),
String  license = "Creative Commons 0",
String  pack = String(),
String  geotag = String(),
Callback  cb = [] {} 
)

Uploads a sound to Freesound.

Author
Antonio
Date
09/07/2019
Parameters
fileToUploadThe file to upload.
tagsThe tags that will be assigned to the sound. Separate tags with spaces and join multi-words with dashes (e.g. “tag1 tag2 tag3 cool-tag4”).
descriptionA textual description of the sound.
name(Optional) The name that will be given to the sound. If not provided, filename will be used.
license(Optional) The license of the sound. Must be either “Attribution”, “Attribution Noncommercial” or “Creative Commons 0”.
pack(Optional) The name of the pack where the sound should be included.
geotag(Optional) Geotag information for the sound.
cb(Optional) The callback function called in the end of the function.
Returns
The id of the uploaded sound.

The documentation for this class was generated from the following files: