InterpolateMacro.hpp
1 #pragma once
2 #include <Scenario/Commands/Interval/Rack/AddSlotToRack.hpp>
3 #include <Scenario/Commands/Scenario/ShowRackInViewModel.hpp>
4 #include <Scenario/Commands/ScenarioCommandFactory.hpp>
5 #include <Scenario/Document/Interval/IntervalModel.hpp>
6 
7 #include <score/command/AggregateCommand.hpp>
8 #include <score/tools/IdentifierGeneration.hpp>
9 
10 #include <ossia/detail/algorithms.hpp>
11 
12 namespace Scenario
13 {
14 namespace Command
15 {
16 // RENAMEME
17 // One InterpolateMacro per interval
19 {
20  SCORE_COMMAND_DECL(
22  "Add processes to intervals")
23 };
24 
26 {
27  SCORE_COMMAND_DECL(
28  CommandFactoryName(), AddMultipleProcessesToIntervalMacro,
29  "Add processes to interval")
30 
31 public:
32  auto& commands() { return m_cmds; }
33  auto&& takeCommands() { return std::move(m_cmds); }
34 
35  // Use this constructor when the interval does not exist yet.
37  {
38  // Then create a slot in this rack
39  auto cmd_slot = new Scenario::Command::AddSlotToRack{cstpath};
40  addCommand(cmd_slot);
41 
42  slotsToUse.push_back({cstpath, 0});
43  }
44 
45  // Use this constructor when the interval already exists
47  {
48  // If no slot : create slot
49  if(interval.smallView().empty())
50  {
51  auto cmd_slot = new Scenario::Command::AddSlotToRack{interval};
52  addCommand(cmd_slot);
53  slotsToUse.push_back({interval, 0});
54  }
55  else
56  {
57  auto it
58  = ossia::find_if(interval.smallView(), [](auto& slt) { return !slt.nodal; });
59  if(it != interval.smallView().end())
60  {
61  int slot_index = it - interval.smallView().begin();
62  slotsToUse.push_back({interval, slot_index});
63  }
64  else
65  {
66  auto cmd_slot = new Scenario::Command::AddSlotToRack{interval};
67  addCommand(cmd_slot);
68  slotsToUse.push_back({interval, (int)interval.smallView().size()});
69  }
70  }
71  }
72 
73  // No need to save this, it is useful only for construction.
74  std::vector<SlotPath> slotsToUse;
75 };
76 
78 makeAddProcessMacro(const IntervalModel& interval, int num_processes)
79 {
80  return new AddMultipleProcessesToIntervalMacro{interval};
81 }
82 }
83 }
The Path class is a typesafe wrapper around ObjectPath.
Definition: Path.hpp:52
The AddSlotToRack class.
Definition: AddSlotToRack.hpp:26
Definition: IntervalModel.hpp:50
Allows for grouping of multiple commands in a single one.
Definition: AggregateCommand.hpp:15
void addCommand(score::Command *cmd)
Add a command to be redone after the others.
Definition: AggregateCommand.cpp:37
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14