summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/qt/qtsupport.py
blob: c2dd024772b1d603e101ff522ba4942f1c4b6f3a (plain)
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
# This script generates a Python interface for an Apple Macintosh Manager.
# It uses the "bgen" package to generate C code.
# The function specifications are generated by scanning the mamager's header file,
# using the "scantools" package (customized for this particular manager).

#error missing SetActionFilter

import string

# Declarations that change for each manager
MACHEADERFILE = 'Movies.h'		# The Apple header file
MODNAME = '_Qt'				# The name of the module
OBJECTNAME = 'Movie'			# The basic name of the objects used here

# The following is *usually* unchanged but may still require tuning
MODPREFIX = 'Qt'			# The prefix for module-wide routines
OBJECTTYPE = "Movie"		# The C type used to represent them
OBJECTPREFIX = MODPREFIX + 'Obj'	# The prefix for object methods
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
OUTPUTFILE = MODNAME + "module.c"	# The file generated by this program

from macsupport import *

# Create the type objects

includestuff = includestuff + """
#include <QuickTime/QuickTime.h>


#ifdef USE_TOOLBOX_OBJECT_GLUE
extern PyObject *_TrackObj_New(Track);
extern int _TrackObj_Convert(PyObject *, Track *);
extern PyObject *_MovieObj_New(Movie);
extern int _MovieObj_Convert(PyObject *, Movie *);
extern PyObject *_MovieCtlObj_New(MovieController);
extern int _MovieCtlObj_Convert(PyObject *, MovieController *);
extern PyObject *_TimeBaseObj_New(TimeBase);
extern int _TimeBaseObj_Convert(PyObject *, TimeBase *);
extern PyObject *_UserDataObj_New(UserData);
extern int _UserDataObj_Convert(PyObject *, UserData *);
extern PyObject *_MediaObj_New(Media);
extern int _MediaObj_Convert(PyObject *, Media *);

#define TrackObj_New _TrackObj_New
#define TrackObj_Convert _TrackObj_Convert
#define MovieObj_New _MovieObj_New
#define MovieObj_Convert _MovieObj_Convert
#define MovieCtlObj_New _MovieCtlObj_New
#define MovieCtlObj_Convert _MovieCtlObj_Convert
#define TimeBaseObj_New _TimeBaseObj_New
#define TimeBaseObj_Convert _TimeBaseObj_Convert
#define UserDataObj_New _UserDataObj_New
#define UserDataObj_Convert _UserDataObj_Convert
#define MediaObj_New _MediaObj_New
#define MediaObj_Convert _MediaObj_Convert
#endif

/* Macro to allow us to GetNextInterestingTime without duration */
#define GetMediaNextInterestingTimeOnly(media, flags, time, rate, rv) \
			GetMediaNextInterestingTime(media, flags, time, rate, rv, NULL)
			
/*
** Parse/generate time records
*/
static PyObject *
QtTimeRecord_New(TimeRecord *itself)
{
	if (itself->base)
		return Py_BuildValue("O&lO&", PyMac_Buildwide, &itself->value, itself->scale, 
			TimeBaseObj_New, itself->base);
	else
		return  Py_BuildValue("O&lO", PyMac_Buildwide, &itself->value, itself->scale, 
			Py_None);
}

static int
QtTimeRecord_Convert(PyObject *v, TimeRecord *p_itself)
{
	PyObject *base = NULL;
	if( !PyArg_ParseTuple(v, "O&l|O", PyMac_Getwide, &p_itself->value, &p_itself->scale,
			&base) )
		return 0;
	if ( base == NULL || base == Py_None )
		p_itself->base = NULL;
	else
		if ( !TimeBaseObj_Convert(base, &p_itself->base) )
			return 0;
	return 1;
}



"""

initstuff = initstuff + """
	PyMac_INIT_TOOLBOX_OBJECT_NEW(Track, TrackObj_New);
	PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Track, TrackObj_Convert);
	PyMac_INIT_TOOLBOX_OBJECT_NEW(Movie, MovieObj_New);
	PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Movie, MovieObj_Convert);
	PyMac_INIT_TOOLBOX_OBJECT_NEW(MovieController, MovieCtlObj_New);
	PyMac_INIT_TOOLBOX_OBJECT_CONVERT(MovieController, MovieCtlObj_Convert);
	PyMac_INIT_TOOLBOX_OBJECT_NEW(TimeBase, TimeBaseObj_New);
	PyMac_INIT_TOOLBOX_OBJECT_CONVERT(TimeBase, TimeBaseObj_Convert);
	PyMac_INIT_TOOLBOX_OBJECT_NEW(UserData, UserDataObj_New);
	PyMac_INIT_TOOLBOX_OBJECT_CONVERT(UserData, UserDataObj_Convert);
	PyMac_INIT_TOOLBOX_OBJECT_NEW(Media, MediaObj_New);
	PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Media, MediaObj_Convert);
"""

# Our (opaque) objects
Movie = OpaqueByValueType('Movie', 'MovieObj')
NullMovie = FakeType("(Movie)0")
Track = OpaqueByValueType('Track', 'TrackObj')
Media = OpaqueByValueType('Media', 'MediaObj')
UserData = OpaqueByValueType('UserData', 'UserDataObj')
TimeBase = OpaqueByValueType('TimeBase', 'TimeBaseObj')
MovieController = OpaqueByValueType('MovieController', 'MovieCtlObj')
IdleManager = OpaqueByValueType('IdleManager', 'IdleManagerObj')
SGOutput = OpaqueByValueType('SGOutput', 'SGOutputObj')

# Other opaque objects
Component = OpaqueByValueType('Component', 'CmpObj')
MediaHandlerComponent = OpaqueByValueType('MediaHandlerComponent', 'CmpObj')
DataHandlerComponent = OpaqueByValueType('DataHandlerComponent', 'CmpObj')
CompressorComponent = OpaqueByValueType('CompressorComponent', 'CmpObj')
DecompressorComponent = OpaqueByValueType('DecompressorComponent', 'CmpObj')
CodecComponent = OpaqueByValueType('CodecComponent', 'CmpObj')
GraphicsImportComponent = OpaqueByValueType('GraphicsImportComponent', 'CmpObj')
GraphicsExportComponent = OpaqueByValueType('GraphicsExportComponent', 'CmpObj')
ImageTranscoderComponent = OpaqueByValueType('ImageTranscoderComponent', 'CmpObj')
DataCodecComponent = OpaqueByValueType('DataCodecComponent', 'CmpObj')
GraphicImageMovieImportComponent = OpaqueByValueType('GraphicImageMovieImportComponent', 'CmpObj')
MovieExportComponent = OpaqueByValueType('MovieExportComponent', 'CmpObj')
MovieImportComponent = OpaqueByValueType('MovieImportComponent', 'CmpObj')
QTVideoOutputComponent = OpaqueByValueType('QTVideoOutputComponent', 'CmpObj')
SeqGrabComponent = OpaqueByValueType('SeqGrabComponent', 'CmpObj')
TextExportComponent = OpaqueByValueType('TextExportComponent', 'CmpObj')
TweenerComponent = OpaqueByValueType('TweenerComponent', 'CmpObj')
pnotComponent = OpaqueByValueType('pnotComponent', 'CmpObj')
VideoDigitizerComponent = OpaqueByValueType('VideoDigitizerComponent', 'CmpObj')

ComponentInstance = OpaqueByValueType('ComponentInstance', 'CmpInstObj')
MediaHandler = OpaqueByValueType('MediaHandler', 'CmpInstObj')
DataHandler = OpaqueByValueType('DataHandler', 'CmpInstObj')
SGChannel = OpaqueByValueType('SGChannel', 'CmpInstObj')

ConstFSSpecPtr = FSSpec_ptr
GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj")
Byte = Boolean # XXXX For GetPaused and SetPaused

RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
PicHandle = OpaqueByValueType("PicHandle", "ResObj")
CTabHandle = OpaqueByValueType("CTabHandle", "ResObj")
PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj")
SampleDescriptionHandle = OpaqueByValueType("SampleDescriptionHandle", "ResObj")
ImageDescriptionHandle = OpaqueByValueType("ImageDescriptionHandle", "ResObj")
TextDescriptionHandle = OpaqueByValueType("TextDescriptionHandle", "ResObj")
TEHandle = OpaqueByValueType("TEHandle", "ResObj")
CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj")
GDHandle = OpaqueByValueType("GDHandle", "OptResObj")
AliasHandle = OpaqueByValueType("AliasHandle", "ResObj")
SoundDescriptionHandle = OpaqueByValueType("SoundDescriptionHandle", "ResObj")
VdigBufferRecListHandle = OpaqueByValueType("VdigBufferRecListHandle", "ResObj")
VDCompressionListHandle = OpaqueByValueType("VDCompressionListHandle", "ResObj")
TimeCodeDescriptionHandle = OpaqueByValueType("TimeCodeDescriptionHandle", "ResObj")
DataHFileTypeOrderingHandle = OpaqueByValueType("DataHFileTypeOrderingHandle", "ResObj")
# Silly Apple, passing an OStype by reference...
OSType_ptr = OpaqueType("OSType", "PyMac_BuildOSType", "PyMac_GetOSType")
# And even sillier: passing floats by address
float_ptr = ByAddressType("float", "f")

RGBColor = OpaqueType("RGBColor", "QdRGB")
RGBColor_ptr = RGBColor
TimeRecord = OpaqueType("TimeRecord", "QtTimeRecord")
TimeRecord_ptr = TimeRecord

# Non-opaque types, mostly integer-ish
TimeValue = Type("TimeValue", "l")
TimeScale = Type("TimeScale", "l")
TimeBaseFlags = Type("TimeBaseFlags", "l")
QTCallBackFlags = Type("QTCallBackFlags", "H")
TimeBaseStatus = Type("TimeBaseStatus", "l")
QTCallBackType = Type("QTCallBackType", "H")
nextTimeFlagsEnum = Type("nextTimeFlagsEnum", "H")
createMovieFileFlagsEnum = Type("createMovieFileFlagsEnum", "l")
movieFlattenFlagsEnum = Type("movieFlattenFlagsEnum", "l")
dataRefAttributesFlags = Type("dataRefAttributesFlags", "l")
playHintsEnum = Type("playHintsEnum", "l")
mediaHandlerFlagsEnum = Type("mediaHandlerFlagsEnum", "l")
ComponentResult = Type("ComponentResult", "l")
VideoDigitizerError = Type("ComponentResult", "l")
HandlerError = Type("HandlerError", "l")
Ptr = InputOnlyType("Ptr", "s")
StringPtr = Type("StringPtr", "s")
mcactionparams = InputOnlyType("void *", "s")
QTParameterDialog = Type("QTParameterDialog", "l")
QTAtomID = Type("QTAtomID", "l")
MCInterfaceElement = Type("MCInterfaceElement", "l")
CodecType = OSTypeType("CodecType")
GWorldPtr = OpaqueByValueType("GWorldPtr", "GWorldObj")
QTFloatSingle = Type("QTFloatSingle", "f")
CodecQ = Type("CodecQ", "l")

# Could-not-be-bothered-types (NewMovieFromFile)
dummyshortptr = FakeType('(short *)0')
dummyStringPtr = FakeType('(StringPtr)0')

# XXXX Need to override output_tp_newBody() to allow for None initializer.
class QtGlobalObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
	def outputCheckNewArg(self):
		# We don't allow NULL pointers to be returned by QuickTime API calls,
		# in stead we raise an exception
		Output("""if (itself == NULL) {
					PyErr_SetString(Qt_Error,"Cannot create %s from NULL pointer");
					return NULL;
				}""", self.name)
	
	def outputCheckConvertArg(self):
		# But what we do allow is passing None whereever a quicktime object is
		# expected, and pass this as NULL to the API routines. Note you can
		# call methods too by creating an object with None as the initializer.
		Output("if (v == Py_None)")
		OutLbrace()
		Output("*p_itself = NULL;")
		Output("return 1;")
		OutRbrace()
	
class MovieObjectDefinition(QtGlobalObjectDefinition):
	def outputFreeIt(self, itselfname):
		Output("if (%s) DisposeMovie(%s);", itselfname, itselfname)

class TrackObjectDefinition(QtGlobalObjectDefinition):
	def outputFreeIt(self, itselfname):
		Output("if (%s) DisposeMovieTrack(%s);", itselfname, itselfname)

class MediaObjectDefinition(QtGlobalObjectDefinition):
	def outputFreeIt(self, itselfname):
		Output("if (%s) DisposeTrackMedia(%s);", itselfname, itselfname)

class UserDataObjectDefinition(QtGlobalObjectDefinition):
	def outputFreeIt(self, itselfname):
		Output("if (%s) DisposeUserData(%s);", itselfname, itselfname)

class TimeBaseObjectDefinition(QtGlobalObjectDefinition):
	pass
	
class MovieCtlObjectDefinition(QtGlobalObjectDefinition):
	def outputFreeIt(self, itselfname):
		Output("if (%s) DisposeMovieController(%s);", itselfname, itselfname)

class IdleManagerObjectDefinition(QtGlobalObjectDefinition):
	pass
	
class SGOutputObjectDefinition(QtGlobalObjectDefinition):
	# XXXX I'm not sure I fully understand how SGOutput works. It seems it's always tied
	# to a specific SeqGrabComponent, but I'm not 100% sure. Also, I'm not sure all the
	# routines that return an SGOutput actually return a *new* SGOutput. Need to read up on
	# this.
	pass


# From here on it's basically all boiler plate...

# Create the generator groups and link them
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
Movie_object = MovieObjectDefinition('Movie', 'MovieObj', 'Movie')
Track_object = TrackObjectDefinition('Track', 'TrackObj', 'Track')
Media_object = MediaObjectDefinition('Media', 'MediaObj', 'Media')
UserData_object = UserDataObjectDefinition('UserData', 'UserDataObj', 'UserData')
TimeBase_object = TimeBaseObjectDefinition('TimeBase', 'TimeBaseObj', 'TimeBase')
MovieController_object = MovieCtlObjectDefinition('MovieController', 'MovieCtlObj', 'MovieController')
IdleManager_object = IdleManagerObjectDefinition('IdleManager', 'IdleManagerObj', 'IdleManager')
SGOutput_object = SGOutputObjectDefinition('SGOutput', 'SGOutputObj', 'SGOutput')

module.addobject(IdleManager_object)
module.addobject(MovieController_object)
module.addobject(TimeBase_object)
module.addobject(UserData_object)
module.addobject(Media_object)
module.addobject(Track_object)
module.addobject(Movie_object)
module.addobject(SGOutput_object)

# Test which types we are still missing.
execfile(string.lower(MODPREFIX) + 'typetest.py')

# Create the generator classes used to populate the lists
Function = OSErrWeakLinkFunctionGenerator
Method = OSErrWeakLinkMethodGenerator

# Create and populate the lists
functions = []
IdleManager_methods = []
MovieController_methods = []
TimeBase_methods = []
UserData_methods = []
Media_methods = []
Track_methods = []
Movie_methods = []
SGOutput_methods = []
execfile(INPUTFILE)

#
# Some functions from ImageCompression.h that we need:
ICMAlignmentProcRecordPtr = FakeType('(ICMAlignmentProcRecordPtr)0')
dummyRect = FakeType('(Rect *)0')

f = Function(void, 'AlignWindow',
	(WindowPtr, 'wp', InMode),
	(Boolean, 'front', InMode),
	(dummyRect, 'alignmentRect', InMode),
	(ICMAlignmentProcRecordPtr, 'alignmentProc', InMode),
)
functions.append(f)

f = Function(void, 'DragAlignedWindow',
	(WindowPtr, 'wp', InMode),
	(Point, 'startPt', InMode),
	(Rect_ptr, 'boundsRect', InMode),
	(dummyRect, 'alignmentRect', InMode),
	(ICMAlignmentProcRecordPtr, 'alignmentProc', InMode),
)
functions.append(f)

# And we want the version of MoviesTask without a movie argument
f = Function(void, 'MoviesTask',
    (NullMovie, 'theMovie', InMode),
    (long, 'maxMilliSecToUse', InMode),
)
functions.append(f)

# And we want a GetMediaNextInterestingTime without duration
f = Method(void, 'GetMediaNextInterestingTimeOnly',
    (Media, 'theMedia', InMode),
    (short, 'interestingTimeFlags', InMode),
    (TimeValue, 'time', InMode),
    (Fixed, 'rate', InMode),
    (TimeValue, 'interestingTime', OutMode),
)
Media_methods.append(f)

# add the populated lists to the generator groups
# (in a different wordl the scan program would generate this)
for f in functions: module.add(f)
for f in MovieController_methods: MovieController_object.add(f)
for f in TimeBase_methods: TimeBase_object.add(f)
for f in UserData_methods: UserData_object.add(f)
for f in Media_methods: Media_object.add(f)
for f in Track_methods: Track_object.add(f)
for f in Movie_methods: Movie_object.add(f)

# generate output (open the output file as late as possible)
SetOutputFileName(OUTPUTFILE)
module.generate()