SpectMorph
smmorphoperator.hh
1 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl-2.1.html
2 
3 #ifndef SPECTMORPH_MORPH_OPERATOR_HH
4 #define SPECTMORPH_MORPH_OPERATOR_HH
5 
6 #include "smoutfile.hh"
7 #include "sminfile.hh"
8 #include "smsignal.hh"
9 #include "smproperty.hh"
10 
11 #include <map>
12 #include <memory>
13 
14 namespace SpectMorph
15 {
16 
18 {
19  virtual ~MorphOperatorConfig();
20 };
21 
22 class MorphOperatorView;
23 class MorphPlan;
24 class MorphOperatorPtr;
25 
27 {
28 public:
29  typedef std::map<std::string, MorphOperator *> OpNameMap;
30 
31 protected:
32  MorphPlan *m_morph_plan;
33  std::string m_name;
34  std::string m_id;
35  bool m_folded;
36  std::map<std::string, std::unique_ptr<Property>> m_properties;
37 
38  LogProperty *add_property_log (float *value, const std::string& identifier,
39  const std::string& label, const std::string& value_label,
40  float def, float mn, float mx);
41  LogProperty *add_property_log (ModulationData *mod_data, const std::string& identifier,
42  const std::string& label, const std::string& value_label,
43  float def, float mn, float mx);
44  XParamProperty *add_property_xparam (float *value, const std::string& identifier,
45  const std::string& label, const std::string& value_label,
46  float def, float mn, float mx, float slope);
47  LinearProperty *add_property (float *value, const std::string& identifier,
48  const std::string& label, const std::string& value_label,
49  float def, float mn, float mx);
50  LinearProperty *add_property (ModulationData *mod_data, const std::string& identifier,
51  const std::string& label, const std::string& value_label,
52  float def, float mn, float mx);
53  IntProperty *add_property (int *value, const std::string& identifier,
54  const std::string& label, const std::string& value_label,
55  int def, int mn, int mx);
56  IntVecProperty *add_property (int *value, const std::string& identifier,
57  const std::string& label, const std::string& value_label,
58  int def, const std::vector<int>& vec);
59  BoolProperty *add_property (bool *value, const std::string& identifier,
60  const std::string& label,
61  bool def);
62  template<typename Enum>
63  EnumProperty *
64  add_property_enum (Enum *value, const std::string& identifier,
65  const std::string& label, int def, const EnumInfo& ei)
66  {
67  return add_property_enum (identifier, label, def, ei,
68  [value]() { return *value; },
69  [value](int new_value) { *value = static_cast<Enum> (new_value); });
70  }
71 
72  EnumProperty *
73  add_property_enum (const std::string& identifier,
74  const std::string& label, int def, const EnumInfo& ei,
75  std::function<int()> read_func,
76  std::function<void(int)> write_func);
77 
78 public:
79  enum OutputType {
80  OUTPUT_NONE,
81  OUTPUT_AUDIO,
82  OUTPUT_CONTROL
83  };
84  enum ControlType {
85  CONTROL_GUI = 1,
86  CONTROL_SIGNAL_1 = 2,
87  CONTROL_SIGNAL_2 = 3,
88  CONTROL_OP = 4,
89 
90  /* note: don't reorder items here, as we need to be compatible with old files */
91  CONTROL_SIGNAL_3 = 5,
92  CONTROL_SIGNAL_4 = 6,
93 
94  CONTROL_VELOCITY = 7
95  };
96  typedef uintptr_t PtrID;
97 
98  MorphOperator (MorphPlan *morph_plan);
99  virtual ~MorphOperator();
100 
101  virtual const char *type() = 0;
102  virtual int insert_order() = 0;
103  virtual bool save (OutFile& out_file) = 0;
104  virtual bool load (InFile& in_file) = 0;
105  virtual void post_load (OpNameMap& op_name_map);
106  virtual OutputType output_type() = 0;
107  virtual std::vector<MorphOperator *> dependencies();
108  virtual MorphOperatorConfig *clone_config() = 0;
109 
110  void get_property_dependencies (std::vector<MorphOperator *>& deps, const std::vector<std::string>& identifiers);
111  void register_property (Property *property);
112 
113  Property *property (const std::string& identifier);
114  void write_properties (OutFile& out_file);
115  bool read_property_event (InFile& in_file);
116  void read_properties_post_load (OpNameMap& op_name_map);
117 
118  MorphPlan *morph_plan();
119 
120  std::string type_name();
121 
122  std::string name();
123  void set_name (const std::string& name);
124 
125  bool can_rename (const std::string& name);
126 
127  std::string id();
128  void set_id (const std::string& id);
129 
130  bool folded() const;
131  void set_folded (bool folded);
132 
133  PtrID
134  ptr_id() const
135  {
136  /* ptr_id is derived from MorphOperator*, which means that for a given
137  * MorphPlan, these ids never collide, but if the plan is modified,
138  * the same ptr_id can be taken by a new MorphOperator*
139  */
140  return PtrID (this);
141  }
142 
143  static MorphOperator *create (const std::string& type, MorphPlan *plan);
144 };
145 
147 {
148 private:
149  MorphOperator *m_ptr = nullptr;
150 public:
151  operator bool() const { return m_ptr != nullptr; };
152  MorphOperator *get() const { return m_ptr; }
153 
154  MorphOperator::PtrID
155  ptr_id() const
156  {
157  return MorphOperator::PtrID (m_ptr);
158  }
159 
160  void
161  set (MorphOperator *ptr)
162  {
163  m_ptr = ptr;
164  };
165 };
166 
167 }
168 
169 #endif
Definition: smproperty.hh:247
Definition: smproperty.hh:298
Definition: smproperty.hh:320
Class to read SpectMorph binary data.
Definition: sminfile.hh:27
Definition: smproperty.hh:97
Definition: smproperty.hh:167
Definition: smproperty.hh:524
Definition: smproperty.hh:496
Definition: smmodulationlist.hh:17
Definition: smmorphoperator.hh:147
Definition: smmorphoperator.hh:27
Definition: smmorphplan.hh:18
Definition: smoutfile.hh:19
Definition: smproperty.hh:25
Definition: smsignal.hh:35
Definition: smproperty.hh:551
Definition: smmorphoperator.hh:18