summaryrefslogtreecommitdiff
path: root/audio/cynthiune/files/patch-SongInspectorController.m
blob: 7214144cc55148b9dbde65ba95181c5507902aa3 (plain) (blame)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
--- ./SongInspectorController.m.orig	2012-03-05 20:56:28.000000000 -0500
+++ ./SongInspectorController.m	2012-03-05 21:03:15.000000000 -0500
@@ -34,8 +34,6 @@
 #import <Foundation/NSString.h>
 #import <Foundation/NSThread.h>
 
-#import <musicbrainz/mb_c.h>
-
 #import <Cynthiune/Format.h>
 #import <Cynthiune/NSViewExtensions.h>
 #import <Cynthiune/utils.h>
@@ -156,10 +154,10 @@
     {
       if (!threadRunning)
         {
-          [lookupButton setEnabled: YES];
-          [lookupButton setImage: [NSImage imageNamed: @"lookup-mb-on"]];
+          [lookupButton setEnabled: NO];
+          [lookupButton setImage: [NSImage imageNamed: @"lookup-mb-off"]];
           [lookupAnimation setImage: nil];
-          [lookupStatusLabel setStringValue: @""];
+          [lookupStatusLabel setStringValue: @"MB lookup doesn't work!"];
         }
     }
   else
@@ -320,39 +318,6 @@
                               forKey: @"song"]];
 }
 
-- (char *) _generateTrmId
-{
-  id <Format> stream;
-  trm_t trmGen;
-  int size;
-  char sig[17];
-  unsigned char buffer[4096];
-  char *trmId;
-
-  stream = [song openStreamForSong];
-  if (stream)
-    {
-      trmGen = trm_New ();
-      trm_SetPCMDataInfo (trmGen,
-                          [stream readRate], [stream readChannels], 16);
-      trm_SetSongLength (trmGen, [stream readDuration]);
-      size = [stream readNextChunk: buffer withSize: 4096];
-      while (!trm_GenerateSignature (trmGen, (char *) buffer, size))
-        size = [stream readNextChunk: buffer withSize: 4096];
-
-      trm_FinalizeSignature (trmGen, sig, NULL);
-
-      trmId = malloc (37);
-      trm_ConvertSigToASCII (trmGen, sig, trmId);
-      trm_Delete (trmGen);
-      [stream streamClose];
-    }
-  else
-    trmId = NULL;
-
-  return trmId;
-}
-
 - (void) updateField: (NSTextField *) field
           withString: (NSString *) string
 {
@@ -418,132 +383,6 @@
                                    selector: @selector (_updateFieldsWithTrackInfos:)];
 }
 
-- (NSDictionary *) readMB: (musicbrainz_t) mb
-                    track: (int) track
-{
-  NSMutableDictionary *trackInfos;
-  NSString *string;
-  char cString[100];
-  int releases;
-
-  trackInfos = [NSMutableDictionary new];
-  [trackInfos autorelease];
-
-  mb_Select1 (mb, MBS_SelectTrack, track);
-  if (mb_GetResultData (mb, MBE_TrackGetTrackName, cString, 100))
-    {
-      string = [NSString stringWithUTF8String: cString];
-      [trackInfos setObject: string forKey: @"title"];
-    }
-
-  if (mb_GetResultData (mb, MBE_TrackGetArtistName, cString, 100))
-    {
-      string = [NSString stringWithUTF8String: cString];
-      [trackInfos setObject: string forKey: @"artist"];
-    }
-
-  if (mb_GetResultData (mb, MBE_TrackGetTrackNum, cString, 100))
-    {
-      string = [NSString stringWithUTF8String: cString];
-      [trackInfos setObject: string forKey: @"trackNumber"];
-    }
-
-  if (mb_Select (mb, MBS_SelectTrackAlbum))
-    {
-      if (mb_GetResultData (mb, MBE_AlbumGetAlbumName, cString, 100))
-        {
-          string = [NSString stringWithUTF8String: cString];
-          [trackInfos setObject: string forKey: @"album"];
-        }
-#ifdef MBE_AlbumGetNumReleaseDates
-      releases = mb_GetResultInt (mb, MBE_AlbumGetNumReleaseDates);
-      if (releases)
-        {
-          mb_Select1 (mb, MBS_SelectReleaseDate, 1);
-          if (mb_GetResultData (mb, MBE_ReleaseGetDate, cString, 100))
-            {
-              *(cString + 4) = 0;
-              string = [NSString stringWithUTF8String: cString];
-              [trackInfos setObject: string forKey: @"year"];
-            }
-          mb_Select (mb, MBS_Back);
-        }
-#endif
-
-      mb_Select (mb, MBS_Back);
-    }
-
-  mb_Select (mb, MBS_Rewind);
-
-  return trackInfos;
-}
-
-- (void) _parseMB: (musicbrainz_t) mb
-{
-  int count, results;
-  NSMutableArray *allTrackInfos;
-
-  results = mb_GetResultInt (mb, MBE_GetNumTracks);
-  allTrackInfos = [[NSMutableArray alloc] initWithCapacity: results];
-  [allTrackInfos autorelease];
-
-  for (count = 0; count < results; count++)
-    [allTrackInfos addObject: [self readMB: mb track: count + 1]];
-
-  [self performSelectorOnMainThread: @selector (_updateSongFields:)
-        withObject: allTrackInfos
-        waitUntilDone: YES];
-}
-
-- (void) lookupThread
-{
-  NSAutoreleasePool *pool;
-  char *trmId;
-  musicbrainz_t mb;
-  char **qis;
-  char error[80];
-
-  pool = [NSAutoreleasePool new];
-
-  [self updateField: lookupStatusLabel
-        withString: LOCALIZED(@"Generating TRM...")];
-  trmId = [self _generateTrmId];
-  if (trmId && !threadShouldDie)
-    {
-      qis = MakeQis (trmId, song);
-
-      if (strcasecmp (trmId, busyTrmId))
-        {
-          [self updateField: lookupStatusLabel
-                withString: LOCALIZED (@"Querying MusicBrainz server...")];
-          mb = mb_New ();
-          mb_UseUTF8 (mb, YES);
-          if (mb_QueryWithArgs (mb, MBQ_TrackInfoFromTRMId, qis))
-            [self _parseMB: mb];
-          else
-            {
-//            FIXME: there should be an accurate error message here...
-              [self updateField: lookupStatusLabel
-                    withString: @""];
-              mb_GetQueryError (mb, error, 80);
-              NSLog (@"Musicbrainz error: %s (%s)", error, trmId);
-            }
-          mb_Delete (mb);
-        }
-      else
-        [self updateField: lookupStatusLabel
-              withString: LOCALIZED (@"The MusicBrainz server was too busy")];
-
-      FreeQis (qis);
-    }
-
-  [self performSelectorOnMainThread: @selector (lookupThreadEnded)
-        withObject: nil
-        waitUntilDone: NO];
-
-  [pool release];
-}
-
 - (void) mbLookup: (id)sender
 {
   if (song)