Loading...
Searching...
No Matches
MakeBus.hpp
1#pragma once
2#include <Scenario/Commands/ScenarioCommandFactory.hpp>
3#include <Scenario/Document/Interval/IntervalModel.hpp>
4#include <Scenario/Document/ScenarioDocument/ScenarioDocumentModel.hpp>
5
6#include <score/command/Command.hpp>
7
8#include <ossia/detail/algorithms.hpp>
9
10namespace Scenario
11{
12class IntervalModel;
13class ScenarioDocumentModel;
14}
15namespace Scenario::Command
16{
17class SetBus final : public score::Command
18{
19 SCORE_COMMAND_DECL(CommandFactoryName(), SetBus, "Make an interval a bus")
20public:
21 SetBus(const ScenarioDocumentModel& src, const IntervalModel& tgt, bool bus)
22 : m_doc{src}
23 , m_itv{tgt}
24 , m_old{ossia::contains(src.busIntervals, &tgt)}
25 , m_new{bus}
26 {
27 }
28
29 void undo(const score::DocumentContext& ctx) const override
30 {
31 auto& doc = m_doc.find(ctx);
32 auto& itv = m_itv.find(ctx);
33 if(m_old)
34 doc.addBus(&itv);
35 else
36 doc.removeBus(&itv);
37 }
38 void redo(const score::DocumentContext& ctx) const override
39 {
40 auto& doc = m_doc.find(ctx);
41 auto& itv = m_itv.find(ctx);
42 if(m_new)
43 doc.addBus(&itv);
44 else
45 doc.removeBus(&itv);
46 }
47
48protected:
49 void serializeImpl(DataStreamInput& s) const override
50 {
51 s << m_doc << m_itv << m_old << m_new;
52 }
53 void deserializeImpl(DataStreamOutput& s) override
54 {
55 s >> m_doc >> m_itv >> m_old >> m_new;
56 }
57
58private:
61
62 bool m_old{}, m_new{};
63};
64}
The Path class is a typesafe wrapper around ObjectPath.
Definition Path.hpp:52
Definition MakeBus.hpp:18
Definition IntervalModel.hpp:50
Definition ScenarioDocumentModel.hpp:29
The Command class.
Definition Command.hpp:34
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13
Definition DataStreamHelpers.hpp:99
Definition DataStreamHelpers.hpp:103
Definition DocumentContext.hpp:18