Line 0
Link Here
|
|
|
1 |
--- ./SongInspectorController.m.orig 2012-03-05 20:56:28.000000000 -0500 |
2 |
+++ ./SongInspectorController.m 2012-03-05 21:03:15.000000000 -0500 |
3 |
@@ -34,8 +34,6 @@ |
4 |
#import <Foundation/NSString.h> |
5 |
#import <Foundation/NSThread.h> |
6 |
|
7 |
-#import <musicbrainz/mb_c.h> |
8 |
- |
9 |
#import <Cynthiune/Format.h> |
10 |
#import <Cynthiune/NSViewExtensions.h> |
11 |
#import <Cynthiune/utils.h> |
12 |
@@ -156,10 +154,10 @@ |
13 |
{ |
14 |
if (!threadRunning) |
15 |
{ |
16 |
- [lookupButton setEnabled: YES]; |
17 |
- [lookupButton setImage: [NSImage imageNamed: @"lookup-mb-on"]]; |
18 |
+ [lookupButton setEnabled: NO]; |
19 |
+ [lookupButton setImage: [NSImage imageNamed: @"lookup-mb-off"]]; |
20 |
[lookupAnimation setImage: nil]; |
21 |
- [lookupStatusLabel setStringValue: @""]; |
22 |
+ [lookupStatusLabel setStringValue: @"MB lookup doesn't work!"]; |
23 |
} |
24 |
} |
25 |
else |
26 |
@@ -320,39 +318,6 @@ |
27 |
forKey: @"song"]]; |
28 |
} |
29 |
|
30 |
-- (char *) _generateTrmId |
31 |
-{ |
32 |
- id <Format> stream; |
33 |
- trm_t trmGen; |
34 |
- int size; |
35 |
- char sig[17]; |
36 |
- unsigned char buffer[4096]; |
37 |
- char *trmId; |
38 |
- |
39 |
- stream = [song openStreamForSong]; |
40 |
- if (stream) |
41 |
- { |
42 |
- trmGen = trm_New (); |
43 |
- trm_SetPCMDataInfo (trmGen, |
44 |
- [stream readRate], [stream readChannels], 16); |
45 |
- trm_SetSongLength (trmGen, [stream readDuration]); |
46 |
- size = [stream readNextChunk: buffer withSize: 4096]; |
47 |
- while (!trm_GenerateSignature (trmGen, (char *) buffer, size)) |
48 |
- size = [stream readNextChunk: buffer withSize: 4096]; |
49 |
- |
50 |
- trm_FinalizeSignature (trmGen, sig, NULL); |
51 |
- |
52 |
- trmId = malloc (37); |
53 |
- trm_ConvertSigToASCII (trmGen, sig, trmId); |
54 |
- trm_Delete (trmGen); |
55 |
- [stream streamClose]; |
56 |
- } |
57 |
- else |
58 |
- trmId = NULL; |
59 |
- |
60 |
- return trmId; |
61 |
-} |
62 |
- |
63 |
- (void) updateField: (NSTextField *) field |
64 |
withString: (NSString *) string |
65 |
{ |
66 |
@@ -418,132 +383,6 @@ |
67 |
selector: @selector (_updateFieldsWithTrackInfos:)]; |
68 |
} |
69 |
|
70 |
-- (NSDictionary *) readMB: (musicbrainz_t) mb |
71 |
- track: (int) track |
72 |
-{ |
73 |
- NSMutableDictionary *trackInfos; |
74 |
- NSString *string; |
75 |
- char cString[100]; |
76 |
- int releases; |
77 |
- |
78 |
- trackInfos = [NSMutableDictionary new]; |
79 |
- [trackInfos autorelease]; |
80 |
- |
81 |
- mb_Select1 (mb, MBS_SelectTrack, track); |
82 |
- if (mb_GetResultData (mb, MBE_TrackGetTrackName, cString, 100)) |
83 |
- { |
84 |
- string = [NSString stringWithUTF8String: cString]; |
85 |
- [trackInfos setObject: string forKey: @"title"]; |
86 |
- } |
87 |
- |
88 |
- if (mb_GetResultData (mb, MBE_TrackGetArtistName, cString, 100)) |
89 |
- { |
90 |
- string = [NSString stringWithUTF8String: cString]; |
91 |
- [trackInfos setObject: string forKey: @"artist"]; |
92 |
- } |
93 |
- |
94 |
- if (mb_GetResultData (mb, MBE_TrackGetTrackNum, cString, 100)) |
95 |
- { |
96 |
- string = [NSString stringWithUTF8String: cString]; |
97 |
- [trackInfos setObject: string forKey: @"trackNumber"]; |
98 |
- } |
99 |
- |
100 |
- if (mb_Select (mb, MBS_SelectTrackAlbum)) |
101 |
- { |
102 |
- if (mb_GetResultData (mb, MBE_AlbumGetAlbumName, cString, 100)) |
103 |
- { |
104 |
- string = [NSString stringWithUTF8String: cString]; |
105 |
- [trackInfos setObject: string forKey: @"album"]; |
106 |
- } |
107 |
-#ifdef MBE_AlbumGetNumReleaseDates |
108 |
- releases = mb_GetResultInt (mb, MBE_AlbumGetNumReleaseDates); |
109 |
- if (releases) |
110 |
- { |
111 |
- mb_Select1 (mb, MBS_SelectReleaseDate, 1); |
112 |
- if (mb_GetResultData (mb, MBE_ReleaseGetDate, cString, 100)) |
113 |
- { |
114 |
- *(cString + 4) = 0; |
115 |
- string = [NSString stringWithUTF8String: cString]; |
116 |
- [trackInfos setObject: string forKey: @"year"]; |
117 |
- } |
118 |
- mb_Select (mb, MBS_Back); |
119 |
- } |
120 |
-#endif |
121 |
- |
122 |
- mb_Select (mb, MBS_Back); |
123 |
- } |
124 |
- |
125 |
- mb_Select (mb, MBS_Rewind); |
126 |
- |
127 |
- return trackInfos; |
128 |
-} |
129 |
- |
130 |
-- (void) _parseMB: (musicbrainz_t) mb |
131 |
-{ |
132 |
- int count, results; |
133 |
- NSMutableArray *allTrackInfos; |
134 |
- |
135 |
- results = mb_GetResultInt (mb, MBE_GetNumTracks); |
136 |
- allTrackInfos = [[NSMutableArray alloc] initWithCapacity: results]; |
137 |
- [allTrackInfos autorelease]; |
138 |
- |
139 |
- for (count = 0; count < results; count++) |
140 |
- [allTrackInfos addObject: [self readMB: mb track: count + 1]]; |
141 |
- |
142 |
- [self performSelectorOnMainThread: @selector (_updateSongFields:) |
143 |
- withObject: allTrackInfos |
144 |
- waitUntilDone: YES]; |
145 |
-} |
146 |
- |
147 |
-- (void) lookupThread |
148 |
-{ |
149 |
- NSAutoreleasePool *pool; |
150 |
- char *trmId; |
151 |
- musicbrainz_t mb; |
152 |
- char **qis; |
153 |
- char error[80]; |
154 |
- |
155 |
- pool = [NSAutoreleasePool new]; |
156 |
- |
157 |
- [self updateField: lookupStatusLabel |
158 |
- withString: LOCALIZED(@"Generating TRM...")]; |
159 |
- trmId = [self _generateTrmId]; |
160 |
- if (trmId && !threadShouldDie) |
161 |
- { |
162 |
- qis = MakeQis (trmId, song); |
163 |
- |
164 |
- if (strcasecmp (trmId, busyTrmId)) |
165 |
- { |
166 |
- [self updateField: lookupStatusLabel |
167 |
- withString: LOCALIZED (@"Querying MusicBrainz server...")]; |
168 |
- mb = mb_New (); |
169 |
- mb_UseUTF8 (mb, YES); |
170 |
- if (mb_QueryWithArgs (mb, MBQ_TrackInfoFromTRMId, qis)) |
171 |
- [self _parseMB: mb]; |
172 |
- else |
173 |
- { |
174 |
-// FIXME: there should be an accurate error message here... |
175 |
- [self updateField: lookupStatusLabel |
176 |
- withString: @""]; |
177 |
- mb_GetQueryError (mb, error, 80); |
178 |
- NSLog (@"Musicbrainz error: %s (%s)", error, trmId); |
179 |
- } |
180 |
- mb_Delete (mb); |
181 |
- } |
182 |
- else |
183 |
- [self updateField: lookupStatusLabel |
184 |
- withString: LOCALIZED (@"The MusicBrainz server was too busy")]; |
185 |
- |
186 |
- FreeQis (qis); |
187 |
- } |
188 |
- |
189 |
- [self performSelectorOnMainThread: @selector (lookupThreadEnded) |
190 |
- withObject: nil |
191 |
- waitUntilDone: NO]; |
192 |
- |
193 |
- [pool release]; |
194 |
-} |
195 |
- |
196 |
- (void) mbLookup: (id)sender |
197 |
{ |
198 |
if (song) |