2 #include <Process/Inspector/ProcessInspectorWidgetDelegate.hpp>
3 #include <Process/Inspector/ProcessInspectorWidgetDelegateFactory.hpp>
5 #include <score/command/Dispatchers/OngoingCommandDispatcher.hpp>
6 #include <score/document/DocumentContext.hpp>
7 #include <score/tools/Bind.hpp>
8 #include <score/widgets/DoubleSlider.hpp>
9 #include <score/widgets/SignalUtils.hpp>
11 #include <ossia/detail/math.hpp>
13 #include <QFormLayout>
16 #include <Patternist/Commands/PatternProperties.hpp>
17 #include <Patternist/PatternModel.hpp>
26 : InspectorWidgetDelegate_T{obj, parent}
27 , m_dispatcher{doc.dispatcher}
29 , m_currentPattern{
this}
34 m_duration.setRange(4, 32);
35 m_rate.setRange(1, 64);
36 m_channel.setRange(1, 16);
37 m_lanes.setRange(1, 127);
39 m_channel.setValue(obj.channel());
41 if(!ossia::valid_index(obj.currentPattern(), obj.patterns()))
43 const Pattern& pat = obj.patterns()[obj.currentPattern()];
44 m_lanes.setValue(pat.lanes.size());
45 m_duration.setValue(pat.length);
46 m_rate.setValue(pat.division);
48 auto lay =
new QFormLayout{
this};
50 con(process(), &ProcessModel::channelChanged,
this, [&](
int c) {
51 if(c != m_channel.value())
52 m_channel.setValue(c);
54 con(process(), &ProcessModel::currentPatternChanged,
this, [&](
int c) {
55 if(c == m_currentPattern.value())
58 m_currentPattern.setValue(c);
60 const Pattern& pat = obj.patterns()[c];
61 m_lanes.blockSignals(
true);
62 m_duration.blockSignals(
true);
63 m_rate.blockSignals(
true);
65 m_lanes.setValue(pat.lanes.size());
66 m_duration.setValue(pat.length);
67 m_rate.setValue(pat.division);
69 m_lanes.blockSignals(
false);
70 m_duration.blockSignals(
false);
71 m_rate.blockSignals(
false);
73 con(process(), &ProcessModel::patternsChanged,
this, [&] {
74 if(!ossia::valid_index(obj.currentPattern(), obj.patterns()))
77 const Pattern& pat = obj.patterns()[obj.currentPattern()];
78 m_lanes.blockSignals(
true);
79 m_duration.blockSignals(
true);
80 m_rate.blockSignals(
true);
82 m_lanes.setValue(pat.lanes.size());
83 m_duration.setValue(pat.length);
84 m_rate.setValue(pat.division);
86 m_lanes.blockSignals(
false);
87 m_duration.blockSignals(
false);
88 m_rate.blockSignals(
false);
91 con(m_channel, qOverload<int>(&QSpinBox::valueChanged),
this, [&](
int v) {
92 if(v != obj.channel())
93 m_dispatcher.
submit<SetPatternChannel>(obj, v);
95 con(m_channel, &QSpinBox::editingFinished,
this, [&] { m_dispatcher.
commit(); });
97 con(m_lanes, qOverload<int>(&QSpinBox::valueChanged),
this, [&](
int nn) {
101 if(!ossia::valid_index(obj.currentPattern(), obj.patterns()))
104 const std::size_t n = nn;
106 auto p = obj.patterns()[obj.currentPattern()];
107 if(n == p.lanes.size())
111 else if(n < p.lanes.size())
117 auto last_lane = p.lanes.back();
118 while(p.lanes.size() < n)
119 p.lanes.push_back(last_lane);
125 con(m_lanes, &QSpinBox::editingFinished,
this, [&]() { m_dispatcher.
commit(); });
127 con(m_currentPattern, qOverload<int>(&QSpinBox::valueChanged),
this, [&](
int v) {
128 if(v != obj.currentPattern())
129 m_dispatcher.
submit<SetCurrentPattern>(obj, v);
131 con(m_currentPattern, &QSpinBox::editingFinished,
this,
132 [&]() { m_dispatcher.
commit(); });
134 con(m_duration, qOverload<int>(&QSpinBox::valueChanged),
this, [&]() {
135 int n = m_duration.value();
139 auto p = obj.patterns()[obj.currentPattern()];
144 if(p.length > int64_t(p.lanes[0].pattern.size()))
146 for(auto& lane : p.lanes)
148 lane.pattern.resize(n);
154 con(m_duration, &QSpinBox::editingFinished,
this, [&]() { m_dispatcher.
commit(); });
156 con(m_rate, &QDoubleSpinBox::editingFinished,
this, [&] {
157 auto p = obj.patterns()[obj.currentPattern()];
158 if(p.division != m_rate.value())
159 p.division = m_rate.value();
164 lay->addRow(tr(
"Channel"), &m_channel);
165 lay->addRow(tr(
"Current pattern"), &m_currentPattern);
166 lay->addRow(tr(
"Lanes"), &m_lanes);
167 lay->addRow(tr(
"Steps"), &m_duration);
168 lay->addRow(tr(
"Rate"), &m_rate);
175 QSpinBox m_currentPattern;
178 QDoubleSpinBox m_rate;
183 SCORE_CONCRETE(
"03d55730-fc4a-42a7-b573-35c330c5bad2")
The OngoingCommandDispatcher class.
Definition: OngoingCommandDispatcher.hpp:27
void submit(Args &&... args)
Definition: OngoingCommandDispatcher.hpp:37
void commit()
Definition: OngoingCommandDispatcher.hpp:61
Definition: PatternInspector.hpp:182
Definition: PatternModel.hpp:36
Definition: PatternProperties.hpp:16
Definition: PatternModel.hpp:24
Definition: DocumentContext.hpp:18