OK - multiple points:
a) I think I found a non-deterministic bug in either "nwcdraw.barSegment" or our ConnectBarLines code: The upper segment must be drawn with nwcdraw.barSegment(barType,y+yPosTop,y+4), not with nwcdraw.barSegment(barType,y+4,y+yPosTop). In my somewhat extended experiments, the latter code at some point stopped drawing anything; and the documentation says "Y1 and Y2 determine the upper and lower end points for the bar segment" - it does not specify that happens if Y1 is below Y2. Still, it worked up to now ... so something might be fishy in nwcdraw ...
b) I have a horrendous piece of code that searches backwards to matching Boundary objects to get the current upper and lower heights (see below; attached is also my test score). I have no idea why this actually searches to the beginning of the whole score - I copied it from Mike's NWC's "BarCounter", which can do this. In my much simpler first attempt, :find only searched in the printed part of the staff, i.e., not far enough - I would be happy if someone could (somewhere else?) explain to me why my "find('prior', ...) stopped much sooner, and what the code does ...
... but it seems that my code does not find what it should. I'll try to find out what goes on there (but tomorrow morning, we will be on our way back from the Bretagne to Germany, so it might take two or three days ...).
c) What do we want?
1) should there still be a "Standard" functionality that works only on the immediately following bar?
2) should the object draw something in edit mode (right now, my modification is totally silent ... but one could draw e.g. "BrokenSingle" bars everywhere to indicated what would happen at the right end of each printed staff?)
and finally
d) is this the right place to discuss this sort of (very) experimental programming? - or should I continue this somewhere else on the forum or in private messages?
Edit: Lloyd & me will continue this offline somewhat ... when something working turns up, we'll be back ...
H.M.
Current experimental code of "ConnectBarLines" that tries to heed Boundary heights - but does not ...
-- Version 0.1
--[[--------------------------------------------------------------------------
This plugin will connect barlines with the staff below. You must specify if the current staff is Upper, Middle or Lower staff in order to draw connections correctly.
--]]--------------------------------------------------------------------------
local userObjTypeName = ...
local nextBar = nwc.drawpos.new()
local prevBoundary = nwc.drawpos.new()
local drawpos = nwcdraw.user
local drawidx1 = nwc.drawpos
local objidx = nwc.ntnidx
local searchidx = objidx.new()
local c = nwcdraw
local object_spec = {
{ id='System', label='Staff Location', type='enum', default='Top Staff', list={'Top Staff', 'Middle Staff', 'Bottom Staff'}},
}
local function do_create(t)
t.Class = 'StaffSig'
end
local function do_draw(t)
local w = nwc.toolbox.drawStaffSigLabel('BarLines3')
if not nwcdraw.isDrawing() then return w end
-- if nwcdraw.getTarget() ~= 'print' then return end
if drawpos:isHidden() then return end
local yPosTop
local yPosBottom
local setTopIfNil = function(value)
if not yPosTop then
yPosTop = value
end
end
local setBottomIfNil = function(value)
if not yPosBottom then
yPosBottom = value
end
end
local drawSegment = function(x,y,bType)
if t.System == 'Top Staff' then
nwcdraw.moveTo(x,y)
nwcdraw.barSegment(bType,y-4,y-yPosBottom)
elseif t.System == 'Middle Staff' then
nwcdraw.moveTo(x,y)
nwcdraw.barSegment(bType,y+yPosTop,y+4)
nwcdraw.moveTo(x,y)
nwcdraw.barSegment(bType,y-4,y-yPosBottom)
elseif t.System == 'Bottom Staff' then
nwcdraw.moveTo(x,y)
nwcdraw.barSegment(bType,y+yPosTop,y+4)
end
end
--- I do not understand the following (copied from BarCounter)
local me = c.user
local me_autoins = me:isAutoInsert()
drawidx1:reset()
-- don't do anything when hidden
if me:isHidden() then return end
if me_autoins then
drawidx1:find('first')
else
drawidx1:find('prior','bar')
end
if me_autoins and drawidx1:find('first','noteOrRest') then
if drawidx1:isAutoInsert() and (drawidx1:objType() == 'RestMultiBar') then
pendingBar = drawidx1:barCounter()
end
else
drawidx1:reset()
end
-- start from the first note and count bars backwards
objidx:reset()
searchidx:find(drawidx1)
while searchidx:find('prior') and (searchidx > objidx) do
--- end "I do not understand"
if searchidx:objType() == 'Boundary' and searchidx:objProp('Style') == 'NewSize' then
setTopIfNil(searchidx:objProp('Upper'))
setBottomIfNil(searchidx:objProp('Lower'))
nwc.debug("c2", yPosTop, yPosBottom)
elseif searchidx:objType() == 'Boundary' and searchidx:objProp('Style') == 'Reset' then
setTopIfNil(nwcdraw.getStaffProp('BoundaryTop'))
setBottomIfNil(nwcdraw.getStaffProp('BoundaryBottom'))
nwc.debug("c3", yPosTop, yPosBottom)
end
end
setTopIfNil(nwcdraw.getStaffProp('BoundaryTop'))
setBottomIfNil(nwcdraw.getStaffProp('BoundaryBottom'))
nwc.debug("c5", yPosTop, yPosBottom)
nextBar:reset()
local found = nextBar:find('last', 'bar')
if found then
found = nextBar:find('next', 'bar')
end
if found then
local x,y = nextBar:xyAnchor()
local barType = nextBar:objProp('Style')
drawSegment(x, y, barType)
end
nextBar:reset()
while nextBar:find('next', 'bar') do
local x,y = nextBar:xyAnchor()
drawSegment(x, y, 'BrokenDouble')
end
end
return {
spec = object_spec,
create = do_create,
width = do_draw,
draw = do_draw,
}