1 //
2 // File: iTunesAPI.c
3 //
4 // Abstract: part of iTunes Visual SDK
5 //
6 // Version: 1.2
7 //
8 // Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ( "Apple" )
9 // in consideration of your agreement to the following terms, and your use,
10 // installation, modification or redistribution of this Apple software
11 // constitutes acceptance of these terms. If you do not agree with these
12 // terms, please do not use, install, modify or redistribute this Apple
13 // software.
14 //
15 // In consideration of your agreement to abide by the following terms, and
16 // subject to these terms, Apple grants you a personal, non - exclusive
17 // license, under Apple's copyrights in this original Apple software ( the
18 // "Apple Software" ), to use, reproduce, modify and redistribute the Apple
19 // Software, with or without modifications, in source and / or binary forms;
20 // provided that if you redistribute the Apple Software in its entirety and
21 // without modifications, you must retain this notice and the following text
22 // and disclaimers in all such redistributions of the Apple Software. Neither
23 // the name, trademarks, service marks or logos of Apple Inc. may be used to
24 // endorse or promote products derived from the Apple Software without specific
25 // prior written permission from Apple. Except as expressly stated in this
26 // notice, no other rights or licenses, express or implied, are granted by
27 // Apple herein, including but not limited to any patent rights that may be
28 // infringed by your derivative works or by other works in which the Apple
29 // Software may be incorporated.
30 //
31 // The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
32 // WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
33 // WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
34 // PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION
35 // ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
36 //
37 // IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
38 // CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 // INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION
41 // AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER
42 // UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR
43 // OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 //
45 // Copyright ( C ) 2000-2007 Apple Inc. All Rights Reserved.
46 //
47 #include "iTunesAPI.h"
48 #include "iTunesVisualAPI.h"
49
50 // MyMemClear
51 //
MyMemClear(LogicalAddress dest,SInt32 length)52 static void MyMemClear (LogicalAddress dest, SInt32 length)
53 {
54 register unsigned char *ptr;
55
56 ptr = (unsigned char *) dest;
57
58 if( length > 16 )
59 {
60 register unsigned long *longPtr;
61
62 while( ((unsigned long) ptr & 3) != 0 )
63 {
64 *ptr++ = 0;
65 --length;
66 }
67
68 longPtr = (unsigned long *) ptr;
69
70 while( length >= 4 )
71 {
72 *longPtr++ = 0;
73 length -= 4;
74 }
75
76 ptr = (unsigned char *) longPtr;
77 }
78
79 while( --length >= 0 )
80 {
81 *ptr++ = 0;
82 }
83 }
84
85
86 // SetNumVersion
87 //
SetNumVersion(NumVersion * numVersion,UInt8 majorRev,UInt8 minorAndBugRev,UInt8 stage,UInt8 nonRelRev)88 void SetNumVersion (NumVersion *numVersion, UInt8 majorRev, UInt8 minorAndBugRev, UInt8 stage, UInt8 nonRelRev)
89 {
90 numVersion->majorRev = majorRev;
91 numVersion->minorAndBugRev = minorAndBugRev;
92 numVersion->stage = stage;
93 numVersion->nonRelRev = nonRelRev;
94 }
95
96
97 // ITCallApplication
98 //
ITCallApplicationInternal(void * appCookie,ITAppProcPtr handler,OSType message,UInt32 messageMajorVersion,UInt32 messageMinorVersion,PlayerMessageInfo * messageInfo)99 static OSStatus ITCallApplicationInternal (void *appCookie, ITAppProcPtr handler, OSType message, UInt32 messageMajorVersion, UInt32 messageMinorVersion, PlayerMessageInfo *messageInfo)
100 {
101 PlayerMessageInfo localMessageInfo;
102
103 if (messageInfo == nil)
104 {
105 MyMemClear(&localMessageInfo, sizeof(localMessageInfo));
106
107 messageInfo = &localMessageInfo;
108 }
109
110 messageInfo->messageMajorVersion = messageMajorVersion;
111 messageInfo->messageMinorVersion = messageMinorVersion;
112 messageInfo->messageInfoSize = sizeof(PlayerMessageInfo);
113
114 return handler(appCookie, message, messageInfo);
115 }
116
117 // ITCallApplication
118 //
ITCallApplication(void * appCookie,ITAppProcPtr handler,OSType message,PlayerMessageInfo * messageInfo)119 OSStatus ITCallApplication (void *appCookie, ITAppProcPtr handler, OSType message, PlayerMessageInfo *messageInfo)
120 {
121 return ITCallApplicationInternal(appCookie, handler, message, kITPluginMajorMessageVersion, kITPluginMinorMessageVersion, messageInfo);
122 }
123
124
125 // PlayerSetFullScreen
126 //
PlayerSetFullScreen(void * appCookie,ITAppProcPtr appProc,Boolean fullScreen)127 OSStatus PlayerSetFullScreen (void *appCookie, ITAppProcPtr appProc, Boolean fullScreen)
128 {
129 PlayerMessageInfo messageInfo;
130
131 MyMemClear(&messageInfo, sizeof(messageInfo));
132
133 messageInfo.u.setFullScreenMessage.fullScreen = fullScreen;
134
135 return ITCallApplication(appCookie, appProc, kPlayerSetFullScreenMessage, &messageInfo);
136 }
137
138
139 // PlayerSetFullScreenOptions
140 //
PlayerSetFullScreenOptions(void * appCookie,ITAppProcPtr appProc,SInt16 minBitDepth,SInt16 maxBitDepth,SInt16 preferredBitDepth,SInt16 desiredWidth,SInt16 desiredHeight)141 OSStatus PlayerSetFullScreenOptions (void *appCookie, ITAppProcPtr appProc, SInt16 minBitDepth, SInt16 maxBitDepth, SInt16 preferredBitDepth, SInt16 desiredWidth, SInt16 desiredHeight)
142 {
143 PlayerMessageInfo messageInfo;
144
145 MyMemClear(&messageInfo, sizeof(messageInfo));
146
147 messageInfo.u.setFullScreenOptionsMessage.minBitDepth = minBitDepth;
148 messageInfo.u.setFullScreenOptionsMessage.maxBitDepth = maxBitDepth;
149 messageInfo.u.setFullScreenOptionsMessage.preferredBitDepth = preferredBitDepth;
150 messageInfo.u.setFullScreenOptionsMessage.desiredWidth = desiredWidth;
151 messageInfo.u.setFullScreenOptionsMessage.desiredHeight = desiredHeight;
152
153 return ITCallApplication(appCookie, appProc, kPlayerSetFullScreenOptionsMessage, &messageInfo);
154 }
155
156 // PlayerGetCurrentTrackCoverArt
157 //
PlayerGetCurrentTrackCoverArt(void * appCookie,ITAppProcPtr appProc,Handle * coverArt,OSType * coverArtFormat)158 OSStatus PlayerGetCurrentTrackCoverArt (void *appCookie, ITAppProcPtr appProc, Handle *coverArt, OSType *coverArtFormat)
159 {
160 OSStatus status;
161 PlayerMessageInfo messageInfo;
162
163 MyMemClear(&messageInfo, sizeof(messageInfo));
164
165 messageInfo.u.getCurrentTrackCoverArtMessage.coverArt = nil;
166
167 status = ITCallApplication(appCookie, appProc, kPlayerGetCurrentTrackCoverArtMessage, &messageInfo);
168
169 *coverArt = messageInfo.u.getCurrentTrackCoverArtMessage.coverArt;
170 if (coverArtFormat)
171 *coverArtFormat = messageInfo.u.getCurrentTrackCoverArtMessage.coverArtFormat;
172 return status;
173 }
174
175 // PlayerGetPluginData
176 //
PlayerGetPluginData(void * appCookie,ITAppProcPtr appProc,void * dataPtr,UInt32 dataBufferSize,UInt32 * dataSize)177 OSStatus PlayerGetPluginData (void *appCookie, ITAppProcPtr appProc, void *dataPtr, UInt32 dataBufferSize, UInt32 *dataSize)
178 {
179 OSStatus status;
180 PlayerMessageInfo messageInfo;
181
182 MyMemClear(&messageInfo, sizeof(messageInfo));
183
184 messageInfo.u.getPluginDataMessage.dataPtr = dataPtr;
185 messageInfo.u.getPluginDataMessage.dataBufferSize = dataBufferSize;
186
187 status = ITCallApplication(appCookie, appProc, kPlayerGetPluginDataMessage, &messageInfo);
188
189 if (dataSize != nil)
190 *dataSize = messageInfo.u.getPluginDataMessage.dataSize;
191
192 return status;
193 }
194
195
196 // PlayerSetPluginData
197 //
PlayerSetPluginData(void * appCookie,ITAppProcPtr appProc,void * dataPtr,UInt32 dataSize)198 OSStatus PlayerSetPluginData (void *appCookie, ITAppProcPtr appProc, void *dataPtr, UInt32 dataSize)
199 {
200 PlayerMessageInfo messageInfo;
201
202 MyMemClear(&messageInfo, sizeof(messageInfo));
203
204 messageInfo.u.setPluginDataMessage.dataPtr = dataPtr;
205 messageInfo.u.setPluginDataMessage.dataSize = dataSize;
206
207 return ITCallApplication(appCookie, appProc, kPlayerSetPluginDataMessage, &messageInfo);
208 }
209
210
211 // PlayerGetPluginNamedData
212 //
PlayerGetPluginNamedData(void * appCookie,ITAppProcPtr appProc,ConstStringPtr dataName,void * dataPtr,UInt32 dataBufferSize,UInt32 * dataSize)213 OSStatus PlayerGetPluginNamedData (void *appCookie, ITAppProcPtr appProc, ConstStringPtr dataName, void *dataPtr, UInt32 dataBufferSize, UInt32 *dataSize)
214 {
215 OSStatus status;
216 PlayerMessageInfo messageInfo;
217
218 MyMemClear(&messageInfo, sizeof(messageInfo));
219
220 messageInfo.u.getPluginNamedDataMessage.dataName = dataName;
221 messageInfo.u.getPluginNamedDataMessage.dataPtr = dataPtr;
222 messageInfo.u.getPluginNamedDataMessage.dataBufferSize = dataBufferSize;
223
224 status = ITCallApplication(appCookie, appProc, kPlayerGetPluginNamedDataMessage, &messageInfo);
225
226 if (dataSize != nil)
227 *dataSize = messageInfo.u.getPluginNamedDataMessage.dataSize;
228
229 return status;
230 }
231
232
233 // PlayerSetPluginNamedData
234 //
PlayerSetPluginNamedData(void * appCookie,ITAppProcPtr appProc,ConstStringPtr dataName,void * dataPtr,UInt32 dataSize)235 OSStatus PlayerSetPluginNamedData (void *appCookie, ITAppProcPtr appProc, ConstStringPtr dataName, void *dataPtr, UInt32 dataSize)
236 {
237 PlayerMessageInfo messageInfo;
238
239 MyMemClear(&messageInfo, sizeof(messageInfo));
240
241 messageInfo.u.setPluginNamedDataMessage.dataName = dataName;
242 messageInfo.u.setPluginNamedDataMessage.dataPtr = dataPtr;
243 messageInfo.u.setPluginNamedDataMessage.dataSize = dataSize;
244
245 return ITCallApplication(appCookie, appProc, kPlayerSetPluginNamedDataMessage, &messageInfo);
246 }
247
248
249 // PlayerIdle
250 //
PlayerIdle(void * appCookie,ITAppProcPtr appProc)251 OSStatus PlayerIdle (void *appCookie, ITAppProcPtr appProc)
252 {
253 return ITCallApplication(appCookie, appProc, kPlayerIdleMessage, nil);
254 }
255
256
257 // PlayerShowAbout
258 //
PlayerShowAbout(void * appCookie,ITAppProcPtr appProc)259 void PlayerShowAbout (void *appCookie, ITAppProcPtr appProc)
260 {
261 ITCallApplication(appCookie, appProc, kPlayerShowAboutMessage, nil);
262 }
263
264
265 // PlayerOpenURL
266 //
PlayerOpenURL(void * appCookie,ITAppProcPtr appProc,SInt8 * string,UInt32 length)267 void PlayerOpenURL (void *appCookie, ITAppProcPtr appProc, SInt8 *string, UInt32 length)
268 {
269 PlayerMessageInfo messageInfo;
270
271 MyMemClear(&messageInfo, sizeof(messageInfo));
272
273 messageInfo.u.openURLMessage.url = string;
274 messageInfo.u.openURLMessage.length = length;
275
276 ITCallApplication(appCookie, appProc, kPlayerOpenURLMessage, &messageInfo);
277 }
278
279 // PlayerUnregisterPlugin
280 //
PlayerUnregisterPlugin(void * appCookie,ITAppProcPtr appProc,PlayerMessageInfo * messageInfo)281 OSStatus PlayerUnregisterPlugin (void *appCookie, ITAppProcPtr appProc, PlayerMessageInfo *messageInfo)
282 {
283 return ITCallApplication(appCookie, appProc, kPlayerUnregisterPluginMessage, messageInfo);
284 }
285
286
287 // PlayerRegisterVisualPlugin
288 //
PlayerRegisterVisualPlugin(void * appCookie,ITAppProcPtr appProc,PlayerMessageInfo * messageInfo)289 OSStatus PlayerRegisterVisualPlugin (void *appCookie, ITAppProcPtr appProc, PlayerMessageInfo *messageInfo)
290 {
291 return ITCallApplicationInternal(appCookie, appProc, kPlayerRegisterVisualPluginMessage, kITVisualPluginMajorMessageVersion, kITVisualPluginMinorMessageVersion, messageInfo);
292 }
293
294
295 // PlayerHandleMacOSEvent
296 //
PlayerHandleMacOSEvent(void * appCookie,ITAppProcPtr appProc,const EventRecord * theEvent,Boolean * eventHandled)297 OSStatus PlayerHandleMacOSEvent (void *appCookie, ITAppProcPtr appProc, const EventRecord *theEvent, Boolean *eventHandled)
298 {
299 PlayerMessageInfo messageInfo;
300 OSStatus status;
301
302 MyMemClear(&messageInfo, sizeof(messageInfo));
303
304 messageInfo.u.handleMacOSEventMessage.theEvent = theEvent;
305
306 status = ITCallApplication(appCookie, appProc, kPlayerHandleMacOSEventMessage, &messageInfo);
307
308 if( eventHandled != nil )
309 *eventHandled = messageInfo.u.handleMacOSEventMessage.handled;
310
311 return status;
312 }
313
314 // PlayerGetPluginFileSpec
315 //
316 #if TARGET_OS_MAC
PlayerGetPluginFileSpec(void * appCookie,ITAppProcPtr appProc,FSSpec * pluginFileSpec)317 OSStatus PlayerGetPluginFileSpec (void *appCookie, ITAppProcPtr appProc, FSSpec *pluginFileSpec)
318 {
319 PlayerMessageInfo messageInfo;
320
321 MyMemClear(&messageInfo, sizeof(messageInfo));
322
323 messageInfo.u.getPluginFileSpecMessage.fileSpec = pluginFileSpec;
324
325 return ITCallApplication(appCookie, appProc, kPlayerGetPluginFileSpecMessage, &messageInfo);
326 }
327 #endif // TARGET_OS_MAC
328
329 // PlayerGetPluginITFileSpec
330 //
PlayerGetPluginITFileSpec(void * appCookie,ITAppProcPtr appProc,ITFileSpec * pluginFileSpec)331 OSStatus PlayerGetPluginITFileSpec (void *appCookie, ITAppProcPtr appProc, ITFileSpec *pluginFileSpec)
332 {
333 PlayerMessageInfo messageInfo;
334
335 MyMemClear(&messageInfo, sizeof(messageInfo));
336
337 messageInfo.u.getPluginITFileSpecMessage.fileSpec = pluginFileSpec;
338
339 return ITCallApplication(appCookie, appProc, kPlayerGetPluginITFileSpecMessage, &messageInfo);
340 }
341
342 // PlayerGetFileTrackInfo
343 //
PlayerGetFileTrackInfo(void * appCookie,ITAppProcPtr appProc,const ITFileSpec * fileSpec,ITTrackInfo * trackInfo)344 OSStatus PlayerGetFileTrackInfo (void *appCookie, ITAppProcPtr appProc, const ITFileSpec *fileSpec, ITTrackInfo *trackInfo)
345 {
346 PlayerMessageInfo messageInfo;
347
348 MyMemClear(&messageInfo, sizeof(messageInfo));
349
350 messageInfo.u.getFileTrackInfoMessage.fileSpec = fileSpec;
351 messageInfo.u.getFileTrackInfoMessage.trackInfo = trackInfo;
352
353 return ITCallApplication(appCookie, appProc, kPlayerGetFileTrackInfoMessage, &messageInfo);
354 }
355
356 // PlayerSetFileTrackInfo
357 //
PlayerSetFileTrackInfo(void * appCookie,ITAppProcPtr appProc,const ITFileSpec * fileSpec,const ITTrackInfo * trackInfo)358 OSStatus PlayerSetFileTrackInfo (void *appCookie, ITAppProcPtr appProc, const ITFileSpec *fileSpec, const ITTrackInfo *trackInfo)
359 {
360 PlayerMessageInfo messageInfo;
361
362 MyMemClear(&messageInfo, sizeof(messageInfo));
363
364 messageInfo.u.setFileTrackInfoMessage.fileSpec = fileSpec;
365 messageInfo.u.setFileTrackInfoMessage.trackInfo = trackInfo;
366
367 return ITCallApplication(appCookie, appProc, kPlayerSetFileTrackInfoMessage, &messageInfo);
368 }
369
370 // PlayerGetITTrackInfoSize
371 //
PlayerGetITTrackInfoSize(void * appCookie,ITAppProcPtr appProc,UInt32 appPluginMajorVersion,UInt32 appPluginMinorVersion,UInt32 * itTrackInfoSize)372 OSStatus PlayerGetITTrackInfoSize (void *appCookie, ITAppProcPtr appProc, UInt32 appPluginMajorVersion, UInt32 appPluginMinorVersion, UInt32 *itTrackInfoSize)
373 {
374 PlayerMessageInfo messageInfo;
375 OSStatus status;
376
377 /*
378 Note: appPluginMajorVersion and appPluginMinorVersion are the versions given to the plugin by iTunes in the plugin's init message.
379 These versions are *not* the version of the API used when the plugin was compiled.
380 */
381
382 *itTrackInfoSize = 0;
383
384 MyMemClear(&messageInfo, sizeof(messageInfo));
385
386 status = ITCallApplication(appCookie, appProc, kPlayerGetITTrackInfoSizeMessage, &messageInfo);
387 if( status == noErr )
388 {
389 *itTrackInfoSize = messageInfo.u.getITTrackInfoSizeMessage.itTrackInfoSize;
390 }
391 else if( appPluginMajorVersion == 10 && appPluginMinorVersion == 2 )
392 {
393 // iTunes 2.0.x
394
395 *itTrackInfoSize = ((UInt32) &((ITTrackInfo *) 0)->composer);
396
397 status = noErr;
398 }
399 else if( appPluginMajorVersion == 10 && appPluginMinorVersion == 3 )
400 {
401 // iTunes 3.0.x
402
403 *itTrackInfoSize = ((UInt32) &((ITTrackInfo *) 0)->beatsPerMinute);
404
405 status = noErr;
406 }
407 else
408 {
409 // iTunes 4.0 and later implement the kPlayerGetITTrackInfoSizeMessage message. If you got here
410 // then the appPluginMajorVersion or appPluginMinorVersion are incorrect.
411
412 status = paramErr;
413 }
414
415 if( status == noErr && (*itTrackInfoSize) > sizeof(ITTrackInfo) )
416 {
417 // iTunes is using a larger ITTrackInfo than the one when this plugin was compiled. Pin *itTrackInfoSize to the plugin's known size
418
419 *itTrackInfoSize = sizeof(ITTrackInfo);
420 }
421
422 return status;
423 }
424