39enum class SequenceWalkControl
60 std::function<bool(
const Sequence& sequence,
76inline bool walkSequenceContent(
Sequence sequence,
83 if (
const auto fullMeasure = sequence.fullMeasure()) {
86 if (
const auto time = measure->calcCurrentTime()) {
92 if (!hooks.
onFullMeasure(sequence, fullMeasure.value(), start, fullMeasureDuration, c)) {
100 SequenceWalkContext& ctxRef,
103 for (
const auto item : current) {
104 bool allowChildren =
true;
107 const SequenceWalkControl control = hooks.
onItem(item, ctxRef);
108 if (control == SequenceWalkControl::Stop) {
111 if (control == SequenceWalkControl::SkipChildren) {
112 allowChildren =
false;
117 const auto event = item.get<sequence::Event>();
118 const auto start = ctxRef.elapsedTime;
119 const auto actualDuration =
event.duration() * ctxRef.timeRatio;
121 if (!hooks.
onEvent(event, start, actualDuration, ctxRef)) {
125 ctxRef.elapsedTime += actualDuration;
128 const auto grace = item.get<sequence::Grace>();
129 SequenceWalkContext child = ctxRef;
131 child.inGrace =
true;
132 if (!self(grace.content(), child, self)) {
138 const auto tuplet = item.get<sequence::Tuplet>();
140 SequenceWalkContext child = ctxRef;
141 child.timeRatio = ctxRef.timeRatio * tuplet.ratio();
142 if (!self(tuplet.content(), child, self)) {
146 ctxRef.elapsedTime = child.elapsedTime;
149 ctxRef.elapsedTime += tuplet.outer() * ctxRef.timeRatio;
152 const auto tremolo = item.get<sequence::MultiNoteTremolo>();
153 const auto multiple = tremolo.outer().multiple();
154 if (allowChildren && multiple > 0) {
155 const auto startTime = ctxRef.elapsedTime;
156 const auto expectedDuration = tremolo.outer() * ctxRef.timeRatio;
157 SequenceWalkContext child = ctxRef;
159 if (!self(tremolo.content(), child, self)) {
162 const auto actualDuration = child.elapsedTime - startTime;
163 if (actualDuration != expectedDuration) {
165 child.elapsedTime = startTime + expectedDuration;
167 ctxRef.elapsedTime = child.elapsedTime;
169 ctxRef.elapsedTime += tremolo.outer() * ctxRef.timeRatio;
172 const auto space = item.get<sequence::Space>();
173 ctxRef.elapsedTime += space.duration() * ctxRef.timeRatio;
184 return walkImpl(sequence.content(), c, walkImpl);
202inline bool iterateSequenceEvents(Sequence sequence,
203 std::function<
bool(
const sequence::Event& event,
204 const FractionValue& startDuration,
205 const FractionValue& actualDuration)> iterator)
207 SequenceWalkHooks hooks;
208 hooks.
onEvent = [&](
const sequence::Event& event,
209 const FractionValue& startDuration,
210 const FractionValue& actualDuration,
211 SequenceWalkContext&) ->
bool
214 return iterator(event, startDuration, actualDuration);
217 return walkSequenceContent(sequence, hooks);
std::optional< T > getEnclosingElement() const
Returns the enclosing array element for this instance. If T is a type that can be nested (e....
Definition Implementations.cpp:69
Class for content arrays.
Definition BaseTypes.h:763
Base class for objects that are elements of content arrays.
Definition BaseTypes.h:685
A sequence of events and other items in this measure for a voice in a part.
Definition Sequence.h:695
Represents a single measure in a part in an MNX document. It contains the majority of the musical inf...
Definition Part.h:356
Represents a musical event within a sequence.
Definition Sequence.h:418
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition Sequence.h:483
Represents a page in a score.
Definition Sequence.h:673
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition Sequence.h:556
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition Sequence.h:607
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition Sequence.h:526
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition Sequence.h:665
Represents a detached arithmetic fraction with normalization.
Definition CommonClasses.h:59
Traversal context passed through walkSequenceContent.
Definition WalkSequenceContent.h:32
bool inGrace
true while descending through grace note content
Definition WalkSequenceContent.h:35
FractionValue timeRatio
accumulated tuplet time ratio.
Definition WalkSequenceContent.h:34
FractionValue elapsedTime
current elapsed time.
Definition WalkSequenceContent.h:33
Hook set for walkSequenceContent.
Definition WalkSequenceContent.h:48
std::function< bool(const sequence::Event &event, const FractionValue &startDuration, const FractionValue &actualDuration, SequenceWalkContext &ctx)> onEvent
Called for events with computed timing.
Definition WalkSequenceContent.h:57
std::function< void(const ContentObject &item, SequenceWalkContext &ctx)> onAfterItem
Called for every content object after recursion / time advancement.
Definition WalkSequenceContent.h:68
std::function< SequenceWalkControl(const ContentObject &item, SequenceWalkContext &ctx)> onItem
Called for every content object before recursion or time advancement.
Definition WalkSequenceContent.h:51
std::function< bool(const Sequence &sequence, const sequence::FullMeasureRest &fullMeasure, const FractionValue &startDuration, const FractionValue &actualDuration, SequenceWalkContext &ctx)> onFullMeasure
Called when the sequence is a full-measure rest.
Definition WalkSequenceContent.h:64