1 /******************************************************************************* 2 / 3 / File: ParameterWeb.h 4 / 5 / Description: A BParameterWeb is a description of media controls within a BControllable 6 / Media Kit Node. 7 / BParameter, BParameterGroup, BContinuousParameter, BDiscreteParameter and 8 / BNullParameter are "data classes" used to describe the relation within a 9 / BParameterWeb. These are NOT direct visible classes like BControls; just data 10 / containers which applications can use to decide what kind of views to create. 11 / 12 / Copyright 1997-98, Be Incorporated, All Rights Reserved 13 / 14 *******************************************************************************/ 15 16 #if !defined(_CONTROL_WEB_H) 17 #define _CONTROL_WEB_H 18 19 #include <Flattenable.h> 20 #include <MediaDefs.h> 21 #include <MediaNode.h> 22 #include <TypeConstants.h> 23 24 25 // It is highly unfortunate that a linker bug forces these symbols out 26 // from the BParameter class. Hope they don't collide with anything else. 27 28 /* These are control KINDs */ 29 /* kind used when you don't know or care */ 30 extern const char * const B_GENERIC; 31 /* kinds used for sliders */ 32 extern const char * const B_MASTER_GAIN; /* Main Volume */ 33 extern const char * const B_GAIN; 34 extern const char * const B_BALANCE; 35 extern const char * const B_FREQUENCY; /* like a radio tuner */ 36 extern const char * const B_LEVEL; /* like for effects */ 37 extern const char * const B_SHUTTLE_SPEED; /* Play, SloMo, Scan 1.0 == regular */ 38 extern const char * const B_CROSSFADE; /* 0 == first input, +100 == second input */ 39 extern const char * const B_EQUALIZATION; /* depth (dB) */ 40 41 /* kinds used for compressors */ 42 extern const char * const B_COMPRESSION; /* 0% == no compression, 99% == 100:1 compression */ 43 extern const char * const B_QUALITY; /* 0% == full compression, 100% == no compression */ 44 extern const char * const B_BITRATE; /* in bits/second */ 45 extern const char * const B_GOP_SIZE; /* Group Of Pictures. a k a "Keyframe every N frames" */ 46 /* kinds used for selectors */ 47 extern const char * const B_MUTE; /* 0 == thru, 1 == mute */ 48 extern const char * const B_ENABLE; /* 0 == disable, 1 == enable */ 49 extern const char * const B_INPUT_MUX; /* "value" 1-N == input selected */ 50 extern const char * const B_OUTPUT_MUX; /* "value" 1-N == output selected */ 51 extern const char * const B_TUNER_CHANNEL; /* like cable TV */ 52 extern const char * const B_TRACK; /* like a CD player; "value" should be 1-N */ 53 extern const char * const B_RECSTATE; /* like mutitrack tape deck, 0 == silent, 1 == play, 2 == record */ 54 extern const char * const B_SHUTTLE_MODE; /* -1 == backwards, 0 == stop, 1 == play, 2 == pause/cue */ 55 extern const char * const B_RESOLUTION; 56 extern const char * const B_COLOR_SPACE; /* "value" should be color_space */ 57 extern const char * const B_FRAME_RATE; 58 extern const char * const B_VIDEO_FORMAT; /* 1 == NTSC-M, 2 == NTSC-J, 3 == PAL-BDGHI, 4 == PAL-M, 5 == PAL-N, 6 == SECAM, 7 == MPEG-1, 8 == MPEG-2 */ 59 /* kinds used for junctions */ 60 // the prefix of "WEB" is to avoid collission with an enum in Defs.h 61 extern const char * const B_WEB_PHYSICAL_INPUT; /* a jack on the back of the card */ 62 extern const char * const B_WEB_PHYSICAL_OUTPUT; 63 extern const char * const B_WEB_ADC_CONVERTER; /* from analog to digital signals */ 64 extern const char * const B_WEB_DAC_CONVERTER; /* from digital to analog signals */ 65 extern const char * const B_WEB_LOGICAL_INPUT; /* an "input" that may not be physical */ 66 extern const char * const B_WEB_LOGICAL_OUTPUT; 67 extern const char * const B_WEB_LOGICAL_BUS; /* a logical connection point that is neither input nor output; auxilliary bus */ 68 extern const char * const B_WEB_BUFFER_INPUT; /* an input that corresponds to a media_input */ 69 extern const char * const B_WEB_BUFFER_OUTPUT; 70 71 // a simple transport control is a discrete parameter with five values (states): 72 // rewinding, stopped, playing, paused, and fast-forwarding 73 extern const char * const B_SIMPLE_TRANSPORT; 74 75 class BList; 76 class BParameterGroup; 77 class BParameter; 78 class BNullParameter; 79 class BContinuousParameter; 80 class BDiscreteParameter; 81 class BTextParameter; 82 83 84 /* Set these flags on parameters and groups to control how a Theme will */ 85 /* render the Web. Hidden means, generally, "don't show". Advanced means, */ 86 /* generally, that you can show it or not depending on your whim. */ 87 enum media_parameter_flags { 88 B_HIDDEN_PARAMETER = 0x1, 89 B_ADVANCED_PARAMETER = 0x2 90 }; 91 92 93 class BParameterWeb : 94 public BFlattenable 95 { 96 public: 97 BParameterWeb(); 98 ~BParameterWeb(); 99 100 media_node Node(); 101 102 BParameterGroup * MakeGroup( 103 const char * name); 104 105 int32 CountGroups(); 106 BParameterGroup * GroupAt( 107 int32 index); 108 int32 CountParameters(); 109 BParameter * ParameterAt( 110 int32 index); 111 112 virtual bool IsFixedSize() const; 113 virtual type_code TypeCode() const; 114 virtual ssize_t FlattenedSize() const; 115 virtual status_t Flatten(void *buffer, ssize_t size) const; 116 virtual bool AllowsTypeCode(type_code code) const; 117 virtual status_t Unflatten(type_code c, const void *buf, ssize_t size); 118 119 private: 120 121 friend class BParameterGroup; 122 friend class BControllable; 123 124 BParameterWeb( 125 const BParameterWeb & clone); 126 BParameterWeb & operator=( 127 const BParameterWeb & clone); 128 129 /* Mmmh, stuffing! */ 130 virtual status_t _Reserved_ControlWeb_0(void *); 131 virtual status_t _Reserved_ControlWeb_1(void *); 132 virtual status_t _Reserved_ControlWeb_2(void *); 133 virtual status_t _Reserved_ControlWeb_3(void *); 134 virtual status_t _Reserved_ControlWeb_4(void *); 135 virtual status_t _Reserved_ControlWeb_5(void *); 136 virtual status_t _Reserved_ControlWeb_6(void *); 137 virtual status_t _Reserved_ControlWeb_7(void *); 138 139 BList * mGroups; 140 media_node mNode; 141 uint32 _reserved_control_web_[8]; 142 143 BList * mOldRefs; 144 BList * mNewRefs; 145 146 void AddRefFix( 147 void * oldItem, 148 void * newItem); 149 }; 150 151 152 class BParameterGroup : 153 public BFlattenable 154 { 155 private: 156 157 BParameterGroup( 158 BParameterWeb * web, 159 const char * name); 160 virtual ~BParameterGroup(); 161 162 public: 163 164 BParameterWeb * Web() const; 165 const char * Name() const; 166 167 void SetFlags(uint32 flags); 168 uint32 Flags() const; 169 170 BNullParameter * MakeNullParameter( 171 int32 id, 172 media_type m_type, 173 const char * name, 174 const char * kind); 175 BContinuousParameter * MakeContinuousParameter( 176 int32 id, 177 media_type m_type, 178 const char * name, 179 const char * kind, 180 const char * unit, 181 float minimum, 182 float maximum, 183 float stepping); 184 BDiscreteParameter * MakeDiscreteParameter( 185 int32 id, 186 media_type m_type, 187 const char * name, 188 const char * kind); 189 BTextParameter * MakeTextParameter( 190 int32 id, 191 media_type m_type, 192 const char * name, 193 const char * kind, 194 size_t max_bytes); 195 BParameterGroup * MakeGroup( 196 const char * name); 197 198 int32 CountParameters(); 199 BParameter * ParameterAt( 200 int32 index); 201 int32 CountGroups(); 202 BParameterGroup * GroupAt( 203 int32 index); 204 205 virtual bool IsFixedSize() const; 206 virtual type_code TypeCode() const; 207 virtual ssize_t FlattenedSize() const; 208 virtual status_t Flatten(void *buffer, ssize_t size) const; 209 virtual bool AllowsTypeCode(type_code code) const; 210 virtual status_t Unflatten(type_code c, const void *buf, ssize_t size); 211 212 private: 213 214 BParameterGroup(); /* private unimplemented */ 215 BParameterGroup( 216 const BParameterGroup & clone); 217 BParameterGroup & operator=( 218 const BParameterGroup & clone); 219 220 /* Mmmh, stuffing! */ 221 virtual status_t _Reserved_ControlGroup_0(void *); 222 virtual status_t _Reserved_ControlGroup_1(void *); 223 virtual status_t _Reserved_ControlGroup_2(void *); 224 virtual status_t _Reserved_ControlGroup_3(void *); 225 virtual status_t _Reserved_ControlGroup_4(void *); 226 virtual status_t _Reserved_ControlGroup_5(void *); 227 virtual status_t _Reserved_ControlGroup_6(void *); 228 virtual status_t _Reserved_ControlGroup_7(void *); 229 230 friend class BParameterWeb; 231 232 BParameterWeb * mWeb; 233 BList * mControls; 234 BList * mGroups; 235 char * mName; 236 uint32 mFlags; 237 uint32 _reserved_control_group_[7]; 238 239 BParameter * MakeControl( 240 int32 type); 241 }; 242 243 244 /* After you create a BParameter, hook it up by calling AddInput() and/or AddOutput() */ 245 /* (which will call the reciprocal in the target) and optionally call SetChannelCount() and SetMediaType() */ 246 class BParameter : 247 public BFlattenable 248 { 249 public: 250 251 /* This is a parameter TYPE */ 252 enum media_parameter_type 253 { 254 B_NULL_PARAMETER, 255 B_DISCRETE_PARAMETER, 256 B_CONTINUOUS_PARAMETER, 257 B_TEXT_PARAMETER 258 }; 259 260 media_parameter_type Type() const; 261 BParameterWeb * Web() const; 262 BParameterGroup * Group() const; 263 const char * Name() const; 264 const char * Kind() const; 265 const char * Unit() const; 266 int32 ID() const; 267 268 void SetFlags(uint32 flags); 269 uint32 Flags() const; 270 271 virtual type_code ValueType() = 0; 272 /* These functions are typically used by client apps; they will result in */ 273 /* your BControllable getting called to read/write values. */ 274 status_t GetValue( 275 void * buffer, 276 size_t * ioSize, 277 bigtime_t * when); 278 status_t SetValue( 279 const void * buffer, 280 size_t size, 281 bigtime_t when); 282 int32 CountChannels(); /* Number of ValueType() values; default is 1 */ 283 void SetChannelCount( /* One value could still control e g a stereo pair */ 284 int32 channel_count); 285 286 media_type MediaType(); /* Optional (default is B_MEDIA_NO_TYPE) */ 287 void SetMediaType(media_type m_type); 288 289 int32 CountInputs(); 290 BParameter * InputAt( 291 int32 index); 292 void AddInput( 293 BParameter * input); 294 int32 CountOutputs(); 295 BParameter * OutputAt( 296 int32 index); 297 void AddOutput( 298 BParameter * output); 299 300 virtual bool IsFixedSize() const; 301 virtual type_code TypeCode() const; 302 virtual ssize_t FlattenedSize() const; 303 virtual status_t Flatten(void *buffer, ssize_t size) const; 304 virtual bool AllowsTypeCode(type_code code) const; 305 virtual status_t Unflatten(type_code c, const void *buf, ssize_t size); 306 307 private: 308 friend class BNullParameter; 309 friend class BContinuousParameter; 310 friend class BDiscreteParameter; 311 friend class BTextParameter; 312 friend class BParameterGroup; 313 friend class BParameterWeb; 314 315 bool SwapOnUnflatten() { return mSwapDetected; } 316 317 /* Mmmh, stuffing! */ 318 virtual status_t _Reserved_Control_0(void *); 319 virtual status_t _Reserved_Control_1(void *); 320 virtual status_t _Reserved_Control_2(void *); 321 virtual status_t _Reserved_Control_3(void *); 322 virtual status_t _Reserved_Control_4(void *); 323 virtual status_t _Reserved_Control_5(void *); 324 virtual status_t _Reserved_Control_6(void *); 325 virtual status_t _Reserved_Control_7(void *); 326 327 328 BParameter( 329 int32 id, 330 media_type m_type, 331 media_parameter_type type, 332 BParameterWeb * web, 333 const char * name, 334 const char * kind, 335 const char * unit); 336 ~BParameter(); 337 338 int32 mID; 339 media_parameter_type mType; 340 BParameterWeb * mWeb; 341 BParameterGroup * mGroup; 342 char * mName; 343 char * mKind; 344 char * mUnit; 345 BList * mInputs; 346 BList * mOutputs; 347 bool mSwapDetected; 348 media_type mMediaType; 349 int32 mChannels; 350 uint32 mFlags; 351 uint32 _reserved_control_[7]; 352 353 virtual void FixRefs( 354 BList & old, 355 BList & updated); 356 }; 357 358 359 class BContinuousParameter : 360 public BParameter 361 { 362 public: 363 364 virtual type_code ValueType(); 365 366 float MinValue(); 367 float MaxValue(); 368 float ValueStep(); 369 370 /* The "response" specifies what value to display to the user. */ 371 /* Thus, if response is B_POLYNOMIAL with factor 2, an actual */ 372 /* control value of 10 would be displayed to the user as 100, and */ 373 /* if response was B_EXPONENTIAL and factor was 2, an actual */ 374 /* value of 3 would display 8 (two to the third). The ValueStep() */ 375 /* is given in actual control values, before the transformation for */ 376 /* display is done. Thus, with min 0, max 4 and value step 1, and an */ 377 /* exponential response with factor 10, you will get the displayed */ 378 /* values 1, 10, 100, 1000 and 10000 equally spaced across a slider */ 379 /* (or whatever UI the app puts to the parameter). */ 380 /* The "offset" is added to the value after transformation, before display. */ 381 /* If "resp" is negative, the resulting value/display relation is turned upside down. */ 382 enum response { 383 B_UNKNOWN = 0, 384 B_LINEAR = 1, /* factor is direct multiplier >= 0 */ 385 B_POLYNOMIAL, /* factor should be power; typically "2" for squared or "-1" for inverse */ 386 B_EXPONENTIAL, /* factor should be base, typically 2 or 10 */ 387 B_LOGARITHMIC /* factor should be base, typically 2 or 10 */ 388 }; 389 void SetResponse( 390 int resp, 391 float factor, 392 float offset); 393 void GetResponse( 394 int * resp, 395 float * factor, 396 float * offset); 397 398 virtual ssize_t FlattenedSize() const; 399 virtual status_t Flatten(void *buffer, ssize_t size) const; 400 virtual status_t Unflatten(type_code c, const void *buf, ssize_t size); 401 402 private: 403 404 /* Mmmh, stuffing! */ 405 virtual status_t _Reserved_ContinuousParameter_0(void *); 406 virtual status_t _Reserved_ContinuousParameter_1(void *); 407 virtual status_t _Reserved_ContinuousParameter_2(void *); 408 virtual status_t _Reserved_ContinuousParameter_3(void *); 409 virtual status_t _Reserved_ContinuousParameter_4(void *); 410 virtual status_t _Reserved_ContinuousParameter_5(void *); 411 virtual status_t _Reserved_ContinuousParameter_6(void *); 412 virtual status_t _Reserved_ContinuousParameter_7(void *); 413 friend class BParameterGroup; 414 415 BContinuousParameter( 416 int32 id, 417 media_type m_type, 418 BParameterWeb * web, 419 const char * name, 420 const char * kind, 421 const char * unit, 422 float minimum, 423 float maximum, 424 float stepping); 425 ~BContinuousParameter(); 426 427 float mMinimum; 428 float mMaximum; 429 float mStepping; 430 response mResponse; 431 float mFactor; 432 float mOffset; 433 uint32 _reserved_control_slider_[8]; 434 435 }; 436 437 438 class BDiscreteParameter : 439 public BParameter 440 { 441 public: 442 443 virtual type_code ValueType(); 444 445 int32 CountItems(); 446 const char * ItemNameAt( 447 int32 index); 448 int32 ItemValueAt( 449 int32 index); 450 status_t AddItem( 451 int32 value, 452 const char * name); 453 status_t MakeItemsFromInputs(); 454 status_t MakeItemsFromOutputs(); 455 void MakeEmpty(); 456 457 virtual ssize_t FlattenedSize() const; 458 virtual status_t Flatten(void *buffer, ssize_t size) const; 459 virtual status_t Unflatten(type_code c, const void *buf, ssize_t size); 460 461 private: 462 /* Mmmh, stuffing! */ 463 virtual status_t _Reserved_DiscreteParameter_0(void *); 464 virtual status_t _Reserved_DiscreteParameter_1(void *); 465 virtual status_t _Reserved_DiscreteParameter_2(void *); 466 virtual status_t _Reserved_DiscreteParameter_3(void *); 467 virtual status_t _Reserved_DiscreteParameter_4(void *); 468 virtual status_t _Reserved_DiscreteParameter_5(void *); 469 virtual status_t _Reserved_DiscreteParameter_6(void *); 470 virtual status_t _Reserved_DiscreteParameter_7(void *); 471 472 friend class BParameterGroup; 473 474 BList * mSelections; 475 BList * mValues; 476 uint32 _reserved_control_selector_[8]; 477 478 BDiscreteParameter( 479 int32 id, 480 media_type m_type, 481 BParameterWeb * web, 482 const char * name, 483 const char * kind); 484 ~BDiscreteParameter(); 485 }; 486 487 488 class BNullParameter : 489 public BParameter 490 { 491 public: 492 493 virtual type_code ValueType(); 494 495 virtual ssize_t FlattenedSize() const; 496 virtual status_t Flatten(void *buffer, ssize_t size) const; 497 virtual status_t Unflatten(type_code c, const void *buf, ssize_t size); 498 499 private: 500 /* Mmmh, stuffing! */ 501 virtual status_t _Reserved_NullParameter_0(void *); 502 virtual status_t _Reserved_NullParameter_1(void *); 503 virtual status_t _Reserved_NullParameter_2(void *); 504 virtual status_t _Reserved_NullParameter_3(void *); 505 virtual status_t _Reserved_NullParameter_4(void *); 506 virtual status_t _Reserved_NullParameter_5(void *); 507 virtual status_t _Reserved_NullParameter_6(void *); 508 virtual status_t _Reserved_NullParameter_7(void *); 509 510 friend class BParameterGroup; 511 512 uint32 _reserved_control_junction_[8]; 513 514 BNullParameter( 515 int32 id, 516 media_type m_type, 517 BParameterWeb * web, 518 const char * name, 519 const char * kind); 520 ~BNullParameter(); 521 522 }; 523 524 525 class BTextParameter : 526 public BParameter 527 { 528 public: 529 530 size_t MaxBytes() const; 531 virtual type_code ValueType(); 532 533 virtual ssize_t FlattenedSize() const; 534 virtual status_t Flatten(void *buffer, ssize_t size) const; 535 virtual status_t Unflatten(type_code c, const void *buf, ssize_t size); 536 537 private: 538 /* Mmmh, stuffing! */ 539 virtual status_t _Reserved_TextParameter_0(void *); 540 virtual status_t _Reserved_TextParameter_1(void *); 541 virtual status_t _Reserved_TextParameter_2(void *); 542 virtual status_t _Reserved_TextParameter_3(void *); 543 virtual status_t _Reserved_TextParameter_4(void *); 544 virtual status_t _Reserved_TextParameter_5(void *); 545 virtual status_t _Reserved_TextParameter_6(void *); 546 virtual status_t _Reserved_TextParameter_7(void *); 547 548 friend class BParameterGroup; 549 550 uint32 mMaxBytes; 551 uint32 _reserved_control_junction_[8]; 552 553 BTextParameter( 554 int32 id, 555 media_type m_type, 556 BParameterWeb * web, 557 const char * name, 558 const char * kind, 559 size_t max_bytes); 560 ~BTextParameter(); 561 562 }; 563 564 #endif /* _CONTROL_WEB_H */ 565