MUSX Document Model
Loading...
Searching...
No Matches
Tie.h
1/*
2 * Copyright (C) 2025, Robert Patterson
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22#pragma once
23
24#include <optional>
25#include <utility>
26
27#include "musx/dom/Details.h"
28#include "musx/dom/EnumClasses.h"
29#include "musx/dom/Options.h"
30
31namespace musx {
32namespace dom {
33class NoteInfoPtr;
34}
35
36namespace util {
37
40class Tie
41{
42public:
45 enum class EndPointKind
46 {
47 Notehead,
50 };
51
63
70
78
86
93
99 [[nodiscard]]
100 static dom::CurveContourDirection calcDefaultDirection(const dom::NoteInfoPtr& noteInfo, bool forTieEnd = false);
101
107 [[nodiscard]]
108 static dom::CurveContourDirection calcEffectiveDirection(const dom::NoteInfoPtr& noteInfo, bool forTieEnd = false);
109
114 [[nodiscard]]
115 static std::optional<std::pair<dom::TieConnectStyleType, dom::TieConnectStyleType>> calcConnectStyleTypes(
116 const dom::NoteInfoPtr& noteInfo, bool forTieEnd);
117
121 [[nodiscard]]
123
130 [[nodiscard]]
131 static std::optional<dom::details::TieAlterBase::ConnectionType> calcConnectionType(
132 const dom::NoteInfoPtr& noteInfo, bool forTieEnd, bool forEndPoint, bool forPageView = true);
133
141 [[nodiscard]]
142 static dom::options::TieOptions::ConnectStyle calcEndpointOffsets(const dom::NoteInfoPtr& noteInfo, bool forTieEnd, bool forEndPoint,
143 std::optional<dom::CurveContourDirection> direction = std::nullopt, bool forPageView = true);
144
152 [[nodiscard]]
153 static std::optional<ContourResult> calcContourStyleType(
154 const dom::NoteInfoPtr& noteInfo, const ContourGeometry& geometry, bool forTieEnd = false);
155
165 [[nodiscard]]
166 static std::optional<ContourControlPoints> calcDefaultContourControlPoints(
168
179 [[nodiscard]]
180 static std::optional<ContourControlPoints> calcEffectiveContourControlPoints(
181 const dom::NoteInfoPtr& noteInfo, bool forTieEnd, dom::options::TieOptions::ControlStyleType styleType, dom::Evpu length);
182
188 [[nodiscard]]
189 static std::optional<ContourMetrics> calcEffectiveContourMetrics(
190 const dom::NoteInfoPtr& noteInfo, const ContourGeometry& geometry, bool forTieEnd = false);
191
192private:
205 [[nodiscard]]
206 static std::optional<dom::TieConnectStyleType> calcConnectStyleTypeAtEndPoint(
207 const dom::NoteInfoPtr& noteInfo, bool forTieEnd, dom::CurveContourDirection direction, bool stemUp,
208 const dom::NoteInfoPtr& tieAlterContext, bool forEndPoint,
209 std::optional<size_t> noteIndexOverride = std::nullopt, std::optional<size_t> noteCountOverride = std::nullopt,
210 std::optional<bool> upStemSecondOverride = std::nullopt, std::optional<bool> downStemSecondOverride = std::nullopt);
211};
212
213} // namespace util
214} // namespace musx
Wraps an EntryInfo instance and a note index.
Definition Entries.h:1553
InsetStyle
Enumeration for inset styles.
Definition Options.h:1624
ControlStyleType
Enumeration for tie control style types.
Definition Options.h:1634
Static class containing utilites for ties.
Definition Tie.h:41
static std::optional< ContourControlPoints > calcEffectiveContourControlPoints(const dom::NoteInfoPtr &noteInfo, bool forTieEnd, dom::options::TieOptions::ControlStyleType styleType, dom::Evpu length)
Calculates effective contour control points (inset/height) for a tie.
Definition Tie.cpp:976
static std::optional< std::pair< dom::TieConnectStyleType, dom::TieConnectStyleType > > calcConnectStyleTypes(const dom::NoteInfoPtr &noteInfo, bool forTieEnd)
Calculates the connect style types for both endpoints of a tie.
Definition Tie.cpp:556
EndPointKind
Classifies what the tie endpoint attaches to for contour-length calculations.
Definition Tie.h:46
@ Notehead
Endpoint attaches to a notehead.
@ MeasureBoundary
Endpoint attaches to a measure boundary (not a notehead).
@ SystemBoundary
Endpoint attaches to a system boundary (start/end of system).
static dom::CurveContourDirection calcEffectiveDirection(const dom::NoteInfoPtr &noteInfo, bool forTieEnd=false)
Calculates the effective tie direction taking into account overrides and special rules.
Definition Tie.cpp:459
static dom::options::TieOptions::ConnectStyle calcEndpointOffsets(const dom::NoteInfoPtr &noteInfo, bool forTieEnd, bool forEndPoint, std::optional< dom::CurveContourDirection > direction=std::nullopt, bool forPageView=true)
Resolves endpoint offsets for a tie endpoint from default policy and tie-alter overrides.
Definition Tie.cpp:783
static std::optional< dom::details::TieAlterBase::ConnectionType > calcConnectionType(const dom::NoteInfoPtr &noteInfo, bool forTieEnd, bool forEndPoint, bool forPageView=true)
Calculates the default connection type for a tie endpoint.
Definition Tie.cpp:692
static bool calcIsOuterConnectStyle(dom::TieConnectStyleType type)
Returns true if the connect style is an outer placement.
Definition Tie.cpp:687
static dom::CurveContourDirection calcDefaultDirection(const dom::NoteInfoPtr &noteInfo, bool forTieEnd=false)
Calculates the default tie direction for the specified note.
Definition Tie.cpp:334
static std::optional< ContourResult > calcContourStyleType(const dom::NoteInfoPtr &noteInfo, const ContourGeometry &geometry, bool forTieEnd=false)
Calculates the tie control style span using caller-supplied horizontal geometry.
Definition Tie.cpp:819
static std::optional< ContourControlPoints > calcDefaultContourControlPoints(const dom::NoteInfoPtr &noteInfo, dom::options::TieOptions::ControlStyleType styleType, dom::Evpu length)
Calculates default contour control points (inset/height) for a given control style.
Definition Tie.cpp:902
static std::optional< ContourMetrics > calcEffectiveContourMetrics(const dom::NoteInfoPtr &noteInfo, const ContourGeometry &geometry, bool forTieEnd=false)
Calculates span classification and control points in one call.
Definition Tie.cpp:1006
CurveContourDirection
Curve contour direction for ties and slurs.
Definition EnumClasses.h:62
int32_t Efix
EFIX value (64 per EVPU, 64*288=18432 per inch)
Definition Fundamentals.h:60
TieConnectStyleType
Enumeration for tie connect style types.
Definition EnumClasses.h:176
int32_t Evpu
EVPU value (288 per inch)
Definition Fundamentals.h:57
double EvpuFloat
EVPU fractional value (288.0 per inch)
Definition Fundamentals.h:58
object model for musx file (enigmaxml)
Definition BaseClasses.h:36
Struct for tie connect style.
Definition Options.h:1669
Control point parameters for a tie contour.
Definition Tie.h:73
dom::Efix insetRatio
Inset ratio (percent-based inset).
Definition Tie.h:74
dom::Evpu height
Height of the control point in EVPU.
Definition Tie.h:75
dom::Evpu insetFixed
Fixed inset in EVPU (used when inset style is Fixed).
Definition Tie.h:76
Control points for a tie contour (left/right endpoints).
Definition Tie.h:81
ContourControlPoint left
Left control point.
Definition Tie.h:82
dom::options::TieOptions::InsetStyle insetStyle
Which inset value is active.
Definition Tie.h:84
ContourControlPoint right
Right control point.
Definition Tie.h:83
Caller-supplied horizontal geometry used for contour span classification.
Definition Tie.h:54
dom::EvpuFloat startNoteheadWidth
Width of the start notehead in EVPU.
Definition Tie.h:56
dom::EvpuFloat startToEndLeft
End-left X minus start-left X in EVPU.
Definition Tie.h:55
EndPointKind startPointKind
Attachment kind for the start endpoint.
Definition Tie.h:60
EndPointKind endPointKind
Attachment kind for the end endpoint.
Definition Tie.h:61
dom::EvpuFloat endAdjustment
Caller-supplied end endpoint adjustment in EVPU (for engine-specific spacing/system rules).
Definition Tie.h:59
std::optional< dom::EvpuFloat > endNoteheadWidth
Width of the end notehead in EVPU; defaults to startNoteheadWidth when omitted.
Definition Tie.h:57
dom::EvpuFloat startAdjustment
Caller-supplied start endpoint adjustment in EVPU (for engine-specific spacing/system rules).
Definition Tie.h:58
Combined contour metrics for tie geometry and control points.
Definition Tie.h:89
ContourResult contour
Span type and computed length.
Definition Tie.h:90
ContourControlPoints controlPoints
Control points for the selected span type.
Definition Tie.h:91
Result of contour style classification.
Definition Tie.h:66
dom::options::TieOptions::ControlStyleType styleType
Selected control style span type.
Definition Tie.h:67
dom::Evpu length
Computed tie length in EVPU used for span classification.
Definition Tie.h:68