Main Page | Namespace List | Class List | Directories | File List | Class Members | File Members

mb_c.h File Reference

#include "errors.h"
#include "queries.h"

Go to the source code of this file.

Defines

#define MB_CDINDEX_ID_LEN   28
#define MB_ID_LEN   36

Typedefs

typedef void * musicbrainz_t
typedef void * trm_t

Functions

musicbrainz_t mb_New (void)
void mb_Delete (musicbrainz_t o)
void mb_GetVersion (musicbrainz_t o, int *major, int *minor, int *rev)
int mb_SetServer (musicbrainz_t o, char *serverAddr, short serverPort)
void mb_SetDebug (musicbrainz_t o, int debug)
int mb_SetProxy (musicbrainz_t o, char *serverAddr, short serverPort)
int mb_Authenticate (musicbrainz_t o, char *userName, char *password)
int mb_SetDevice (musicbrainz_t o, char *device)
void mb_UseUTF8 (musicbrainz_t o, int useUTF8)
void mb_SetDepth (musicbrainz_t o, int depth)
void mb_SetMaxItems (musicbrainz_t o, int maxItems)
int mb_Query (musicbrainz_t o, char *rdfObject)
int mb_QueryWithArgs (musicbrainz_t o, char *rdfObject, char **args)
int mb_GetWebSubmitURL (musicbrainz_t o, char *url, int urlLen)
void mb_GetQueryError (musicbrainz_t o, char *error, int errorLen)
int mb_Select (musicbrainz_t o, char *selectQuery)
int mb_Select1 (musicbrainz_t o, char *selectQuery, int ord)
int mb_SelectWithArgs (musicbrainz_t o, char *selectQuery, int *ordinals)
int mb_GetResultData (musicbrainz_t o, char *resultName, char *data, int dataLen)
int mb_GetResultData1 (musicbrainz_t o, char *resultName, char *data, int maxDataLen, int ordinal)
int mb_DoesResultExist (musicbrainz_t o, char *resultName)
int mb_DoesResultExist1 (musicbrainz_t o, char *resultName, int ordinal)
int mb_GetResultInt (musicbrainz_t o, char *resultName)
int mb_GetResultInt1 (musicbrainz_t o, char *resultName, int ordinal)
int mb_GetResultRDF (musicbrainz_t o, char *RDF, int RDFLen)
int mb_GetResultRDFLen (musicbrainz_t o)
int mb_SetResultRDF (musicbrainz_t o, char *RDF)
void mb_GetIDFromURL (musicbrainz_t o, char *url, char *id, int idLen)
void mb_GetFragmentFromURL (musicbrainz_t o, char *url, char *fragment, int fragmentLen)
int mb_GetOrdinalFromList (musicbrainz_t o, char *listType, char *URI)
int mb_GetMP3Info (musicbrainz_t o, char *fileName, int *duration, int *bitrate, int *stereo, int *samplerate)
trm_t trm_New (void)
void trm_Delete (trm_t o)
int trm_SetProxy (trm_t o, char *proxyAddr, short proxyPort)
int trm_SetPCMDataInfo (trm_t o, int samplesPerSecond, int numChannels, int bitsPerSample)
void trm_SetSongLength (trm_t o, long int seconds)
int trm_GenerateSignature (trm_t o, char *data, int size)
int trm_FinalizeSignature (trm_t o, char signature[17], char *collectionID)
void trm_ConvertSigToASCII (trm_t o, char sig[17], char ascii_sig[37])


Define Documentation

#define MB_CDINDEX_ID_LEN   28
 

The length of a CD Index id in characters

#define MB_ID_LEN   36
 

The length of a Artist/Album/Track id in characters


Typedef Documentation

typedef void* musicbrainz_t
 

Basic C abstraction for the MusicBrainz Object

typedef void* trm_t
 

Basic C abstraction for the TRM Object


Function Documentation

int mb_Authenticate musicbrainz_t  o,
char *  userName,
char *  password
 

This function must be called if you want to submit data to the server and give the user credit for the submission. If you're looking up data from the server, you do not need to call mb_Authenticate. If you are submitting data to the MB server and you want your submissions be submitted anonymously, then do not call this function.

Parameters:
o the musicbrainz_t object returned from mb_New()
userName the name of the user
password the plaintext password of the user.
Returns:
returns true if the server authentication was correctly initiated.

void mb_Delete musicbrainz_t  o  ) 
 

The destructor for the MusicBrainz class.

See also:
mb_New()
Parameters:
o the musicbrainz_t object to delete

int mb_DoesResultExist musicbrainz_t  o,
char *  resultName
 

Check to see if a piece of information exists in data returned by a successful query. This function takes the same resultName argument as mb_GetResultData()

See also:
mb_GetResultData
Parameters:
o the musicbrainz_t object returned from mb_New()
resultName The name of the piece of data to query (MBE_)
Returns:
true if the result data exists, false otherwise

int mb_DoesResultExist1 musicbrainz_t  o,
char *  resultName,
int  ordinal
 

Check to see if a piece of information exists in data returned by a successful query. This function takes the same resultName and ordinal arguments as mb_GetResultData1()

See also:
mb_GetResultData1
Parameters:
o the musicbrainz_t object returned from mb_New()
resultName The name of the piece of data to query (MBE_)
ordinal The ordinal required by the resultName.
Returns:
true if the result data exists, false otherwise

void mb_GetFragmentFromURL musicbrainz_t  o,
char *  url,
char *  fragment,
int  fragmentLen
 

Extract the identifier fragment from a URI. Given a URI this function will return the string that follows the # seperator. (e.g. when passed 'http://musicbrainz.org/mm/mq-1.1#ArtistResult', this function will return 'ArtistResult'

Parameters:
o the musicbrainz_t object returned from mb_New()
url the url returned from a mb_GetResultData call
fragment the location where the fragment will be stored
fragmentLen the length of the id field.

void mb_GetIDFromURL musicbrainz_t  o,
char *  url,
char *  id,
int  idLen
 

Extract the actual artist/album/track ID from a MBE_GETxxxxxId query. The MBE_GETxxxxxId functions return a URL to where the more RDF metadata for the given ID can be retrieved. Callers may wish to extract only the ID of an artist/album/track for reference in elsewhere.

See also:
mb_GetResultData
Parameters:
o the musicbrainz_t object returned from mb_New()
url the url returned from a mb_GetResultData call
id the location where the id will be stored
idLen the length of the id field. 64 characters should suffice.

int mb_GetMP3Info musicbrainz_t  o,
char *  fileName,
int *  duration,
int *  bitrate,
int *  stereo,
int *  samplerate
 

This helper function calculates the crucial pieces of information for an MP3 files. This function returns the duration of the MP3 in milliseconds, which is handy for passing the length of the track to the TRM generation routines. Beware: The TRM routines are expecting the duratin in SECONDS, so you will need to divide the duration returned by this function by 1000 before you pass it to the TRM routines.

Parameters:
o the musicbrainz_t object returned from mb_New()
fileName the file to get mp3 info for
duration the duration of the mp3 filein milliseconds.
bitrate the bitrate of the mp3 file in kilobits/second
stereo true (1) if stereo false (0) otherwise.
samplerate the sample rate for this MP3 file.
Returns:
true if the mp3 was successfully examined, false otherwise.

int mb_GetOrdinalFromList musicbrainz_t  o,
char *  listType,
char *  URI
 

Get the ordinal (list position) of an item in a list. This function is normally used to retrieve the track number out of a list of tracks in an album using a list query (usually MBE_AlbumGetTrackList)

See also:
MBE_AlbumGetTrackList
Parameters:
o the musicbrainz_t object returned from mb_New()
listType (usually MBE_AlbumGetTrackList)
URI of the item from the list to return.

void mb_GetQueryError musicbrainz_t  o,
char *  error,
int  errorLen
 

Retrieve the error message that was generated during the last call to mb_Query() or mb_QueryWithArgs().

See also:
mb_Query mb_QueryWithArgs
Parameters:
o the musicbrainz_t object returned from mb_New()
error the location where the error message will be written
errorLen the length of the error location

int mb_GetResultData musicbrainz_t  o,
char *  resultName,
char *  data,
int  dataLen
 

Extract a piece of information from the data returned by a successful query. This function takes a resultName (usually named starting with MBE_), as defined in the MusicBrainz HOWTO.

See also:
mb_GetResultData1
Parameters:
o the musicbrainz_t object returned from mb_New()
resultName The name of the piece of data to query (MBE_)
data The place to store the extracted data
dataLen The number of bytes set aside in data
Returns:
true if the correct piece of data was returned and found, false otherwise.

int mb_GetResultData1 musicbrainz_t  o,
char *  resultName,
char *  data,
int  maxDataLen,
int  ordinal
 

Extract a piece of information from the data returned by a successful query. This function takes a resultName (usually named starting with MBE_), as defined in the MusicBrainz HOWTO, and on ordinal argument.

See also:
mb_GetResultData
Parameters:
o the musicbrainz_t object returned from mb_New()
resultName The name of the piece of data to query (MBE_)
data The place to store the extracted data
maxDataLen The number of bytes set aside in data
ordinal The ordinal required by the resultName.
Returns:
true if the correct piece of data was returned and found, false otherwise.

int mb_GetResultInt musicbrainz_t  o,
char *  resultName
 

Return the integer value of a result from the data returned by a successful Query. This function takes the same resultName argument as mb_GetResultData()

See also:
mb_GetResultData
Parameters:
o the musicbrainz_t object returned from mb_New()
resultName The name of the piece of data to query (MBE_)
Returns:
the integer value of the result

int mb_GetResultInt1 musicbrainz_t  o,
char *  resultName,
int  ordinal
 

Return the integer value of a result from the data returned by a successful query. This function takes the same resultName and ordinal arguments as mb_GetResultData1()

See also:
Parameters:
o the musicbrainz_t object returned from mb_New()
resultName The name of the piece of data to query (MBE_)
ordinal The ordinal required by the resultName.
Returns:
the integer value of the result

int mb_GetResultRDF musicbrainz_t  o,
char *  RDF,
int  RDFLen
 

Retrieve the RDF that was returned by the server. Most users will not want to use this function!

See also:
mb_GetResultRDFLen
Parameters:
o the musicbrainz_t object returned from mb_New()
RDF a string where the rdf will be stored.
RDFLen the length of the string

int mb_GetResultRDFLen musicbrainz_t  o  ) 
 

Returns the length (in bytes) of the current RDF result. Advanced users only!

See also:
mb_GetResultRDF
Parameters:
o the musicbrainz_t object returned from mb_New()
Returns:
the size in bytes of the current RDF result.

void mb_GetVersion musicbrainz_t  o,
int *  major,
int *  minor,
int *  rev
 

Get the version number of this library

Parameters:
o the musicbrainz_t object returned from mb_New
major an int pointer that will receive the major number of the version
minor an int pointer that will receive the minor number
rev an int pointer that will receive the rev number

int mb_GetWebSubmitURL musicbrainz_t  o,
char *  url,
int  urlLen
 

Use this function to query the current CD-ROM and to calculate the web submit URL that can be opened in a browser in order to start the web based CD-ROM Submission to MusicBrainz. The CD-ROM in the CD-ROM drive set by mb_SetDevice() will be queried.

See also:
mb_SetDevice
Parameters:
o the musicbrainz_t object returned from mb_New()
url the location where the url will be stored.
urlLen the length of the url field.
Returns:
true if the url was successfully generated, false if an error occurred.

musicbrainz_t mb_New void   ) 
 

Create a new handle (a C abstraction) to the MusicBrainz object. Call mb_Delete() when done with the handle.

See also:
mb_Delete()
Returns:
the musicbrainz_t type is used in subsequent musicbrainz functions.

int mb_Query musicbrainz_t  o,
char *  rdfObject
 

Query the MusicBrainz server. Use this function if your query requires no arguments other than the query itself. Please refer to the HOWTO for the documentation on the available queries.

See also:
mb_GetQueryError mb_QueryWithArgs
Parameters:
o the musicbrainz_t object returned from mb_New()
rdfObject the query to execute. See the HOWTO for details.
Returns:
true if the query succeeded (even if no items are returned) and false if the query failed. Call mb_GetQueryError() for details on the error that occurred.

int mb_QueryWithArgs musicbrainz_t  o,
char *  rdfObject,
char **  args
 

Query the MusicBrainz server. Use this function if your query requires one or more arguments. The arguments are specified via a pointer to an array of char *. To pass two arguments to the mb_QueryWithArgs() call, do this

 
    char *args[3];
    args[0] = "Portishead";
    args[1] = "Dummy";
    args[3] = NULL;
    mb_QueryWithArgs(MBQ_AlbumFindAlbum, args);
 
Note that the last element in the args array must point to NULL, to prevent the client library from crashing should an incorrect number of arguments be specified for the given query. Please refer to the HOWTO for the documentation on the available queries and the number of required arguments
See also:
mb_GetQueryError mb_Query
Parameters:
o the musicbrainz_t object returned from mb_New()
rdfObject the query to execute. See the HOWTO for details.
args The array of character pointers that contain the arguments.
Returns:
true if the query succeeded (even if no items are returned) and false if the query failed. Call mb_GetQueryError() for details on the error that occurred.

int mb_Select musicbrainz_t  o,
char *  selectQuery
 

Select a context in the result query. Use this function if your Select requires no ordinal arguments. Pass this function a select query (starts with MBS_) Please refer to the MusicBrainz HOWTO for more details on why you need to do a Select and what types of Selects are available.

See also:
mb_Select1, mb_SelectWithArgs
Parameters:
o the musicbrainz_t object returned from mb_New()
selectQuery The select query as outlined in the MusicBrainz HOWTO.
Returns:
true if the select succeeded, false otherwise.

int mb_Select1 musicbrainz_t  o,
char *  selectQuery,
int  ord
 

Select a context in the result query. Use this function if your Select requires one ordinal argument. Pass this function a selectQuery (usually start with MBS_) as defined in the MusicBrainz HOWTO. See the HOWTO for more details on why you need to do a Select and what types of Selects are available.

See also:
mb_Select, mb_SelectWithArgs
Parameters:
o the musicbrainz_t object returned from mb_New()
selectQuery The select query as outlined in the MusicBrainz HOWTO.
ord The ordinal as used to select items in a list.
Returns:
true if the select succeeded, false otherwise.

int mb_SelectWithArgs musicbrainz_t  o,
char *  selectQuery,
int *  ordinals
 

Select a context in the result query. Use this function if your Select requires more than one ordinal argument. Pass this function a selectQuery (usually start with MBS_) as defined in the MusicBrainz HOWTO. The ordinal arguments are passed in an array of ints, with the last int being a zero:

 
    int ordinals[3];
    ordinals[0] = 2;
    ordinals[1] = 3;
    ordinals[3] = 0;
    mb_QueryWithArgs(MBQ_AlbumFindAlbum, ordinals);
 
Note that the last element in the ordinals array must be 0. be specified for the given query. Please refer to the HOWTO for the Please refer to the MusicBrainz HOWTO for more details on why you need to do a Select and what types of Selects are available.
See also:
mb_QueryWithArgs, mb_Select, mb_Select1
Parameters:
o the musicbrainz_t object returned from mb_New()
selectQuery The select query as outlined in the MusicBrainz HOWTO.
ordinals The array of character pointers that contain the arguments.
Returns:
true if the select succeeded, false otherwise.

void mb_SetDebug musicbrainz_t  o,
int  debug
 

Enable debug out to stdout by sending a non-zero value to this function.

Parameters:
o the musicbrainz_t object returned from mb_New
debug whether or not to enable debug (non zero enables debug output)

void mb_SetDepth musicbrainz_t  o,
int  depth
 

Set the search depth of the query. Please refer to the MusicBrainz HOWTO for an explanation of this value. Defaults to 2.

See also:
mb_Query()
Parameters:
o the musicbrainz_t object returned from mb_New()
depth an integer value from zero or greater

int mb_SetDevice musicbrainz_t  o,
char *  device
 

Call this function to set the CD-ROM drive device if you plan to use the client library to identify and look up CD-ROMs using MusicBrainz. Unix: specify a device such as /dev/cdrom. Defaults to /dev/cdrom Windows: specify a drive letter of a CD-ROM drive. e.g. E:

Parameters:
o the musicbrainz_t object returned from mb_New()
device see above
Returns:
always returns true. :-)

void mb_SetMaxItems musicbrainz_t  o,
int  maxItems
 

Set the maximum number of items to return to the client. If a search query yields more items than this max number, the server will omit the excess items and not return them to the client. This value defaults to 25.

See also:
mb_Query()
Parameters:
o the musicbrainz_t object returned from mb_New()
maxItems the maximum number of items to return for a search

int mb_SetProxy musicbrainz_t  o,
char *  serverAddr,
short  serverPort
 

Set the name of the HTTP Proxy to use. This function must be called anytime the client library must communicate via a proxy firewall.

See also:
mb_SetServer
Parameters:
o the musicbrainz_t object returned from mb_New()
serverAddr the name of the proxy server to use e.g. proxy.mydomain.com
serverPort the port number to use. e.g. 8080

int mb_SetResultRDF musicbrainz_t  o,
char *  RDF
 

Set an RDF object for so that the Get functions can be used to extract data from the RDF. Advanced users only!

See also:
mb_GetRDFResult
Parameters:
o the musicbrainz_t object returned from mb_New()
RDF A pointer to the RDF to set for extraction

int mb_SetServer musicbrainz_t  o,
char *  serverAddr,
short  serverPort
 

Set the name and the port of the MusicBrainz server to use. If this function is not called, the default www.musicbrainz.org server on port 80 will be used.

See also:
mb_SetProxy
Parameters:
o the musicbrainz_t object returned from mb_New
serverAddr the name of the musicbrainz server to use e.g. www.musicbrainz.org
serverPort the port number to use. e.g. 80

void mb_UseUTF8 musicbrainz_t  o,
int  useUTF8
 

Use this function to set the output returned by the Get function. The Get functions can return data in ISO-8859-1 encoding or in UTF-8. Defaults to ISO-8859-1.

See also:
Parameters:
o the musicbrainz_t object returned from mb_New()
useUTF8 if set to a non-zero value, UTF-8 will be used.

void trm_ConvertSigToASCII trm_t  o,
char  sig[17],
char  ascii_sig[37]
 

This translates the 16 character raw signature into a 36 character human-readable string containing only letters and numbers. Used after trm_GenerateSignature() or trm_GenerateSignatureNow() has generated a signature.

Parameters:
o the trm_t object returned by trm_New()
sig the raw 16 character signature returned by one of the Generate functions.
ascii_sig the more human readable form of the signature.

void trm_Delete trm_t  o  ) 
 

The destructor for the TRM class.

See also:
trm_New()
Parameters:
o the trm_t object to delete

int trm_FinalizeSignature trm_t  o,
char  signature[17],
char *  collectionID
 

Used when there is no more audio data available or trm_GenerateSignature() has returned a '1'. This function finishes the generation of a signature from the data already sent via trm_GenerateSignature(). This function will access the Relatable signature server to generate the signature itself. Windows only: You will need to call mb_WSAInit before you can use this function. If your program already uses sockets, you will not need to call WSAInit and WSAStop.

See also:
trm_SetPCMDataInfo()

trm_GenerateSignature()

mb_WSAInit

mb_WSAStop

Parameters:
o the trm_t object returned by trm_New()
signature a 17 character array to store the signature in.
collectionID an optional 16-byte string to associate the signature with a particular collection in the Relatable Engine. Generally, pass in NULL.
Returns:
Returns 0 on success, -1 on failure

int trm_GenerateSignature trm_t  o,
char *  data,
int  size
 

The main functionality of the TRM class. Audio is passed to this function and stored for analysis. trm_SetPCMDataInfo() needs to be called before calling this function. trm_FinalizeSignature() needs to be called after this function has returned a '1' or there is no more audio data to be passed in.

See also:
trm_SetPCMDataInfo()

trm_FinalizeSignature()

mb_WSAInit

mb_WSAStop

Parameters:
o the trm_t object returned by trm_New()
data a pointer to the block of audio data being sent to the function. It needs to be raw PCM data in the format specified by the call to trm_SetPCMDataInfo()
size the size in bytes of the data block.
Returns:
returns 1 if enough data has been sent to generate a signature, or 0 if more data is still needed. After it returns a '1', trm_FinalizeSignature must be called.

trm_t trm_New void   ) 
 

The contructor for the TRM class. Call trm_Delete() when done with the object.

See also:
trm_Delete()
Returns:
the trm_t object used to refer to the class instance.

int trm_SetPCMDataInfo trm_t  o,
int  samplesPerSecond,
int  numChannels,
int  bitsPerSample
 

Called to set the type of audio being sent to be signatured. This MUST be called before attempting to generate a signature.

See also:
trm_GenerateSignature()

trm_GenerateSignatureNow()

Parameters:
o the trm_t object returned by trm_New()
samplesPerSecond the sampling rate of the audio. eg. 44100
numChannels the number of audio channels in the audio. must be 1 or 2 for mono or stereo respectively.
bitsPerSample the number of bits per audio sample. must be 8 or 16.
Returns:
1 on success, 0 on failure

int trm_SetProxy trm_t  o,
char *  proxyAddr,
short  proxyPort
 

Called to set a proxy server to use for Internet access.

Parameters:
o the trm_t object returned by trm_New()
proxyAddr the name of the proxy server to use. eg. proxy.domain.com
proxyPort the port number that the proxy server uses. eg. 8080
Returns:
1 on success, 0 on failure

void trm_SetSongLength trm_t  o,
long int  seconds
 

Called to set the total length of the song in seconds. Optional, but if this function is not used, trm_GenerateSignature() will calculate the length of the audio instead. Must be called after trm_SetPCMDataInfo() but before any calls to trm_GenerateSignature().

See also:
trm_SetPCMDataInfo()

trm_GenerateSignature()

Parameters:
o the trm_t object returned by trm_New()
seconds the total number of seconds of the track


Generated on Mon Nov 14 18:02:35 2005 for MusicBrainz Client Library by  doxygen 1.4.2