File: protocol.h

package info (click to toggle)
libtunepimp 0.5.3-7
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,668 kB
  • ctags: 3,470
  • sloc: ansic: 15,652; cpp: 12,752; sh: 11,929; perl: 1,179; python: 720; makefile: 310; pascal: 33
file content (110 lines) | stat: -rw-r--r-- 3,853 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* ------------------------------------------------------------------

   libofa -- the Open Fingerprint Architecture library

   Public Domain (PD) 2006 Predixis Corporation
   No rights reserved.

-------------------------------------------------------------------*/
#ifndef __PROTOCOL_H__
#define __PROTOCOL_H__

#include <string>
#include "ofa1/ofa.h"

using namespace std;

// This object must be filled out completely prior to making any
// calls to the server.  On return, some fields will be filled out.
class TrackInformation {
private:
    string puid;
    string print;
    string encoding;        // All other strings must honor this encoding
    string client_key;      // Get your unique key at http://www.musicdns.org
    string client_version;  // Use your own version here: "1.0 beta 2"
    bool   get_metadata;    // If false, only the PUID will be returned
    int    bitrate;         // i.e. "192kbps", use 0 for VBR or freeformat
    string format;          // File extension
    long   length_in_ms;    // In milliseconds
    string artist;
    string track;
    string album;
    int    trackNum;        // use 0 if not known
    string genre;
    string year;
public:
    // Get your unique key at http://www.musicdns.org
    TrackInformation(string _key, string _version) :
	client_key(_key), client_version(_version), get_metadata(false),
	bitrate(0), length_in_ms(0), trackNum(0) {}
    ~TrackInformation() {}
    void setPrint(string p) { print = p; }
    string getPrint() const { return print; }
    // Only supported encodings are UTF-8 (default) and ISO-8859-15
    void setEncoding(string e) { encoding = e; }
    string getEncoding() const { return encoding; }
    string getClientKey() const { return client_key; }
    string getClientVersion() const { return client_version; }
    void setMetadataFlag(bool b) { get_metadata = b; }
    bool getMetadataFlag() const { return get_metadata; }
    void setBitrate(int b) { bitrate = b; }
    int getBitrate() const { return bitrate; }
    void setFormat(string fmt) { format = fmt; }
    string getFormat() const { return format; }
    void setLengthInMS(long ms) { length_in_ms = ms; }
    long getLengthInMS() const { return length_in_ms; }
    void setArtist(string name) { artist = name; }
    string getArtist() const { return artist; }
    void setTrack(string name) { track = name; }
    string getTrack() const { return track; }
    void setAlbum(string name) { album = name; }
    string getAlbum() const { return album; }
    void setTrackNum(int t) { trackNum = t; }
    int getTrackNum() const { return trackNum; }
    void setGenre(string g) { genre = g; }
    string getGenre() const { return genre; }
    void setYear(string y) { year = y; }
    string getYear() const { return year; }
    void setPUID(string id)  { puid = id; }
    string getPUID() const { return puid; }
};

bool retrieve_metadata(TrackInformation *info);

class AudioData {
private:
    unsigned char *samples;
    int byteOrder;
    long size;
    int sRate;
    bool stereo;
public:
    TrackInformation info;
    AudioData(string _key, string _version) : samples(0), size(0), sRate(0),
					      stereo(false), info(_key, _version) {}
    virtual ~AudioData() {
	delete[] samples;
    }
    void setData(unsigned char*_samples, int _byteOrder, long _size, int _sRate, bool _stereo) {
	samples = _samples;
	byteOrder = _byteOrder;
	size = _size;
	sRate = _sRate;
	stereo = _stereo;
    }
    int getByteOrder() const { return byteOrder; }
    long getSize() const { return size; }
    int getSRate() const { return sRate; }
    bool getStereo() const { return stereo; }
    bool createPrint() {
	const char *print = ofa_create_print(samples, byteOrder, size, sRate, stereo);
        samples = 0;
	if (!print)
	    return false;
	info.setPrint(print);
	return true;
    }
};

#endif