-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnwcuser.lua
98 lines (79 loc) · 3.15 KB
/
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
-- Version 0.0
--[[--------------------------------------------------------------------------
This is a new plugin object. This comnment will appear each time a user
selects this object type for insertion into the staff.
@field1
This is the help text for field1.
@field2
This is the help text for field2.
@field3
This is the help text for field3.
--]]--------------------------------------------------------------------------
-- our object type is passed into the script
local userObjTypeName = ...
-- things work best when all fields supported by the plugin are published in a
-- spec table
local object_spec = {
{ id='field1', label='Field 1', type='text', default='' },
{ id='field2', label='Field 2', type='enum', default='value1', list={'value1','value2','value3'} },
{ id='field3', label='Field 3', type='int', default=0, min=0, max=20, step=2 },
}
------------------------------------------------------------------------------
-- the 'create' method is used to establish the object properties that will
-- control our plugin object
local function do_create(t)
t.field1 = 'Hello'
end
------------------------------------------------------------------------------
-- the 'audit' method is called whenever the object is first opened or pasted
-- into the editor
local function do_audit(t)
end
------------------------------------------------------------------------------
-- the 'spin' method is called whenever the user applied the +/- keys to our
-- object from within the editor
local function do_spin(t,d)
t.field3 = t.field3 + d
-- assigning this to itself enforces the spec table min and max
t.field3 = t.field3
end
------------------------------------------------------------------------------
-- the 'transpose' method is called whenever the user runs the Transpose Staff
-- command from within the editor
local function do_transpose(t,semitones,notepos,updpatch)
end
------------------------------------------------------------------------------
-- the 'play' method is called whenever our notatation is compiled into a
-- midi performance
local function do_play(t)
end
------------------------------------------------------------------------------
-- the 'width' and 'draw' methods are combined here, and are used in the
-- formatting and display of our object on the NWC staff
--
local function do_draw(t)
nwcdraw.setFontClass('StaffBold')
local w,h,descent = nwcdraw.calcTextSize(userObjTypeName)
if not nwcdraw.isDrawing() then
-- the user can always add spacers to control width and placement, but one
-- is provided here for demonstration purposes...a dedicated width method
-- could also be created for an object (it need not be done in 'draw')
return w
end
nwcdraw.alignText('baseline','left')
nwcdraw.moveTo(-nwcdraw.width())
nwcdraw.text(userObjTypeName)
end
------------------------------------------------------------------------------
-- all object plug-ins must return the methods that they support in a
-- standard method table; uncomment any additional methods as needed
return {
spec = object_spec,
create = do_create,
-- audit = do_audit,
spin = do_spin,
-- transpose = do_transpose,
-- play = do_play,
width = do_draw,
draw = do_draw
}