[Gridflow-cvs] [svn] commit: r3338 - in /trunk/format: aalib.c main.c mpeg3.c opengl.c quartz.m quicktimeapple.c quicktimehw.c sdl.c videodev.c x11.c

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Fri Mar 28 16:24:45 EDT 2008


Author: matju
Date: Fri Mar 28 16:24:45 2008
New Revision: 3338

Log:
removed \def 0 close (turned into C++ destructors)

Modified:
    trunk/format/aalib.c
    trunk/format/main.c
    trunk/format/mpeg3.c
    trunk/format/opengl.c
    trunk/format/quartz.m
    trunk/format/quicktimeapple.c
    trunk/format/quicktimehw.c
    trunk/format/sdl.c
    trunk/format/videodev.c
    trunk/format/x11.c

Modified: trunk/format/aalib.c
==============================================================================
--- trunk/format/aalib.c (original)
+++ trunk/format/aalib.c Fri Mar 28 16:24:45 2008
@@ -42,7 +42,7 @@
 	bool raw_mode;
 	FormatAALib () : context(0), autodraw(1) {}
 	\decl void initialize (t_symbol *mode, string target);
-	\decl 0 close ();
+	~FormatAALib () {if (context) aa_close(context);}
 	\decl 0 hidecursor ();
 	\decl 0 print (int y, int x, int a, string text);
 	\decl 0 draw ();
@@ -97,13 +97,6 @@
 	if (autodraw==1) aa_flush(context);
 } GRID_END
 
-\def 0 close () {
-	if (context) {
-		aa_close(context);
-		context=0;
-	}
-}
-
 \def 0 hidecursor () { aa_hidemouse(context); }
 \def 0 draw () { aa_flush(context); }
 \def 0 print (int y, int x, int a, string text) {

Modified: trunk/format/main.c
==============================================================================
--- trunk/format/main.c (original)
+++ trunk/format/main.c Fri Mar 28 16:24:45 2008
@@ -48,11 +48,11 @@
 		last frame (mpeg/quicktime used to do this)
 	def 0 seek(Integer i) :     select one frame to be read next (by number)
 	def 0 length() : ^Integer   returns number of frames (never implemented ?)
-	def 0 close() :             close a handler
 	def 0 grid() : frame to write
 	def 0 ...() : options
 	outlet 0 grid() frame just read
 	outlet 1 ...() everything else
+	destructor : close a handler
 */
 
 std::map<std::string,std::string> suffix_table;
@@ -100,7 +100,7 @@
 }
 \end class FormatLookup {install("gf.format_lookup",1,1);}
 
-\class Format < GridObject
+\class Format : GridObject
 \def void initialize (t_symbol *mode, ...) {
 	SUPER;
 	if (mode==gensym("out")) this->mode=2; else
@@ -185,7 +185,10 @@
 	\decl 0 headerless_m (...);
 	\decl 0 headerful ();
 	\decl 0 type (NumberTypeE nt);
-	\decl 0 close();
+	~FormatGrid() {
+		//@stream.close if @stream
+		//GridFlow.hunt_zombies
+	}
 //	\decl void raw_open_gzip_in(String filename);
 //	\decl void raw_open_gzip_out(String filename);
 };
@@ -269,10 +272,6 @@
 	//if (pid=fork) {GridFlow.subprocesses[pid]=true; r.close; @stream = w;}
 	//else {w.close; STDIN.reopen r; STDOUT.reopen filename, "w"; exec "gzip", "-c";}
 
-\def 0 close () {
-	//@stream.close if @stream
-	//GridFlow.hunt_zombies
-}
 \end class FormatGrid {install_format("#io.grid",6,"grid");}
 
 void startup_format () {

Modified: trunk/format/mpeg3.c
==============================================================================
--- trunk/format/mpeg3.c (original)
+++ trunk/format/mpeg3.c Fri Mar 28 16:24:45 2008
@@ -31,10 +31,10 @@
 	mpeg3_t *mpeg;
 	int track;
 	FormatMPEG3 () : track(0) {}
+	~FormatMPEG3 () {if (mpeg) {mpeg3_close(mpeg); mpeg=0;}}
 	\decl void initialize (t_symbol *mode, string filename);
 	\decl 0 seek (int frame);
 	\decl 0 bang ();
-	\decl 0 close ();
 };
 
 \def 0 seek (int frame) { mpeg3_set_frame(mpeg,frame,track); }
@@ -60,11 +60,6 @@
 //	return INT2NUM(nframe);
 }
 
-\def 0 close () {
-	if (mpeg) { mpeg3_close(mpeg); mpeg=0; }
-	SUPER;
-}
-
 // libmpeg3 may be nice, but it won't take a filehandle, only filename
 \def void initialize (t_symbol *mode, string filename) {
 	SUPER;

Modified: trunk/format/opengl.c
==============================================================================
--- trunk/format/opengl.c (original)
+++ trunk/format/opengl.c Fri Mar 28 16:24:45 2008
@@ -50,9 +50,18 @@
 	t_clock *clock;
 	\decl void call ();
 	\decl void initialize (Symbol mode);
-	\decl 0 close ();
 	\decl 0 resize_window (int sx, int sy);
 	\grin 0
+	~FormatOpenGL () {
+		clock_unset(clock);
+		if (gltex) glDeleteTextures(1, (GLuint*)&gltex);
+		if (buf) delete buf;
+		in_use=false;
+		if ((unsigned)window!=0xDeadBeef) {
+			glutDestroyWindow(window);
+			window=0xDeadBeef;
+		}
+	}
 };
 
 static jmp_buf hack;
@@ -134,17 +143,6 @@
 	} GRID_FINISH {
 } GRID_END
 
-\def 0 close () {
-	clock_unset(clock);
-	if (gltex) glDeleteTextures(1, (GLuint*)&gltex);
-	if (buf) delete buf;
-	in_use=false;
-	if ((unsigned)window!=0xDeadBeef) {
-		glutDestroyWindow(window);
-		window=0xDeadBeef;
-	}
-}
-
 \def void initialize (Symbol mode) {
 	SUPER;
 	if (in_use) RAISE("only one #io:opengl object at a time; sorry");

Modified: trunk/format/quartz.m
==============================================================================
--- trunk/format/quartz.m (original)
+++ trunk/format/quartz.m Fri Mar 28 16:24:45 2008
@@ -120,9 +120,16 @@
 	GFView *widget; /* GridFlow's Cocoa widget */
 	NSDate *distantFuture;
 	t_clock *clock;
+	~FormatQuartz () {
+		clock_unset(clock);
+		clock_free(clock);
+		clock = 0;
+		[window autorelease];
+		[window setReleasedWhenClosed: YES];
+		[window close];
+	}
 	\decl void initialize (Symbol mode);
 	\decl 0 delete_m ();
-	\decl 0 close ();
 	\decl 0 call ();
 	\grin 0
 };
@@ -211,15 +218,6 @@
 \def 0 delete_m () {
 	[window autorelease];
 }
-\def 0 close () {
-	clock_unset(clock);
-	clock_free(clock);
-	clock = 0;
-	SUPER;
-	[window autorelease];
-	[window setReleasedWhenClosed: YES];
-	[window close];
-}
 \end class FormatQuartz {
 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 	distantFuture = [NSDate distantFuture];

Modified: trunk/format/quicktimeapple.c
==============================================================================
--- trunk/format/quicktimeapple.c (original)
+++ trunk/format/quicktimeapple.c Fri Mar 28 16:24:45 2008
@@ -191,9 +191,15 @@
   int m_quality;
 //int m_colorspace;
   FormatQuickTimeCamera() : vdc(0) {}
+  ~FormatQuickTimeCamera() {
+    if (m_vc) if (::SGDisposeChannel(m_sg, m_vc)) RAISE("SGDisposeChannel");
+    if (m_sg) {
+      if (::CloseComponent(m_sg)) RAISE("CloseComponent");
+      if (m_srcGWorld) ::DisposeGWorld(m_srcGWorld);
+    }
+  }
   \decl void initialize (t_symbol *mode, string filename);
   \decl 0 frame ();
-  \decl 0 close ();
   \grin 0 int
 };
 
@@ -307,23 +313,6 @@
     out.send(dim->prod(),buf);
 }
 
-\def 0 close () {
-  if (m_vc) {
-    if (::SGDisposeChannel(m_sg, m_vc)) RAISE("SGDisposeChannel");
-    m_vc=0;
-  }
-  if (m_sg) {
-    if (::CloseComponent(m_sg)) RAISE("CloseComponent");
-    m_sg = NULL;
-    if (m_srcGWorld) {
-	::DisposeGWorld(m_srcGWorld);
-	m_pixMap = NULL;
-	m_srcGWorld = NULL;
-	m_baseAddr = NULL;
-    }
-  }
-}
-
 GRID_INLET(FormatQuickTimeCamera,0) {
 	RAISE("Unimplemented. Sorry.");
 //!@#$
@@ -347,8 +336,14 @@
 	int nframe, nframes;
 	FormatQuickTimeApple() : movie(0), time(0), movie_file(0), gw(0),
 		buffer(), dim(0), nframe(0), nframes(0) {}
+	~FormatQuickTimeApple() {
+		if (movie) {
+			DisposeMovie(movie);
+			DisposeGWorld(gw);
+			CloseMovieFile(movie_file);
+		}
+	}
 	\decl void initialize (t_symbol *mode, string filename);
-	\decl 0 close ();
 	\decl 0 codec_m (String c);
 	\decl 0 colorspace_m (Symbol c);
 	\decl 0 bang ();
@@ -413,17 +408,6 @@
 
 \def 0 codec_m      (String c) { RAISE("Unimplemented. Sorry."); }
 \def 0 colorspace_m (Symbol c) { RAISE("Unimplemented. Sorry."); }
-
-\def 0 close () {
-//!@#$
-	if (movie) {
-		DisposeMovie(movie);
-		DisposeGWorld(gw);
-		CloseMovieFile(movie_file);
-		movie_file=0;
-	}
-	SUPER;
-}
 
 \def void initialize (t_symbol *mode, string filename) {
 	int err;

Modified: trunk/format/quicktimehw.c
==============================================================================
--- trunk/format/quicktimehw.c (original)
+++ trunk/format/quicktimehw.c Fri Mar 28 16:24:45 2008
@@ -47,8 +47,8 @@
 	int jpeg_quality; // in theory we shouldn't need this, but...
 	FormatQuickTimeHW() : track(0), dim(0), codec(QUICKTIME_RAW), 
 		started(false), force(0), framerate(29.97), bit_packing(0), jpeg_quality(75) {}
+	~FormatQuickTimeHW() {if (anim) quicktime_close(anim);}
 	\decl void initialize (t_symbol *mode, string filename);
-	\decl 0 close ();
 	\decl 0 bang ();
 	\decl 0 seek (int frame);
 	\decl 0 force_size (int32 height, int32 width);
@@ -167,11 +167,6 @@
 	} else if (c=="yuva")    { channels=4; colorspace=BC_YUVA8888;
 	} else if (c=="YUV420P") { channels=3; colorspace=BC_YUV420P;
 	} else RAISE("unknown colorspace '%s' (supported: rgb, rgba, bgr, bgrn, yuv, yuva)",c.data());
-}
-
-\def 0 close () {
-	if (anim) { quicktime_close(anim); anim=0; }
-	SUPER;
 }
 
 \def 0 get () {

Modified: trunk/format/sdl.c
==============================================================================
--- trunk/format/sdl.c (original)
+++ trunk/format/sdl.c Fri Mar 28 16:24:45 2008
@@ -40,8 +40,12 @@
 	void resize_window (int sx, int sy);
 	void call ();
 	\decl void initialize (Symbol mode);
-	\decl 0 close ();
 	\grin 0 int
+	~FormatSDL () {
+		clock_unset(clock);
+		clock_free(clock);
+		in_use=false;
+	}
 };
 
 void FormatSDL::call() {
@@ -82,13 +86,6 @@
 	SDL_UpdateRect(screen,0,0,in->dim->get(1),in->dim->get(0));
 } GRID_END
 
-\def 0 close () {
-	clock_unset(clock);
-	clock_free(clock);
-	clock = 0;
-	in_use=false;
-}
-
 \def void initialize (Symbol mode) {
 	dim=0;screen=0;
 	SUPER;

Modified: trunk/format/videodev.c
==============================================================================
--- trunk/format/videodev.c (original)
+++ trunk/format/videodev.c Fri Mar 28 16:24:45 2008
@@ -245,7 +245,8 @@
 	void frame_ask ();
 	\decl void initialize (string mode, string filename);
 	void initialize2 ();
-	\decl 0 close ();
+	~FormatVideoDev () {if (image) dealloc_image();}
+
 	\decl 0 bang ();
 	\grin 0 int
 
@@ -570,11 +571,6 @@
 	WIOCTL(fd, VIDIOCSFREQ, &frequency);
 }
 
-\def 0 close () {
-	if (image) dealloc_image();
-	SUPER;
-}
-
 \def 0 colorspace (string c) { /* y yuv rgb */
 	if      (c=="y") {}
 	else if (c=="yuv") {}

Modified: trunk/format/x11.c
==============================================================================
--- trunk/format/x11.c (original)
+++ trunk/format/x11.c Fri Mar 28 16:24:45 2008
@@ -89,6 +89,13 @@
 		, shm_info(0)
 #endif
 	{}
+	~FormatX11 () {
+		clock_unset(clock);
+		if (is_owner) XDestroyWindow(display,window);
+		XSync(display,0);
+		dealloc_image();
+		XCloseDisplay(display);
+	}
 	template <class T> void frame_by_type (T bogus);
 	void show_section(int x, int y, int sx, int sy);
 	void set_wm_hints ();
@@ -101,7 +108,6 @@
 	Window search_window_tree (Window xid, Atom key, const char *value, int level=0);
 	\decl void initialize (...);
 	\decl 0 bang ();
-	\decl 0 close ();
 	void call ();
 	\decl 0 out_size (int sy, int sx);
 	\decl 0 setcursor (int shape);
@@ -419,18 +425,6 @@
 	show_section(0,0,in->dim->get(1),in->dim->get(0));
 } GRID_END
 
-\def 0 close () {
-	if (!this) RAISE("stupid error: trying to close display NULL. =)");
-	bit_packing=0;
-	clock_unset(clock);
-	if (is_owner) XDestroyWindow(display,window);
-	XSync(display,0);
-	dealloc_image();
-	XCloseDisplay(display);
-	display=0;
-	SUPER;
-}
-
 \def 0 out_size (int sy, int sx) { resize_window(sx,sy); }
 
 \def 0 setcursor (int shape) {



More information about the Gridflow-cvs mailing list