-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.lua
More file actions
228 lines (189 loc) · 7.1 KB
/
render.lua
File metadata and controls
228 lines (189 loc) · 7.1 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
require( "globals" )
local controls = require( "controls" )
local skin = require( "skin" )
local settings = require( "settings" )
local render = {}
function render.stack( pass )
pass:draw( skin.mdl_amp, 0, 0, 0 )
if settings.session.show_eq then pass:draw( skin.mdl_eq, 0, 0, 0 ) end
if settings.session.show_pl then pass:draw( skin.mdl_pl, 0, 0, 0 ) end
pass:draw( skin.mdl_case, 0, 0, 0 )
if settings.session.show_eq or settings.session.show_pl then
pass:draw( skin.mdl_case, 0, -metrics.case_height - metrics.feet_height, 0 )
end
if settings.session.show_eq and settings.session.show_pl then
pass:draw( skin.mdl_case, 0, 2 * (0 - metrics.case_height) - (2 * metrics.feet_height), 0 )
end
-- color LEDs
if settings.session.show_eq then render.led( pass, "amp_led_eq" ) end
if settings.session.show_pl then render.led( pass, "amp_led_pl" ) end
if winamp_info.shuffle == 1 then render.led( pass, "amp_led_shuffle" ) end
if winamp_info.repeatval == 1 then render.led( pass, "amp_led_repeat" ) end
-- color sliders
render.tint_slider( pass, "amp_slider_vol", "amp_slider_vol_bg" )
render.tint_slider( pass, "amp_slider_pan", "amp_slider_pan_bg" )
-- small lcds
render.small_lcd( pass, "amp_lcd_khz_bg", winamp_info.track_khz )
render.small_lcd( pass, "amp_lcd_kbps_bg", winamp_info.track_kbps )
-- track lcd
render.track_lcd( pass )
-- mono/stereo labels
font:setPixelDensity( metrics.pixel_density_monostereo )
local col1, col2 = { 0.8, 0.8, 0.8 }, { 0, 1, 0 }
if winamp_info.mono_stereo == 1 then
col1, col2 = col2, col1
end
render.label( pass, "amp_label_mono", col1, "mono" )
render.label( pass, "amp_label_stereo", col2, "stereo" )
-- main lcd
render.main_lcd( pass )
end
function render.led( pass, led_id )
local parent = controls[ led_id ].parent
local x, y, z = controls[ led_id ].pos:unpack()
local px, py, pz = controls[ parent ].model:getNodePosition( parent )
local dx, dy, dz = controls[ led_id ].dim:unpack()
pass:setColor( 0, 1, 0 )
pass:plane( x, y, pz + 0.0026, dx, dy )
end
function render.tint_slider( pass, slider_id, bg_id )
local min = controls[ slider_id ].min
local max = controls[ slider_id ].max
local val, y, z = controls[ slider_id ].model:getNodePosition( slider_id )
local t = (val - min) / (max - min)
if slider_id == "amp_slider_pan" then
t = math.abs( 2 * t - 1 );
end
local R = t
local G = 1 - t
local B = 0
local x, y, z = controls[ bg_id ].pos:unpack()
local dx, dy, dz = controls[ bg_id ].dim:unpack()
pass:setColor( R, G, B, 1 )
pass:plane( x, y, z + 0.001, dx, dy )
pass:setColor( 1, 1, 1, 1 )
end
function render.set_environment( pass )
pass:setFaceCull( "back" )
pass:setBlendMode()
pass:skybox( skybox )
pass:setShader( shader )
pass:send( "cubemap", environmentMap )
pass:send( "sphericalHarmonics", sphericalHarmonics )
end
function render.small_lcd( pass, id, info )
font:setPixelDensity( metrics.pixel_density_small_lcd )
local x, y, z = controls[ id ].pos:unpack()
local dx, dy, dz = controls[ id ].dim:unpack()
local tex = controls[ id ].tex
local tex_pass = controls[ id ].pass
tex_pass:reset()
tex_pass:setProjection( 1, mat4():orthographic( tex_pass:getDimensions() ) )
tex_pass:setColor( 0, 1, 0, 1 )
local tdx, tdy = tex:getDimensions()
tex_pass:text( tostring( info ), tdx / 2, tdy / 2, 0, 1 )
pass:setMaterial( tex )
pass:plane( x, y, z + 0.001, dx, dy )
pass:setMaterial()
passes[ #passes + 1 ] = tex_pass
end
function render.track_lcd( pass )
local hwnd = find_window( "Winamp v1.x", nil )
local text_length = user32.GetWindowTextLengthA( hwnd )
local buffer_size = text_length + 1
local title_buffer = ffi.new( "char[?]", buffer_size )
user32.GetWindowTextA( hwnd, title_buffer, buffer_size )
local title_string = ffi.string( title_buffer, text_length )
local x, y, z = controls[ "amp_lcd_info_bg" ].pos:unpack()
local dx, dy, dz = controls[ "amp_lcd_info_bg" ].dim:unpack()
local tex = controls[ "amp_lcd_info_bg" ].tex
local tex_pass = controls[ "amp_lcd_info_bg" ].pass
tex_pass:reset()
tex_pass:setProjection( 1, mat4():orthographic( tex_pass:getDimensions() ) )
tex_pass:setColor( 0, 1, 0, 1 )
local tdx, tdy = tex:getDimensions()
font:setPixelDensity( metrics.pixel_density_title )
local w = font:getWidth( title_string )
if w > tdx then
if timer_scroll_title:get_elapsed() > 0.2 then
timer_scroll_title:reset()
if scroll_title_amount > w then
scroll_title_amount = 0
end
scroll_title_amount = scroll_title_amount + 30
end
tex_pass:text( title_string, (w / 2) - scroll_title_amount, tdy / 2, 0, 1 )
tex_pass:text( title_string, (w + (w / 2)) - scroll_title_amount, tdy / 2, 0, 1 )
else
scroll_title_amount = 0
tex_pass:text( title_string, (w / 2) - scroll_title_amount, tdy / 2, 0, 1 )
end
pass:setMaterial( tex )
pass:plane( x, y, z + 0.001, dx, dy )
pass:setMaterial()
passes[ #passes + 1 ] = tex_pass
end
function render.main_lcd( pass )
-- font:setPixelDensity( 1 )
local x, y, z = controls[ "amp_lcd_main_bg" ].pos:unpack()
local dx, dy, dz = controls[ "amp_lcd_main_bg" ].dim:unpack()
local tex = controls[ "amp_lcd_main_bg" ].tex
local tex_pass = controls[ "amp_lcd_main_bg" ].pass
tex_pass:reset()
tex_pass:setSampler( "nearest" )
tex_pass:setProjection( 1, mat4():orthographic( tex_pass:getDimensions() ) )
tex_pass:setColor( 0, 1, 0, 1 )
tex_pass:plane( 250, 30, 0, 12, 4 )
tex_pass:plane( 250, 46, 0, 12, 4 )
-- playing = 1, paused = 3, stopped = 0
if winamp_info.playing_state == 0 then
tex_pass:plane( 78, 38, 0, 20, 20 )
pass:draw( tex, x, y, z + 0.001, dx ) -- NOTE wtf is happening here? z is way off
elseif winamp_info.playing_state == 3 then
tex_pass:plane( 66, 38, 0, 12, 20 )
tex_pass:plane( 90, 38, 0, 12, 20 )
pass:draw( tex, x, y, z + 0.001, dx )
elseif winamp_info.playing_state == 1 then
tex_pass:plane( 58, 26, 0, 12, 12 )
tex_pass:polygon( 78, 21, 0, 95, 38, 0, 78, 55, 0 )
tex_pass:setColor( 0.31, 0.06, 0, 1 )
tex_pass:plane( 58, 50, 0, 12, 12 )
pass:draw( tex, x, y, z + 0.001, dx )
end
if winamp_info.playing_state == 1 or winamp_info.playing_state == 3 then
-- render bars and peaks
tex_pass:setColor( 1, 1, 1, 1 )
local xoff = 58
local yoff = 0
local peaks_y = 0
for i = 1, 19 do
local val = skin.sa_bars.data[ i ]
tex_pass:setMaterial( skin.sa_bars[ val ] )
tex_pass:plane( xoff, 116, 0, 12, 56 )
peaks_y = skin.sa_bars.peaks[ i ].y
yoff = map_range( 1, 14, 144, 88, peaks_y )
tex_pass:setMaterial()
tex_pass:setColor( 0.59, 0.59, 0.59, 1 )
tex_pass:plane( xoff, yoff, 0, 12, 4 )
xoff = xoff + 16
end
tex_pass:setMaterial()
end
passes[ #passes + 1 ] = tex_pass
end
function render.label( pass, id, col, str )
local x, y, z = controls[ id ].pos:unpack()
local dx, dy, dz = controls[ id ].dim:unpack()
local tex = controls[ id ].tex
local tex_pass = controls[ id ].pass
tex_pass:reset()
tex_pass:setProjection( 1, mat4():orthographic( tex_pass:getDimensions() ) )
tex_pass:setColor( col )
local tdx, tdy = tex:getDimensions()
tex_pass:text( str, tdx / 2, tdy / 2, 0, 1 )
pass:setBlendMode( "alpha" )
pass:setShader()
pass:draw( tex, x, y, z + 0.001, dx )
passes[ #passes + 1 ] = tex_pass
end
return render