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 #include <rtti/binarywriter.h>
21 
22 namespace nap
23 {
25 
26  // forward declares
27  class SequenceController;
28 
35  {
37  mDateTime(dateTime), mActionType(actionType)
38  { }
39 
43  };
44 
49  class NAPAPI SequenceEditor : public Resource
50  {
51  friend class SequenceController;
52 
53  RTTI_ENABLE(Resource)
54  public:
56 
62  bool init(utility::ErrorState& errorState) override;
63 
68  void save(const std::string& file);
69 
74  void load(const std::string& file);
75 
80  void changeSequenceDuration(double newDuration);
81 
87  SequenceController *getControllerWithTrackType(rtti::TypeInfo trackType);
88 
95  SequenceController* getControllerWithTrackID(const std::string& trackID);
96 
97 
103  template<typename T>
105  {
106  assert(mControllers.find(RTTI_OF(T)) != mControllers.end()); // type not found
107  return static_cast<T &>(*mControllers[RTTI_OF(T)].get());
108  }
109 
110 
116  void insertMarker(double time, const std::string& message);
117 
123  void changeMarkerTime(const std::string& markerID, double time);
124 
129  void deleteMarker(const std::string& markerID);
130 
136  void changeMarkerMessage(const std::string& markerID, const std::string& markerMessage);
137 
143  void takeSnapshot(rtti::TypeInfo actionType);
144 
148  void undo();
149 
153  void redo();
154 
159  void jumpToHistoryPointIndex(int index);
160 
164  void clearHistory();
165 
170  const std::deque<std::unique_ptr<SequenceEditorHistoryPoint>>& getHistory() const{ return mHistory; }
171 
176  size_t getHistoryIndex() const{ return mHistoryIndex; }
177 
182  size_t getHistorySize() const{ return mHistory.size(); }
183 
184  // properties
185  ResourcePtr<SequencePlayer> mSequencePlayer = nullptr;
186  int mUndoSteps = 100;
187  private:
188  // map of all controllers
189  std::unordered_map<rttr::type, std::unique_ptr<SequenceController>> mControllers;
190 
195  void performEdit(std::function<void()> action);
196 
197  // make sure we don't perform two edit actions at the same time and make sure they are executed on the main thread
198  // during the update call to the SequenceEditor
199  std::atomic_bool mPerformingEditAction = {false};
200 
201  // service reference
202  SequenceService& mService;
203 
204  // History index
205  int mHistoryIndex = 0;
206 
207  // History
208  std::deque<std::unique_ptr<SequenceEditorHistoryPoint>> mHistory;
209  };
210 
212 }
nap::SequenceEditor::getController
T & getController()
Definition: sequenceeditor.h:104
nap::SequenceEditor::getHistoryIndex
size_t getHistoryIndex() const
Definition: sequenceeditor.h:176
nap::SequenceEditor
Definition: sequenceeditor.h:49
nap::SequenceEditorHistoryPoint::SequenceEditorHistoryPoint
SequenceEditorHistoryPoint(DateTime dateTime, rtti::TypeInfo actionType)
Definition: sequenceeditor.h:36
nap::SequenceController
Definition: sequencecontroller.h:25
nap::rtti::ObjectPtr
Definition: objectptr.h:154
nap::SequenceService
Definition: sequenceservice.h:42
nap::DateTime
Definition: datetime.h:173
nap::rtti::ObjectCreator
Definition: factory.h:49
nap::utility::ErrorState
Definition: errorstate.h:19
nap::SequenceEditorHistoryPoint
Definition: sequenceeditor.h:34
nap::SequenceEditorHistoryPoint::mBinaryWriter
rtti::BinaryWriter mBinaryWriter
Definition: sequenceeditor.h:42
nap::SequenceEditorHistoryPoint::mDateTime
DateTime mDateTime
Definition: sequenceeditor.h:40
nap::rtti::BinaryWriter
Definition: binarywriter.h:15
nap
Definition: templateapp.h:17
nap::Resource
Definition: resource.h:19
nap::SequenceEditorHistoryPoint::mActionType
rtti::TypeInfo mActionType
Definition: sequenceeditor.h:41
nap::SequenceEditor::getHistorySize
size_t getHistorySize() const
Definition: sequenceeditor.h:182
nap::rtti::TypeInfo
rttr::type TypeInfo
Definition: typeinfo.h:140
nap::SequenceEditor::getHistory
const std::deque< std::unique_ptr< SequenceEditorHistoryPoint > > & getHistory() const
Definition: sequenceeditor.h:170