Skip to content

Commit 240e30c

Browse files
committed
calc_contour_index code-complete
1 parent e63d962 commit 240e30c

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

src/library/tie.lua

+49-2
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ function tie.activate_endpoints(note, tie_mod, for_pageview, tie_prefs)
612612
end
613613
end
614614

615-
local calc_tie_length = function(note, tie_mod, for_pageview, direction, tie_prefs)
615+
local calc_tie_length = function(note, tie_mod, for_pageview, direction, tie_prefs, tie_placement_prefs)
616616
local cell_metrics_start = finale.FCCellMetrics()
617617
local entry_metrics_start = finale.FCEntryMetrics()
618618
cell_metrics_start:LoadAtEntry(note.Entry)
@@ -667,7 +667,7 @@ local calc_tie_length = function(note, tie_mod, for_pageview, direction, tie_pre
667667
end
668668
horz_end = horz_end / horz_stretch
669669
else
670-
local entry_metrics = tie_mod:IsStartTie() and cell_metrics_end or cell_metrics_start
670+
local entry_metrics = tie_mod:IsStartTie() and entry_metrics_end or entry_metrics_start
671671
local note_index = start_note.NoteIndex
672672
if end_note then
673673
-- if tie_mod:IsStartTie() is true, then end_note will never be nil here (see top if statement),
@@ -681,6 +681,53 @@ local calc_tie_length = function(note, tie_mod, for_pageview, direction, tie_pre
681681
horz_end = horz_end + (entry_metrics_start:GetNoteWidth(note.NoteIndex) * (1.0 - OUTER_NOTE_OFFSET_PCTG))
682682
end
683683
end
684+
685+
local start_offset = tie_mod.StartHorizontalPos
686+
if not tie_mod:IsStartPointActive() then
687+
start_offset = calc_prefs_offset_for_endpoint(note, tie_prefs, tie_placement_prefs, lplacement, false, not tie_mod:IsStartTie(), for_pageview)
688+
end
689+
local end_offset = tie_mod.EndHorizontalPos
690+
if not tie_mod:IsEndPointActive() then
691+
end_offset = calc_prefs_offset_for_endpoint(note, tie_prefs, tie_placement_prefs, lplacement, true, not tie_mod:IsStartTie(), for_pageview)
692+
end
693+
694+
local tie_length = horz_end - horz_start
695+
-- 'undo' page/sys/line % scaling to get absolute EVPUs.
696+
tie_length = tie_length / staff_scaling
697+
tie_length = tie_length + ((end_offset + incr_end) - (start_offset + incr_start))
698+
return math.floor(tie_length + 0.5)
699+
end
700+
701+
--[[
702+
% calc_contour_index
703+
704+
Calculates the current contour index of a tie based on context and FCTiePrefs.
705+
706+
@ note (FCNote) the note for which to return the tie direction.
707+
@ tie_mod (FCTieMod) the tie mods for the note, if any.
708+
@ for_pageview (bool) true if calculating for Page View, false for Scroll/Studio View
709+
@ direction (number) one of the TIEMOD_DIRECTION values or nil (if you don't know it yet)
710+
@ [tie_prefs] (FCTiePrefs) use these tie prefs if supplied
711+
: (number) CONTOUR_INDEXES value for tie
712+
]]
713+
function tie.calc_contour_index(note, tie_mod, for_pageview, direction, tie_prefs)
714+
if not tie_prefs then
715+
tie_prefs = finale.FCTiePrefs()
716+
tie_prefs:Load(0)
717+
end
718+
direction = direction and direction ~= finale.TIEMODDIR_AUTOMATIC and direction or tie.calc_direction(note, tie_mod, tie_prefs)
719+
local tie_placement_prefs = tie_prefs:CreateTiePlacementPrefs()
720+
if tie_prefs.UseTieEndStyle then
721+
return finale.TCONTOURIDX_TIEENDS
722+
end
723+
local tie_length = calc_tie_length(note, tie_mod, for_pageview, direction, tie_prefs, tie_placement_prefs)
724+
local tie_contour_prefs = tie_prefs:CreateTieContourPrefs()
725+
if tie_length >= tie_contour_prefs:GetSpan(finale.TCONTOURIDX_LONG) then
726+
return finale.TCONTOURIDX_LONG
727+
elseif tie_length <= tie_contour_prefs:GetSpan(finale.TCONTOURIDX_SHORT) then
728+
return finale.TCONTOURIDX_SHORT
729+
end
730+
return finale.TCONTOURIDX_MEDIUM
684731
end
685732

686733
return tie

0 commit comments

Comments
 (0)