Fingerprint.h | Fingerprint.h | |||
---|---|---|---|---|
/************************************************************************** | /* | |||
* | Copyright 2009 Last.fm Ltd. | |||
* Copyright 2005-2009 Last.fm Ltd. | - Primarily authored by Max Howell, Jono Cole and Doug Mansell | |||
* | ||||
* | This file is part of liblastfm. | |||
* | ||||
* This program is free software; you can redistribute it and/or modify | liblastfm is free software: you can redistribute it and/or modify | |||
* | it under the terms of the GNU General Public License as published by | |||
* it under the terms of the GNU General Public License as published by | the Free Software Foundation, either version 3 of the License, or | |||
* | (at your option) any later version. | |||
* the Free Software Foundation; either version 2 of the License, or | ||||
* | liblastfm is distributed in the hope that it will be useful, | |||
* (at your option) any later version. | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* | GNU General Public License for more details. | |||
* | ||||
* This program is distributed in the hope that it will be useful, | You should have received a copy of the GNU General Public License | |||
* | along with liblastfm. If not, see <http://www.gnu.org/licenses/>. | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | */ | |||
* | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* | ||||
* GNU General Public License for more details. | ||||
* | ||||
* | ||||
* | ||||
* You should have received a copy of the GNU General Public License | ||||
* | ||||
* along with this program; if not, write to the | ||||
* | ||||
* Free Software Foundation, Inc., | ||||
* | ||||
* 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
* | ||||
************************************************************************** | ||||
*/ | ||||
#ifndef LASTFM_FINGERPRINT_H | #ifndef LASTFM_FINGERPRINT_H | |||
#define LASTFM_FINGERPRINT_H | #define LASTFM_FINGERPRINT_H | |||
#include <lastfm/FingerprintId> | #include "FingerprintId.h" | |||
#include <lastfm/Track> | ||||
namespace lastfm | namespace lastfm | |||
{ | { | |||
class FingerprintableSource; | ||||
class Track; | ||||
class LASTFM_FINGERPRINT_DLLEXPORT Fingerprint | class LASTFM_FINGERPRINT_DLLEXPORT Fingerprint | |||
{ | { | |||
lastfm::Track m_track; | ||||
QByteArray m_data; | ||||
int m_id; | ||||
int m_duration; | ||||
protected: | protected: | |||
bool m_complete; | class FingerprintPrivate * const d; | |||
public: | public: | |||
/** represents a partial fingerprint of 20 seconds of music, this i s | /** represents a partial fingerprint of 20 seconds of music, this i s | |||
* considered 99.9999...9999% unique and so we use it for most stu ff as | * considered 99.9999...9999% unique and so we use it for most stu ff as | |||
* it is much quicker than a complete fingerprint, still though, y ou | * it is much quicker than a complete fingerprint, still though, y ou | |||
* should do the generate step in a thread. */ | * should do the generate step in a thread. */ | |||
Fingerprint( const lastfm::Track& ); | Fingerprint( const lastfm::Track& ); | |||
~Fingerprint(); | ||||
/** if the id isNull(), then you'll need to do generate, submit and decode */ | /** if the id isNull(), then you'll need to do generate, submit and decode */ | |||
FingerprintId id() const { return m_id; } | FingerprintId id() const; | |||
/** The actual data that is the fingerprint, this is about 70kB or so, | /** The actual data that is the fingerprint, this is about 70kB or so, | |||
* there isn't anything in it until you call generate. | * there isn't anything in it until you call generate. */ | |||
* HEY! The QByteArray returned is not valid if Fingerprint object | QByteArray data() const; | |||
is | ||||
* deleted or falls off the stack. Seriously! Even if you copy it! | ||||
Although | ||||
* you can of course *deep-copy* the data. */ | ||||
QByteArray data() const { return m_data; } | ||||
enum Error | enum Error | |||
{ | { | |||
ReadError = 0, | ReadError = 0, | |||
/** failed to extract samplerate, bitrate, channels, duration e tc */ | /** failed to extract samplerate, bitrate, channels, duration e tc */ | |||
HeadersError, | HeadersError, | |||
DecodeError, | DecodeError, | |||
skipping to change at line 77 | skipping to change at line 72 | |||
/** the fingerprint service went wrong, or we submitted bad dat a, | /** the fingerprint service went wrong, or we submitted bad dat a, | |||
* or myabe the request failed, whatever, we couldn't parse th e | * or myabe the request failed, whatever, we couldn't parse th e | |||
* result */ | * result */ | |||
BadResponseError, | BadResponseError, | |||
/** sorry, liblastfm sucks, report bug with log! */ | /** sorry, liblastfm sucks, report bug with log! */ | |||
InternalError | InternalError | |||
}; | }; | |||
/** This is CPU intensive, do it in a thread in your GUI applicatio n */ | /** This is CPU intensive, do it in a thread in your GUI applicatio n */ | |||
void generate() throw( Error ); | void generate( FingerprintableSource* ) throw( Error ); | |||
/** Submits the fingerprint data to Last.fm in order to get a Finge rprintId | /** Submits the fingerprint data to Last.fm in order to get a Finge rprintId | |||
* back. You need to wait for the QNetworkReply to finish before y ou can | * back. You need to wait for the QNetworkReply to finish before y ou can | |||
* pass it to decode clearly. */ | * pass it to decode clearly. */ | |||
QNetworkReply* submit() const; | QNetworkReply* submit() const; | |||
/** Pass a finished reply from submit(), if the response is sound, id() | /** Pass a finished reply from submit(), if the response is sound, id() | |||
* will be valid. Otherwise we will throw. You always get a valid id | * will be valid. Otherwise we will throw. You always get a valid id | |||
* or a throw. | * or a throw. | |||
*/ | */ | |||
void decode( QNetworkReply*, bool* lastfm_needs_a_complete_fingerpr int = 0 ) throw( Error ); | void decode( QNetworkReply*, bool* lastfm_needs_a_complete_fingerpr int = 0 ) throw( Error ); | |||
}; | }; | |||
class LASTFM_FINGERPRINT_DLLEXPORT CompleteFingerprint : public Fingerp rint | class LASTFM_FINGERPRINT_DLLEXPORT CompleteFingerprint : public Fingerp rint | |||
{ | { | |||
public: | CompleteFingerprint( const lastfm::Track& t ); | |||
CompleteFingerprint( const lastfm::Track& t ) : Fingerprint( t ) | ~CompleteFingerprint(); | |||
{ | ||||
m_complete = true; | ||||
} | ||||
}; | }; | |||
} | } | |||
inline QDebug operator<<( QDebug d, lastfm::Fingerprint::Error e ) | QDebug operator<<( QDebug d, lastfm::Fingerprint::Error e ); | |||
{ | ||||
#define CASE(x) case lastfm::Fingerprint::x: return d << #x; | ||||
switch (e) | ||||
{ | ||||
CASE(ReadError) | ||||
CASE(HeadersError) | ||||
CASE(DecodeError) | ||||
CASE(TrackTooShortError) | ||||
CASE(BadResponseError) | ||||
CASE(InternalError) | ||||
} | ||||
} | ||||
#endif | #endif | |||
End of changes. 11 change blocks. | ||||
72 lines changed or deleted | 32 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |