SpectMorph
smmorphplansynth.hh
1 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl-2.1.html
2 
3 #ifndef SPECTMORPH_MORPH_PLAN_SYNTH_HH
4 #define SPECTMORPH_MORPH_PLAN_SYNTH_HH
5 
6 #include "smmorphplan.hh"
7 #include "smmorphoperator.hh"
8 #include "smrandom.hh"
9 #include "smtimeinfo.hh"
10 #include <map>
11 #include <memory>
12 
13 namespace SpectMorph {
14 
15 class MorphPlanVoice;
16 class MorphModuleSharedState;
17 class MorphOperatorModule;
18 class MorphOutputModule;
19 
21 protected:
22  std::vector<MorphPlanVoice *> voices;
23  std::vector<std::unique_ptr<MorphModuleSharedState>> voices_shared_states;
24 
25  std::vector<std::string> m_last_update_ids;
26  std::string m_last_plan_id;
27  std::vector<std::unique_ptr<MorphOperatorConfig>> m_active_configs;
28 
29  float m_mix_freq;
30  Random m_random_gen;
31  bool m_have_cycle = false;
32 
33 public:
34  struct OpModule {
35  std::unique_ptr<MorphOperatorModule> module;
36  MorphOperator::PtrID ptr_id;
37  MorphOperatorConfig *config = nullptr;
38  };
40  {
41  MorphOutputModule *output_module = nullptr;
42  std::vector<OpModule> new_modules;
43  };
44  struct Update
45  {
46  struct Op
47  {
48  MorphOperator::PtrID ptr_id;
49  std::string type;
50  MorphOperatorConfig *config = nullptr;
51  };
52  bool cheap = false; // cheap update: same set of operators
53  bool have_cycle = false; // plan contains cycles?
54  std::vector<Op> ops;
55  std::vector<std::unique_ptr<MorphOperatorConfig>> new_configs;
56  std::vector<FullUpdateVoice> voice_full_updates;
57  std::vector<std::unique_ptr<MorphModuleSharedState>> new_shared_states; // full updates only
58  };
59  typedef std::shared_ptr<Update> UpdateP;
60 
61  MorphPlanSynth (float mix_freq, size_t n_voices);
62  ~MorphPlanSynth();
63 
64  UpdateP prepare_update (const MorphPlan& new_plan);
65  void apply_update (UpdateP update);
66 
67  void update_shared_state (const TimeInfo& time_info);
68 
69  MorphPlanVoice *voice (size_t i) const;
70 
71  float mix_freq() const;
72  bool have_output() const;
73  Random *random_gen();
74  bool have_cycle() const;
75 };
76 
77 }
78 
79 
80 #endif
Definition: smmorphoutputmodule.hh:14
Definition: smmorphplansynth.hh:20
Definition: smmorphplanvoice.hh:16
Definition: smmorphplan.hh:18
Definition: smrandom.hh:15
Definition: smtimeinfo.hh:11
Definition: smmorphoperator.hh:18
Definition: smmorphplansynth.hh:40
Definition: smmorphplansynth.hh:34
Definition: smmorphplansynth.hh:47
Definition: smmorphplansynth.hh:45