Skip to content

Commit adddbd2

Browse files
committed
capture current wip code
1 parent 240e30c commit adddbd2

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

src/library/tie.lua

+57-1
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ default values. If an endpoint is already activated, that endpoint is not touche
596596
@ tie_mod (FCTieMod) the tie mods for the note, if any.
597597
@ for_pageview (bool) true if calculating for Page View, false for Scroll/Studio View
598598
@ [tie_prefs] (FCTiePrefs) use these tie prefs if supplied
599+
: (boolean) returns true if anything changed
599600
]]
600601
function tie.activate_endpoints(note, tie_mod, for_pageview, tie_prefs)
601602
if not tie_prefs then
@@ -610,6 +611,7 @@ function tie.activate_endpoints(note, tie_mod, for_pageview, tie_prefs)
610611
if lactivated and ractivated then
611612
tie_mod:LocalizeFromPreferences()
612613
end
614+
return lactivated or ractivated
613615
end
614616

615617
local calc_tie_length = function(note, tie_mod, for_pageview, direction, tie_prefs, tie_placement_prefs)
@@ -655,7 +657,7 @@ local calc_tie_length = function(note, tie_mod, for_pageview, direction, tie_pre
655657

656658
if tie_mod:IsStartTie() and (not end_note or cell_metrics_start.StaffSystem ~= cell_metrics_end.StaffSystem) then
657659
local next_cell_metrics = finale.FCCellMetrics()
658-
local next_metrics_loaded = next_cell_metrics:LoadAtCell(finale.FCCell(note.Entry.Measure + 1, note.entry.Staff))
660+
local next_metrics_loaded = next_cell_metrics:LoadAtCell(finale.FCCell(note.Entry.Measure + 1, note.Entry.Staff))
659661
if not next_metrics_loaded or cell_metrics_start.StaffSystem ~= cell_metrics_end.StaffSystem then
660662
-- note: a tie to an empty measure on the same system will get here, but
661663
-- currently we do not correctly calculate its span. To do so we would have to
@@ -730,4 +732,58 @@ function tie.calc_contour_index(note, tie_mod, for_pageview, direction, tie_pref
730732
return finale.TCONTOURIDX_MEDIUM
731733
end
732734

735+
local calc_inset_and_height = function(tie_prefs, tie_contour_prefs, length, contour_index, get_fixed_func, get_relative_func, get_height_func)
736+
-- This function is based on observed Finale behavior and may not precisely capture the exact same interpolated values.
737+
-- However, it appears that Finale interpolates from Short to Medium for lengths in that span and from Medium to Long
738+
-- for lengths in that span.
739+
local height = get_height_func(tie_contour_prefs, contour_index)
740+
local inset = tie_prefs.FixedInsetStyle and get_fixed_func(tie_contour_prefs, contour_index) or get_relative_func(tie_contour_prefs, contour_index)
741+
if tie_prefs.UseInterpolation and contour_index == finale.TCONTOURIDX_MEDIUM then
742+
local interpolation_length, interepolation_percent
743+
if length <= tie_contour_prefs:GetSpan(finale.TCONTOURIDX_MEDIUM) then
744+
interpolation_length = tie_contour_prefs:GetSpan(finale.TCONTOURIDX_MEDIUM) - tie_contour_prefs:GetSpan(finale.TCONTOURIDX_SHORT)
745+
interpolation_percent = (tie_contour_prefs:GetSpan(finale.TCONTOURIDX_MEDIUM) - length) / interpolation_length
746+
else
747+
interpolation_length = tie_contour_prefs:GetSpan(finale.TCONTOURIDX_LONG) - tie_contour_prefs:GetSpan(finale.TCONTOURIDX_MEDIUM)
748+
interpolation_percent = (tie_contour_prefs:GetSpan(finale.TCONTOURIDX_LONG) - length) / interpolation_length
749+
end
750+
height = height * interpolation_percent
751+
if not tie_prefs.FixedInsetStyle then
752+
inset = inset * interpolation_percent
753+
end
754+
end
755+
return inset, height
756+
end
757+
758+
--[[
759+
% activate_contour
760+
761+
Activates the contour fields of the input tie_mod and initializes them with their
762+
default values. If the contour field are already activated, nothing is changed.
763+
764+
@ note (FCNote) the note for which to return the tie direction.
765+
@ tie_mod (FCTieMod) the tie mods for the note, if any.
766+
@ for_pageview (bool) true if calculating for Page View, false for Scroll/Studio View
767+
@ [tie_prefs] (FCTiePrefs) use these tie prefs if supplied
768+
: (boolean) returns true if anything changed
769+
]]
770+
function tie.activate_contour(note, tie_mod, for_pageview, tie_contour_index, tie_prefs)
771+
if tie_mod:IsContourActive() then
772+
return false
773+
end
774+
if not tie_prefs then
775+
tie_prefs = finale.FCTiePrefs()
776+
tie_prefs:Load(0)
777+
end
778+
local direction = tie.calc_direction(note, tie_mod, tie_prefs)
779+
local tie_contour_index = tie.calc_contour_index(note, tie_mod, for_pageview, direction, tie_prefs)
780+
local tie_contour_prefs = tie_prefs:CreateTieContourPrefs()
781+
local left_height = tie_contour_prefs:GetLeftHeight(tie_contour_index)
782+
local left_inset = tie_prefs.FixedInsetStyle and tie_contour_prefs:GetLeftFixedInset(tie_contour_index) or tie_contour_prefs:GetLeftRawRelativeInset(tie_contour_index)
783+
local right_height = tie_contour_prefs:GetRightHeight(tie_contour_index)
784+
local right_inset = tie_prefs.FixedInsetStyle and tie_contour_prefs:GetRightFixedInset(tie_contour_index) or tie_contour_prefs:GetRightRawRelativeInset(tie_contour_index)
785+
tie_mod:ActivateContour(left_inset, left_height, right_inset, right_height, tie_prefs.FixedInsetStyle)
786+
return true
787+
end
788+
733789
return tie

0 commit comments

Comments
 (0)