github.com/256dpi/max-go@v0.7.0/lib/max/ext_parameter.h (about)

     1  /*
     2   *  ext_parameter.h
     3   *
     4   *  Copyright 2008 Cycling '74. All rights reserved.
     5   *
     6   */
     7  
     8  #ifndef _EXT_PARAMETER_H_
     9  #define _EXT_PARAMETER_H_
    10  
    11  #include "ext_prefix.h"
    12  #include "ext_mess.h"
    13  #include "ext_dictionary.h"
    14  #include "jpatcher_api.h"
    15  
    16  BEGIN_USING_C_LINKAGE
    17  
    18  enum t_parameter_method_flag {
    19  	PARAMETER_METHOD_FLAG_OVERRIDE 	= 0,			// default is to override normal method with standard method
    20  	PARAMETER_METHOD_FLAG_PRE 		= (1L << 0L),	// user-defined pre-processing function for standard method
    21  	PARAMETER_METHOD_FLAG_POST		= (1L << 1L),	// user-defined post-processing function for standard method
    22  	PARAMETER_METHOD_FLAG_FULL		= (1L << 2L),	// user-defined override method
    23  	PARAMETER_METHOD_FLAG_DONOTHING	= (1L << 15L),	// don't override at all
    24  };
    25  
    26  enum t_parameter_color_flag {
    27  	PARAMETER_COLOR_FLAG_DEFAULT	= 0,
    28  	PARAMETER_COLOR_FLAG_STYLE		= (1L << 0L)	// use style system for color rather than defaults system
    29  };
    30  
    31  enum {
    32  	PARAMETER_GESTURE_INDEX = 999999
    33  };
    34  
    35  typedef enum {
    36  	PARAM_TYPE_INVALID = -1,
    37  	// these parameter types can be automated
    38  	PARAM_TYPE_FLOAT = 0,
    39  	PARAM_TYPE_INT,
    40  	PARAM_TYPE_ENUM,
    41  	
    42  	///////////////////////////////////////////////////////
    43  	// these parameter types cannot be automated, not are they known to anyone but Max
    44  	PARAM_TYPE_BLOB,	// generic atom type, can be stored, but doesn't use 
    45  						// any other parameter features at this time (order excepted)
    46  
    47  	PARAM_TYPE_FILE
    48  } PARAM_TYPE;
    49  
    50  typedef enum {
    51  	PARAM_FLAGS_NONE = 0,
    52  	PARAM_FLAGS_FORCE_TYPE = 0x1,
    53  } PARAM_FLAGS;
    54  
    55  typedef enum {
    56  	PARAM_TYPE_ENABLE_OFF,	// parameter type menu not available in the inspector
    57  	PARAM_TYPE_ENABLE_ON,	// enables basic parameter types Int, Float, Enum in the parameter type menu
    58  	PARAM_TYPE_ENABLE_BLOB,	// and additionally Blob
    59  	PARAM_TYPE_ENABLE_BLOB_ONLY,
    60  } PARAM_TYPE_ENABLE;
    61  
    62  typedef enum {
    63  	PARAM_UNITSTYLE_INVALID = -1,
    64  	PARAM_UNITSTYLE_INT,
    65  	PARAM_UNITSTYLE_FLOAT,
    66  	PARAM_UNITSTYLE_MS,
    67  	PARAM_UNITSTYLE_HZ,
    68  	PARAM_UNITSTYLE_DB,
    69  	PARAM_UNITSTYLE_PERCENT,
    70  	PARAM_UNITSTYLE_PAN,
    71  	PARAM_UNITSTYLE_SEMITONE,
    72  	PARAM_UNITSTYLE_MIDINOTE,
    73  	PARAM_UNITSTYLE_CUSTOM, // what does this do?
    74  	PARAM_UNITSTYLE_NATIVE, // use the type of the parameter to determine style
    75  } PARAM_UNITSTYLE;
    76  
    77  typedef enum {
    78  	PARAM_MOD_INVALID = -1,
    79  	PARAM_MOD_NONE,
    80  	PARAM_MOD_UNI,
    81  	PARAM_MOD_BI,
    82  	PARAM_MOD_ADD,
    83  	PARAM_MOD_ABS
    84  } PARAM_MOD;
    85  
    86  typedef enum {
    87  	PARAM_DATA_TYPE_INVALID = -1,
    88  	PARAM_DATA_TYPE_VALUE,
    89  	PARAM_DATA_TYPE_TYPE,
    90  	PARAM_DATA_TYPE_TYPE_ENABLE,
    91  	PARAM_DATA_TYPE_ORDER,
    92  	PARAM_DATA_TYPE_LONGNAME,
    93  	PARAM_DATA_TYPE_SHORTNAME,
    94  	PARAM_DATA_TYPE_MIN,
    95  	PARAM_DATA_TYPE_MAX,
    96  	PARAM_DATA_TYPE_ENUM,
    97  	PARAM_DATA_TYPE_MODMODE,
    98  	PARAM_DATA_TYPE_MODMIN,
    99  	PARAM_DATA_TYPE_MODMAX,
   100  	PARAM_DATA_TYPE_INITIAL_ENABLE,
   101  	PARAM_DATA_TYPE_INITIAL,
   102  	PARAM_DATA_TYPE_INITIAL_EDITABLE,
   103  	PARAM_DATA_TYPE_UNITSTYLE,
   104  	PARAM_DATA_TYPE_EXPONENT,
   105  	PARAM_DATA_TYPE_STEPS,
   106  	PARAM_DATA_TYPE_SPEEDLIM,
   107  	PARAM_DATA_TYPE_SMOOTHING, // unimplemented
   108  	PARAM_DATA_TYPE_UNITS,
   109  	PARAM_DATA_TYPE_INFO,
   110  	PARAM_DATA_TYPE_FOCUS, // read-only. use object_parameter_wants_focus() to set focus
   111  	PARAM_DATA_TYPE_INVISIBLE,
   112  	PARAM_DATA_TYPE_AUTOMATION_VALUE,
   113  	PARAM_DATA_TYPE_AUTOMATION_STATE,
   114  	PARAM_DATA_TYPE_MODULATION_VALUE,
   115  	PARAM_DATA_TYPE_DIRTY,
   116  	PARAM_DATA_TYPE_ASSIGNMENT_TEXT_MIDI,
   117  	PARAM_DATA_TYPE_ASSIGNMENT_TEXT_KEY,
   118  	PARAM_DATA_TYPE_ASSIGNMENT_TEXT_MACRO,
   119  	PARAM_DATA_TYPE_LEARNING_MODE,
   120  	PARAM_DATA_TYPE_FILEREF_PATH,
   121  	PARAM_DATA_TYPE_FILEREF_DISPLAYPATH,
   122  	PARAM_DATA_TYPE_FILEREF_DISPLAYNAME,
   123  	PARAM_DATA_TYPE_DEVICESTATE, // read-only
   124  	PARAM_DATA_TYPE_DEFER,
   125  	PARAM_DATA_TYPE_MAPPING_INDEX, // deprecated, do not use
   126  	PARAM_DATA_TYPE_NOBLOBCACHE,
   127  	PARAM_DATA_TYPE_RANGE,
   128  	PARAM_DATA_TYPE_REALVAL,
   129  	PARAM_DATA_TYPE_DISTANCEVAL,
   130  	PARAM_DATA_TYPE_LINEARVAL,
   131  } PARAM_DATA_TYPE;
   132  
   133  typedef enum {
   134  	PARAM_VALUE_SET_DISTANCE = 0,
   135  	PARAM_VALUE_SET_REAL,
   136  	PARAM_VALUE_SET_GETONLY,
   137  	PARAM_VALUE_SET_DISTANCE_NONOTIFY,
   138  	PARAM_VALUE_SET_REAL_NONOTIFY
   139  } PARAM_VALUE_SET_TYPE;
   140  
   141  typedef enum {
   142  	PARAM_VALUE_GET_OUTPUT = 0,
   143  	PARAM_VALUE_GET_AUTOMATION,
   144  	PARAM_VALUE_GET_MODULATION
   145  } PARAM_VALUE_GET_TYPE;
   146  
   147  typedef enum {
   148  	PARAM_VALUE_DISTANCE = 0,
   149  	PARAM_VALUE_LINEAR,
   150  	PARAM_VALUE_REAL
   151  } PARAM_VALUE_FORMAT;
   152  
   153  typedef enum {
   154  	PARAM_AUTOMATION_STATE_NONE			= 0x00,
   155  	PARAM_AUTOMATION_STATE_AUTOMATED	= 0x01,
   156  	PARAM_AUTOMATION_STATE_AUTOENABLED	= 0x02,
   157  	PARAM_AUTOMATION_STATE_IRRELEVANT	= 0x04,
   158  	PARAM_AUTOMATION_STATE_DISABLED		= 0x08,
   159  	PARAM_AUTOMATION_STATE_MACRO		= 0x10
   160  } PARAM_AUTOMATION_STATE;
   161  
   162  typedef enum {
   163  	PARAM_DEVICESTATE_ACTIVE			= 0,
   164  	PARAM_DEVICESTATE_INACTIVE			= 1
   165  } PARAM_DEVICESTATE;
   166  
   167  typedef enum {
   168  	PARAM_LEARNING_TYPE_NONE = 0,
   169  	PARAM_LEARNING_TYPE_MIDI,
   170  	PARAM_LEARNING_TYPE_KEY,
   171  	PARAM_LEARNING_TYPE_MACRO
   172  } PARAM_LEARNING_TYPE;
   173  
   174  typedef struct _parameter_notify_data {
   175  	PARAM_DATA_TYPE		 type;
   176  	long				 ac;
   177  	t_atom				*av;
   178  } t_parameter_notify_data;
   179  
   180  typedef struct _param_class_defcolor_data {
   181  	t_symbol			*classname;
   182  	t_symbol			*attrname;
   183  	t_symbol			*colorname;
   184  	long				flags;
   185  } t_param_class_defcolor_data;
   186  
   187  enum {
   188  	PARAM_VALUECHANGED_UNDEFINED	= 0x00,
   189  	PARAM_VALUECHANGED_VISIBLE		= 0x01
   190  };
   191  
   192  enum {
   193  	PARAM_VISIBILITY_VISIBLE = 0,
   194  	PARAM_VISIBILITY_STOREONLY, // no automation, only store (in blob)
   195  	PARAM_VISIBILITY_HIDDEN
   196  };
   197  
   198  // call in main function
   199  t_max_err class_parameter_init(t_class *c);
   200  // call in new function
   201  t_max_err object_parameter_init(t_object *x, PARAM_TYPE type);
   202  // call in new function
   203  t_max_err object_parameter_init_flags(t_object *x, PARAM_TYPE type, PARAM_FLAGS flags);
   204  // call at end of new function, passing in object dictionary
   205  t_max_err object_parameter_dictionary_process(t_object *x, t_dictionary *d);
   206  // call in free function
   207  t_max_err object_parameter_free(t_object *x);
   208  // call in notify function, return value of TRUE means the notification was param data, in the pnd struct
   209  t_bool object_parameter_notify(t_object *x, t_symbol *s, t_symbol *msg, void *sender, void *data, t_parameter_notify_data *pnd);
   210  // get the value of a particular parameter datum
   211  t_max_err object_parameter_getinfo(t_object *x, PARAM_DATA_TYPE type, long *ac, t_atom **av);
   212  // set the value of a particular parameter datum
   213  t_max_err object_parameter_setinfo(t_object *x, PARAM_DATA_TYPE type, long ac, t_atom *av);
   214  // get the display string for a particular value
   215  t_max_err object_parameter_string_get(t_object *x, double val, char **outstr);
   216  // convert the string according to parameter type and unit to a value
   217  t_max_err object_parameter_stringtovalue(t_object *x, double *value, char *str);
   218  // set object value, returns clipped/stepped value
   219  t_max_err object_parameter_value_set(t_object *x, PARAM_VALUE_SET_TYPE how, double *linear, double *real, char blobnotify);
   220  // get the specified value, in the specified format
   221  t_max_err object_parameter_value_get(t_object *x, PARAM_VALUE_GET_TYPE how, PARAM_VALUE_FORMAT what, double *value);
   222  // set the initial value from the current value
   223  t_max_err object_parameter_current_to_initial(t_object *x);
   224  // get RGB color (0.-1.) based on one of the color symbols, listed below
   225  t_max_err object_parameter_color_get(t_object *x, t_symbol *s, t_jrgba *jrgba);
   226  
   227  // set object value using atoms, most useful for blob or file types
   228  t_max_err object_parameter_value_setvalueof(t_object *x, long ac, t_atom *av, char blobnotify);
   229  t_max_err object_parameter_value_setvalueof_nonotify(t_object *x, long ac, t_atom *av, char blobnotify);
   230  // get object value using atoms, most useful for blob or file types
   231  t_max_err object_parameter_value_getvalueof(t_object *x, long *ac, t_atom **av);
   232  //
   233  t_max_err object_parameter_value_changed(t_object *x, char blobnotify);
   234  t_max_err object_parameter_value_changed_nonotify(t_object *x, char blobnotify);
   235  
   236  t_max_err class_parameter_addmethod(t_class *c, method m, char *name, long flags, ...);
   237  
   238  t_max_err parameter_default_int(t_object *x, long n);
   239  t_max_err parameter_default_float(t_object *x, double d);
   240  t_max_err parameter_default_anything(t_object *x, t_symbol *s, long ac, t_atom *av);
   241  
   242  t_max_err class_parameter_register_default_color(t_class *c, t_symbol *attrname, t_symbol *colorname);
   243  t_max_err class_parameter_register_default_color_flags(t_class *c, t_symbol *attrname, t_symbol *colorname, long flags);
   244  
   245  t_bool object_parameter_is_initialized(t_object *x);
   246  t_bool object_parameter_is_in_Live(t_object *x);
   247  t_bool object_parameter_is_in_maxtilde(t_object *x);
   248  t_bool object_parameter_is_automated(t_object *x);
   249  t_max_err object_parameter_wants_focus(t_object *x);
   250  t_bool object_parameter_is_parameter(t_object *x);
   251  t_atom_long object_parameter_get_order(t_object *x);
   252  
   253  typedef enum {
   254  	PARAMETER_ENABLE_SAVESTATE_UNSAVED = -1,
   255  	PARAMETER_ENABLE_SAVESTATE_OFF = 0,
   256  	PARAMETER_ENABLE_SAVESTATE_ON
   257  } PARAMETER_ENABLE_SAVESTATE;
   258  
   259  PARAMETER_ENABLE_SAVESTATE object_parameter_getenable_savestate(t_object *x);
   260  
   261  enum {
   262  	PARAMETER_MAPPABLE_CONFIG_FLAGS_NONE = 0,
   263  	PARAMETER_MAPPABLE_CONFIG_FLAGS_TOGGLE_ZEROONE	= 0x01,	// this object is a toggle with values 0 and 1 (will be locked to enum)
   264  	PARAMETER_MAPPABLE_CONFIG_FLAGS_TOGGLE_OFFON 	= 0x02,	// this object is a toggle with values off and on (will be locked to enum)
   265  	PARAMETER_MAPPABLE_CONFIG_FLAGS_ENUM			= 0x03,	// this object is an enum and will require an override to specify the range
   266  	PARAMETER_MAPPABLE_CONFIG_FLAGS_INT_MIDI		= 0x04, // this object is an int (0 - 127)
   267  	PARAMETER_MAPPABLE_CONFIG_FLAGS_INT_FULL		= 0x05, // this object is an int (0 - 255)
   268  	PARAMETER_MAPPABLE_CONFIG_FLAGS_INT				= 0x06, // this object is an int and will require an override to specify the range
   269  
   270  	PARAMETER_MAPPABLE_CONFIG_FLAGS_WANTSOVERRIDE	= 0x10	// this object uses a known pattern ('min'/'max' or 'size'), the kernel should autogenerate overrides
   271  };
   272  
   273  enum {
   274  	PARAMETER_MAPPABLE_CONFIG_NOOVERRIDE = 0,
   275  	PARAMETER_MAPPABLE_CONFIG_OVERRIDE_MINMAX, // the object already has individual attributes for min/max
   276  	PARAMETER_MAPPABLE_CONFIG_OVERRIDE_SIZE, // the object already has an individual size attribute (min = 0, max = size - 1)
   277  	PARAMETER_MAPPABLE_CONFIG_OVERRIDE_OBJ // object will implement minmax getter/setter methods if necessary
   278  };
   279  
   280  typedef t_bool (*t_hasminmax_getmethod)(void *);
   281  typedef t_max_err (*t_hasminmax_setmethod)(void *, t_bool);
   282  
   283  typedef t_max_err (*t_minmax_getmethod)(void *, double *, double *);
   284  typedef t_max_err (*t_minmax_setmethod)(void *, double, double);
   285  
   286  typedef t_max_err (*t_enum_getmethod)(void *, long *, t_atom **);
   287  typedef t_max_err (*t_enum_setmethod)(void *, long, t_atom *);
   288  
   289  typedef struct _parameter_mappable_override_minmax {
   290  	t_symbol *minimum;
   291  	t_symbol *maximum;
   292  	t_bool readonly; // do not allow the parameter to change the min/max
   293  } t_parameter_mappable_override_minmax;
   294  
   295  typedef struct _parameter_mappable_override_size {
   296  	t_symbol *size;
   297  	t_bool readonly; // do not allow the parameter to change the size
   298  } t_parameter_mappable_override_size;
   299  
   300  typedef struct _parameter_mappable_override_obj {
   301  	t_minmax_getmethod getmethod;
   302  	t_minmax_setmethod setmethod;
   303  	t_symbol *watchattr; // when this attr changes, we need to pull the new range
   304  } t_parameter_mappable_override_obj;
   305  
   306  typedef union _parameter_mappable_override {
   307  	t_parameter_mappable_override_minmax minmax;
   308  	t_parameter_mappable_override_size size;
   309  	t_parameter_mappable_override_obj obj;
   310  } t_parameter_mappable_override;
   311  
   312  typedef struct _parameter_mappable_hasminmax {
   313  	t_hasminmax_getmethod getmethod;
   314  	t_hasminmax_setmethod setmethod;
   315  } t_parameter_mappable_hasminmax;
   316  
   317  typedef struct _parameter_mappable_enum {
   318  	t_enum_getmethod getmethod;
   319  	t_enum_setmethod setmethod;
   320  } t_parameter_mappable_enum;
   321  
   322  typedef struct _parameter_mappable_config {
   323  	long 							flags;
   324  	long							override_type;
   325  	t_parameter_mappable_override	override_value;
   326  	t_parameter_mappable_hasminmax	hasminmax;
   327  	t_parameter_mappable_enum		enuminfo;
   328  } t_parameter_mappable_config;
   329  
   330  t_bool object_parameter_hasminmax_false(void *x);
   331  t_bool object_parameter_hasminmax_true(void *x);
   332  
   333  void class_parameter_mappable(t_class *c, t_parameter_mappable_config *config);
   334  t_max_err class_parameter_setinfo(t_class *c, PARAM_DATA_TYPE type, long ac, t_atom *av);
   335  t_max_err class_parameter_getinfo(t_class *c, PARAM_DATA_TYPE type, long *ac, t_atom **av);
   336  
   337  END_USING_C_LINKAGE
   338  
   339  #endif //_EXT_PARAMETER_H_