File: generic-controller.h

package info (click to toggle)
ecasound 2.9.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 6,292 kB
  • sloc: cpp: 39,475; sh: 4,335; lisp: 1,918; ansic: 1,883; makefile: 888; python: 617; ruby: 202
file content (92 lines) | stat: -rw-r--r-- 2,255 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef INCLUDED_GENERIC_CONTROLLER_H
#define INCLUDED_GENERIC_CONTROLLER_H

#include "ctrl-source.h"
#include "eca-operator.h"

/**
 * Generic controller class that connects controller sources
 * to objects supporting dynamic parameter control (classes 
 * which inherit DYNAMIC_PARAMETERS).
 * 
 * Related design patterns:
 *     - Decorator (GoF175)
 */
class GENERIC_CONTROLLER : public CONTROLLER_SOURCE {

 public:

  /** @name Constructors and destructors */
  /*@{*/

  GENERIC_CONTROLLER(CONTROLLER_SOURCE* source,
		     OPERATOR* dobj = 0, 
		     int param_id = 0, 
		     double range_low = 0.0, 
		     double range_high = 0.0);

  GENERIC_CONTROLLER* clone(void) const { return(0); }
  GENERIC_CONTROLLER* new_expr(void) const { return(new GENERIC_CONTROLLER(0)); }

  /*@}*/

  /** @name Public functions reimplemented from CONTROLLER_SOURCE */
  /*@{*/

  virtual void init(void);

  /**
   * Returns the current value, scale it and
   * applies it to target objects.
   *
   * @pre is_valid() == true
   */
  virtual parameter_t value(double pos_secs);

  virtual void set_initial_value(parameter_t arg) { }

  /*@}*/

  /** @name Public functions reimplemented from ECA_OBJECT */
  /*@{*/

  virtual std::string name(void) const { return(source == 0 ? string("") : source->name()); }

  /*@}*/

  /** @name Public functions reimplemented from DYNAMIC_PARAMETERS */
  /*@{*/

  virtual bool variable_params(void) const { return true; }
  virtual std::string parameter_names(void) const { return("param-id,range-low,range-high," +  source->parameter_names()); }
  virtual void set_parameter(int param, parameter_t value);
  virtual parameter_t get_parameter(int param) const;

  /*@}*/

  /** @name Public functions  */
  /*@{*/

  bool is_valid(void) const { return(target != 0 && source != 0); }
  std::string status(void) const;

  void assign_target(OPERATOR* obj);
  void assign_source(CONTROLLER_SOURCE* obj);

  CONTROLLER_SOURCE* source_pointer(void) const { return(source); }
  OPERATOR* target_pointer(void) const { return(target); }

  /*@}*/
 
private:

  OPERATOR* target;
  CONTROLLER_SOURCE* source;

  bool init_called_rep;
  int param_id_rep;
  double rangelow_rep, rangehigh_rep;
  double last_value_pos_rep;
};

#endif