[Gridflow-cvs] [svn] commit: r6084 - in /trunk/src: aalib.cxx classes1.cxx classes2.cxx classes3.cxx formats.cxx sdl.cxx videodev.cxx x11.cxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Fri Aug 13 15:55:32 EDT 2010


Author: matju
Date: Fri Aug 13 15:55:28 2010
New Revision: 6084

Log:
various shortcuts

Modified:
    trunk/src/aalib.cxx
    trunk/src/classes1.cxx
    trunk/src/classes2.cxx
    trunk/src/classes3.cxx
    trunk/src/formats.cxx
    trunk/src/sdl.cxx
    trunk/src/videodev.cxx
    trunk/src/x11.cxx

Modified: trunk/src/aalib.cxx
==============================================================================
--- trunk/src/aalib.cxx (original)
+++ trunk/src/aalib.cxx Fri Aug 13 15:55:28 2010
@@ -58,10 +58,24 @@
 		post("aalib image size: %s",Dim(3,v).to_s());
 	}
 	~FormatAALib () {if (context) aa_close(context);}
-	\decl 0 hidecursor ();
-	\decl 0 print (int y, int x, int a, string text);
-	\decl 0 draw ();
-	\decl 0 dump ();
+	\decl 0 hidecursor () {aa_hidemouse(context);}
+	\decl 0 print (int y, int x, int a, string text) {
+		aa_puts(context,x,y,(AAAttr)a,(char *)text.data());
+		if (autodraw==1) aa_flush(context);
+	}
+	\decl 0 draw () {aa_flush(context);}
+	\decl 0 dump () {
+		int32 v[] = {aa_scrheight(context), aa_scrwidth(context), 2};
+		GridOut out(this,0,Dim(3,v));
+		for (int y=0; y<aa_scrheight(context); y++) {
+			for (int x=0; x<aa_scrwidth(context); x++) {
+				int32 data[2];
+				data[0] = context->textbuffer[y*aa_scrwidth(context)+x];
+				data[1] = context->attrbuffer[y*aa_scrwidth(context)+x];
+				out.send(2,data);
+			}
+		}
+	}
 	\grin 0 int
 };
 
@@ -110,26 +124,6 @@
 	if (autodraw==1) aa_flush(context);
 } GRID_END
 
-\def 0 hidecursor () { aa_hidemouse(context); }
-\def 0 draw () { aa_flush(context); }
-\def 0 print (int y, int x, int a, string text) {
-	aa_puts(context,x,y,(AAAttr)a,(char *)text.data());
-	if (autodraw==1) aa_flush(context);
-}
-
-\def 0 dump () {
-	int32 v[] = {aa_scrheight(context), aa_scrwidth(context), 2};
-	GridOut out(this,0,Dim(3,v));
-	for (int y=0; y<aa_scrheight(context); y++) {
-		for (int x=0; x<aa_scrwidth(context); x++) {
-			int32 data[2];
-			data[0] = context->textbuffer[y*aa_scrwidth(context)+x];
-			data[1] = context->attrbuffer[y*aa_scrwidth(context)+x];
-			out.send(2,data);
-		}
-	}
-}
-
 \end class FormatAALib {
 	const aa_driver *const *p = aa_drivers;
 	for (; *p; p++) drivers[(*p)->shortname] = *p;

Modified: trunk/src/classes1.cxx
==============================================================================
--- trunk/src/classes1.cxx (original)
+++ trunk/src/classes1.cxx Fri Aug 13 15:55:28 2010
@@ -120,7 +120,6 @@
 		process(n,(uint8 *)s.data());
 	}
 	\decl 0 bang() {_0_list(0,0);}
-	//\decl 0 list(...);
 	\decl 1 per_message() {per_message=true; dim_grid=0;}
 	\grin 0
 	\grin 1 int32
@@ -144,6 +143,7 @@
 	per_message=false;
 } GRID_END
 
+// needs to stay a \def because it's implicitly \decl'd in \grin 0
 \def 0 list(...) {//first two lines are there until grins become strictly initialized.
 	if (in.size()<=0) in.resize(1);
 	if (!in[0]) in[0]=new GridInlet((FObject *)this,stromgol);

Modified: trunk/src/classes2.cxx
==============================================================================
--- trunk/src/classes2.cxx (original)
+++ trunk/src/classes2.cxx Fri Aug 13 15:55:28 2010
@@ -364,11 +364,9 @@
 		ostringstream text;
 		if (s) text << *s; else text << "print";
 		prefix = text.str();
-		t_atom a[1];
-		SETSYMBOL(a,gensym(prefix.data()));
+		t_atom2 a[1]; a[0]=gensym(prefix.data());
 		pd_typedmess(&pd_objectmaker,gensym("#print"),1,a);
 		gp = pd_newest();
-		SETPOINTER(a,(t_gpointer *)bself);
 	}
 	~GFPrint () {pd_free(gp);}
 	\decl 0 grid(...) {pd_typedmess(gp,gensym("grid"),argc,argv);}
@@ -590,7 +588,7 @@
 		do_bind(argc-n,argv+n);
 	}
 	\decl 0 bang () {_0_list(0,0);}
-	\decl 0 symbol (t_symbol *s) {t_atom2 a[1]; SETSYMBOL(a,s); _0_list(1,a);}
+	\decl 0 symbol (t_symbol *s) {t_atom2 a[1]; a[0]=s; _0_list(1,a);}
 	\decl 0 list (...) {do_unbind(); do_bind(argc,argv);}
 	void do_bind (int argc, t_atom2 *argv) {
 		ac = argc;
@@ -773,9 +771,9 @@
 	int n;
 	\constructor (int n=0) {this->n=n;}
 	\decl 0 bang () {MOM;
-		t_atom a[2];
-		SETFLOAT(a+0,m->gl_obj.te_xpix);
-		SETFLOAT(a+1,m->gl_obj.te_ypix);
+		t_atom2 a[2];
+		a[0]=m->gl_obj.te_xpix;
+		a[1]=m->gl_obj.te_ypix;
 		out[0](2,a);
 	}
 };
@@ -1087,11 +1085,9 @@
 		t_widgetbehavior *wb = class_getwidget(c);
 		if (!wb) RAISE("not a patchable object");
 		if (!canvas_contains(mom,(t_gobj *)s->s_thing)) RAISE("object is not in this canvas");
-		int x1,y1,x2,y2; t_atom a[4];
+		int x1,y1,x2,y2;
 		wb->w_getrectfn((t_gobj *)s->s_thing,mom,&x1,&y1,&x2,&y2);
-		SETFLOAT(a+0,x1); SETFLOAT(a+1,y1);
-		SETFLOAT(a+2,x2); SETFLOAT(a+3,y2);
-		out[0](4,a);
+		t_atom2 a[4]; a[0]=x1; a[1]=y1; a[2]=x2; a[3]=y2; out[0](4,a);
 	}
 };
 
@@ -1255,16 +1251,16 @@
 			_0_get(gensym("folder"));
 		}
 		if (s==gensym("version")) {
-			t_atom a[3];
-			SETFLOAT(a+0,GF_VERSION_A);
-			SETFLOAT(a+1,GF_VERSION_B);
-			SETFLOAT(a+2,GF_VERSION_C);
+			t_atom2 a[3];
+			a[0]=GF_VERSION_A;
+			a[1]=GF_VERSION_B;
+			a[2]=GF_VERSION_C;
 			out[0](s,3,a);
 		}
 		if (s==gensym("folder")) {
-			t_atom a[1];
+			t_atom2 a[1];
 			extern t_symbol *gridflow_folder;
-			SETSYMBOL(a+0,gridflow_folder);
+			a[0]=gridflow_folder;
 			out[0](s,1,a);
 		}
 	}

Modified: trunk/src/classes3.cxx
==============================================================================
--- trunk/src/classes3.cxx (original)
+++ trunk/src/classes3.cxx Fri Aug 13 15:55:28 2010
@@ -1290,31 +1290,29 @@
 \class GridRotatificator : FObject {
 	int angle;
 	int from, to, n;
-	\decl 0 float (int scale);
-	\decl 0 axis (int from, int to, int n);
+	\decl 0 float (int scale) {
+		int32 rotator[n*n];
+		for (int i=0; i<n; i++) for (int j=0; j<n; j++) rotator[i*n+j] = scale * (i==j);
+		float th = angle * M_PI / 18000;
+		for (int i=0; i<2; i++) for (int j=0; j<2; j++)
+			rotator[(i?to:from)*n+(j?to:from)] = (int32)round(scale*cos(th+(j-i)*M_PI/2));
+		GridOut go(this,0,Dim(n,n),int32_e);
+		go.send(n*n,rotator);
+	}
+	\decl 0 axis (int from, int to, int n) {
+		if (n<0) RAISE("n-axis number incorrect");
+		if (from<0 || from>=n) RAISE("from-axis number incorrect");
+		if (to  <0 || to  >=n) RAISE(  "to-axis number incorrect");
+		this->from = from;
+		this->  to =   to;
+		this->   n =    n;
+	}
 	\constructor (int from=0, int to=1, int n=2) {
 		angle=0;
 		_0_axis(from,to,n);
 	}
 	\decl 1 float(int angle) {this->angle = angle;}
 };
-\def 0 float (int scale) {
-	int32 rotator[n*n];
-	for (int i=0; i<n; i++) for (int j=0; j<n; j++) rotator[i*n+j] = scale * (i==j);
-	float th = angle * M_PI / 18000;
-	for (int i=0; i<2; i++) for (int j=0; j<2; j++)
-		rotator[(i?to:from)*n+(j?to:from)] = (int32)round(scale*cos(th+(j-i)*M_PI/2));
-	GridOut go(this,0,Dim(n,n),int32_e);
-	go.send(n*n,rotator);
-}
-\def 0 axis(int from, int to, int n) {
-	if (n<0) RAISE("n-axis number incorrect");
-	if (from<0 || from>=n) RAISE("from-axis number incorrect");
-	if (to  <0 || to  >=n) RAISE(  "to-axis number incorrect");
-	this->from = from;
-	this->  to =   to;
-	this->   n =    n;
-}
 \end class {install("#rotatificator",2,1);}
 
 static void expect_min_one_dim (const Dim &d) {

Modified: trunk/src/formats.cxx
==============================================================================
--- trunk/src/formats.cxx (original)
+++ trunk/src/formats.cxx Fri Aug 13 15:55:28 2010
@@ -76,8 +76,7 @@
 		for (char *u=t+1; *u; u++) *u=tolower(*u);
 		out[1](gensym(t+1));
 		map<string,string>::iterator u = suffix_table.find(string(t+1));
-		if (u==suffix_table.end()) out[0]();
-		else out[0](gensym((char *)u->second.data()));
+		if (u==suffix_table.end()) out[0](); else out[0](gensym((char *)u->second.data()));
 	}
 	free(s);
   }
@@ -166,15 +165,23 @@
 		_0_open(mode,filename);
 	}
 	\decl 0 bang ();
-	\decl 0 headerless (...);
-	\decl 0 headerful ();
-	\decl 0 seek_byte (int64 bytepos);
-	~FormatGrid() {
-		//@stream.close if @stream
-		//GridFlow.hunt_zombies
-	}
-//	\decl void raw_open_gzip_in(string filename);
-//	\decl void raw_open_gzip_out(string filename);
+	\decl 0 headerless (...) {
+		if (argc>=0 && argv[0].a_type==A_LIST) {
+			t_binbuf *b = (t_binbuf *)argv[0]; argc = binbuf_getnatom(b); argv = (t_atom2 *)binbuf_getvec(b);}
+		int v[argc];
+		for (int i=0; i<argc; i++) v[i] = argv[i];
+		dim = Dim(argc,v);
+		headerless = true;
+	}
+	\decl 0 headerful () {headerless = false;}
+	\decl 0 seek_byte (int64 pos) {fseek(f,pos,SEEK_SET);}
+	~FormatGrid() {/* @stream.close if @stream; GridFlow.hunt_zombies */}
+	//\decl void raw_open_gzip_in( string filename) {
+		//r,w = IO.pipe; if (pid=fork) {GridFlow.subprocesses[pid]=true; w.close; @stream = r;}
+		//else {r.close; STDOUT.reopen w; STDIN.reopen filename, "r"; exec "gzip", "-dc";}
+	//\decl void raw_open_gzip_out(string filename) {
+		//r,w = IO.pipe; 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 bang () {
 	//post("#io.grid 0 bang: ftell=%ld",ftell(f));
@@ -247,30 +254,11 @@
 	fflush(f);
 } GRID_END
 
-\def 0 headerless (...) {
-	if (argc>=0 && argv[0].a_type==A_LIST) {
-		t_binbuf *b = (t_binbuf *)argv[0]; argc = binbuf_getnatom(b); argv = (t_atom2 *)binbuf_getvec(b);}
-	int v[argc];
-	for (int i=0; i<argc; i++) v[i] = argv[i];
-	dim = Dim(argc,v);
-	headerless = true;
-}
-\def 0 headerful () {headerless = false;}
-\def 0 seek_byte (int64 pos) {fseek(f,pos,SEEK_SET);}
-
-//\def void raw_open_gzip_in(string filename) {
-	//r,w = IO.pipe
-	//if (pid=fork) {GridFlow.subprocesses[pid]=true; w.close; @stream = r;}
-	//else {r.close; STDOUT.reopen w; STDIN.reopen filename, "r"; exec "gzip", "-dc";}
-//\def void raw_open_gzip_out(string filename) {
-	//r,w = IO.pipe
-	//if (pid=fork) {GridFlow.subprocesses[pid]=true; r.close; @stream = w;}
-	//else {w.close; STDIN.reopen r; STDOUT.reopen filename, "w"; exec "gzip", "-c";}
-
 \end class FormatGrid {install_format("#io.grid",6,"grid");}
 
 ////////////////////////////////////////////////////////////////////////////////////////////////
 
+#define RERR RAISE("error reading header: %s",feof(f) ? "end of file" : strerror(ferror(f)))
 \class FormatNetPBM : Format {
 	\grin 0
 	\constructor (t_symbol *mode, string filename) {Format::_0_open(mode,filename);}
@@ -291,7 +279,6 @@
 	}
 	\decl 0 bang ();
 };
-#define RERR RAISE("error reading header: %s",feof(f) ? "end of file" : strerror(ferror(f)))
 \def 0 bang () {
 	int a = fgetc(f); if (a==EOF) RAISE("error reading header magic");
 	int b = fgetc(f); if (a==EOF) RAISE("error reading header magic");
@@ -312,8 +299,7 @@
 	switch (b) {
 		case '2': case '3': {
 			size_t n = out.dim.prod();
-			int32 x;
-			for (size_t i=0; i<n; i++) if (fscanf(f,"%d",&x)<1) RERR; else out.send(1,&x);
+			for (size_t i=0; i<n; i++) {int32 x; if (fscanf(f,"%d",&x)<1) RERR; else out.send(1,&x);}
 		} break;
 		case '5': case '6': {
 			for (size_t y=0; y<sy; y++) if (fread(row,1,sxc,f)<sxc) RERR; else out.send(sxc,row);

Modified: trunk/src/sdl.cxx
==============================================================================
--- trunk/src/sdl.cxx (original)
+++ trunk/src/sdl.cxx Fri Aug 13 15:55:28 2010
@@ -150,7 +150,7 @@
 	void call ();
 	\decl 0 setcursor (int shape);
 	\decl 0 hidecursor ();
-	\decl 0 title (string title);
+	\decl 0 title (const char *title) {SDL_WM_SetCaption(title,title);}
 	\decl 0 position   (...) {out[0](gensym("position"),  argc,argv);}
 	\decl 0 keypress   (...) {out[0](gensym("keypress"),  argc,argv);}
 	\decl 0 keyrelease (...) {out[0](gensym("keyrelease"),argc,argv);}
@@ -168,7 +168,7 @@
 			break;
 		default: RAISE("%d bytes/pixel: how do I deal with that?",f->BytesPerPixel); break;
 		}
-		_0_title(string("GridFlow SDL"));
+		_0_title("GridFlow SDL");
 	}
 	\grin 0 int
 	~FormatSDL () {
@@ -177,7 +177,6 @@
 	}
 };
 
-\def 0 title (string title) {SDL_WM_SetCaption(title.data(),title.data());}
 void FormatSDL::call() {HandleEvent(); clock_delay(cloque,20);}
 void FormatSDL_call(FormatSDL *self) {self->call();}
 

Modified: trunk/src/videodev.cxx
==============================================================================
--- trunk/src/videodev.cxx (original)
+++ trunk/src/videodev.cxx Fri Aug 13 15:55:28 2010
@@ -494,7 +494,7 @@
 	if (0> IOCTL(fd, VIDIOCGTUNER, &vtuner)) {
 		post("no tuner #%d", value);
 	} else {
-		vtuner.mode = value; //gfpost(&vtuner);
+		vtuner.mode = value;
 		WIOCTL(fd, VIDIOCSTUNER, &vtuner);
 	}
 }

Modified: trunk/src/x11.cxx
==============================================================================
--- trunk/src/x11.cxx (original)
+++ trunk/src/x11.cxx Fri Aug 13 15:55:28 2010
@@ -118,7 +118,7 @@
 #endif
 		int sy=240, sx=320; // defaults
 		argv++, argc--;
-		t_symbol *domain = argc<1 ? gensym("here") : argv[0];
+		t_symbol *domain = argc<1 ? gensym("here") : (t_symbol *)argv[0];
 		int i;
 		char host[256];
 		if (domain==gensym("here")) {
@@ -208,7 +208,17 @@
 		_0_border(1);
 	}
 
-	\decl 0 bang ();
+	\decl 0 bang () {
+		XGetSubImage(display, window, 0, 0, dim[1], dim[0], (unsigned)-1, ZPixmap, ximage, 0, 0);
+		GridOut go(this,0,dim,cast);
+		int sy=dim[0], sx=dim[1], bs=dim.prod(1);
+		uint8 b2[bs];
+		for(int y=0; y<sy; y++) {
+			uint8 *b1 = image + ximage->bytes_per_line * y;
+			bit_packing->unpack(sx,b1,b2);
+			go.send(bs,b2);
+		}
+	}
 	void call ();
 	\decl 0 out_size (int sy, int sx) {resize_window(sx,sy);}
 	\decl 0 setcursor (int shape) {
@@ -242,7 +252,21 @@
 		XWarpPointer(display,None,None,0,0,0,0,x,y);
 		XFlush(display);
 	}
-	\decl 0 fullscreen (bool toggle=1); // not working
+	\decl 0 fullscreen (bool toggle=1) { // not working
+		fullscreen=toggle;
+		XEvent xev; CLEAR(&xev); typeof(xev.xclient) &xc = xev.xclient;
+		xc.type = ClientMessage;
+		xc.serial = 0;
+		xc.send_event = True;
+		xc.message_type = XA_NET_WM_STATE;
+		xc.window = window;
+		xc.format = 32;
+		xc.data.l[0] = toggle;
+		xc.data.l[1] = XA_NET_WM_STATE_FULLSCREEN;
+		if (!XSendEvent(display,root_window,False,SubstructureRedirectMask|SubstructureNotifyMask,&xev))
+		RAISE("can't set fullscreen");
+		XFlush(display);
+	}
 	\decl 0 border     (bool toggle=1);
 	\decl 0 loadbang () {out[0](gensym("nogrey"),0,0);}
 //	\decl 0 raise ();
@@ -261,25 +285,6 @@
 	//XConfigureWindow(display,window,CWStackMode,&changes);
 	//XFlush(display);
 //}
-
-\def 0 fullscreen (bool toggle=1) {
-	fullscreen=toggle;
-	XEvent xev; typeof(xev.xclient) &xc = xev.xclient;
-        xc.type = ClientMessage;
-        xc.serial = 0;
-        xc.send_event = True;
-        xc.message_type = XA_NET_WM_STATE;
-        xc.window = window;
-        xc.format = 32;
-        xc.data.l[0] = toggle;
-        xc.data.l[1] = XA_NET_WM_STATE_FULLSCREEN;
-        xc.data.l[2] = 0;
-        xc.data.l[3] = 0;
-        xc.data.l[4] = 0;
-        if (!XSendEvent(display,root_window,False,SubstructureRedirectMask|SubstructureNotifyMask,&xev))
-            RAISE("can't set fullscreen");
-        XFlush(display);
-}
 
 // from Motif:
 #define MWM_HINTS_FUNCTIONS     (1L << 0)
@@ -407,39 +412,29 @@
 		XNextEvent(display,&e);
 		switch (e.type) {
 		case Expose:{
-			XExposeEvent *ex = (XExposeEvent *)&e;
-			if (mode==2) show_section(ex->x,ex->y,ex->width,ex->height);
+			XExposeEvent &ex = e.xexpose;
+			if (mode==2) show_section(ex.x,ex.y,ex.width,ex.height);
 		}break;
-		case ButtonPress:{
-			XButtonEvent *eb = (XButtonEvent *)&e;
-			eb->state |= 128<<eb->button;
-			report_pointer(eb->y,eb->x,eb->state);
-		}break;
-		case ButtonRelease:{
-			XButtonEvent *eb = (XButtonEvent *)&e;
-			eb->state &= ~(128<<eb->button);
-			report_pointer(eb->y,eb->x,eb->state);
-		}break;
+		case ButtonPress:  {XButtonEvent &eb = e.xbutton; eb.state |=   128<<eb.button ;
+			report_pointer(eb.y,eb.x,eb.state);}break;
+		case ButtonRelease:{XButtonEvent &eb = e.xbutton; eb.state &= ~(128<<eb.button);
+			report_pointer(eb.y,eb.x,eb.state);}break;
 		case KeyPress:
 		case KeyRelease:{
-			XKeyEvent *ek = (XKeyEvent *)&e;
+			XKeyEvent &ek = e.xkey;
 			//XLookupString(ek, buf, 63, 0, 0);
-			char *kss = XKeysymToString(XLookupKeysym(ek, 0));
+			char *kss = XKeysymToString(XLookupKeysym(&ek,0));
 			char buf[64];
 			if (!kss) return; /* unknown keys ignored */
 			if (isdigit(*kss)) sprintf(buf,"D%s",kss); else strcpy(buf,kss);
-			t_atom at[4];
 			t_symbol *sel = gensym(const_cast<char *>(e.type==KeyPress ? "keypress" : "keyrelease"));
-			SETFLOAT(at+0,ek->y);
-			SETFLOAT(at+1,ek->x);
-			SETFLOAT(at+2,ek->state);
-			SETSYMBOL(at+3,gensym(buf));
+			t_atom2 at[4] = {ek.y,ek.x,ek.state,gensym(buf)};
 			out[0](sel,4,at);
 			//XFree(kss);
 		}break;
 		case MotionNotify:{
-			XMotionEvent *em = (XMotionEvent *)&e;
-			report_pointer(em->y,em->x,em->state);
+			XMotionEvent &em = *(XMotionEvent *)&e;
+			report_pointer(em.y,em.x,em.state);
 		}break;
 		case DestroyNotify:{
 			post("This window is being closed, so this handler will close too!");
@@ -452,18 +447,6 @@
 	clock_delay(clock,20);
 }
 void FormatX11_call(FormatX11 *p) {p->call();}
-
-\def 0 bang () {
-	XGetSubImage(display, window, 0, 0, dim[1], dim[0], (unsigned)-1, ZPixmap, ximage, 0, 0);
-	GridOut go(this,0,dim,cast);
-	int sy=dim[0], sx=dim[1], bs=dim.prod(1);
-	uint8 b2[bs];
-	for(int y=0; y<sy; y++) {
-		uint8 *b1 = image + ximage->bytes_per_line * y;
-		bit_packing->unpack(sx,b1,b2);
-		go.send(bs,b2);
-	}
-}
 
 /* loathe Xlib's error handlers */
 static FormatX11 *current_x11;



More information about the Gridflow-cvs mailing list