// The movie.c source code can generate either the movie or imovie // objects //#define IMOVIE done in imovie.h - see prefix in c/c++ prefs #include #include #include #include //for fixed point matrix math #include #include "ext.h" #include "ext_wind.h" #ifdef IMOVIE #include "ext_user.h" #endif #include "ext_common.h" #include "ext_strings.h" /* #define MASOCHIST */ //added boolean defs since I removed precompiled header #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #define DefaultStep 5 #define DefaultHeight 122 #define DefaultWidth 162 #define Default15Height 182 #define Default15Width 202 #define DefaultFlags 1 /* border + no scaling */ #define MIN_QUALITY 5000 /* values of the controller "ctrl" message */ /* To draw thumbnails of a movie, GetMovieTime returns the timescale in the timerecord, you can convert this to milliseconds (i.e. 600 is 1/600 of a second) GetMoviePict(movie,time=timerecord) returns a PicHandle you can draw, it might be too big */ #define CtrlMovieIdle 1L #define CtrlMovieFreed 2L #define CtrlMovieMoved 3L #define CtrlMovieNew 4L /* new features: add scaling */ typedef struct _film { Movie f_m; t_symbol *f_name; short f_vol; short f_refNum; struct _movie *f_parent; Rect f_rect; struct _film *f_next; } t_film; /* ---- movie.c --- Play QuickTime movies -- */ long qtVersion; typedef struct _movie { #ifdef IMOVIE struct box m_box; #else t_object m_ob; struct wind *m_wind; #endif struct _film *m_f; Point m_origin; Rect m_oldbox; struct _movie *m_next; Movie m_m; Movie m_pending; Fixed m_rate; void *m_yout; void *m_xout; void *m_timeout; short m_refNum; short m_top,m_left; short m_vol; void *m_clock; t_symbol *m_sym; /* symbolized name of the current movie */ t_symbol *m_get; /* movie to get next */ t_symbol *m_curname; /* name of current movie */ short m_vRefNum; /* volume reference number */ char m_border; /* border on? */ char m_titled; void *m_controller; /* std play controller */ fptr m_ctrlmeth; /* lookup "playbar.ctrl" and use it */ void *m_patcher; /* owning patcher */ char m_autofit; /* automatically fit to window/box size */ char m_passive; // doesn't draw a frame unless it receives a bang char m_palindrome; // palindrome looping char m_loopmode; long m_quality; double m_nextshowing; long m_loopstart; long m_loopend; TimeBase m_tb; /* void *m_cb; */ } t_movie; void ReportError(char *proc); void mmovie_gqfn(void *x); void mmovie_init(void); short mmovie_ctrl(t_movie *x, long value); void mmovie_active(t_movie *x,long way); void *mmovie_findfilm(t_movie *x, t_symbol *s); void mmovie_addfilm(t_movie *x, Movie m, Rect *r, t_symbol *name, short vol, short refNum); void mmovie_freefilms(t_movie *x); void mmovie_freefilm(t_movie *x, t_film *d); void mmovie_bang(t_movie *x); void mmovie_start(t_movie *x,t_symbol *s); void mmovie_end(t_movie *x); void mmovie_pause(t_movie *x); void mmovie_resume(t_movie *x); void mmovie_next(t_movie *x, long howmuch); void mmovie_nextmovie(t_movie *x); void mmovie_donextmovie(t_movie *x); void mmovie_switch(t_movie *x, t_symbol *s); void mmovie_doswitch(t_movie *x, t_symbol *s, short argc, t_atom *argv); void mmovie_prev(t_movie *x,long howmuch); void mmovie_dorate(t_movie *x, t_symbol *s, short argc, t_atom *argv); void mmovie_rate(t_movie *x, t_symbol *s, short argc, t_atom *argv); void mmovie_rational(double f, long *n, long *d); void mmovie_getrate(t_movie *x); void mmovie_quality(t_movie *x, long n); void mmovie_passive(t_movie *x, long n); void mmovie_loadintoram(t_movie *x, long n); void mmovie_doloadintoram(t_movie *x, t_symbol *s, short argc, t_atom *argv); void mmovie_mute(t_movie *x, long muting); void mmovie_time(t_movie *x); void mmovie_length(t_movie *x); void mmovie_timescale(t_movie *x); void mmovie_duration(t_movie *x); void mmovie_tick(t_movie *x); void mmovie_int(t_movie *x,long n); void mmovie_vol(t_movie *x, long n); void mmovie_doborder(t_movie *x, t_symbol *s, short ac, t_atom *av); void mmovie_border(t_movie *x, long way); void mmovie_vis(t_movie *x); void mmovie_cliptobox(t_movie *x); void mmovie_checkmove(t_movie *x); void mmovie_update(t_movie *x); void mmovie_close(t_movie *x); void mmovie_idle(t_movie *x, Point pt, short within); void mmovie_mouseout(t_movie *x, Point pt); void mmovie_drag(t_movie *x, Point pt, short but); void mmovie_click(t_movie *x, Point pt, short dbl, short mod); void mmovie_save(t_movie *x, void *w); void mmovie_psave(t_movie *x, void *w); void mmovie_info(t_movie *x, void *p, void *b); void mmovie_dblclick(t_movie *x); void mmovie_open(t_movie *x); void mmovie_wclose(t_movie *x); void mmovie_dowclose(t_movie *x); void mmovie_windowpos(t_movie *x, long left, long top, long right, long bottom); void mmovie_dowindowpos(t_movie *x, t_symbol *s, short argc, t_atom *argv); void *mmovie_film(t_movie *x, t_symbol *which); void mmovie_free(t_movie *x); void mmovie_doclear(t_movie *x); void mmovie_clear(t_movie *x); void mmovie_reload(t_movie *x); void mmovie_doread(t_movie *x, t_symbol *s); void mmovie_doreadany(t_movie *x, t_symbol *s); void mmovie_doload(t_movie *x); void mmovie_read(t_movie *x, t_symbol *s); void mmovie_readany(t_movie *x, t_symbol *s); void mmovie_controller(t_movie *x, t_symbol *in, t_symbol *out1, t_symbol *out2); void mmovie_link(t_movie *x); void mmovie_unlink(t_movie *x); void mmovie_assist(t_movie *x, void *b, long m, long a, char *s); void *mmovie_new(t_symbol *s, short ac, t_atom *av); void *mmovie_menucreate(void *p, long x, long y, long font); void mmovie_dispose(t_movie *x, t_symbol *name); void mmovie_dodispose(t_movie *x, t_symbol *name); void mmovie_setfilm(t_movie *x, t_film *f); void mmovie_dobang(t_movie *x); void mmovie_dostart(t_movie *x, t_symbol *s, short argc, t_atom *argv); void mmovie_doend(t_movie *x); void mmovie_dopause(t_movie *x); void mmovie_doresume(t_movie *x); void mmovie_donext(t_movie *x, long howmuch); void mmovie_doprev(t_movie *x, long howmuch); void mmovie_domute(t_movie *x, long muting); void mmovie_doint(t_movie *x, long n); void mmovie_dovol(t_movie *x, long n); void mmovie_savefilms(t_movie *x, void *w); void ConstrainRect(Rect *a, Rect *b, short margin); void mmovie_rect(t_movie *x, long xpos, long ypos, long width, long height); void mmovie_wsize(t_movie *x, short h, short v); void mmovie_autofit(t_movie *x, long c); void mmovie_matrix(t_movie *x, t_symbol *s, long argc, t_atom *argv); void mmovie_loop(t_movie *x, long n); void mmovie_palindrome(t_movie *x, long n); void mmovie_loopstart(t_movie *x, long n); void mmovie_loopend(t_movie *x, long n); void mmovie_loopset(t_movie *x, long start, long end); void mmovie_settimebase(t_movie *x); void mmovie_startat(t_movie *x, t_symbol *s, short argc, t_atom *argv); short CmdKeyDown(void); short AnyKeyDown(void); short IsKeyDown(short knum); void *mmovie_class; void *gqelem; t_symbol *ps_nothing,*ps_imovie,*ps_ctrl; t_movie *mmovie_head = 0; long inited; Fixed stopRate,startRate; Pattern grrr; long mmovie_typelist[] = { 'MooV','sooV','TVex','AIFF','AIFC','MPG ','WAVE','MPEG','VfW ','dvc!','FLI ','GIFf', 'Sd2f','.WAV','BINA','qmed','Cach','SWFL','RTSP','SDP ','Mp3 ','MPG3','PLAY','SwaT','.SMI', 'JPEG','3DMF','MPGv','MPGx','BMP ','8BPS','PNGf','PNG ', 'qdgx','qtif','SGI ','TPIC','TIFF','FLI ','PICS'}; #define MMOVIE_NTYPES 40 main(fptr *f) { #ifdef IMOVIE setup(&mmovie_class, mmovie_new, (method)mmovie_free, (short)sizeof(t_movie), mmovie_menucreate, A_GIMME, 0); #else setup((t_messlist **)&mmovie_class, (method)mmovie_new, (method)mmovie_free, (short)sizeof(t_movie), 0L, A_GIMME, 0); #endif addint((method)mmovie_int); addbang((method)mmovie_bang); addmess((method)mmovie_read, "read", A_DEFSYM,0); addmess((method)mmovie_readany, "readany", A_DEFSYM,0); addmess((method)mmovie_pause, "stop", 0); addmess((method)mmovie_doread, "rd", A_DEFSYM,0); addmess((method)mmovie_start, "start", A_DEFSYM,0); // addmess((method)mmovie_start, "startat", A_GIMME,0); changed to... addmess((method)mmovie_startat, "startat", A_GIMME,0); addmess((method)mmovie_pause, "pause", 0); addmess((method)mmovie_resume, "resume", 0); addmess((method)mmovie_next, "next", A_DEFLONG,0); addmess((method)mmovie_nextmovie,"nextmovie",0); addmess((method)mmovie_switch, "switch", A_SYM, 0); addmess((method)mmovie_prev, "prev", A_DEFLONG,0); addmess((method)mmovie_mute, "mute", A_LONG,0); addmess((method)mmovie_reload, "reload", 0); addmess((method)mmovie_dispose, "dispose", A_DEFSYM, 0); addmess((method)mmovie_rate, "rate", A_GIMME,0); addmess((method)mmovie_vol, "vol", A_LONG,0); addmess((method)mmovie_clear, "clear", 0); addmess((method)mmovie_click, "click", A_CANT,0); addmess((method)mmovie_update, "update", A_CANT,0); addmess((method)mmovie_time, "time", 0); addmess((method)mmovie_active, "active", A_LONG,0); addmess((method)mmovie_assist, "assist", A_CANT,0); addmess((method)mmovie_film, "film", A_CANT,0); addmess((method)mmovie_length, "length", 0); addmess((method)mmovie_timescale,"timescale",0); addmess((method)mmovie_duration,"duration", 0); addmess((method)mmovie_controller, "controller", A_SYM, A_SYM, A_SYM, 0); addmess((method)mmovie_quality, "quality", A_LONG, 0); addmess((method)mmovie_getrate, "getrate", 0); addmess((method)mmovie_border, "border", A_LONG,0); addmess((method)mmovie_passive, "passive", A_LONG, 0); addmess((method)mmovie_loadintoram,"loadintoram", A_LONG, 0); #ifdef IMOVIE addmess((method)mmovie_psave, "psave", A_CANT,0); addmess((method)mmovie_info, "info", A_CANT,0); addmess((method)mmovie_vis, "vis", A_CANT,0); addmess((method)mmovie_click, "click", A_CANT, 0); #else addmess((method)mmovie_save, "save", A_CANT,0); addmess((method)mmovie_open, "open", 0); addmess((method)mmovie_close, "close", A_CANT,0); addmess((method)mmovie_idle, "idle", A_CANT,0); addmess((method)mmovie_dblclick,"dblclick", A_CANT,0); addmess((method)mmovie_windowpos,"windowpos", A_LONG, A_LONG, A_LONG, A_LONG, 0); addmess((method)mmovie_wclose, "wclose", 0); /* addmess((method)mmovie_save, "save", A_CANT,0); */ #endif addmess((method)mmovie_rect,"rect",A_DEFLONG,A_DEFLONG,A_DEFLONG,A_DEFLONG,0); addmess((method)mmovie_autofit,"autofit",A_DEFLONG,0); addmess((method)mmovie_wsize,"wsize",A_CANT,0); addmess((method)mmovie_matrix,"matrix",A_GIMME,0); // looping stuff addmess((method)mmovie_loop, "loop", A_LONG, 0); addmess((method)mmovie_palindrome,"palindrome", A_LONG, 0); addmess((method)mmovie_loopstart,"loopstart", A_LONG, 0); addmess((method)mmovie_loopend,"loopend", A_LONG, 0); addmess((method)mmovie_loopset,"loopset", A_DEFLONG, A_DEFLONG, 0); #ifndef IMOVIE finder_addclass("Graphics","movie"); rescopy('STR#',3060); #else rescopy('STR#',3560); #endif ps_nothing = gensym(""); ps_imovie = gensym("imovie"); ps_ctrl = gensym("ctrl"); inited = FALSE; stopRate = FixRatio(0,1); startRate = FixRatio(1,1); GetIndPattern(&grrr,sysPatListID,4); } // peeks at MoviesError and posts a message in the Max window void ReportError(char *proc) { OSErr err; if (err = GetMoviesError()) { if (proc) error("movie error %d in _%s",err,proc); else error("QuickTime error %d",err); } } // the global queue function for all movies void mmovie_gqfn(void *dummy) { t_movie *x; GrafPort *gp; double time = 0.; clock_getftime(&time); #ifdef IMOVIE // two separate mmovie_heads, one for movie and one for imovie for (x = mmovie_head; x; x = x->m_next) { if (x->m_m /* && !IsMovieDone(x->m_m) */) { if ((!x->m_passive) && ((!x->m_quality) || (x->m_nextshowing <= time))) { if (gp = patcher_setport(x->m_box.b_patcher)) { if (!box_nodraw((t_box *)x)) { if (EqualRect(&x->m_box.b_rect,&x->m_oldbox)) { if (!mmovie_ctrl(x,CtrlMovieIdle)) MoviesTask(x->m_m,0); } box_enddraw((t_box *)x); } } x->m_nextshowing += x->m_quality; } } if (x->m_nextshowing < time - MIN_QUALITY) x->m_nextshowing = time; } #else for (x = mmovie_head; x; x = x->m_next) { if (x->m_m && x->m_wind && x->m_wind->w_vis && !IsMovieDone(x->m_m)) { if ((!x->m_passive) && ((!x->m_quality) || (x->m_nextshowing <= time))) { if (!mmovie_ctrl(x,CtrlMovieIdle)) MoviesTask(x->m_m,0); x->m_nextshowing += x->m_quality; } } if (x->m_nextshowing < time - MIN_QUALITY) x->m_nextshowing = time; } #endif qelem_set(gqelem); } void mmovie_init(void) { OSErr err; long version; t_symbol *ps_qtInit; qtVersion = 0; version = 0; Gestalt('qtim',&version); if (!version) goto posterr; qtVersion = version; ps_qtInit = gensym("##qtInit"); if (!ps_qtInit->s_thing) { if (err = EnterMovies()) { goto posterr; } ps_qtInit->s_thing = (void *)-1L; } gqelem = qelem_new(0,(void *)mmovie_gqfn); inited = true; qelem_set(gqelem); return; posterr: error("movie: QuickTime not installed %d",err); } short mmovie_ctrl(t_movie *x, long value) { if (!x->m_controller) { return (FALSE); } if (NOGOOD(x->m_controller)) { error("controller corrupt"); x->m_controller = 0; return (FALSE); } if (!x->m_ctrlmeth) { x->m_ctrlmeth = (fptr)egetfn(x->m_controller,ps_ctrl); } switch (value) { case CtrlMovieIdle: (*x->m_ctrlmeth)(x->m_controller,CtrlMovieIdle,x->m_m); break; case CtrlMovieFreed: (*x->m_ctrlmeth)(x->m_controller,CtrlMovieFreed,0L); break; #ifdef IMOVIE case CtrlMovieMoved: (*x->m_ctrlmeth)(x->m_controller,CtrlMovieMoved,&x->m_box.b_rect); break; #endif case CtrlMovieNew: (*x->m_ctrlmeth)(x->m_controller,CtrlMovieNew,x->m_m); break; } return (TRUE); } void mmovie_active(t_movie *x,long way) { Boolean bway; if (x->m_m) { bway = way?TRUE:FALSE; SetMovieActive(x->m_m,bway); ReportError("SetMovieActive"); } } void *mmovie_findfilm(t_movie *x, t_symbol *s) { t_film *f; for (f = x->m_f; f; f = f->f_next) if (f->f_name == s) return (f); return (0); } void mmovie_addfilm(t_movie *x, Movie m, Rect *r, t_symbol *name, short vol, short refNum) { t_film *f; f = (t_film *)getbytes((short)sizeof(t_film)); f->f_m = m; f->f_vol = vol; f->f_refNum = refNum; f->f_name = name; f->f_parent = x; f->f_next = x->m_f; f->f_rect = *r; x->m_f = f; } void mmovie_freefilms(t_movie *x) { t_film *f,*temp; for (f = x->m_f; f; ) { if (f->f_m == x->m_m) { mmovie_ctrl(x,CtrlMovieFreed); x->m_m = 0; } DisposeMovie(f->f_m); // post("dispose movie %d",GetMoviesError()); CloseMovieFile(f->f_refNum); temp = f->f_next; freebytes((char *)f,(short)sizeof(t_film)); f = temp; } x->m_f = 0; if (x->m_tb) DisposeTimeBase(x->m_tb); } void mmovie_freefilm(t_movie *x, t_film *d) { t_film *f,*prev; for (prev = 0, f = x->m_f; f; prev = f, f = f->f_next) { if (f == d) { if (f->f_m == x->m_m) { mmovie_ctrl(x,CtrlMovieFreed); x->m_m = 0; /* possible other shutting down activities */ } DisposeMovie(d->f_m); CloseMovieFile(d->f_refNum); if (prev) prev->f_next = d->f_next; else x->m_f = d->f_next; freebytes((char *)d,(short)sizeof(t_film)); break; } } } void mmovie_setfilm(t_movie *x, t_film *f) { x->m_m = f->f_m; mmovie_ctrl(x,CtrlMovieNew); x->m_curname = f->f_name; mmovie_settimebase(x); } void *mmovie_film(t_movie *x, t_symbol *which) { t_film *f; void *res; if (!which || (which == ps_nothing)) f = x->m_f; else f = mmovie_findfilm(x,which); if (f && f->f_m) res = f->f_m; else res = 0; return (res); } void mmovie_nextmovie(t_movie *x) { defer(x,(method)mmovie_donextmovie,0,0,0); } void mmovie_donextmovie(t_movie *x) { t_film *f; for (f = x->m_f; f; f = f->f_next) { if (x->m_curname == f->f_name) { if (f->f_next) mmovie_setfilm(x,f->f_next); else mmovie_setfilm(x,x->m_f); break; } } } void mmovie_switch(t_movie *x, t_symbol *s) { defer(x,(method)mmovie_doswitch,s,0,0); } void mmovie_doswitch(t_movie *x, t_symbol *s, short argc, t_atom *argv) { t_film *f; for (f = x->m_f; f; f = f->f_next) { if (x->m_curname == s) { mmovie_setfilm(x,f); break; } } } void mmovie_dobang(t_movie *x) { GrafPtr gp; if (x->m_passive) { #ifdef IMOVIE if (!x->m_m) return; if (gp = patcher_setport(x->m_box.b_patcher)) { if (!box_nodraw((t_box *)x)) { if (EqualRect(&x->m_box.b_rect,&x->m_oldbox)) { if (!mmovie_ctrl(x,CtrlMovieIdle)) { MoviesTask(x->m_m,0); UpdateMovie(x->m_m); } } box_enddraw((t_box *)x); } SetPort(gp); } #else if (x->m_wind && (gp = wind_setport(x->m_wind))) { if (!mmovie_ctrl(x,CtrlMovieIdle)) { MoviesTask(x->m_m,0); UpdateMovie(x->m_m); } SetPort(gp); } #endif } else { SetMovieRate(x->m_m,x->m_rate); ReportError("SetMovieRate"); } } // start playing from current location void mmovie_bang(t_movie *x) { if (x->m_m) defer(x,(method)mmovie_dobang,0L,0,0L); } // start playing from the beginning */ void mmovie_dostart(t_movie *x, t_symbol *s, short argc, t_atom *argv) { t_film *f; long when = argv->a_w.w_long; if (s != ps_nothing) { f = mmovie_findfilm(x,s); if (f && f->f_m != x->m_m) { mmovie_setfilm(x,f); } /* maybe other things */ } if (x->m_m) { SetMovieActive(x->m_m,TRUE); ReportError("SetMovieActive"); SetMovieTimeValue(x->m_m,when); /* GotoBeginningOfMovie(x->m_m); */ StartMovie(x->m_m); ReportError("StartMovie"); x->m_rate = startRate; //mmovie_time(x); mmovie_ctrl(x,CtrlMovieIdle); } } // wow, flexible, args can appear in either order void mmovie_startat(t_movie *x, t_symbol *s, short argc, t_atom *argv) { long when = 0; t_symbol *name = ps_nothing; t_atom a; if (argc) { if (argv->a_type == A_LONG) when = argv->a_w.w_long; else if (argv->a_type == A_SYM) name = argv->a_w.w_sym; argc--; argv++; } if (argc) { if (argv->a_type == A_LONG) when = argv->a_w.w_long; else if (argv->a_type == A_SYM) name = argv->a_w.w_sym; argc--; argv++; } a.a_type = A_LONG; a.a_w.w_long = when; defer(x,(method)mmovie_dostart,s,1,&a); } void mmovie_start(t_movie *x,t_symbol *s) { t_atom a; a.a_w.w_long = 0; a.a_type = A_LONG; defer(x,(method)mmovie_dostart,s,1,&a); } void mmovie_doend(t_movie *x) { TimeValue end; if (x->m_m) { end = GetMovieDuration(x->m_m); SetMovieTimeValue(x->m_m,end); ReportError("GotoEndOfMovie"); } } void mmovie_end(t_movie *x) { defer(x,(method)mmovie_doend,0L,0,0L); } void mmovie_dopause(t_movie *x) { if (x->m_m) { SetMovieRate(x->m_m,stopRate); ReportError("SetMovieRate"); mmovie_ctrl(x,CtrlMovieIdle); } } void mmovie_pause(t_movie *x) { defer(x,(method)mmovie_dopause,0L,0,0L); } void mmovie_doresume(t_movie *x) { if (x->m_m) { SetMovieRate(x->m_m,x->m_rate); ReportError("SetMovieRate"); mmovie_ctrl(x,CtrlMovieIdle); } } void mmovie_resume(t_movie *x) { defer(x,(method)mmovie_doresume,0L,0,0L); } // step forward void mmovie_donext(t_movie *x, long howmuch) { TimeRecord tr; if (howmuch==0) howmuch = DefaultStep; if (x->m_m) { GetMovieTime(x->m_m,&tr); SetMovieTimeValue(x->m_m,tr.value.lo+howmuch); mmovie_ctrl(x,CtrlMovieIdle); } } void mmovie_next(t_movie *x, long howmuch) { defer(x,(method)mmovie_donext,(void *)howmuch,0,0L); } // step backward void mmovie_doprev(t_movie *x, long howmuch) { TimeRecord tr; if (howmuch==0) howmuch = DefaultStep; if (x->m_m) { GetMovieTime(x->m_m,&tr); SetMovieTimeValue(x->m_m,MAX(tr.value.lo-howmuch,0L)); mmovie_ctrl(x,CtrlMovieIdle); } } void mmovie_prev(t_movie *x, long howmuch) { defer(x,(method)mmovie_doprev,(void *)howmuch,0,0L); } // set speed, can be negative void mmovie_dorate(t_movie *x, t_symbol *s, short argc, t_atom *argv) { long n,d = 1; if (argc == 1) { if (argv->a_type == A_LONG) n = argv->a_w.w_long; else if (argv->a_type == A_FLOAT) mmovie_rational(argv->a_w.w_float,&n,&d); else return; } else { // 2 or more if (argv->a_type == A_LONG) n = argv->a_w.w_long; else if (argv->a_type == A_FLOAT) n = argv->a_w.w_float; else return; argv++; if (argv->a_type == A_LONG) d = argv->a_w.w_long; else if (argv->a_type == A_FLOAT) d = argv->a_w.w_float; else return; if (d == 0) d = 1; } x->m_rate = FixRatio(n,d); if (x->m_m) { SetMovieRate(x->m_m,x->m_rate); ReportError("SetMovieRate"); mmovie_ctrl(x,CtrlMovieIdle); } } void mmovie_rate(t_movie *x, t_symbol *s, short argc, t_atom *argv) { if (argc) defer(x,(method)mmovie_dorate,s,argc,argv); } void mmovie_rational(double f, long *n, long *d) { if (f <= 10. && f >= -10.) { *d = 3200; *n = (f * 3200.); } else if (f <= 100. && f >= -100.) { *d = 320; *n = (f * 320.); } else if (f <= 1000. && f >= -1000.) { *d = 32; *n = (f * 32.); } else { *n = f; *d = 1; } } void mmovie_getrate(t_movie *x) { Fixed rate; if (x->m_m) { rate = GetMovieRate(x->m_m); outlet_int(x->m_yout,rate); } } void mmovie_quality(t_movie *x, long n) { x->m_quality = n > 0? n : 0; } void mmovie_passive(t_movie *x, long n) { x->m_passive = n; } void mmovie_loadintoram(t_movie *x, long n) { t_atom a; a.a_type = A_LONG; a.a_w.w_long = n; defer(x,(method)mmovie_doloadintoram,0,1,&a); } void mmovie_doloadintoram(t_movie *x, t_symbol *s, short argc, t_atom *argv) { long way = argv->a_w.w_long; LoadMovieIntoRam(x->m_m,0,GetMovieDuration(x->m_m),way); } void mmovie_domute(t_movie *x, long muting) { if (x->m_m) { if (muting) { if (x->m_vol > 0) { SetMovieVolume(x->m_m,-x->m_vol); ReportError("SetMovieVolume"); x->m_vol = -x->m_vol; mmovie_ctrl(x,CtrlMovieIdle); } } else { if (x->m_vol < 0) { x->m_vol = -x->m_vol; SetMovieVolume(x->m_m,x->m_vol); ReportError("SetMovieVolume"); mmovie_ctrl(x,CtrlMovieIdle); } } } } void mmovie_mute(t_movie *x, long muting) { defer(x,(method)mmovie_domute,(void *)muting,0,0L); } void mmovie_time(t_movie *x) { TimeRecord curTime; if (x->m_m) { GetMovieTime(x->m_m,&curTime); outlet_int(x->m_timeout,curTime.value.lo); } } void mmovie_length(t_movie *x) { TimeValue curTime; if (x->m_m) { curTime = GetMovieDuration(x->m_m); outlet_int(x->m_timeout,curTime); } } void mmovie_timescale(t_movie *x) { TimeValue curTime; if (x->m_m) { curTime = GetMovieTimeScale(x->m_m); outlet_int(x->m_timeout,curTime); } } void mmovie_duration(t_movie *x) { TimeValue curTime,scale; if (x->m_m) { scale = GetMovieTimeScale(x->m_m); if (scale) { curTime = (GetMovieDuration(x->m_m) * 1000) / scale; outlet_int(x->m_timeout,curTime); } } } void mmovie_tick(t_movie *x) { TimeRecord tr; if (x->m_m) { GetMovieTime(x->m_m,&tr); outlet_int(x->m_timeout,tr.value.lo); } } void mmovie_doint(t_movie *x, long n) { /* set movie time to n */ if (x->m_m) { SetMovieTimeValue(x->m_m,n); ReportError("SetMovieTimeValue"); mmovie_ctrl(x,CtrlMovieIdle); } } void mmovie_int(t_movie *x, long n) { defer(x,(method)mmovie_doint,(void *)n,0,0L); } void mmovie_dovol(t_movie *x, long n) { if (n < -255) n = -255; if (n > 255) n = 255; x->m_vol = n; if (x->m_m) { SetMovieVolume(x->m_m,x->m_vol); ReportError("SetMovieVolume"); mmovie_ctrl(x,CtrlMovieIdle); } } void mmovie_vol(t_movie *x, long n) { defer(x,(method)mmovie_dovol,(void *)n,0,0L); } void mmovie_doborder(t_movie *x, t_symbol *s, short ac, t_atom *av) { int way; GrafPort *gp; way = av->a_w.w_long; if (way != x->m_border) { x->m_border = way; #ifdef IMOVIE x->m_box.b_outline = x->m_border; if (gp = patcher_setport(x->m_box.b_patcher)) { if (!box_nodraw((t_box *)x)) { box_erase((t_box *)x); box_enddraw((t_box *)x); } SetPort(gp); } #else // change the window type if (x->m_wind) { short wasvis = x->m_wind->w_vis,x1,x2,y1,y2,styleflag; x1 = x->m_wind->w_x1; y1 = x->m_wind->w_y1; x2 = x->m_wind->w_x2; y2 = x->m_wind->w_y2; freeobject((t_object *)x->m_wind); styleflag = x->m_border? WCLOSE : WSHADOWPROC; x->m_wind = (void *)wind_new(x, x1, y1, x2, y2, styleflag | WSGROW | WCOLOR); if (wasvis) { wind_vis(x->m_wind); gp = wind_setport(x->m_wind); mmovie_vis(x); SetPort(gp); } } #endif } } void mmovie_border(t_movie *x, long way) { t_atom a; way = way? 1 : 0; SETLONG(&a,way); defer(x,(method)mmovie_doborder,0L,1,&a); } #ifdef IMOVIE void mmovie_cliptobox(t_movie *x) { RgnHandle cr,oldRgn; Rect f; cr = NewRgn(); oldRgn = NewRgn(); GetClip(oldRgn); f = x->m_box.b_rect; InsetRect(&f,1,1); RectRgn(cr,&f); SectRgn(cr,oldRgn,cr); SetMovieDisplayClipRgn(x->m_m,cr); DisposeRgn(cr); DisposeRgn(oldRgn); } void mmovie_checkmove(t_movie *x) { short dx,dy; Rect curBox; if (!EqualRect(&x->m_oldbox,&x->m_box.b_rect)) { if (x->m_m) { mmovie_cliptobox(x); if (x->m_autofit) { SetMovieBox(x->m_m,&x->m_box.b_rect); } else { dx = x->m_box.b_rect.left - x->m_oldbox.left; dy = x->m_box.b_rect.top - x->m_oldbox.top; if (dx || dy) { GetMovieBox(x->m_m,&curBox); OffsetRect(&curBox,dx,dy); SetMovieBox(x->m_m,&curBox); } } mmovie_ctrl(x,CtrlMovieMoved); } x->m_oldbox = x->m_box.b_rect; } } #endif void mmovie_vis(t_movie *x) { t_film *f; CGrafPtr cp; GDHandle gdh; GetGWorld(&cp,&gdh); for (f = x->m_f; f; f = f->f_next) { if (f->f_m) SetMovieGWorld(f->f_m,cp,gdh); } } void mmovie_autofit(t_movie *x, long c) { Rect r; MatrixRecord matrix; x->m_autofit = c; #ifdef IMOVIE if (x->m_m) { #else if (x->m_m && x->m_wind) { #endif if (x->m_autofit) { #ifdef IMOVIE r = x->m_box.b_rect; #else r.left = 0; r.top = 0; r.right = x->m_wind->w_x2 - x->m_wind->w_x1; r.bottom = x->m_wind->w_y2 - x->m_wind->w_y1; #endif SetMovieBox(x->m_m,&r); } else { SetIdentityMatrix(&matrix); SetMovieMatrix(x->m_m,&matrix); #ifdef IMOVIE GetMovieBox(x->m_m, &r); OffsetRect(&r,x->m_box.b_rect.left+1-r.left,x->m_box.b_rect.top+1-r.top); SetMovieBox(x->m_m, &r); mmovie_cliptobox(x); #endif } } } void mmovie_wsize(t_movie *x, short h, short v) { Rect r; if (x->m_autofit&&x->m_m){ r.left = 0; r.top = 0; r.right = h; r.bottom = v; SetMovieBox(x->m_m,&r); } } void mmovie_matrix(t_movie *x, t_symbol *s, long argc, t_atom *argv) { MatrixRecord matrix; int i=0,j=0; #ifdef IMOVIE Rect r; #endif if (argc&&argv) { GetMovieMatrix(x->m_m,&matrix); while (argc--) { if (j==2) { if (argv) if (argv->a_type == A_FLOAT) matrix.matrix[i][j] = FloatToFract(argv->a_w.w_float); else if (argv->a_type == A_LONG) matrix.matrix[i][j] = (argv->a_w.w_long)<<30L; i++; j=0; } else{ if (argv) if (argv->a_type == A_FLOAT) matrix.matrix[i][j] = FloatToFixed(argv->a_w.w_float); else if (argv->a_type == A_LONG) matrix.matrix[i][j] = (argv->a_w.w_long)<<16L; j++; } argv++; } SetMovieMatrix(x->m_m,&matrix); #ifdef IMOVIE GetMovieBox(x->m_m, &r); OffsetRect(&r,x->m_box.b_rect.left+1,x->m_box.b_rect.top+1); SetMovieBox(x->m_m, &r); mmovie_cliptobox(x); #endif } } void mmovie_update(t_movie *x) { if (x->m_pending) { SetMovieGWorld(x->m_pending,0L,0L); x->m_m = x->m_pending; x->m_pending = 0; } #ifdef IMOVIE mmovie_checkmove(x); if (x->m_m) mmovie_cliptobox(x); #endif if (x->m_m) { if (x->m_passive) MoviesTask(x->m_m,0); UpdateMovie(x->m_m); ReportError("UpdateMovie"); } #ifdef IMOVIE if (!x->m_border && !box_ownerlocked((t_box *)x)) { PenPat(&grrr); FrameRect(&x->m_box.b_rect); PenNormal(); } #endif } #ifndef IMOVIE void mmovie_close(t_movie *x) { wind_invis((void *)x->m_wind); } void mmovie_idle(t_movie *x, Point pt, short within) { if (within) { if (CmdKeyDown() && !x->m_border) wind_setcursor(C_GROW); else wind_setcursor(C_ARROW); } } #endif void mmovie_mouseout(t_movie *x, Point pt) { short savelock; savelock = lockout_set(1); outlet_int(x->m_xout,(long)pt.h - x->m_origin.h); outlet_int(x->m_yout,(long)pt.v - x->m_origin.v); lockout_set(savelock); } void mmovie_drag(t_movie *x, Point pt, short but) { mmovie_mouseout(x,pt); } void mmovie_click(t_movie *x, Point pt, short dbl, short mod) { #ifdef IMOVIE x->m_origin.h = x->m_box.b_rect.left; x->m_origin.v = x->m_box.b_rect.top; #else x->m_origin.h = x->m_origin.v = 0; if ((!x->m_border) && (mod & cmdKey)) { // this is how you drag the window RgnHandle gr = LMGetGrayRgn(); Rect r = (*gr)->rgnBBox; GrafPtr gp,gp2; LocalToGlobal(&pt); DragWindow(wind_syswind(x->m_wind),pt,&r); // now figure out where the window was moved to pt.h = pt.v = 0; gp = wind_setport(x->m_wind); GetPort(&gp2); LocalToGlobal(&pt); x->m_wind->w_x1 = pt.h; x->m_wind->w_y1 = pt.v; x->m_wind->w_x2 = pt.h + (gp2->portRect.right - gp2->portRect.left); x->m_wind->w_y2 = pt.v + (gp2->portRect.bottom - gp2->portRect.top); SetPort(gp); } #endif mmovie_mouseout(x,pt); wind_drag((void *)mmovie_drag,x,pt); } void mmovie_savefilms(t_movie *x, void *w) { t_film *f; for (f = x->m_f; f; f = f->f_next) { if (f->f_name != x->m_sym) binbuf_vinsert(w,"sss",gensym("#M"),gensym("rd"),f->f_name); } } // looping void mmovie_loop(t_movie *x, long n) { x->m_loopmode = n? 1 : 0; defer(x,(method)mmovie_settimebase,0,0,0); } void mmovie_palindrome(t_movie *x, long n) { x->m_palindrome = n? 1 : 0; defer(x,(method)mmovie_settimebase,0,0,0); } void mmovie_loopstart(t_movie *x, long n) { x->m_loopstart = n; if (x->m_loopmode) defer(x,(method)mmovie_settimebase,0,0,0); } void mmovie_loopend(t_movie *x, long n) { x->m_loopend = n; if (x->m_loopmode) defer(x,(method)mmovie_settimebase,0,0,0); } void mmovie_loopset(t_movie *x, long start, long end) { x->m_loopstart = start; x->m_loopend = end; if (x->m_loopmode) defer(x,(method)mmovie_settimebase,0,0,0); } void mmovie_settimebase(t_movie *x) { TimeRecord tr2; TimeBase tb; long end,flags,dur; if (!x->m_m) return; tb = GetMovieTimeBase(x->m_m); flags = GetTimeBaseFlags(tb); if (x->m_loopmode) { flags |= loopTimeBase; if (x->m_palindrome) flags |= palindromeLoopTimeBase; else flags &= ~palindromeLoopTimeBase; SetMoviePlayHints(x->m_m, hintsLoop, hintsLoop); } else flags &= ~(loopTimeBase | palindromeLoopTimeBase); //post("flags %ld",flags); SetTimeBaseFlags(tb,flags); GetMovieTime(x->m_m,&tr2); tr2.value.lo = x->m_loopstart; SetTimeBaseStartTime(tb,&tr2); dur = GetMovieDuration(x->m_m); end = x->m_loopend > 0? x->m_loopend : dur; if (end > dur) end = dur; tr2.value.lo = end; SetTimeBaseStopTime(tb,&tr2); } #ifdef IMOVIE void mmovie_psave(t_movie *x, void *w) { Rect *r; long flags; r = &x->m_box.b_rect; flags = 0; flags |= x->m_border ? 1 : 0; /* other flags: controller hidden or showing scale movie to fit in box */ if (x->m_box.b_hidden) { binbuf_vinsert(w,"ssssllllls", gensym("#P"),gensym("hidden"),gensym("user"), ps_imovie, (long)(r->left), (long)(r->top), (long)(r->right - r->left),(long)(r->bottom - r->top), flags, x->m_sym); } else { binbuf_vinsert(w,"sssllllls", gensym("#P"),gensym("user"), ps_imovie, (long)(r->left), (long)(r->top), (long)(r->right - r->left),(long)(r->bottom - r->top), flags, x->m_sym); } mmovie_savefilms(x,w); } void mmovie_info(t_movie *x, void *p, void *b) { mmovie_doread(x,ps_nothing); } #else void mmovie_save(t_movie *x, void *w) { binbuf_vinsert(w,"sssllll", gensym("#N"),gensym("movie"),x->m_sym, (long)x->m_wind->w_x1,(long)x->m_wind->w_y1,(long)x->m_wind->w_x2,(long)x->m_wind->w_y2); mmovie_savefilms(x,w); } void mmovie_dblclick(t_movie *x) { Boolean wasvis; GrafPtr gp; if (x->m_m) { wasvis = ((t_wind *)x->m_wind)->w_vis; wind_vis((void *)x->m_wind); if (!wasvis) { gp = wind_setport(x->m_wind); mmovie_vis(x); SetPort(gp); } } } void mmovie_open(t_movie *x) { defer(x,(method)mmovie_dblclick,0L,0,0L); } void mmovie_wclose(t_movie *x) { defer(x,(method)mmovie_dowclose,0,0,0); } void mmovie_dowclose(t_movie *x) { wind_invis(x->m_wind); } void mmovie_windowpos(t_movie *x, long left, long top, long right, long bottom) { t_atom argv[4]; argv[0].a_type = argv[1].a_type = argv[2].a_type = argv[3].a_type = A_LONG; argv[0].a_w.w_long = left; argv[1].a_w.w_long = top; argv[2].a_w.w_long = right; argv[3].a_w.w_long = bottom; defer(x,(method)mmovie_dowindowpos,0,4,argv); } void mmovie_dowindowpos(t_movie *x, t_symbol *s, short argc, t_atom *argv) { long left, top, right, bottom; left = argv->a_w.w_long; top = (argv+1)->a_w.w_long; right = (argv+2)->a_w.w_long; bottom = (argv+3)->a_w.w_long; if (left > right || top > bottom) { error("movie: windowpos: bad argument order"); return; } if (x->m_wind) { x->m_wind->w_x1 = left; x->m_wind->w_x2 = right; x->m_wind->w_y1 = top; x->m_wind->w_y2 = bottom; if (x->m_wind->w_vis) { MoveWindow(wind_syswind(x->m_wind),left,top,false); SizeWindow(wind_syswind(x->m_wind),right-left,bottom-top,true); } } } #endif void mmovie_free(t_movie *x) { if (x->m_m) mmovie_freefilms(x); if (message_patcherUnregister) // if this symbol is defined... message_patcherUnregister(gensym("start"),gensym("movie"),(void *)x,x->m_get,x->m_patcher); #ifdef IMOVIE box_free((t_box *)x); #else // wind_free(x->m_wind); freeobject((t_object *)x->m_wind); #endif mmovie_unlink(x); } void mmovie_doclear(t_movie *x) { if (x->m_pending) { x->m_m = x->m_pending; x->m_pending = 0; } if (x->m_m) { mmovie_ctrl(x,CtrlMovieFreed); DisposeMovie(x->m_m); CloseMovieFile(x->m_refNum); x->m_m = 0; } #ifndef IMOVIE wind_invis((void *)x->m_wind); #endif } void mmovie_clear(t_movie *x) { defer(x,(method)mmovie_doclear,0L,0,0L); } void mmovie_reload(t_movie *x) { if (x->m_m) defer_low(x,(void *)mmovie_doload,0L,0,0L); } void mmovie_doread(t_movie *x, t_symbol *s) { short vol,r; unsigned long type; OSType res; char cs[256]; if (isr()) return; x->m_get = 0; strcpy(cs,s->s_name); if (s==ps_nothing) { if (!open_dialog(cs, &vol,&type,(unsigned long *)mmovie_typelist,MMOVIE_NTYPES)) x->m_get = gensym(cs); else return; } else if (!locatefile_extended(cs,&vol,(long *)&type,(long *)mmovie_typelist,MMOVIE_NTYPES)) x->m_get = gensym(cs); else { post("movie: can't find file %s",s->s_name); return; } x->m_vRefNum = vol; mmovie_doload(x); } void mmovie_doreadany(t_movie *x, t_symbol *s) { short vol,r; unsigned long type; OSType res; char cs[256]; if (isr()) return; x->m_get = 0; strcpy(cs,s->s_name); if (s==ps_nothing) { if (!open_dialog(cs, &vol,&type,NULL,-1)) x->m_get = gensym(cs); else return; } else if (!locatefile_extended(cs,&vol,(long *)&type,(long *)NULL,-1)) x->m_get = gensym(cs); else { post("movie: can't find file %s",s->s_name); return; } x->m_vRefNum = vol; mmovie_doload(x); } void mmovie_doload(t_movie *x) { PATH_SPEC spec; short resRefNum; Movie theMovie; Rect dispBounds,windPos; GrafPtr gp; RgnHandle oldClip,dcr; Rect f; OSErr err; Str255 pname; if (!x->m_get) return; path_tospec(x->m_vRefNum,x->m_get->s_name,&spec); if (err = OpenMovieFile(&spec, &resRefNum, 0)) { error("movie: %s: error %d opening file",x->m_get->s_name,err); return; } oldClip = NewRgn(); GetClip(oldClip); GetPort(&gp); ClipRect(&gp->portRect); if (err = NewMovieFromFile(&theMovie,resRefNum, 0L, 0L, newMovieActive, 0L)) { //error("movie: error %d call to _NewMovieFromFile",err); error("movie: error %d call to _NewMovieFromFile while opening %s",err,x->m_get->s_name); SetClip(oldClip); DisposeRgn(oldClip); return; } GetMovieBox(theMovie, &dispBounds); /* Get the bounds for the movie */ mmovie_addfilm(x,theMovie, &dispBounds, x->m_get, x->m_vRefNum, resRefNum); #ifdef IMOVIE OffsetRect(&dispBounds,x->m_box.b_rect.left+1-dispBounds.left, x->m_box.b_rect.top+1-dispBounds.top); SetMovieBox(theMovie, &dispBounds); if (patcher_setport(x->m_box.b_patcher)) { SetMovieGWorld(theMovie,0L,0L); /* Play the movie in the window */ ReportError("SetMovieGWorld"); x->m_m = theMovie; x->m_pending = 0; mmovie_cliptobox(x); } else { /* do in update event */ x->m_pending = theMovie; x->m_m = 0; } #else OffsetRect(&dispBounds,-dispBounds.left,-dispBounds.top); SetMovieBox(theMovie, &dispBounds); windPos = dispBounds; OffsetRect(&windPos,x->m_wind->w_x1,x->m_wind->w_y1); // ConstrainRect(&windPos,&(*LMGetGrayRgn())->rgnBBox,1); ConstrainRect(&windPos,&(*GetGrayRgn())->rgnBBox,1); //changed since LowMem.h says should use GetGrayRgn() for carbon wind_invis((void *)x->m_wind); x->m_wind->w_x1 = windPos.left; x->m_wind->w_x2 = windPos.right; x->m_wind->w_y1 = windPos.top; x->m_wind->w_y2 = windPos.bottom; if (!EmptyRect(&windPos)) { /* it's a movie with visual content */ wind_vis((void *)x->m_wind); wind_setport((void *)x->m_wind); SetMovieGWorld(theMovie,0L,0L); /* Play the movie in the window */ ReportError("SetMovieGWorld"); } x->m_m = theMovie; x->m_pending = 0; #endif x->m_refNum = resRefNum; x->m_curname = x->m_get; if (message_patcherRegister) message_patcherRegister(gensym("start"),gensym("movie"),(void *)x,x->m_get,x->m_patcher); #ifndef IMOVIE wind_settitle(x->m_wind,x->m_get->s_name,FALSE); /* I'd use arg here */ x->m_titled = 1; #endif /* mmovie_cbsetup(x); */ mmovie_ctrl(x,CtrlMovieNew); SetPort(gp); SetClip(oldClip); DisposeRgn(oldClip); } void mmovie_read(t_movie *x, t_symbol *s) { defer_low(x,(method)mmovie_doread,s,0,0L); } void mmovie_readany(t_movie *x, t_symbol *s) { defer_low(x,(method)mmovie_doreadany,s,0,0L); } /* this message will be sent to set and clear a controller, when in->s_thing is something, then a controller is active, otherwise it is being freed */ // link a std play controller object to movie void mmovie_controller(t_movie *x, t_symbol *in, t_symbol *out1, t_symbol *out2) { Boolean assign; if (x->m_m || x->m_pending) { assign = !out1->s_thing; if (in->s_thing) { out1->s_thing = (t_object *)x->m_m; out2->s_thing = (t_object *)x; } if (assign) x->m_controller = in->s_thing; in->s_thing = 0; // so no one else gets it } } #ifndef IMOVIE void ConstrainRect(Rect *a, Rect *b, short margin) { Rect b2; b2 = *b; InsetRect(&b2, margin, margin); if (a->left < b2.left) { a->right = (a->right - a->left) + b2.left; a->left = b2.left; } if (a->right > b2.right) { a->left = (a->left - a->right) + b2.right; if (a->left < b2.left) a->left = b2.left; a->right = b2.right; } if (a->top < b2.top) { a->bottom = (a->bottom - a->top) + b2.top; a->top = b2.top; } if (a->bottom > b2.bottom) { a->top = (a->top - a->bottom) + b2.bottom; if (a->top < b2.top) a->top = b2.top; a->bottom = b2.bottom; } } #endif /* keep a linked list of all movies (for doing MoviesTask yourself) */ void mmovie_link(t_movie *x) { x->m_next = mmovie_head; mmovie_head = x; } void mmovie_unlink(t_movie *x) { t_movie *m,*prev; for (prev = 0, m = mmovie_head; m; prev = m, m = m->m_next) { if (m == x) { if (prev) prev->m_next = m->m_next; else mmovie_head = m->m_next; break; } } } void mmovie_assist(t_movie *x, void *b, long m, long a, char *s) { #ifdef IMOVIE assist_string(3560,m,a,1,2,s); #else assist_string(3060,m,a,1,2,s); #endif } void *mmovie_new(t_symbol *s, short ac, t_atom *av) { t_movie *x; short i,styleflag; OSErr err; long init; long flags; t_symbol *name; void *patcher; #ifdef IMOVIE Rect r; #else short x1,y1,x2,y2; #endif x = 0; if (!inited) mmovie_init(); if (!inited) goto bagit; x = (t_movie *)newobject(mmovie_class); x->m_m = 0; x->m_f = 0; /* x->m_cb = 0; */ x->m_pending = 0; x->m_titled = 0; x->m_clock = clock_new(x,(void *)mmovie_tick); x->m_yout = intout(x); x->m_xout = intout(x); x->m_timeout = intout(x); x->m_rate = startRate; x->m_vol = 255; x->m_border = 1; x->m_controller = 0; x->m_ctrlmeth = 0; x->m_passive = 0; x->m_palindrome = 0; mmovie_link(x); #ifdef IMOVIE patcher = av->a_w.w_obj; av++; r.left = av->a_w.w_long; av++; r.top = av->a_w.w_long; av++; r.right = av->a_w.w_long + r.left; av++; r.bottom = av->a_w.w_long + r.top; av++; flags = av->a_w.w_long; av++; if (ac > 6) name = av->a_w.w_sym; else name = ps_nothing; box_new((t_box *)x, patcher, F_DRAWFIRSTIN | F_GROWBOTH | F_SAVVY, r.left,r.top,r.right,r.bottom); x->m_border = x->m_box.b_outline = flags & 1; x->m_box.b_firstin = (void *)x; #else patcher = gensym("#P")->s_thing; if (ac && av->a_type==A_SYM) { name = av->a_w.w_sym; ac--; av++; } else name = ps_nothing; //post("ac %d",ac); if (ac==4) { x1 = av->a_w.w_long; y1 = (av+1)->a_w.w_long; x2 = (av+2)->a_w.w_long; y2 = (av+3)->a_w.w_long; } else { x1 = 100; y1 = 100; x2 = 400; y2 = 400; } //post("wind at %d %d %d %d",x1,y1,x2,y2); styleflag = x->m_border? 0 : WSHADOWPROC; x->m_wind = (void *)wind_new(x, x1, y1, x2, y2, styleflag | WSGROW | WCOLOR | WCLOSE); #endif x->m_curname = name; x->m_sym = name; x->m_patcher = patcher; if (name != ps_nothing) mmovie_doread(x,name); #ifdef IMOVIE box_ready((t_box *)x); x->m_oldbox = x->m_box.b_rect; #endif x->m_autofit = 0; //added x->m_quality = 0; x->m_nextshowing = 0.; x->m_loopstart = 0; x->m_loopend = 0; x->m_loopmode = 0; x->m_tb = 0; gensym("#M")->s_thing = (t_object *)x; bagit: return (x); } #ifdef IMOVIE void *mmovie_menucreate(void *p, long x, long y, long font) { t_atom args[8]; void *res; args->a_type = A_OBJ; args->a_w.w_obj = (struct object *)p; SETLONG(args+1,x); SETLONG(args+2,y); SETLONG(args+3,DefaultWidth); SETLONG(args+4,DefaultHeight); SETLONG(args+5,DefaultFlags); SETSYM(args+6,ps_nothing); res = mmovie_new(ps_imovie,7,args); return (res); } #endif void mmovie_dispose(t_movie *x, t_symbol *name) { defer(x,(method)mmovie_dodispose,name,0,0); } void mmovie_dodispose(t_movie *x, t_symbol *name) { t_film *f; if (name == ps_nothing) { /* dispose all films */ mmovie_freefilms(x); #ifndef IMOVIE wind_invis((void *)x->m_wind); #endif } else { f = mmovie_findfilm(x,name); #ifndef IMOVIE if (x->m_m == f->f_m) wind_invis((void *)x->m_wind); #endif if (f) mmovie_freefilm(x,f); } } void mmovie_rect(t_movie *x, long xpos, long ypos, long width, long height) //added { Rect r; r.top = ypos; r.left = xpos; r.bottom = ypos+height; r.right = xpos+width; #ifdef IMOVIE OffsetRect(&r,x->m_box.b_rect.left+1,x->m_box.b_rect.top+1); #endif if (x->m_m) { SetMovieBox(x->m_m,&r); #ifdef IMOVIE mmovie_cliptobox(x); #endif } } short CmdKeyDown(void) { return (IsKeyDown(55)?cmdKey:0); } short AnyKeyDown(void) { KeyMap k; GetKeys(k); return ((k[0] || k[1] || k[2] || k[3]) ? TRUE:FALSE); } #define BitMask(a) (1L<<(a)) short IsKeyDown(short knum) { short a; char str[30]; char packem[16]; short n,d; n = knum/8; d = knum%8; GetKeys((unsigned long *)packem); if (packem[n]& BitMask(d)) return true; return false; }