NAP
sequenceeditor.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // internal includes
8 #include "sequence.h"
9 #include "sequencecontroller.h"
10 #include "sequencecurveenums.h"
11 #include "sequenceplayer.h"
12 #include "sequenceservice.h"
13 #include "sequenceservice.h"
14 
15 // external includes
16 #include <nap/resource.h>
17 #include <parameter.h>
18 #include <nap/logger.h>
19 #include <atomic>
20 
21 namespace nap
22 {
24 
25  // forward declares
26  class SequenceController;
27 
32  class NAPAPI SequenceEditor : public Resource
33  {
34  friend class SequenceController;
35 
36  RTTI_ENABLE(Resource)
37  public:
39 
45  bool init(utility::ErrorState& errorState) override;
46 
51  void save(const std::string& file);
52 
57  void load(const std::string& file);
58 
63  void changeSequenceDuration(double newDuration);
64 
70  SequenceController *getControllerWithTrackType(rtti::TypeInfo trackType);
71 
78  SequenceController* getControllerWithTrackID(const std::string& trackID);
79 
80 
86  template<typename T>
88  {
89  assert(mControllers.find(RTTI_OF(T)) != mControllers.end()); // type not found
90  return static_cast<T &>(*mControllers[RTTI_OF(T)].get());
91  }
92 
93 
99  void insertMarker(double time, const std::string& message);
100 
106  void changeMarkerTime(const std::string& markerID, double time);
107 
112  void deleteMarker(const std::string& markerID);
113 
119  void changeMarkerMessage(const std::string& markerID, const std::string& markerMessage);
120 
121  // properties
122  ResourcePtr<SequencePlayer> mSequencePlayer = nullptr;
123  private:
124  // map of all controllers
125  std::unordered_map<rttr::type, std::unique_ptr<SequenceController>> mControllers;
126 
131  void performEdit(std::function<void()> action);
132 
133  // make sure we don't perform two edit actions at the same time and make sure they are executed on the main thread
134  // during the update call to the SequenceEditor
135  std::atomic_bool mPerformingEditAction = {false};
136 
137  // service reference
138  SequenceService& mService;
139  };
140 
142 }
nap::SequenceEditor::getController
T & getController()
Definition: sequenceeditor.h:87
nap::SequenceEditor
Definition: sequenceeditor.h:32
nap::SequenceController
Definition: sequencecontroller.h:25
nap::rtti::ObjectPtr
Definition: objectptr.h:154
nap::SequenceService
Definition: sequenceservice.h:42
nap::rtti::ObjectCreator
Definition: factory.h:49
nap::utility::ErrorState
Definition: errorstate.h:19
nap
Definition: templateapp.h:17
nap::Resource
Definition: resource.h:19
nap::rtti::TypeInfo
rttr::type TypeInfo
Definition: typeinfo.h:140