NAP
sequenceguiservice.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 // External Includes
8 #include <nap/service.h>
9 #include <entity.h>
10 #include <nap/datetime.h>
11 #include <rtti/factory.h>
12 #include <imguiservice.h>
13 
14 namespace nap
15 {
17 
18  // forward declares
19  class SequenceEventTrackSegmentViewBase;
20  class SequenceEventTrackView;
21  class SequenceTrackSegmentEventBase;
22  class SequenceTrackView;
23  class SequenceGUIService;
24  class SequenceEditorGUIView;
25  class SequenceEditorGUIState;
26 
27  // shortcuts
28  using SequenceEventTrackSegmentViewFactoryFunc = std::function<std::unique_ptr<SequenceEventTrackSegmentViewBase>()>;
29  using SequenceEventTrackSegmentViewFactoryMap = std::unordered_map<rtti::TypeInfo, SequenceEventTrackSegmentViewFactoryFunc>;
30  using SequenceTrackViewFactoryFunc = std::function<std::unique_ptr<SequenceTrackView>(SequenceGUIService &, SequenceEditorGUIView &, SequenceEditorGUIState &)>;
31  using SequenceTrackViewFactoryMap = std::unordered_map<rtti::TypeInfo, SequenceTrackViewFactoryFunc>;
32  using SequenceTrackTypeForViewTypeMap = std::unordered_map<rtti::TypeInfo, rtti::TypeInfo>;
33  using SequenceEventTrackPasteFunc = std::function<void(SequenceEventTrackView &, const std::string &, const SequenceTrackSegmentEventBase &, double)>;
34  using SequenceEventTrackEditFunc = std::function<void(SequenceEventTrackView &)>;
35 
36  namespace icon
37  {
38  namespace sequencer
39  {
40  inline constexpr const char *play = "seq_play.png";
41  inline constexpr const char *stop = "seq_stop.png";
42  inline constexpr const char *rewind = "seq_replay.png";
43  inline constexpr const char *up = "seq_up-arrow.png";
44  inline constexpr const char *down = "seq_down-arrow.png";
45  inline constexpr const char *pause = "seq_pause.png";
46  inline constexpr const char *unpause = "seq_unpause.png";
47  }
48  }
49 
59  class NAPAPI SequenceGUIService final : public Service
60  {
61  friend class SequencePlayerOutput;
62 
63  RTTI_ENABLE(Service)
64  public:
65 
69  struct Colors
70  {
75  void init(const gui::ColorPalette& palette);
76 
77  ImU32 mHigh1 = 0;
78  ImU32 mHigh2 = 0;
79  ImU32 mHigh3 = 0;
80  ImU32 mHigh4 = 0;
81  ImU32 mDark = 0;
82  ImU32 mBack = 0;
83  ImU32 mFro1 = 0;
84  ImU32 mFro2 = 0;
85  ImU32 mFro3 = 0;
86  ImU32 mFro4 = 0;
87 
88  ImU32 mCurveColors[4] = {4285098440, 4278255360, 4294901760, 4278255615};
89  };
90 
92 
93  ~SequenceGUIService() override;
94 
99  static bool registerObjectCreator(std::unique_ptr<rtti::IObjectCreator>(* objectCreator)(SequenceGUIService*));
100 
107  template<typename T>
108  bool registerEventView();
109 
116  bool registerTrackViewFactory(rtti::TypeInfo trackType, SequenceTrackViewFactoryFunc factory);
117 
124  bool registerTrackTypeForView(rtti::TypeInfo trackType, rtti::TypeInfo viewType);
125 
133  std::unique_ptr<SequenceTrackView> invokeTrackViewFactory(rtti::TypeInfo viewType, SequenceEditorGUIView& view, SequenceEditorGUIState& state);
134 
140  std::unique_ptr<SequenceEventTrackSegmentViewBase> invokeEventTrackSegmentViewFactory(rtti::TypeInfo eventType);
141 
147  rtti::TypeInfo getViewTypeForTrackType(rtti::TypeInfo trackType) const;
148 
153  const std::vector<rtti::TypeInfo>& getRegisteredSegmentEventTypes() const;
154 
160  void invokeEditEventHandler(rtti::TypeInfo actionType, SequenceEventTrackView& view) const;
161 
162 
171  void invokePasteEvent(rtti::TypeInfo eventType, SequenceEventTrackView& view, const std::string& trackID,
172  const SequenceTrackSegmentEventBase& eventBase, double time) const;
173 
178  std::vector<rtti::TypeInfo> getAllTrackTypes() const;
179 
184  std::vector<rtti::TypeInfo> getAllRegisteredEventActions() const;
185 
189  nap::IMGuiService& getGui();
190 
194  const nap::IMGuiService& getGui() const;
195 
196 
201  const Colors &getColors() const{ return mColors; }
202 
203  protected:
208  void registerObjectCreators(rtti::Factory& factory) override;
209 
215  bool init(nap::utility::ErrorState& errorState) override;
216 
224  virtual void getDependentServices(std::vector<rtti::TypeInfo>& dependencies);
225 
226  private:
227  // map of segment view types
228  SequenceEventTrackSegmentViewFactoryMap mEventSegmentViewFactoryMap;
229 
230  // map of view factory functions
231  SequenceTrackViewFactoryMap mTrackViewFactoryMap;
232 
233  // map of segment edit event handlers
234  std::unordered_map<rtti::TypeInfo, SequenceEventTrackEditFunc> mEditEventHandlerMap;
235 
236  // map of segment paste handlers
237  std::unordered_map<rtti::TypeInfo, SequenceEventTrackPasteFunc> mPasteEventMap;
238 
239  // list of event types
240  std::vector<rtti::TypeInfo> mSegmentEventTypes;
241 
242  // which view type belongs to which track type
243  SequenceTrackTypeForViewTypeMap mTrackViewTypeMap;
244 
245  // Link to the gui service
246  IMGuiService* mGuiService = nullptr;
247 
248  // Colors
249  Colors mColors;
250  };
251 }
nap::SequenceTrackTypeForViewTypeMap
std::unordered_map< rtti::TypeInfo, rtti::TypeInfo > SequenceTrackTypeForViewTypeMap
Definition: sequenceguiservice.h:32
nap::SequenceGUIService::getColors
const Colors & getColors() const
Definition: sequenceguiservice.h:201
nap::icon::sequencer::up
constexpr const char * up
Definition: sequenceguiservice.h:43
nap::SequenceEditorGUIState
Definition: sequenceeditorguistate.h:23
nap::icon::sequencer::pause
constexpr const char * pause
Definition: sequenceguiservice.h:45
nap::utility::ErrorState
Definition: errorstate.h:19
nap::icon::sequencer::down
constexpr const char * down
Definition: sequenceguiservice.h:44
nap::SequenceGUIService::Colors
Definition: sequenceguiservice.h:69
nap::icon::sequencer::play
constexpr const char * play
Definition: sequenceguiservice.h:40
nap::ServiceConfiguration
Definition: service.h:28
nap::gui::ColorPalette
Definition: imguiservice.h:90
nap::icon::sequencer::stop
constexpr const char * stop
Definition: sequenceguiservice.h:41
nap::SequenceGUIService
Definition: sequenceguiservice.h:59
nap::SequenceEventTrackView
Definition: sequenceeventtrackview.h:144
nap::SequencePlayerOutput
Definition: sequenceplayeroutput.h:23
nap::SequenceEventTrackSegmentViewFactoryMap
std::unordered_map< rtti::TypeInfo, SequenceEventTrackSegmentViewFactoryFunc > SequenceEventTrackSegmentViewFactoryMap
Definition: sequenceguiservice.h:29
nap::SequenceTrackViewFactoryFunc
std::function< std::unique_ptr< SequenceTrackView >(SequenceGUIService &, SequenceEditorGUIView &, SequenceEditorGUIState &)> SequenceTrackViewFactoryFunc
Definition: sequenceguiservice.h:30
nap::Service
Definition: templateservice.h:8
nap::SequenceEventTrackEditFunc
std::function< void(SequenceEventTrackView &)> SequenceEventTrackEditFunc
Definition: sequenceguiservice.h:34
nap::SequenceEditorGUIView
Definition: sequenceeditorgui.h:82
nap::SequenceTrackSegmentEventBase
Definition: sequencetracksegmentevent.h:21
nap::IMGuiService
Definition: imguiservice.h:165
nap::rtti::Factory
Definition: factory.h:78
nap
Definition: templateapp.h:17
nap::SequenceTrackViewFactoryMap
std::unordered_map< rtti::TypeInfo, SequenceTrackViewFactoryFunc > SequenceTrackViewFactoryMap
Definition: sequenceguiservice.h:31
nap::SequenceEventTrackSegmentViewFactoryFunc
std::function< std::unique_ptr< SequenceEventTrackSegmentViewBase >()> SequenceEventTrackSegmentViewFactoryFunc
Definition: sequenceguiservice.h:28
nap::icon::sequencer::rewind
constexpr const char * rewind
Definition: sequenceguiservice.h:42
nap::rtti::TypeInfo
rttr::type TypeInfo
Definition: typeinfo.h:140
nap::icon::sequencer::unpause
constexpr const char * unpause
Definition: sequenceguiservice.h:46
nap::SequenceEventTrackPasteFunc
std::function< void(SequenceEventTrackView &, const std::string &, const SequenceTrackSegmentEventBase &, double)> SequenceEventTrackPasteFunc
Definition: sequenceguiservice.h:33