ResizeInterval.hpp
1 #pragma once
2 #include <Process/ExpandMode.hpp>
3 #include <Process/TimeValue.hpp>
4 
5 #include <score/plugins/Interface.hpp>
6 #include <score/plugins/InterfaceList.hpp>
7 
8 #include <ossia/detail/algorithms.hpp>
9 
10 #include <score_plugin_scenario_export.h>
11 
12 namespace score
13 {
14 class Command;
15 }
16 namespace Scenario
17 {
18 class IntervalModel;
19 
57 class SCORE_PLUGIN_SCENARIO_EXPORT IntervalResizer : public score::InterfaceBase
58 {
59  SCORE_INTERFACE(IntervalResizer, "8db5b613-a9a8-4a49-9e89-6c07e7117518")
60 public:
61  virtual bool matches(const IntervalModel& m) const noexcept = 0;
62 
63  virtual score::Command* make(
64  const IntervalModel& itv, TimeVal new_duration = TimeVal{1000},
65  ExpandMode = ExpandMode::GrowShrink, LockMode = LockMode::Free) const noexcept = 0;
66 
67  virtual void update(
68  score::Command& cmd, const IntervalModel& interval, TimeVal new_duration,
69  ExpandMode = ExpandMode::GrowShrink, LockMode = LockMode::Free) const noexcept = 0;
70 };
71 
72 class SCORE_PLUGIN_SCENARIO_EXPORT IntervalResizerList final
73  : public score::InterfaceList<IntervalResizer>
74 {
75 public:
76  ~IntervalResizerList() override;
77 
78  IntervalResizer* find(const IntervalModel& m) const
79  {
80  using val_t = decltype(*this->begin());
81  auto it = ossia::find_if(*this, [&](val_t& elt) { return elt.matches(m); });
82  if(it != this->end())
83  return &(*it);
84  return nullptr;
85  }
86 
87  template <typename... Args>
88  score::Command* make(const IntervalModel& m, Args&&... args) const noexcept
89  {
90  using val_t = decltype(*this->begin());
91  auto it = ossia::find_if(*this, [&](val_t& elt) { return elt.matches(m); });
92 
93  return (it != this->end()) ? (*it).make(m, std::forward<Args>(args)...)
94  : (score::Command*)nullptr;
95  }
96 };
97 
99 {
100  SCORE_CONCRETE("1a91f756-da39-4d20-947a-ea08a80e7b8e")
101 
102  bool matches(const IntervalModel& m) const noexcept override;
103  score::Command* make(
104  const IntervalModel& itv, TimeVal new_duration, ExpandMode,
105  LockMode) const noexcept override;
106  void update(
107  score::Command& cmd, const IntervalModel& interval, TimeVal new_duration,
108  ExpandMode, LockMode) const noexcept override;
109 };
111 {
112  SCORE_CONCRETE("4b2ba7d3-2f93-43e0-a034-94c88b74f110")
113 
114  bool matches(const IntervalModel& m) const noexcept override;
115  score::Command* make(
116  const IntervalModel& itv, TimeVal new_duration, ExpandMode,
117  LockMode) const noexcept override;
118  void update(
119  score::Command& cmd, const IntervalModel& interval, TimeVal new_duration,
120  ExpandMode, LockMode) const noexcept override;
121 };
122 
123 }
Definition: ResizeInterval.hpp:111
Definition: IntervalModel.hpp:50
Definition: ResizeInterval.hpp:58
Definition: ResizeInterval.hpp:74
Definition: ResizeInterval.hpp:99
The Command class.
Definition: Command.hpp:34
Base class for plug-in interfaces.
Definition: Interface.hpp:52
InterfaceList Default implementation of InterfaceListBase.
Definition: InterfaceList.hpp:80
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: TimeValue.hpp:21
Definition: ObjectMatches.hpp:6