-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabFret.nw.nwcuser.lua
executable file
·130 lines (102 loc) · 3.53 KB
/
TabFret.nw.nwcuser.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
-- Version 1.21
--[[--------------------------------------------------------------------------
TabFret.nw <http://nwsw.net/-f9191>
TabFret is used to add a guitar fret numbers to a TabStaff. You should add
a TabStaff object first, prior to using this object.
@S1
This is the fret assignment for string #1. Leave it blank if it should not be played.
@S2
This is the fret assignment for string #2. Leave it blank if it should not be played.
@S3
This is the fret assignment for string #3. Leave it blank if it should not be played.
@S4
This is the fret assignment for string #4. Leave it blank if it should not be played.
@S5
This is the fret assignment for string #5. Leave it blank if it should not be played.
@S6
This is the fret assignment for string #6. Leave it blank if it should not be played.
--]]--------------------------------------------------------------------------
-- our object type is passed into the script
local userObjTypeName = ...
local idTabStaff = 'TabStaff.nw'
local obj_spec = {}
local tabStringList = {'S1','S2','S3','S4','S5','S6'}
for i,s in ipairs(tabStringList) do
table.insert(obj_spec,{id=s, label='Fret for String &'..i, type='text', default=''})
end
local scanIdx = nwc.ntnidx.new()
------------------------------------------------------------------------------
local function obj_audit(t)
if scanIdx:find('prior','user',idTabStaff) then
t.Pos = scanIdx:staffPos()
end
end
------------------------------------------------------------------------------
local function obj_create(t)
obj_audit(t)
end
------------------------------------------------------------------------------
local function obj_spin(t,d)
end
------------------------------------------------------------------------------
local function obj_transpose(t,semitones,notepos,updpatch)
end
------------------------------------------------------------------------------
local function obj_play(t)
end
------------------------------------------------------------------------------
local noteDrawIdx = nwc.drawpos.new()
local tabStaffIdx = nwc.drawpos.new()
--
local function ForcesPreserveWidth(idx)
local ot = idx:objType()
if (ot == 'User') and (idx:userType() == userObjTypeName) then return true end
if (ot == 'Bar') then return true end
return false
end
local function obj_draw(t)
if not tabStaffIdx:find('first','user',idTabStaff) then return end
local opaqueMode = tabStaffIdx:userProp('Opaque')
local numStrings = tabStaffIdx:userProp('Strings')
local h = tabStaffIdx:userProp('Size')*3
local total_h = h*(numStrings-1)
local c = nwcdraw
c.setFont('Times',(opaqueMode and 1.3 or 1.4)*h,'r')
local w = c.calcTextSize("8")
local preserveWidth = false
scanIdx:reset()
if scanIdx:find('next','note') then
repeat scanIdx:find('prior') until ForcesPreserveWidth(scanIdx)
if scanIdx:indexOffset() > 0 then
preserveWidth = true
end
else
preserveWidth = true
end
if not c.isDrawing() then
return preserveWidth and w*2 or 0
end
noteDrawIdx:reset()
noteDrawIdx:find('next','note')
local x = preserveWidth and -c.user:width()/2 or noteDrawIdx:xyTimeslot()+w/2
local _,y = tabStaffIdx:xyAnchor()
c.alignText('middle','center')
c.opaqueMode(opaqueMode)
for i,s in ipairs(tabStringList) do
local s_v = string.match(t[s],'%(*%d+%)*') or ''
if s_v ~= '' then
local y1 = y + total_h - (h*(i-1))
c.moveTo(x,y1)
c.text(s_v)
end
end
end
------------------------------------------------------------------------------
return {
spec = obj_spec,
create = obj_create,
audit = obj_audit,
spin = obj_spin,
width = obj_draw,
draw = obj_draw,
}