1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
2 
3 #ifndef SPECTMORPH_MORPH_PLAN_HH
4 #define SPECTMORPH_MORPH_PLAN_HH
5 
6 #include "smindex.hh"
7 #include "smmorphoperator.hh"
8 #include "smobject.hh"
9 #include "smaudio.hh"
10 #include "smutils.hh"
11 #include "smsignal.hh"
12 
13 namespace SpectMorph
14 {
15 
16 class Project;
17 
18 class MorphPlan : public Object
19 {
20 public:
21   class ExtraParameters
22   {
23   public:
24     virtual std::string   section() = 0;
25     virtual void          save (OutFile& out_file) = 0;
26     virtual void          handle_event (InFile& ifile) = 0;
27   };
28 
29   constexpr static int         N_CONTROL_INPUTS = 4;
30 
31 protected:
32   Project                     *m_project = nullptr;
33   Index                        m_index;
34   std::vector<MorphOperator *> m_operators;
35 
36   bool                         in_restore;
37 
38   void  clear();
39   bool  load_index();
40   Error load_internal (GenericIn *in, ExtraParameters *params = nullptr);
41 
42 public:
43   MorphPlan (Project& project);
44   ~MorphPlan();
45 
46   const Index *index();
47   Project     *project();
48 
49   enum AddPos {
50     ADD_POS_AUTO,
51     ADD_POS_END
52   };
53 
54   void add_operator (MorphOperator *op, AddPos = ADD_POS_END, const std::string& name = "", const std::string& id = "", bool load_folded = false);
55   const std::vector<MorphOperator *>& operators();
56   void remove (MorphOperator *op);
57   void move (MorphOperator *op, MorphOperator *op_next);
58 
59   void set_plan_str (const std::string& plan_str);
60   void emit_plan_changed();
61   void emit_index_changed();
62 
63   Error save (GenericOut *file, ExtraParameters *params = nullptr) const;
64   Error load (GenericIn *in, ExtraParameters *params = nullptr);
65 
66   void load_default();
67 
68   MorphPlan *clone() const; // create a deep copy
69 
70   static std::string id_chars();
71   static std::string generate_id();
72 
73   Signal<>                signal_plan_changed;
74   Signal<>                signal_index_changed;
75   Signal<>                signal_need_view_rebuild;
76   Signal<MorphOperator *> signal_operator_removed;
77   Signal<MorphOperator *> signal_operator_added;
78 };
79 
80 typedef RefPtr<MorphPlan> MorphPlanPtr;
81 
82 }
83 
84 #endif
85