github.com/256dpi/max-go@v0.7.0/lib/max/ext_post.h (about) 1 #ifndef _EXT_POST_H_ 2 #define _EXT_POST_H_ 3 4 #include "ext_prefix.h" 5 #include "ext_mess.h" 6 7 BEGIN_USING_C_LINKAGE 8 9 /** 10 Print text to the Max window. 11 Max 5 introduced object_post(), which provides several enhancements to post() 12 where a valid #t_object pointer is available. 13 14 post() is a printf() for the Max window. It even works from non-main threads, 15 queuing up multiple lines of text to be printed when the main thread processing resumes. 16 post() can be quite useful in debugging your external object. 17 18 @ingroup console 19 @param fmt A C-string containing text and printf-like codes 20 specifying the sizes and formatting of the additional arguments. 21 @param ... Arguments of any type that correspond to the format codes in fmtString. 22 23 @remark Note that post only passes 16 bytes of arguments to sprintf, so if 24 you want additional formatted items on a single line, use postatom(). 25 26 Example: 27 @code 28 short whatIsIt; 29 30 whatIsIt = 999; 31 post ("the variable is %ld",(long)whatIsIt); 32 @endcode 33 34 @remark The Max Window output when this code is executed. 35 @code 36 the variable is 999 37 @endcode 38 39 @see object_post() 40 @see error() 41 @see cpost() 42 */ 43 void post(C74_CONST char *fmt, ...); 44 45 46 /** 47 Print text to the system console. 48 On the Mac this post will be visible by launching Console.app in the /Applications/Utilities folder. 49 On Windows this post will be visible by launching the dbgView.exe program, which is a free download 50 as a part of Microsoft's SysInternals. 51 52 @ingroup console 53 @param fmt A C-string containing text and printf-like codes 54 specifying the sizes and formatting of the additional arguments. 55 @param ... Arguments of any type that correspond to the format codes in fmtString. 56 57 @remark Particularly on MacOS 10.5, posting to Console.app can be a computationally expensive operation. 58 Use with care. 59 60 @see post() 61 @see object_post() 62 */ 63 void cpost(C74_CONST char *fmt, ...); 64 65 66 /** 67 Print an error to the Max window. 68 Max 5 introduced object_error(), which provides several enhancements to error() 69 where a valid #t_object pointer is available. 70 71 error() is very similar to post(), thought it offers two additional features: 72 - the post to the Max window is highlighted (with a red background). 73 - the post can be trapped with the error object in a patcher. 74 75 @ingroup console 76 @param fmt A C-string containing text and printf-like codes 77 specifying the sizes and formatting of the additional arguments. 78 @param ... Arguments of any type that correspond to the format codes in fmtString. 79 80 @see object_post() 81 @see post() 82 @see cpost() 83 */ 84 void error(C74_CONST char *fmt, ...); 85 86 /** 87 Put up an error or advisory alert box on the screen. 88 89 Don't use this function. Instead use error(), object_error(), or object_error_obtrusive(). 90 91 This function performs an sprintf() on fmtstring and items, then 92 puts up an alert box. ouchstring() will queue the message to a lower 93 priority level if it's called in an interrupt and there is no alert box 94 request already pending. 95 96 @ingroup console 97 @param s A C-string containing text and printf-like codes 98 specifying the sizes and formatting of the additional arguments. 99 @param ... Arguments of any type that correspond to the format codes in fmtString. 100 101 @see error() 102 @see object_error() 103 @see object_error_obtrusive() 104 */ 105 void ouchstring(C74_CONST char *s, ...); 106 107 108 /** 109 Print multiple items in the same line of text in the Max window. 110 This function prints a single #t_atom on a line in the Max window 111 without a carriage return afterwards, as post() does. Each #t_atom printed 112 is followed by a space character. 113 114 @ingroup console 115 @param ap The address of a #t_atom to print. 116 117 @see object_post() 118 @see post() 119 @see cpost() 120 121 */ 122 void postatom(t_atom *ap); 123 124 void debug_printf(C74_CONST char *,...); 125 126 127 /** Receive messages from the error handler. 128 @ingroup misc 129 @param x The object to be subscribed to the error handler. 130 131 @remark error_subscribe() enables your object to receive a message (error), 132 followed by the list of atoms in the error message posted to the Max 133 window. 134 135 Prior to calling error_subscribe(), you should bind the error 136 message to an internal error handling routine: 137 @code 138 addmess((method)myobject_error, "error", A_GIMME, 0); 139 @endcode 140 Your error handling routine should be declared as follows: 141 @code 142 void myobject_error(t_myobject *x, t_symbol *s, short argc, t_atom *argv); 143 @endcode 144 */ 145 void error_subscribe(t_object *x); 146 147 148 /** Remove an object as an error message recipient. 149 @ingroup misc 150 @param x The object to unsubscribe. 151 */ 152 void error_unsubscribe(t_object *x); 153 154 155 void xsetpost(void); 156 157 void poststring(const char *s); 158 159 enum { 160 POSTROW_POST = 0, 161 POSTROW_ERROR = 1, 162 POSTROW_WARNING = 2, 163 POSTROW_BUG = 3, 164 POSTROW_BADGE = 4 165 }; 166 167 enum { 168 JMAXWINDOW_ADVANCE = 1, 169 JMAXWINDOW_APPEND = 2, 170 JMAXWINDOW_WRITE = 4, 171 JMAXWINDOW_UNIQUE = 8, 172 JMAXWINDOW_MULTILINE = 16 173 }; 174 175 176 /** 177 Print text to the Max window, linked to an instance of your object. 178 179 Max window rows which are generated using object_post() or object_error() can be 180 double-clicked by the user to have Max assist with locating the object in a patcher. 181 Rows created with object_post() and object_error() will also automatically provide 182 the name of the object's class in the correct column in the Max window. 183 184 @ingroup console 185 @param x A pointer to your object. 186 @param s A C-string containing text and printf-like codes 187 specifying the sizes and formatting of the additional arguments. 188 @param ... Arguments of any type that correspond to the format codes in fmtString. 189 190 @remark Example: 191 @code 192 void myMethod(myObject *x, long someArgument) 193 { 194 object_post((t_object*)x, "This is my argument: %ld", someArgument); 195 } 196 @endcode 197 198 @see object_error() 199 */ 200 void object_post(t_object *x, C74_CONST char *s, ...); 201 202 203 /** 204 Print text to the Max window, linked to an instance of your object, 205 and flagged as an error (highlighted with a red background). 206 207 Max window rows which are generated using object_post() or object_error() can be 208 double-clicked by the user to have Max assist with locating the object in a patcher. 209 Rows created with object_post() and object_error() will also automatically provide 210 the name of the object's class in the correct column in the Max window. 211 212 @ingroup console 213 @param x A pointer to your object. 214 @param s A C-string containing text and printf-like codes 215 specifying the sizes and formatting of the additional arguments. 216 @param ... Arguments of any type that correspond to the format codes in fmtString. 217 218 @see object_post() 219 @see object_warn() 220 */ 221 void object_error(t_object *x, C74_CONST char *s, ...); 222 223 224 /** 225 Print text to the Max window, linked to an instance of your object, 226 and flagged as a warning (highlighted with a yellow background). 227 228 Max window rows which are generated using object_post(), object_error(), or object_warn can be 229 double-clicked by the user to have Max assist with locating the object in a patcher. 230 Rows created with object_post(), object_error(), or object_warn() will also automatically provide 231 the name of the object's class in the correct column in the Max window. 232 233 @ingroup console 234 @param x A pointer to your object. 235 @param s A C-string containing text and printf-like codes 236 specifying the sizes and formatting of the additional arguments. 237 @param ... Arguments of any type that correspond to the format codes in fmtString. 238 239 @see object_post() 240 @see object_error() 241 */ 242 void object_warn(t_object *x, C74_CONST char *s, ...); 243 244 // ? 245 void object_bug(t_object *x, C74_CONST char *s, ...); 246 247 // private? 248 void object_poststring(t_object *ob, long kind, long flags, char *text); 249 250 #define STARTUP_CALL_MESSAGE(message, function_name, ...) \ 251 { \ 252 t_bool log = gensym("g_max_startuplog")->s_thing ? TRUE : FALSE; \ 253 double start = log ? systimer_gettime() : 0; \ 254 /* print name before and after so if crashes we know who to blame */ \ 255 /* print name both to minimize confusion for nested calls */ \ 256 const char* msg = message; /* create error if message isn't a string */ \ 257 if (log) cpost("-> %s(%s)\n", #function_name, msg); \ 258 function_name(__VA_ARGS__); \ 259 if (log) cpost("<- %s(%s): %0.3f\n", #function_name, msg, systimer_gettime() - start); \ 260 } 261 262 #define STARTUP_CALL(function_name, ...) STARTUP_CALL_MESSAGE("", function_name, __VA_ARGS__) 263 264 END_USING_C_LINKAGE 265 266 #endif // #ifndef _EXT_POST_H_