-- Version 0.6 --[[----------------------------------------------------------------------------------------- CueStaffTimeSig.test (0.6) @TimeSigBeats Show time signature at start of cue staff if > 0; default 0 (i.e., no time signature is shown). @TimeSigBeatValue Lower value of time signature; default 4. @LeftSpace Space to the left of the time signature @RightSpace Space to the right of the time signature --]]----------------------------------------------------------------------------------------- local userObjTypeName = ... local cueStaffTypeName = 'CueStaff.hmm' local _spec = { {id='TimeSigBeats', label='&Time sign.', type='int', default=4, min=1, max=99, width=7 }, {id='TimeSigBeatValue', label='', type='enum', default='4', list={'1','2','4','8','16','32'}, separator=' ' }, {id='LeftSpace', label='Space at &left...', type='float', default=0, min=0, max=30, step=0.1 }, {id='RightSpace', label='...and &right', type='float', default=1, min=0, max=30, step=0.1, separator=' ' }, } local function _create(t) t.Class = 'Standard' t.Pos = 0 end local function timeSigWidth(t) local beatWidth = nwcdraw.calcTextSize('' .. t.TimeSigBeats) local beatValueWidth = nwcdraw.calcTextSize(t.TimeSigBeatValue) return t.LeftSpace + math.max(beatWidth, beatValueWidth) * 0.85 + t.RightSpace end local function getScale(cueStaff) return cueStaff:userProp('NoStaffScaling') and 1 or (cueStaff:userProp('Scaling') or 200) / 100, (cueStaff:userProp('Scaling') or 200) / 100 end local widthCueStaff = nwc.ntnidx.new() local function _width(t) widthCueStaff:find('prior', 'user', cueStaffTypeName) local staffScale, itemScale = getScale(widthCueStaff) local fontsize = nwcdraw.getFontSize() nwcdraw.setFontClass('StaffSymbols') nwcdraw.setFontSize(fontsize * 2 * staffScale) return timeSigWidth(t) end local drawCueStaff = nwc.ntnidx.new() local drawItem = nwcdraw.user.new() local priorItem = nwcdraw.user.new() local nextItem = nwcdraw.user.new() local function drawTimeSig(t, x, staffScale) nwcdraw.alignText('baseline', 'center') nwcdraw.moveTo(x, 0) nwcdraw.text(t.TimeSigBeats) nwcdraw.moveTo(x, -4 * staffScale) nwcdraw.text(t.TimeSigBeatValue) end local function _draw(t) drawCueStaff:find('prior', 'user', cueStaffTypeName) local staffScale, itemScale = getScale(drawCueStaff) -- set font size for drawing local fontsize = nwcdraw.getFontSize() nwcdraw.setFontClass('StaffSymbols') nwcdraw.setFontSize(fontsize * 2 * staffScale) if drawItem:isAutoInsert() then local xLeft = drawItem:xyAnchor() drawTimeSig(t, xLeft + timeSigWidth(t) / 2, staffScale) else nextItem:find('next') priorItem:find('prior') local xMid = (priorItem:xyRight() + nextItem:xyAnchor()) / 2 drawTimeSig(t, xMid, staffScale) end end return { spec = _spec, create = _create, draw = _draw, width = _width, }