-
Notifications
You must be signed in to change notification settings - Fork 3
/
listing20.html
executable file
·2048 lines (1671 loc) · 63.6 KB
/
listing20.html
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>MovieSprites - /Common Files/QTUtilities.c</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/QuickTime/index.html">QuickTime</a> > <a href="../../samplecode/QuickTime/idxWiredMoviesandSprites-date.html">Wired Movies and Sprites</a> > <A HREF="javascript:location.replace('index.html');">MovieSprites</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">MovieSprites</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/Common Files/QTUtilities.c</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/Application Files/ComApplication.c</option>
<option value="listing2.html">/Application Files/ComApplication.h</option>
<option value="listing3.html">/Application Files/ComResource.h</option>
<option value="listing4.html">/Clippings/AddKeyFrameSampleMedia.txt</option>
<option value="listing5.html">/Clippings/AddMovieResource.txt</option>
<option value="listing6.html">/Clippings/AddOverrideSamples.txt</option>
<option value="listing7.html">/Clippings/AddSpritesToKeyFrameSample.txt</option>
<option value="listing8.html">/Clippings/CreateKeyFrameSample.txt</option>
<option value="listing9.html">/Clippings/CreateSpriteMovie.txt</option>
<option value="listing10.html">/Clippings/CreateSpriteTrackAndMedia.txt</option>
<option value="listing11.html">/Common Files/ComFramework.c</option>
<option value="listing12.html">/Common Files/ComFramework.h</option>
<option value="listing13.html">/Common Files/EndianUtilities.c</option>
<option value="listing14.html">/Common Files/EndianUtilities.h</option>
<option value="listing15.html">/Common Files/ImageCompressionUtilities.c</option>
<option value="listing16.html">/Common Files/ImageCompressionUtilities.h</option>
<option value="listing17.html">/Common Files/MacFramework.c</option>
<option value="listing18.html">/Common Files/MacFramework.h</option>
<option value="listing19.html">/Common Files/MacPrefix.h</option>
<option value="listing20.html">/Common Files/QTUtilities.c</option>
<option value="listing21.html">/Common Files/QTUtilities.h</option>
<option value="listing22.html">/Common Files/SpriteUtilities.c</option>
<option value="listing23.html">/Common Files/SpriteUtilities.h</option>
<option value="listing24.html">/Common Files/WinPrefix.h</option>
<option value="listing25.html">/Completed Lab/QTSprites.c</option>
<option value="listing26.html">/Completed Lab/QTSprites.h</option>
<option value="listing27.html">/Completed Lab/QTSprites.r</option>
<option value="listing28.html">/Start Code/QTSprites.c</option>
<option value="listing29.html">/Start Code/QTSprites.h</option></select>
</p>
</form>
<p><strong><a href="MovieSprites.zip">Download Sample</a></strong> (“MovieSprites.zip”, 2.08M)<BR>
<strong><a href="MovieSprites.dmg">Download Sample</a></strong> (“MovieSprites.dmg”, 2.72M)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">//////////
//
// File: QTUtilities.c
//
// Contains: Some utilities for working with QuickTime movies.
// All utilities start with the prefix "QTUtils_".
//
// Written by: Tim Monroe
// Based on the DTSQTUtilities package by Apple DTS.
// This began as essentially a subset of that package, revised for cross-platform use.
//
// Copyright: © 1996-1999 by Apple Computer, Inc., all rights reserved.
//
// Change History (most recent first):
//
// <33> 03/08/00 rtm removed QTUtils_SaveMovie and QTUtils_PrintMoviePICT
// <32> 03/02/00 rtm added QTUtils_SelectNoneMovie
// <31> 01/10/00 rtm tweaked QTUtils_IsQuickTimeInstalled
// <30> 12/20/99 rtm reworked QTUtils_IsMovieFile, to first test for files of type kQTFileTypeMovie
// <29> 12/09/99 rtm added QTUtils_PutControllerBarOnTop
// <28> 12/08/99 rtm reworked controller button functions to support custom buttom (its mcFlags constant
// is a "Use" constant and not a "Suppress" constant)
// <27> 11/26/99 rtm added endian adjustments to _GetMovieFileLoopingInfo and _GetWindowPositionFromFile
// <26> 11/17/99 rtm added QTUtils_GetWindowPositionFromFile
// <25> 05/19/99 rtm removed QTUtils_GetMovie
// <24> 05/10/99 rtm added QTUtils_UpdateMovieVolumeSetting
// <23> 03/22/99 rtm updated connection speed code to use constants/data types now in Movies.h
// <22> 03/11/99 rtm moved _GetControllerType and _SetControllerType from QTVRUtilities to here;
// added QTUtils_ChangeControllerType
// <21> 02/03/99 rtm moved non-QTVR-specific utilities from QTVRUtilities to here
// <20> 01/26/99 rtm added QTUtils_ConvertCToPascalString; removed "\p" from any constant strings
// <19> 01/25/99 rtm #define'd away QTUtils_GetUsersContentRating and siblings, since content rating
// capability is not in latest feature set
// <18> 12/09/98 rtm added QTUtils_GetUsersContentRating
// <17> 11/18/98 rtm added QTUtils_GetFrameCount
// <16> 10/27/98 rtm added QTUtils_MakeMovieLoop
// <15> 09/14/98 rtm added QTUtils_GetUsersConnectionSpeed and QTUtils_SetUsersConnectionSpeed
// <14> 06/24/98 rtm added QTUtils_GetMaxWindowDepth and QTUtils_GetMaxScreenDepth
// <13> 06/04/98 rtm added QTUtils_DeleteAllReferencesToTrack
// <12> 05/28/98 rtm added some typecasting to minimize MSDev compiler warnings
// <11> 05/19/98 rtm added QTUtils_MovieHasTimeCodeTrack
// <10> 05/04/98 rtm added QTUtils_GetTrackName, QTUtils_SetTrackName, QTUtils_MakeTrackNameByType,
// QTUtils_IsImageFile, and QTUtils_IsMovieFile
// <9> 02/28/98 rtm fixed QTUtils_GetMovieFileLoopingInfo and the like
// <8> 01/14/98 rtm added QTUtils_ConvertFloatToBigEndian
// <7> 12/19/97 rtm added QTUtils_AddUserDataTextToMovie and associated routines;
// added QTUtils_GetMovieFileLoopingInfo and the like
// <6> 11/06/97 rtm added QTUtils_MakeSampleDescription
// <5> 10/29/97 rtm modified QTUtils_IsMediaTypeInMovie and similar routines to use GetMovieIndTrackType
// <4> 10/27/97 rtm added QTUtils_HasQuickTimeVideoEffects
// <3> 10/17/97 rtm added QTUtils_MovieHasSoundTrack
// <2> 09/23/97 rtm added endian adjustment to QTUtils_PrintMoviePICT
// <1> 09/10/97 rtm first file
//
//////////
//////////
//
// header files
//
//////////
#ifndef __QTUtilities__
#include "QTUtilities.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// General utilities.
//
// Use these functions to get information about the availability/features of QuickTime or other services.
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////
//
// QTUtils_TrapAvailable
// Check to see whether a given trap is implemented. This is based on IM: Operating System Utilities (p. 8-22).
//
//////////
#if TARGET_OS_MAC && !TARGET_API_MAC_CARBON
Boolean QTUtils_TrapAvailable (short theTrapWord)
{
TrapType myTrapType;
short myNumToolboxTraps;
// determine whether this is a Toolbox or an Operating System trap
if ((theTrapWord & 0x0800) > 0)
myTrapType = ToolTrap;
else
myTrapType = OSTrap;
if (myTrapType == ToolTrap) {
theTrapWord = theTrapWord & 0x07FF;
if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap))
myNumToolboxTraps = 0x0200;
else
myNumToolboxTraps = 0x0400;
if (theTrapWord >= myNumToolboxTraps)
theTrapWord = _Unimplemented;
}
return(NGetTrapAddress(theTrapWord, myTrapType) != NGetTrapAddress(_Unimplemented, ToolTrap));
}
#endif
//////////
//
// QTUtils_IsQuickTimeInstalled
// Is QuickTime installed?
//
//////////
Boolean QTUtils_IsQuickTimeInstalled (void)
{
long myAttrs;
OSErr myErr = noErr;
myErr = Gestalt(gestaltQuickTime, &myAttrs);
return(myErr == noErr);
}
//////////
//
// QTUtils_IsQuickTimeCFMInstalled
// Are the QuickTime CFM libraries installed?
//
//////////
#if TARGET_CPU_PPC
Boolean QTUtils_IsQuickTimeCFMInstalled (void)
{
Boolean myQTCFMAvail = false;
long myAttrs;
OSErr myErr = noErr;
// test whether the PowerPC QuickTime glue library is present
myErr = Gestalt(gestaltQuickTimeFeatures, &myAttrs);
if (myErr == noErr)
if (myAttrs & (1L << gestaltPPCQuickTimeLibPresent))
myQTCFMAvail = true;
// test whether a function is available (the library is not moved from the Extension folder);
// this is the trick to be used when testing if a function is available via CFM
if (!CompressImage)
myQTCFMAvail = false;
return(myQTCFMAvail);
}
#endif
//////////
//
// QTUtils_GetQTVersion
// Get the version of QuickTime installed.
// The high-order word of the returned long integer contains the version number,
// so you can test a version like this:
//
// if (((QTUtils_GetQTVersion() >> 16) & 0xffff) >= 0x0210) // we require QT 2.1 or greater
// return;
//
//////////
long QTUtils_GetQTVersion (void)
{
long myVersion = 0L;
OSErr myErr = noErr;
myErr = Gestalt(gestaltQuickTime, &myVersion);
if (myErr == noErr)
return(myVersion);
else
return(0L);
}
//////////
//
// QTUtils_HasQuickTimeVideoEffects
// Does the installed version of QuickTime support video effects?
//
// Note: this is a pretty cheesy way of determining whether video effects are available.
//
//////////
Boolean QTUtils_HasQuickTimeVideoEffects (void)
{
return(((QTUtils_GetQTVersion() >> 16) & 0xffff) >= kQTVideoEffectsMinVers);
}
//////////
//
// QTUtils_HasFullScreenSupport
// Does the installed version of QuickTime support the full-screen routines?
//
// Note: this is a pretty cheesy way of determining whether full-screen routines are available.
//
//////////
Boolean QTUtils_HasFullScreenSupport (void)
{
return(((QTUtils_GetQTVersion() >> 16) & 0xffff) >= kQTFullScreenMinVers);
}
//////////
//
// QTUtils_HasWiredSprites
// Does the installed version of QuickTime support wired sprites?
//
// Note: this is a pretty cheesy way of determining whether wired sprites are available.
//
//////////
Boolean QTUtils_HasWiredSprites (void)
{
return(((QTUtils_GetQTVersion() >> 16) & 0xffff) >= kQTWiredSpritesMinVers);
}
//////////
//
// QTUtils_IsQTVRMovie
// Is the specified movie a QTVR movie?
//
// WARNING: This function is intended for use ONLY when you want to determine if you've got a QTVR movie
// but you don't want to use the QuickTime VR API (perhaps QTVR isn't installed...). The preferred way to
// determine if a movie is a QTVR movie is to call QTVRGetQTVRTrack and then QTVRGetQTVRInstance; if you
// get back a non-NULL instance, you've got a QTVR movie.
//
//////////
Boolean QTUtils_IsQTVRMovie (Movie theMovie)
{
Boolean myIsQTVRMovie = false;
OSType myType;
// QTVR movies have a special piece of user data identifying the movie controller type
myType = QTUtils_GetControllerType(theMovie);
if ((myType == kQTVRQTVRType) || (myType == kQTVROldPanoType) || (myType == kQTVROldObjectType))
myIsQTVRMovie = true;
return(myIsQTVRMovie);
}
//////////
//
// QTUtils_IsStreamedMovie
// Is the specified movie a streamed movie?
//
//////////
Boolean QTUtils_IsStreamedMovie (Movie theMovie)
{
return(GetMovieIndTrackType(theMovie, 1, kQTSStreamMediaType, movieTrackMediaType | movieTrackEnabledOnly) != NULL);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Controller bar utilities.
//
// Use these functions to manipulate the controller bar, its buttons, and the help text displayed in it.
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////
//
// QTUtils_IsControllerBarVisible
// Is the controller bar currently visible?
//
//////////
Boolean QTUtils_IsControllerBarVisible (MovieController theMC)
{
return((Boolean)MCGetVisible(theMC));
}
//////////
//
// QTUtils_GetControllerBarHeight
// Return the height of the controller bar displayed by the movie controller.
//
// Note that MCGetControllerBoundsRect returns the rectangle of bar and movie, if attached;
// so we need to detach the controller bar first.
//
//////////
short QTUtils_GetControllerBarHeight (MovieController theMC)
{
Boolean wasAttached = false;
Rect myRect;
// if the controller bar is attached, detach it (and remember we did so)
if (MCIsControllerAttached(theMC) == 1) {
wasAttached = true;
MCSetControllerAttached(theMC, false);
}
// get the rectangle of the controller
MCGetControllerBoundsRect(theMC, &myRect);
// now reattach the controller bar, if it was originally attached
if (wasAttached)
MCSetControllerAttached(theMC, true);
return(myRect.bottom - myRect.top);
}
//////////
//
// QTUtils_HideControllerBar
// Hide the controller bar provided by the movie controller.
//
//////////
void QTUtils_HideControllerBar (MovieController theMC)
{
MCSetVisible(theMC, false);
}
//////////
//
// QTUtils_ShowControllerBar
// Show the controller bar provided by the movie controller.
//
//////////
void QTUtils_ShowControllerBar (MovieController theMC)
{
MCSetVisible(theMC, true);
}
//////////
//
// QTUtils_ToggleControllerBar
// Toggle the state of the controller bar provided by the movie controller.
//
//////////
void QTUtils_ToggleControllerBar (MovieController theMC)
{
if (QTUtils_IsControllerBarVisible(theMC))
QTUtils_HideControllerBar(theMC);
else
QTUtils_ShowControllerBar(theMC);
}
//////////
//
// QTUtils_PutControllerBarOnTop
// Put the movie controller bar at the top of the movie window.
//
//////////
void QTUtils_PutControllerBarOnTop (MovieController theMC)
{
if (theMC == NULL)
return;
if (MCIsControllerAttached(theMC) == 1) {
Rect myMCRect;
Rect myMovieRect;
MCGetControllerBoundsRect(theMC, &myMCRect);
myMovieRect = myMCRect;
myMCRect.bottom = myMCRect.top + QTUtils_GetControllerBarHeight(theMC);
myMovieRect.top = myMCRect.bottom + 1;
MCSetControllerAttached(theMC, false);
MCPositionController(theMC, &myMovieRect, &myMCRect, 0L);
}
}
//////////
//
// QTUtils_HideControllerButton
// Hide the specified button in the controller bar.
//
// Some explanation is probably useful here: the first thing to understand is that every VR movie has
// TWO sets of movie controller flags: (1) a set of "control flags" and (2) a set of "explicit flags".
//
// The control flags work as documented in IM: QuickTime Components (pp. 2-20f) and in VRPWQTVR2.0 (pp. 2-23f):
// if a bit in the set of control flags is set (that is, equal to 1), then the associated action or property is
// enabled. For instance, bit 17 (mcFlagQTVRSuppressZoomBtns) means to suppress the zoom buttons. So, if that
// bit is set in a VR movie's control flags, the zoom buttons are NOT displayed. If that bit is clear, the zoom
// buttons are displayed.
//
// However, the QuickTime VR movie controller sometimes suppresses buttons even when those buttons
// have not been explicitly suppressed in the control flags. For example, if a particular VR movie does not
// contain a sound track, then the movie controller automatically suppresses the speaker/volume button. Likewise,
// if a movie does contain a sound track, then the speaker/volume button is automatically displayed, again without
// regard to the actual value of bit 2 in the control flags.
//
// This might not be what you'd like to happen. For instance, if your application is playing a sound that it
// loaded from a sound resource, you might want the user to be able to adjust the sound's volume using the volume
// control. To do that, you need a way to *force* the speaker/volume button to appear. For this reason, the
// explicit flags were introduced.
//
// The explicit flags indicate which bits in the control flags are to be used explicitly (that is, taken at
// face value). If a certain bit is set in a movie's explicit flags, then the corresponding bit in the control
// flags is interpreted as the desired setting for the feature (and the movie controller will not attempt to
// do anything "clever"). In other words, if bit 17 is set in a movie's explicit flags and bit 17 is clear in
// that movie's control flags, then the zoom buttons are displayed. Similarly, if bit 2 is set in a movie's
// explicit flags and bit 2 is clear in that movie's control flags, then the speaker/volume button is displayed,
// whether or not the movie contains a sound track.
//
// The final thing to understand: to get or set a bit in a movie's explicit flags, you must set the flag
// mcFlagQTVRExplicitFlagSet in your call to mcActionGetFlags or mcActionSetFlags. To get or set a bit in a
// movie's control flags, you must clear the flag mcFlagQTVRExplicitFlagSet in your call to mcActionGetFlags
// or mcActionSetFlags. Note that when you use the defined constants to set values in the explicit flags, the
// constant names might be confusing. For instance, setting the bit mcFlagSuppressSpeakerButton in a movie's
// explicit flags doesn't cause the speaker to be suppressed; it just means: "use the actual value of the
// mcFlagSuppressSpeakerButton bit in the control flags".
//
// Whew! Any questions? Okay, then now you'll understand how to hide or show a button in the controller bar:
// set the appropriate explicit flag to 1 and set the corresponding control flag to the desired value. And
// you'll understand how to let the movie controller do its "clever" work: clear the appropriate explicit flag.
//
// There is one final twist to this story: the mcFlag bit for the custom controller button indicates that the
// custom button should be shown, not (like all other button flags) that the button should be suppressed. So
// we need to treat the custom button specially. Sigh.
//
//////////
void QTUtils_HideControllerButton (MovieController theMC, long theButton)
{
long myControllerFlags;
// handle the custom button separately
if (theButton == kQTUtilsCustomButton) {
MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags & ~theButton));
} else {
// get the current explicit flags and set the explicit flag for the specified button
myControllerFlags = mcFlagQTVRExplicitFlagSet;
MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
MCDoAction(theMC, mcActionSetFlags, (void *)((myControllerFlags | theButton) | mcFlagQTVRExplicitFlagSet));
// get the current control flags and set the suppress flag for the specified button
myControllerFlags = 0;
MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
MCDoAction(theMC, mcActionSetFlags, (void *)((myControllerFlags | theButton) & ~mcFlagQTVRExplicitFlagSet));
}
}
//////////
//
// QTUtils_ShowControllerButton
// Show the specified button in the controller bar.
//
//////////
void QTUtils_ShowControllerButton (MovieController theMC, long theButton)
{
long myControllerFlags;
// handle the custom button separately
if (theButton == kQTUtilsCustomButton) {
MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags | theButton));
} else {
// get the current explicit flags and set the explicit flag for the specified button
myControllerFlags = mcFlagQTVRExplicitFlagSet;
MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
MCDoAction(theMC, mcActionSetFlags, (void *)((myControllerFlags | theButton) | mcFlagQTVRExplicitFlagSet));
// get the current control flags and clear the suppress flag for the specified button
myControllerFlags = 0;
MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags & ~theButton & ~mcFlagQTVRExplicitFlagSet));
}
}
//////////
//
// QTUtils_ToggleControllerButton
// Toggle the state of the specified button in the controller bar.
//
//////////
void QTUtils_ToggleControllerButton (MovieController theMC, long theButton)
{
if (QTUtils_IsControllerButtonVisible(theMC, theButton))
QTUtils_HideControllerButton(theMC, theButton);
else
QTUtils_ShowControllerButton(theMC, theButton);
}
//////////
//
// QTUtils_ResetControllerButton
// Remove any explicit setting of the specified button in the controller bar.
// (This allows the QuickTime VR movie controller to be as clever as it knows how to be.)
//
//////////
void QTUtils_ResetControllerButton (MovieController theMC, long theButton)
{
long myControllerFlags = mcFlagQTVRExplicitFlagSet;
// get the current explicit flags and clear the explicit flag for the specified button
MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
MCDoAction(theMC, mcActionSetFlags, (void *)((myControllerFlags | theButton) & ~mcFlagQTVRExplicitFlagSet));
}
//////////
//
// QTUtils_IsControllerButtonVisible
// Is the specified button in the controller bar currently visible?
//
//////////
Boolean QTUtils_IsControllerButtonVisible (MovieController theMC, long theButton)
{
long myControllerFlags;
// get the current control flags
myControllerFlags = 0;
MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
// the speaker button requires some additional logic, because the QTVR movie controller treats it special;
// be advised that that controller's special behavior could change in the future, so you might need to tweak this code
if (theButton == mcFlagSuppressSpeakerButton) {
long myExplicitFlags;
// get the current explicit flags
myExplicitFlags = mcFlagQTVRExplicitFlagSet;
MCDoAction(theMC, mcActionGetFlags, &myExplicitFlags);
// the speaker button is not showing if the movie has no sound track and the explicit flag is not set
if (!QTUtils_MovieHasSoundTrack(MCGetMovie(theMC)) && !(myExplicitFlags & theButton))
return(false);
}
// the custom button requires some different treatment, since it doesn't have a "Suppress" button constant
if (theButton == mcFlagsUseCustomButton)
if (myControllerFlags & theButton)
return(true);
else
return(false);
// examine the suppress flag for the specified button
if (myControllerFlags & theButton) // if the button is currently suppressed...
return(false);
else
return(true);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Media utilities.
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////
//
// QTUtils_IsMediaTypeInMovie
// Determine whether a specific media type is in a movie.
//
//////////
Boolean QTUtils_IsMediaTypeInMovie (Movie theMovie, OSType theMediaType)
{
return(GetMovieIndTrackType(theMovie, 1, theMediaType, movieTrackMediaType | movieTrackEnabledOnly) != NULL);
}
//////////
//
// QTUtils_MovieHasTimeCodeTrack
// Determine whether a movie contains a timecode track.
//
//////////
Boolean QTUtils_MovieHasTimeCodeTrack (Movie theMovie)
{
return(GetMovieIndTrackType(theMovie, 1, TimeCodeMediaType, movieTrackMediaType) != NULL);
}
//////////
//
// QTUtils_MovieHasSoundTrack
// Determine whether a movie contains a sound track.
//
//////////
Boolean QTUtils_MovieHasSoundTrack (Movie theMovie)
{
return(GetMovieIndTrackType(theMovie, 1, AudioMediaCharacteristic, movieTrackCharacteristic | movieTrackEnabledOnly) != NULL);
}
//////////
//
// QTUtils_GetSoundMediaHandler
// Return the sound media handler for a movie.
//
//////////
MediaHandler QTUtils_GetSoundMediaHandler (Movie theMovie)
{
Track myTrack;
Media myMedia;
myTrack = GetMovieIndTrackType(theMovie, 1, AudioMediaCharacteristic, movieTrackCharacteristic | movieTrackEnabledOnly);
if (myTrack != NULL) {
myMedia = GetTrackMedia(myTrack);
return(GetMediaHandler(myMedia));
}
return(NULL);
}
//////////
//
// QTUtils_UpdateMovieVolumeSetting
// Update the preferred volume setting of the specified movie.
//
//////////
OSErr QTUtils_UpdateMovieVolumeSetting (Movie theMovie)
{
short myPrefVolume;
short myCurrVolume;
OSErr myErr = noErr;
myPrefVolume = GetMoviePreferredVolume(theMovie);
myCurrVolume = GetMovieVolume(theMovie);
myCurrVolume = abs(myCurrVolume);
if (myPrefVolume != myCurrVolume) {
SetMoviePreferredVolume(theMovie, myCurrVolume);
myErr = GetMoviesError();
}
return(myErr);
}
//////////
//
// QTUtils_SelectAllMovie
// Select the entire movie associated with the specified movie controller.
//
//////////
OSErr QTUtils_SelectAllMovie (MovieController theMC)
{
TimeRecord myTimeRecord;
Movie myMovie = NULL;
ComponentResult myErr = noErr;
if (theMC == NULL)
return(paramErr);
myMovie = MCGetMovie(theMC);
if (myMovie == NULL)
return(paramErr);
myTimeRecord.value.hi = 0;
myTimeRecord.value.lo = 0;
myTimeRecord.base = 0;
myTimeRecord.scale = GetMovieTimeScale(myMovie);
myErr = MCDoAction(theMC, mcActionSetSelectionBegin, &myTimeRecord);
if (myErr != noErr)
return((OSErr)myErr);
myTimeRecord.value.hi = 0;
myTimeRecord.value.lo = GetMovieDuration(myMovie);
myTimeRecord.base = 0;
myTimeRecord.scale = GetMovieTimeScale(myMovie);
myErr = MCDoAction(theMC, mcActionSetSelectionDuration, &myTimeRecord);
return((OSErr)myErr);
}
//////////
//
// QTUtils_SelectNoneMovie
// Select none of the movie associated with the specified movie controller.
//
//////////
OSErr QTUtils_SelectNoneMovie (MovieController theMC)
{
TimeRecord myTimeRecord;
Movie myMovie = NULL;
ComponentResult myErr = noErr;
if (theMC == NULL)
return(paramErr);
myMovie = MCGetMovie(theMC);
if (myMovie == NULL)
return(paramErr);
myTimeRecord.value.hi = 0;
myTimeRecord.value.lo = 0;
myTimeRecord.base = 0;
myTimeRecord.scale = GetMovieTimeScale(myMovie);
myErr = MCDoAction(theMC, mcActionSetSelectionDuration, &myTimeRecord);
return((OSErr)myErr);
}
//////////
//
// QTUtils_MakeSampleDescription
// Return a new image description with default and specified values.
//
//////////
ImageDescriptionHandle QTUtils_MakeSampleDescription (long theEffectType, short theWidth, short theHeight)
{
ImageDescriptionHandle mySampleDesc = NULL;
// create a new sample description
mySampleDesc = (ImageDescriptionHandle)NewHandleClear(sizeof(ImageDescription));
if (mySampleDesc == NULL)
return(NULL);
// fill in the fields of the sample description
(**mySampleDesc).idSize = sizeof(ImageDescription);
(**mySampleDesc).cType = theEffectType;
(**mySampleDesc).vendor = kAppleManufacturer;
(**mySampleDesc).temporalQuality = codecNormalQuality;
(**mySampleDesc).spatialQuality = codecNormalQuality;
(**mySampleDesc).width = theWidth;
(**mySampleDesc).height = theHeight;
(**mySampleDesc).hRes = 72L << 16;
(**mySampleDesc).vRes = 72L << 16;
(**mySampleDesc).dataSize = 0L;
(**mySampleDesc).frameCount = 1;
(**mySampleDesc).depth = 24;
(**mySampleDesc).clutID = -1;
return(mySampleDesc);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// User data utilities.
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////
#if CONTENT_RATING_AVAIL
//////////
//
// QTUtils_GetContentRatingFromMovie
// Get the content rating from a movie; return an error if it has none. In any case, return a meaningful
// content rating.
//
//////////
OSErr QTUtils_GetContentRatingFromMovie (Movie theMovie, UInt16 *theRating, UInt32 *theReasons)
{
UserData myUserData = NULL;
QTAltContentRatingRecord myContentRec;
OSErr myErr = paramErr;
*theRating = kQTContentTVYRating;
*theReasons = 0L;
// make sure we've got a movie
if (theMovie == NULL)
return(myErr);
// get the movie's user data list
myUserData = GetMovieUserData(theMovie);
if (myUserData != NULL) {
myErr = GetUserDataItem(myUserData, &myContentRec, sizeof(myContentRec), FOUR_CHAR_CODE('crat'), 0);
if (myErr == noErr) {
*theRating = EndianU16_BtoN(myContentRec.ratings);
*theReasons = EndianU32_BtoN(myContentRec.contentType);
}
}
return(myErr);
}
//////////
//
// QTUtils_AddContentRatingToMovie
// Add a content rating to a movie.
//
// A content rating is stored as a user data item that indicates both the general rating
// (for example, TV-MA [mature audiences only]) and any additional information about the
// content (for example, coarse language). Let's call this additional information the
// "reasons" for the rating. Both the rating and the reasons are specified using constants
// in the file MoviesFormat.h.
//
// This function adds the specified content rating to the movie's user data;
// the updated user data is written to the movie file when the movie is next updated
// (by calling UpdateMovieResource).
//
//////////
OSErr QTUtils_AddContentRatingToMovie (Movie theMovie, UInt16 theRating, UInt32 theReasons)
{
UserData myUserData = NULL;
QTAltContentRatingRecord myContentRec;
OSErr myErr = noErr;
// get the movie's user data list
myUserData = GetMovieUserData(theMovie);
if (myUserData == NULL)
return(paramErr);
myContentRec.flags = 0;
myContentRec.contentType = EndianU32_NtoB(theReasons);
myContentRec.ratings = EndianU16_NtoB(theRating);
// for simplicity, we assume that we want only one content rating in the movie;
// as a result, we won't worry about overwriting any existing item of that type
// add the data to the movie's user data
myErr = SetUserDataItem(myUserData, &myContentRec, sizeof(myContentRec), FOUR_CHAR_CODE('crat'), 0);
return(myErr);
}
#endif // #if CONTENT_RATING_AVAIL
//////////
//
// QTUtils_AddUserDataTextToMovie
// Add a user data item, of the specified type, containing the specified text to a movie.
//
// This function adds the specified text to the movie's user data;
// the updated user data is written to the movie file when the movie is next updated
// (by calling UpdateMovieResource).
//
//////////
OSErr QTUtils_AddUserDataTextToMovie (Movie theMovie, char *theText, OSType theType)
{
UserData myUserData = NULL;
Handle myHandle = NULL;
short myIndex = 0;
long myLength = strlen(theText);
OSErr myErr = noErr;
// get the movie's user data list
myUserData = GetMovieUserData(theMovie);
if (myUserData == NULL)
return(paramErr);
// copy the specified text into a new handle
myHandle = NewHandleClear(myLength);