1 / 20

Advanced Multimedia Development

Advanced Multimedia Development. MUMT 402 E-230 (UCL) Tuesday 4:35pm -7:25pm Ichiro Fujinaga Ich@music.mcgill.ca. Writing max External Objects. Initialization main() Definition of methods to create new object Definition of methods to bind to other messages.

kane-cobb
Download Presentation

Advanced Multimedia Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Multimedia Development MUMT 402 E-230 (UCL) Tuesday 4:35pm -7:25pm Ichiro Fujinaga Ich@music.mcgill.ca

  2. Writing max External Objects • Initialization • main() • Definition of methods to create new object • Definition of methods to bind to other messages MUMT 402: Week 1

  3. The bang object: Initialization #include "ext.h” // Required for all Max external objectsvoid *this_class; // Required. Global pointing to this class • Required for all objects • ext.h in Max/MSP SDK • contains other header files • prototypes • this_class is used as a pointer to this class MUMT 402: Week 1

  4. The bang object: Initialization (data) typedef struct _bang // Data structure for this object{ t_object b_ob; // Must always be the first field; // used by Max void *b_out; // Pointer to an outlet} t_bang; • Must start with t_object (see ext_mess.h) • Max convention: first letter followed by underscore • Every object has an inlet • b_out is a pointer to an outlet MUMT 402: Week 1

  5. The bang object: Initialization (methods) // Prototypes for methods: // need a method for each incoming message void *bang_new(void); // object creation method void bang_bang(t_bang *bang); // method for bang message • Declaration of class methods that will respond to Max messages • Objects respond to messages from the Max environment • Objects receive messages (integer, float ,symbol) in their inlets • Object’s methods will process these messages in some way and then send out messages using the object’s outlets • This bang object responds to: “new” an “bang” messages MUMT 402: Week 1

  6. The bang object: main() • When an object is created for the first time: • External object is loaded into memory • main() is executed once and only once • main() specifies how the object should be initialized: • Setup the class: • Allocate memory for the object • Specify method for the creation of instances of the object • Define messages that the object can respond to and bind each message to a method MUMT 402: Week 1

  7. The bang object: main() cont. void main(void) { // set up our class: create a class definition setup(&this_class, (method)bang_new, 0L, (short)sizeof(t_bang), 0L, 0); // bind method "bang_bang” to the "bang" message addbang((method)bang_bang);} } • Setup creates the class • Get pointer to the class, specify instance creation method, instance free method, size of each instance, GUI object. • addbang binds the method to “bang” message coming into the left inlet (addint, addinx, addmess, addft, and addftx) MUMT 402: Week 1

  8. The bang object: main() cont. void main(void) { // set up our class: create a class definition setup(&this_class, (method)bang_new, 0L, (short)sizeof(t_bang), 0L, 0); // bind method "bang_bang” to the "bang" message addbang((method)bang_bang);} } • Setup creates the class • Get pointer to the class, specify instance creation method, instance free method, size of each instance, GUI object. • addbang binds the method to “bang” message coming into the left inlet (addint, addinx, addmess, addft, and addftx) MUMT 402: Week 1

  9. The Binders Max routines that binds messages to your methods: • addbang(method mp) “bang” message into the left inlet bound to mp • addint(method mp)“int” into left inlet bound to mp • addinx(method mp, short inlet) “int” into inlet bound to mp • addfloat(method mp)“float” into left inlet bound to mp • addftx(method mp, short inlet) “float” into inlet bound to mp • addmess(method mp; char *sym; short types...)any message into left inlet bound to mp MUMT 402: Week 1

  10. The bang object: The object creation function void *bang_new(void) { t_bang *bang; // create the new instance and return a pointer to it bang = (t_bang *)newobject(this_class); bang->b_out = bangout(bang); // create a bang outlet return(bang);// must return a pointer to the new instance } • Creates an instance of the class by newobject() • Outlet is created by bangout() and assigned in the object’ s struct MUMT 402: Week 1

  11. The Outlet Creators Max routines that creates outlets: • bangout(void *your_object) create outlet that sends “bang” • intout(void *your_object) create outlet that sends “int” • floatout(void *your_object) create outlet that sends “float” • listout(void *your_object) create outlet that sends “list” • outlet_new(void *your_object, char *msgType) create outlet that sends any message MUMT 402: Week 1

  12. The bang object: Handling the “bang” message void bang_bang(t_bang *bang) { // send a bang to the outlet bang->b_out outlet_bang(bang->b_out); } • This method is called when “bang” message is received at the left inlet. (because of addbang()) • The bang_bang method simply sends a “bang” messages via the outlet via a max method, outlet_bang() • The outlet, bang->b_out was created by bangout() MUMT 402: Week 1

  13. The Senders Max routines that sends messages from outlets: • outlet_bang(Outlet *outlet) sends “bang” • outlet_int(Outlet *outlet) sends “int” • outlet_float(Outlet *outlet) sends “float” • outlet_list(Outlet *outlet, t_symbol *msg, short argc, t_atom *argv) sends “list” • outlet_anything(Outlet *outlet, t_symbol *msg) sends any message MUMT 402: Week 1

  14. The diff object • Introduces how to add inlets and arguments to your object. • Same as the Max built-in “-” object. • Outputs the difference of two integers: the number coming in on the left inlet minus the number stored in the object which can be either specified via the right inlet or in the argument inside the object’s box. MUMT 402: Week 1

  15. The diff object: Data structure typedef struct _diff // Data structure for this object { t_object d_ob; // Must always be the first field long d_valleft; // Last value sent to left inlet long d_valright; // Last value sent to right inlet long d_valtotal; // Value to be sent to outlet void *d_out; // Pointer to outlet, need one for each outlet } t_diff; • Note that three values are stored within the object. MUMT 402: Week 1

  16. The diff object: Initialization • In the setup function in main() now has A_DEFLONG argument indicating that the object accept one integer argument in the object box. setup((t_messlist **) &this_class, diff_new, 0L, (short)sizeof(t_diff), 0L, A_DEFLONG, 0) • Three methods are bound with the three types of messages: “bang” in the left inlet, integer entered in the left inlet, and integer entered in the right inlet. addbang((method)diff_bang); // bind "diff_bang" to the //"bang" message addint((method)diff_int); // bind "diff_int" to int //received in the left inlet addinx((method)diff_in1,1); // bind "diff_in1" to int // received in the right inlet MUMT 402: Week 1

  17. The diff object: Object creation void *diff_new(long value){ t_diff *diff; diff = (t_diff *)newobject(this_class); // Create new // instance and return a pointer to it diff->d_valright = value; // Initialize the diff values diff->d_valleft = 0; diff->d_valtotal = -value; diff->d_out = intout(diff); // Create our outlet intin(diff,1); // Create the right inlet return(diff); // Return a pointer to the new instance } • Value is passed if the user types a number in the object’s box MUMT 402: Week 1

  18. The diff object: Methods void *diff_int(t_diff *diff, long value) { diff->d_valleft = value; // Store the value received in the // left inlet diff->d_valtotal = diff->d_valleft - diff->d_valright;// Subtract right inlet value from the left diff_bang(diff); // Call bang method right away since it's // the left inlet } • The diff_int method is called when an integer comes in on the left inlet. It stores the value in d_valleft, subtracts that value with d_valright, storing the result in d_valtotal, then calls the diff_bang method to output the result. MUMT 402: Week 1

  19. The diff_assist object: Add to New Object list • To make an entry in the New Object list: Include the following in your main(): finder_addclass("All Objects", "diff_assist"); • To add the object to the :Arithmetic/Logic” list as well, you add the following: finder_addclass("Arithmetic/Logic","diff_assist"); MUMT 402: Week 1

  20. The diff_assist object: diff_assist method • To add assistance message, a method must be defined and bound to the MAX message “assist”. Thus in main(): addmess((method)diff_assist, "assist", A_CANT, 0); • Then define the method: void diff_assist(t_diff *diff, Object *b, long msg, long arg, char *s) • msg == 1 if the cursor is over an inlet • msg == 2 if the cursor is over an outlet • arg is the inlet or outlet number starting at 0 from left • s is where the assistance message is copied MUMT 402: Week 1

More Related