1 /*
2 **  Cddb.h
3 **
4 **  Copyright (c) 2002
5 **
6 **  Author: Yen-Ju  <yjchenx@hotmail.com>
7 **
8 **  This program is free software; you can redistribute it and/or modify
9 **  it under the terms of the GNU Lesser 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 Lesser General Public License
19 **  along with this program; if not, write to the Free Software
20 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
22 
23 #import <Foundation/Foundation.h>
24 
25 #define CD_FPS 75
26 #define FRAMES_TO_MSF(f, M, S, F) {                                     \
27         int value = f;                                                  \
28         *(F) = value%CD_FPS;                                            \
29         value /= CD_FPS;                                                \
30         *(S) = value%60;                                                \
31         value /= 60;                                                    \
32         *(M) = value;                                                   \
33 }
34 #define FRAMES_TO_SECONDS(f, s) \
35         s = f / CD_FPS;
36 
37 @interface Cddb: NSObject
38 {
39   NSURL *defaultSite;
40   NSFileHandle *fileHandler;
41   int level;
42 }
43 
44 /* If the return value is NSString or NSDictionary, nil for nothing (failed).
45  * If the return value is NSArray, empty array for nothing (failed), not nil.
46  */
47 
48 - (BOOL) connect; /* return YES when success. */
49 - (void) disconnect;
50 - (NSString *) request: (NSString *) command;
51 
52 /* High-level methods*/
53 /* Return the discid either through cddb site or calculated locally
54  * The number of object in NSArray are the number of tracks.
55  * The keys of NSDictionary are "length" and "offset".
56  */
57 - (NSString *) discidWithCDTracks: (NSArray *) tracks
58                           locally: (BOOL) locally;
59 
60 /* Return the query using a NSArray of NSDictionary.
61  * The number of object in NSArray are the number of tracks.
62  * The keys of NSDictionary are "length" and "offset".
63  * The return value are a NSArray of NSDictionary.
64  * The keys of return NSDictionary are "category", "discid", "description".
65  */
66 - (NSArray *) queryWithCDTracks: (NSArray *) tracks;
67 
68 /* Return the read using category and discid
69  * The class of objects and keys of returned value are:
70  * NSString, "discid"
71  * NSString, "album"
72  * NSString, "year" (level 4 or up)
73  * NSString, "genre" (level 4 or up)
74  * NSArray, "titles" (title of each track)
75  * NSString, "extdata" (extra data about this album)
76  * NSArray, "exttitles" (extra-title of each track)
77  */
78 - (NSDictionary *) readWithCategory: (NSString *) category
79                              discid: (NSString *) discid
80                         postProcess: (BOOL) postProcess;
81 
82 /* Low-level methods */
83 /* Input format:
84  * "category discid"
85  */
86 - (NSDictionary *) read: (NSString *) input;
87 
88 /* Input format:
89  * "discid ntrks off_1 off_2 ... off_n nsecs"
90  * The returned array of NSDictionary have these keys:
91  * "category", "discid", "description"
92  */
93 - (NSArray *) query: (NSString *) input;
94 
95 /* It would be better to calculate it locally.
96  * Input format:
97  * "ntrks off_1 off_2 ... off_n nsecs"
98  */
99 - (NSString *) discid: (NSString *) input;
100 
101 /* Array of NSDictionary, the keys are:
102  * site, port, latitude, longitude, description
103  */
104 - (NSArray *) sites;
105 
106 - (NSArray *) category;
107 - (NSString *) version;
108 - (int) proto; /* Ask the proto */
109 - (int) proto: (int) level; /* Set proto, and return the result */
110 
111 - (void) setDefaultSite: (NSString *) site;
112 - (NSString *) defaultSite;
113 
114 @end
115