1
# This script generates a Python interface for an Apple Macintosh Manager.
2
# It uses the "bgen" package to generate C code.
3
# The function specifications are generated by scanning the mamager's header file,
4
# using the "scantools" package (customized for this particular manager).
6
#error missing SetActionFilter
10
# Declarations that change for each manager
11
MACHEADERFILE = 'Movies.h' # The Apple header file
12
MODNAME = '_Qt' # The name of the module
13
OBJECTNAME = 'Movie' # The basic name of the objects used here
15
# The following is *usually* unchanged but may still require tuning
16
MODPREFIX = 'Qt' # The prefix for module-wide routines
17
OBJECTTYPE = "Movie" # The C type used to represent them
18
OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
19
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
20
OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
22
from macsupport import *
24
# Create the type objects
26
includestuff = includestuff + """
27
#include <QuickTime/QuickTime.h>
30
#ifdef USE_TOOLBOX_OBJECT_GLUE
31
extern PyObject *_TrackObj_New(Track);
32
extern int _TrackObj_Convert(PyObject *, Track *);
33
extern PyObject *_MovieObj_New(Movie);
34
extern int _MovieObj_Convert(PyObject *, Movie *);
35
extern PyObject *_MovieCtlObj_New(MovieController);
36
extern int _MovieCtlObj_Convert(PyObject *, MovieController *);
37
extern PyObject *_TimeBaseObj_New(TimeBase);
38
extern int _TimeBaseObj_Convert(PyObject *, TimeBase *);
39
extern PyObject *_UserDataObj_New(UserData);
40
extern int _UserDataObj_Convert(PyObject *, UserData *);
41
extern PyObject *_MediaObj_New(Media);
42
extern int _MediaObj_Convert(PyObject *, Media *);
44
#define TrackObj_New _TrackObj_New
45
#define TrackObj_Convert _TrackObj_Convert
46
#define MovieObj_New _MovieObj_New
47
#define MovieObj_Convert _MovieObj_Convert
48
#define MovieCtlObj_New _MovieCtlObj_New
49
#define MovieCtlObj_Convert _MovieCtlObj_Convert
50
#define TimeBaseObj_New _TimeBaseObj_New
51
#define TimeBaseObj_Convert _TimeBaseObj_Convert
52
#define UserDataObj_New _UserDataObj_New
53
#define UserDataObj_Convert _UserDataObj_Convert
54
#define MediaObj_New _MediaObj_New
55
#define MediaObj_Convert _MediaObj_Convert
58
/* Macro to allow us to GetNextInterestingTime without duration */
59
#define GetMediaNextInterestingTimeOnly(media, flags, time, rate, rv) \
60
GetMediaNextInterestingTime(media, flags, time, rate, rv, NULL)
63
** Parse/generate time records
66
QtTimeRecord_New(TimeRecord *itself)
69
return Py_BuildValue("O&lO&", PyMac_Buildwide, &itself->value, itself->scale,
70
TimeBaseObj_New, itself->base);
72
return Py_BuildValue("O&lO", PyMac_Buildwide, &itself->value, itself->scale,
77
QtTimeRecord_Convert(PyObject *v, TimeRecord *p_itself)
79
PyObject *base = NULL;
80
if( !PyArg_ParseTuple(v, "O&l|O", PyMac_Getwide, &p_itself->value, &p_itself->scale,
83
if ( base == NULL || base == Py_None )
84
p_itself->base = NULL;
86
if ( !TimeBaseObj_Convert(base, &p_itself->base) )
92
QtMusicMIDIPacket_Convert(PyObject *v, MusicMIDIPacket *p_itself)
96
if( !PyArg_ParseTuple(v, "hls#", &p_itself->length, &p_itself->reserved, p_itself->data, dummy) )
105
initstuff = initstuff + """
106
PyMac_INIT_TOOLBOX_OBJECT_NEW(Track, TrackObj_New);
107
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Track, TrackObj_Convert);
108
PyMac_INIT_TOOLBOX_OBJECT_NEW(Movie, MovieObj_New);
109
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Movie, MovieObj_Convert);
110
PyMac_INIT_TOOLBOX_OBJECT_NEW(MovieController, MovieCtlObj_New);
111
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(MovieController, MovieCtlObj_Convert);
112
PyMac_INIT_TOOLBOX_OBJECT_NEW(TimeBase, TimeBaseObj_New);
113
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(TimeBase, TimeBaseObj_Convert);
114
PyMac_INIT_TOOLBOX_OBJECT_NEW(UserData, UserDataObj_New);
115
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(UserData, UserDataObj_Convert);
116
PyMac_INIT_TOOLBOX_OBJECT_NEW(Media, MediaObj_New);
117
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Media, MediaObj_Convert);
120
# Our (opaque) objects
121
Movie = OpaqueByValueType('Movie', 'MovieObj')
122
NullMovie = FakeType("(Movie)0")
123
Track = OpaqueByValueType('Track', 'TrackObj')
124
Media = OpaqueByValueType('Media', 'MediaObj')
125
UserData = OpaqueByValueType('UserData', 'UserDataObj')
126
TimeBase = OpaqueByValueType('TimeBase', 'TimeBaseObj')
127
MovieController = OpaqueByValueType('MovieController', 'MovieCtlObj')
128
IdleManager = OpaqueByValueType('IdleManager', 'IdleManagerObj')
129
SGOutput = OpaqueByValueType('SGOutput', 'SGOutputObj')
131
# Other opaque objects
132
Component = OpaqueByValueType('Component', 'CmpObj')
133
MediaHandlerComponent = OpaqueByValueType('MediaHandlerComponent', 'CmpObj')
134
DataHandlerComponent = OpaqueByValueType('DataHandlerComponent', 'CmpObj')
135
CompressorComponent = OpaqueByValueType('CompressorComponent', 'CmpObj')
136
DecompressorComponent = OpaqueByValueType('DecompressorComponent', 'CmpObj')
137
CodecComponent = OpaqueByValueType('CodecComponent', 'CmpObj')
138
GraphicsImportComponent = OpaqueByValueType('GraphicsImportComponent', 'CmpObj')
139
GraphicsExportComponent = OpaqueByValueType('GraphicsExportComponent', 'CmpObj')
140
ImageTranscoderComponent = OpaqueByValueType('ImageTranscoderComponent', 'CmpObj')
141
DataCodecComponent = OpaqueByValueType('DataCodecComponent', 'CmpObj')
142
GraphicImageMovieImportComponent = OpaqueByValueType('GraphicImageMovieImportComponent', 'CmpObj')
143
MovieExportComponent = OpaqueByValueType('MovieExportComponent', 'CmpObj')
144
MovieImportComponent = OpaqueByValueType('MovieImportComponent', 'CmpObj')
145
QTVideoOutputComponent = OpaqueByValueType('QTVideoOutputComponent', 'CmpObj')
146
SeqGrabComponent = OpaqueByValueType('SeqGrabComponent', 'CmpObj')
147
TextExportComponent = OpaqueByValueType('TextExportComponent', 'CmpObj')
148
TweenerComponent = OpaqueByValueType('TweenerComponent', 'CmpObj')
149
pnotComponent = OpaqueByValueType('pnotComponent', 'CmpObj')
150
VideoDigitizerComponent = OpaqueByValueType('VideoDigitizerComponent', 'CmpObj')
152
ComponentInstance = OpaqueByValueType('ComponentInstance', 'CmpInstObj')
153
MediaHandler = OpaqueByValueType('MediaHandler', 'CmpInstObj')
154
DataHandler = OpaqueByValueType('DataHandler', 'CmpInstObj')
155
SGChannel = OpaqueByValueType('SGChannel', 'CmpInstObj')
156
TunePlayer = OpaqueByValueType('TunePlayer', 'CmpInstObj')
157
MusicComponent = OpaqueByValueType('MusicComponent', 'CmpInstObj')
158
NoteAllocator = OpaqueByValueType('NoteAllocator', 'CmpInstObj')
159
QTMIDIComponent = OpaqueByValueType('QTMIDIComponent', 'CmpInstObj')
161
ConstFSSpecPtr = FSSpec_ptr
162
GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj")
163
Byte = Boolean # XXXX For GetPaused and SetPaused
165
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
166
PicHandle = OpaqueByValueType("PicHandle", "ResObj")
167
CTabHandle = OpaqueByValueType("CTabHandle", "ResObj")
168
PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj")
169
SampleDescriptionHandle = OpaqueByValueType("SampleDescriptionHandle", "ResObj")
170
ImageDescriptionHandle = OpaqueByValueType("ImageDescriptionHandle", "ResObj")
171
TextDescriptionHandle = OpaqueByValueType("TextDescriptionHandle", "ResObj")
172
TEHandle = OpaqueByValueType("TEHandle", "ResObj")
173
CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj")
174
GDHandle = OpaqueByValueType("GDHandle", "OptResObj")
175
AliasHandle = OpaqueByValueType("AliasHandle", "ResObj")
176
SoundDescriptionHandle = OpaqueByValueType("SoundDescriptionHandle", "ResObj")
177
VdigBufferRecListHandle = OpaqueByValueType("VdigBufferRecListHandle", "ResObj")
178
VDCompressionListHandle = OpaqueByValueType("VDCompressionListHandle", "ResObj")
179
TimeCodeDescriptionHandle = OpaqueByValueType("TimeCodeDescriptionHandle", "ResObj")
180
DataHFileTypeOrderingHandle = OpaqueByValueType("DataHFileTypeOrderingHandle", "ResObj")
181
QTMIDIPortListHandle = OpaqueByValueType("QTMIDIPortListHandle", "ResObj")
182
GenericKnobDescriptionListHandle = OpaqueByValueType("GenericKnobDescriptionListHandle", "ResObj")
183
InstrumentInfoListHandle = OpaqueByValueType("InstrumentInfoListHandle", "ResObj")
184
# Silly Apple, passing an OStype by reference...
185
OSType_ptr = OpaqueType("OSType", "PyMac_BuildOSType", "PyMac_GetOSType")
186
# And even sillier: passing floats by address
187
float_ptr = ByAddressType("float", "f")
189
RGBColor = OpaqueType("RGBColor", "QdRGB")
190
RGBColor_ptr = RGBColor
191
TimeRecord = OpaqueType("TimeRecord", "QtTimeRecord")
192
TimeRecord_ptr = TimeRecord
193
MusicMIDIPacket = OpaqueType("MusicMIDIPacket", "QtMusicMIDIPacket")
194
MusicMIDIPacket_ptr = MusicMIDIPacket
196
# Non-opaque types, mostly integer-ish
197
TimeValue = Type("TimeValue", "l")
198
TimeScale = Type("TimeScale", "l")
199
TimeBaseFlags = Type("TimeBaseFlags", "l")
200
QTCallBackFlags = Type("QTCallBackFlags", "H")
201
TimeBaseStatus = Type("TimeBaseStatus", "l")
202
QTCallBackType = Type("QTCallBackType", "H")
203
nextTimeFlagsEnum = Type("nextTimeFlagsEnum", "H")
204
createMovieFileFlagsEnum = Type("createMovieFileFlagsEnum", "l")
205
movieFlattenFlagsEnum = Type("movieFlattenFlagsEnum", "l")
206
dataRefAttributesFlags = Type("dataRefAttributesFlags", "l")
207
playHintsEnum = Type("playHintsEnum", "l")
208
mediaHandlerFlagsEnum = Type("mediaHandlerFlagsEnum", "l")
209
ComponentResult = Type("ComponentResult", "l")
210
VideoDigitizerError = Type("ComponentResult", "l")
211
HandlerError = Type("HandlerError", "l")
212
Ptr = InputOnlyType("Ptr", "s")
213
StringPtr = Type("StringPtr", "s")
214
UnsignedLongPtr = Type("unsigned long *", "s")
215
mcactionparams = InputOnlyType("void *", "s")
216
QTParameterDialog = Type("QTParameterDialog", "l")
217
QTAtomID = Type("QTAtomID", "l")
218
MCInterfaceElement = Type("MCInterfaceElement", "l")
219
CodecType = OSTypeType("CodecType")
220
GWorldPtr = OpaqueByValueType("GWorldPtr", "GWorldObj")
221
QTFloatSingle = Type("QTFloatSingle", "f")
222
CodecQ = Type("CodecQ", "l")
223
MusicController = Type("MusicController", "l")
225
# Could-not-be-bothered-types (NewMovieFromFile)
226
dummyshortptr = FakeType('(short *)0')
227
dummyStringPtr = FakeType('(StringPtr)0')
229
# Not-quite-sure-this-is-okay types
230
AtomicInstrument = OpaqueByValueType("AtomicInstrument", "ResObj")
231
AtomicInstrumentPtr = InputOnlyType("AtomicInstrumentPtr", "s")
233
# XXXX Need to override output_tp_newBody() to allow for None initializer.
234
class QtGlobalObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
235
def outputCheckNewArg(self):
236
# We don't allow NULL pointers to be returned by QuickTime API calls,
237
# in stead we raise an exception
238
Output("""if (itself == NULL) {
239
PyErr_SetString(Qt_Error,"Cannot create %s from NULL pointer");
243
def outputCheckConvertArg(self):
244
# But what we do allow is passing None whereever a quicktime object is
245
# expected, and pass this as NULL to the API routines. Note you can
246
# call methods too by creating an object with None as the initializer.
247
Output("if (v == Py_None)")
249
Output("*p_itself = NULL;")
253
class MovieObjectDefinition(QtGlobalObjectDefinition):
254
def outputFreeIt(self, itselfname):
255
Output("if (%s) DisposeMovie(%s);", itselfname, itselfname)
257
class TrackObjectDefinition(QtGlobalObjectDefinition):
258
def outputFreeIt(self, itselfname):
259
Output("if (%s) DisposeMovieTrack(%s);", itselfname, itselfname)
261
class MediaObjectDefinition(QtGlobalObjectDefinition):
262
def outputFreeIt(self, itselfname):
263
Output("if (%s) DisposeTrackMedia(%s);", itselfname, itselfname)
265
class UserDataObjectDefinition(QtGlobalObjectDefinition):
266
def outputFreeIt(self, itselfname):
267
Output("if (%s) DisposeUserData(%s);", itselfname, itselfname)
269
class TimeBaseObjectDefinition(QtGlobalObjectDefinition):
272
class MovieCtlObjectDefinition(QtGlobalObjectDefinition):
273
def outputFreeIt(self, itselfname):
274
Output("if (%s) DisposeMovieController(%s);", itselfname, itselfname)
276
class IdleManagerObjectDefinition(QtGlobalObjectDefinition):
279
class SGOutputObjectDefinition(QtGlobalObjectDefinition):
280
# XXXX I'm not sure I fully understand how SGOutput works. It seems it's always tied
281
# to a specific SeqGrabComponent, but I'm not 100% sure. Also, I'm not sure all the
282
# routines that return an SGOutput actually return a *new* SGOutput. Need to read up on
287
# From here on it's basically all boiler plate...
289
# Create the generator groups and link them
290
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
291
Movie_object = MovieObjectDefinition('Movie', 'MovieObj', 'Movie')
292
Track_object = TrackObjectDefinition('Track', 'TrackObj', 'Track')
293
Media_object = MediaObjectDefinition('Media', 'MediaObj', 'Media')
294
UserData_object = UserDataObjectDefinition('UserData', 'UserDataObj', 'UserData')
295
TimeBase_object = TimeBaseObjectDefinition('TimeBase', 'TimeBaseObj', 'TimeBase')
296
MovieController_object = MovieCtlObjectDefinition('MovieController', 'MovieCtlObj', 'MovieController')
297
IdleManager_object = IdleManagerObjectDefinition('IdleManager', 'IdleManagerObj', 'IdleManager')
298
SGOutput_object = SGOutputObjectDefinition('SGOutput', 'SGOutputObj', 'SGOutput')
300
module.addobject(IdleManager_object)
301
module.addobject(MovieController_object)
302
module.addobject(TimeBase_object)
303
module.addobject(UserData_object)
304
module.addobject(Media_object)
305
module.addobject(Track_object)
306
module.addobject(Movie_object)
307
module.addobject(SGOutput_object)
309
# Test which types we are still missing.
310
execfile(string.lower(MODPREFIX) + 'typetest.py')
312
# Create the generator classes used to populate the lists
313
Function = OSErrWeakLinkFunctionGenerator
314
Method = OSErrWeakLinkMethodGenerator
316
# Create and populate the lists
318
IdleManager_methods = []
319
MovieController_methods = []
320
TimeBase_methods = []
321
UserData_methods = []
325
SGOutput_methods = []
329
# Some functions from ImageCompression.h that we need:
330
ICMAlignmentProcRecordPtr = FakeType('(ICMAlignmentProcRecordPtr)0')
331
dummyRect = FakeType('(Rect *)0')
333
f = Function(void, 'AlignWindow',
334
(WindowPtr, 'wp', InMode),
335
(Boolean, 'front', InMode),
336
(dummyRect, 'alignmentRect', InMode),
337
(ICMAlignmentProcRecordPtr, 'alignmentProc', InMode),
341
f = Function(void, 'DragAlignedWindow',
342
(WindowPtr, 'wp', InMode),
343
(Point, 'startPt', InMode),
344
(Rect_ptr, 'boundsRect', InMode),
345
(dummyRect, 'alignmentRect', InMode),
346
(ICMAlignmentProcRecordPtr, 'alignmentProc', InMode),
350
# And we want the version of MoviesTask without a movie argument
351
f = Function(void, 'MoviesTask',
352
(NullMovie, 'theMovie', InMode),
353
(long, 'maxMilliSecToUse', InMode),
357
# And we want a GetMediaNextInterestingTime without duration
358
f = Method(void, 'GetMediaNextInterestingTimeOnly',
359
(Media, 'theMedia', InMode),
360
(short, 'interestingTimeFlags', InMode),
361
(TimeValue, 'time', InMode),
362
(Fixed, 'rate', InMode),
363
(TimeValue, 'interestingTime', OutMode),
365
Media_methods.append(f)
367
# add the populated lists to the generator groups
368
# (in a different wordl the scan program would generate this)
369
for f in functions: module.add(f)
370
for f in MovieController_methods: MovieController_object.add(f)
371
for f in TimeBase_methods: TimeBase_object.add(f)
372
for f in UserData_methods: UserData_object.add(f)
373
for f in Media_methods: Media_object.add(f)
374
for f in Track_methods: Track_object.add(f)
375
for f in Movie_methods: Movie_object.add(f)
377
# generate output (open the output file as late as possible)
378
SetOutputFileName(OUTPUTFILE)