ManualClock.hpp
1 #pragma once
2 
3 #include <Scenario/Document/Interval/IntervalExecution.hpp>
4 
5 #include <Execution/Clock/ClockFactory.hpp>
6 #include <Execution/Clock/DefaultClock.hpp>
7 #include <Execution/DocumentPlugin.hpp>
8 
9 #include <ossia/editor/scenario/time_value.hpp>
10 
11 #include <QMainWindow>
12 #include <QToolBar>
13 
14 #include <verdigris>
15 
16 namespace Execution
17 {
18 namespace ManualClock
19 {
20 
21 class TimeWidget : public QToolBar
22 {
23  W_OBJECT(TimeWidget)
24 public:
25  TimeWidget(QWidget* parent = nullptr)
26  {
27  {
28  auto pb = addAction("+1");
29  connect(pb, &QAction::triggered, this, [this] { advance(1); });
30  }
31 
32  {
33  auto pb = addAction("+5");
34  connect(pb, &QAction::triggered, this, [this] { advance(5); });
35  }
36 
37  {
38  auto pb = addAction("+100");
39  connect(pb, &QAction::triggered, this, [this] { advance(100); });
40  }
41  }
42 
43  void advance(int arg_1) W_SIGNAL(advance, arg_1);
44 };
45 
46 class Clock final
47  : public QObject
48  , public Execution::Clock
49  , public Nano::Observer
50 {
51 public:
52  Clock(const Execution::Context& ctx)
53  : Execution::Clock{ctx}
54  , m_default{ctx}
55  {
56  }
57 
58  ~Clock() override { }
59 
60 private:
61  TimeWidget* m_widg{};
62  // Clock interface
63  void play_impl(const TimeVal& t) override
64  {
65  m_paused = false;
66 
67  m_widg = new TimeWidget;
68  if(context.doc.app.mainWindow)
69  {
70  context.doc.app.mainWindow->addToolBar(Qt::ToolBarArea::BottomToolBarArea, m_widg);
71  }
72  QObject::connect(m_widg, &TimeWidget::advance, this, [this](int val) {
73  using namespace ossia;
74  ossia::time_interval& itv = *scenario->baseInterval().OSSIAInterval();
75  ossia::time_value time{val};
76  ossia::token_request tok{};
77  itv.tick_offset(time, 0_tv, tok);
78  });
79  m_widg->show();
80 
81  auto& bs = *scenario;
82  m_default.play(t, bs);
83 
84  resume_impl();
85  }
86  void pause_impl() override { }
87  void resume_impl() override { }
88  void stop_impl() override
89  {
90  delete m_widg;
91  context.doc.plugin<DocumentPlugin>().finished();
92  }
93  bool paused() const override { return m_paused; }
94 
95  Execution::DefaultClock m_default;
96  bool m_paused{};
97 };
98 
99 /*
100 class ClockFactory final : public Execution::ClockFactory
101 {
102  SCORE_CONCRETE("5e8d0f1b-752f-4e29-8c8c-ecd65bd69806")
103 
104  QString prettyName() const override { return QObject::tr("Manual"); }
105 
106  std::unique_ptr<Execution::Clock>
107  make(const Execution::Context& ctx) override
108  {
109  return std::make_unique<Clock>(ctx);
110  }
111 
112  Execution::time_function
113  makeTimeFunction(const score::DocumentContext& ctx) const override
114  {
115  constexpr double rate = 44100;
116  return [this](const TimeVal& v) -> ossia::time_value {
117  return v.isInfinite()
118  ? ossia::Infinite
119  : ossia::time_value{std::llround(rate * v.msec() / 1000.)};
120  };
121  }
122 
123  Execution::reverse_time_function
124  makeReverseTimeFunction(const score::DocumentContext& ctx) const override
125  {
126  constexpr double rate = 44100;
127  return [this](const ossia::time_value& v) -> TimeVal {
128  return v.infinite() ? TimeVal::infinite()
129  : TimeVal::fromMsecs(1000. * v.impl / rate);
130  };
131  }
132 };
133 */
134 }
135 }
Definition: ClockFactory.hpp:41
Definition: DefaultClock.hpp:14
Definition: plugins/score-plugin-engine/Execution/DocumentPlugin.hpp:60
Definition: ManualClock.hpp:50
Definition: ManualClock.hpp:22
Components used for the execution of a score.
Definition: ProcessComponent.cpp:12
Definition: ExecutionContext.hpp:76
Definition: TimeValue.hpp:21