Skip to content

Commit c711f1f

Browse files
author
Joash Chee
committed
Implementing Visualizer
1 parent 0d90f02 commit c711f1f

File tree

4 files changed

+151
-3
lines changed

4 files changed

+151
-3
lines changed

game/main.lua

Lines changed: 148 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ local ansi = require("lib.ansi")
3535
require("lib.Music")
3636
require("lib.WriteAiff")
3737

38+
local oneSecTimer = 0 -- used for the one second timer in update(dt)
39+
3840
local game = {}
3941

4042
-- game meta
@@ -44,6 +46,7 @@ game.edition = "(LÖVEJAM 2025 B-side)"
4446

4547
-- game flags
4648
game.dataEntry = false -- flag for when data is being captured from the keyboard
49+
game.vizAnimate = false -- to start / stop Visualizer animation
4750

4851
-- game variables
4952
game.statusBar = "" -- content string for status Bar at the bottom
@@ -56,6 +59,7 @@ game.selected = {
5659
["pattern"] = "a", -- current selected pattern : a..z
5760
["section"] = "about", -- "about", "melody", "harmony1", "harmony2", "bass", "rhythm", "pattern", "sequence"
5861
["noteNum"] = 0, -- 0 = nil, normal range 1..19 , middle = 8, when 1 y=30, when 19 y=12, =32-y
62+
["vizPage"] = 1, -- default to showing 1st page of visualizer
5963
}
6064
game.inputData = "" -- string to cache data captured from keyboard
6165
game.inputPrompt = "" -- prompt for data entry
@@ -108,6 +112,7 @@ end
108112
mkdir("smldata")
109113
mkdir("xtuidata")
110114
mkdir("mmldata")
115+
mkdir("vizdata")
111116
mkdir("music")
112117
mkdir("cache")
113118
mkdir("autosave")
@@ -788,7 +793,70 @@ SML.bassTrackString = {
788793
["z"] = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
789794
}
790795

796+
-- Visualizer data
797+
798+
-- full page is 80 x 12, + 1 column for \n = 81 x 12
799+
-- full table is double width, 81*2 x 12 = 162 x 12
800+
-- each coord stores {color} and string
801+
-- init each odd number coord with {color}
802+
-- init each even number coord with text string char
803+
-- fill 162 x 1..12 with "\n"
804+
--[[
805+
local printTable = {}
806+
-- {{1,1,1,1},"Hello",{1,1,0,1}," world!"}
807+
printTable[1] = {1,1,1,1}
808+
printTable[2] = "Hello"
809+
printTable[3] = {1,1,0,1}
810+
printTable[4] = " world!"
811+
812+
so 1 char needs a table[1..2]
813+
2 chars needs table[1..4]
814+
1 line of 81 chars needs table[1..162]
815+
12 lines of 81 chars needs table[1..1944]
816+
insert "\n" at 1*162, 2*162 .. 12*162
817+
]]
818+
local blankVizPage1 = {}
819+
local blankVizPage2 = {}
820+
local blankVizPage3 = {}
821+
local blankVizPage4 = {}
822+
823+
for i = 1,1944 do
824+
-- if i is odd, fill {0,0,0,0}
825+
-- if i is even, fill with "."
826+
if (i % 2 == 0) then
827+
-- even number
828+
blankVizPage1[i] = ""
829+
blankVizPage2[i] = ""
830+
blankVizPage3[i] = ""
831+
blankVizPage4[i] = ""
832+
else
833+
-- odd number
834+
blankVizPage1[i] = {i/1944,0,0,1}
835+
blankVizPage2[i] = {0,i/1944,0,1}
836+
blankVizPage3[i] = {0,0,i/1944,1}
837+
blankVizPage4[i] = {i/1944,i/1944,i/1944,1}
838+
end
839+
end
840+
for i = 1,12 do
841+
blankVizPage1[i*162] = "\n"
842+
blankVizPage2[i*162] = "\n"
843+
blankVizPage3[i*162] = "\n"
844+
blankVizPage4[i*162] = "\n"
845+
end
846+
847+
848+
local VIZ = {}
849+
850+
VIZ.about = {
851+
[1] = blankVizPage1,
852+
[2] = blankVizPage2,
853+
[3] = blankVizPage3,
854+
[4] = blankVizPage4,
855+
}
856+
791857

858+
VIZ.mouseX = 0
859+
VIZ.mouseY = 0
792860

793861
--[[
794862
Create a 32x1 pixel transparent-to-white gradient drawable image.
@@ -1351,6 +1419,8 @@ function love.load()
13511419
dividerMML = json.decode(love.filesystem.read("xtui/0-divider-mml.xtui"))
13521420
textWindowBlank = json.decode(love.filesystem.read("xtui/0-textwindow-blank.xtui"))
13531421
bassLeftPanel = json.decode(love.filesystem.read("xtui/0-bass-leftpanel.xtui"))
1422+
visualizerTop = json.decode(love.filesystem.read("xtui/0-visualizer-top.xtui"))
1423+
visualizerBottom = json.decode(love.filesystem.read("xtui/0-visualizer-bottom.xtui"))
13541424

13551425
melodyGroove = {
13561426
[1] = json.decode(love.filesystem.read("xtui/0-melody-groove1.xtui")),
@@ -1429,9 +1499,15 @@ function love.draw()
14291499
love.graphics.setColor(color.white)
14301500
love.graphics.print(instrumentsPanel,1280/2,0) -- instruments panel
14311501
love.graphics.print(functionKeys,1280/2,0) -- function keys help
1432-
love.graphics.print(dividerWalkthru,0,FONT_HEIGHT*30) -- divider : walkthru
1502+
1503+
-- love.graphics.print(dividerWalkthru,0,FONT_HEIGHT*30) -- divider : walkthru
1504+
-- love.graphics.print(textWindowBlank,0,FONT_HEIGHT*31) -- text window left : blank
1505+
1506+
-- new Visualizer section draw
1507+
love.graphics.print(visualizerTop,FONT_WIDTH*0,FONT_HEIGHT*30) -- divider : Visualizer top
1508+
love.graphics.print(visualizerBottom,FONT_WIDTH*0,FONT_HEIGHT*43) -- divider : Visualizer bottom
1509+
14331510
love.graphics.print(dividerMML,FONT_WIDTH*80,FONT_HEIGHT*30) -- divider : MML
1434-
love.graphics.print(textWindowBlank,0,FONT_HEIGHT*31) -- text window left : blank
14351511
love.graphics.print(textWindowBlank,FONT_WIDTH*80,FONT_HEIGHT*31) -- text window right : blank
14361512
-- draw meta data
14371513
love.graphics.setFont(monoFont)
@@ -1703,6 +1779,13 @@ function love.draw()
17031779

17041780

17051781
-- draw for Visualizer window
1782+
love.graphics.setColor(color.white)
1783+
love.graphics.print(VIZ.mouseX,FONT_WIDTH*68,FONT_HEIGHT*30)
1784+
love.graphics.print(VIZ.mouseY,FONT_WIDTH*75,FONT_HEIGHT*30)
1785+
if game.selected["section"]== "about" then
1786+
love.graphics.print(VIZ.about[game.selected["vizPage"]],FONT_WIDTH*0,FONT_HEIGHT*31)
1787+
end
1788+
17061789

17071790

17081791
-- draw for MML Preview window
@@ -1776,6 +1859,40 @@ end
17761859
function love.update(dt)
17771860
-- Your game update here
17781861

1862+
-- oneSecTimer code for simple frame animation
1863+
local currentFrame = 0 -- init currentFrame
1864+
if oneSecTimer < 1/4 then
1865+
currentFrame = 1
1866+
end
1867+
oneSecTimer = oneSecTimer + dt
1868+
if oneSecTimer > 1/4 and currentFrame == 1 then
1869+
currentFrame = 2
1870+
end
1871+
if oneSecTimer > 2/4 and currentFrame == 2 then
1872+
currentFrame = 3
1873+
end
1874+
if oneSecTimer > 3/4 and currentFrame == 3 then
1875+
currentFrame = 4
1876+
end
1877+
if oneSecTimer > 4/4 and currentFrame == 4 then
1878+
currentFrame = 1
1879+
oneSecTimer = 0
1880+
end
1881+
1882+
-- stuff that happens on 4fps
1883+
if currentFrame == 1 then
1884+
1885+
end
1886+
if currentFrame == 2 then
1887+
1888+
end
1889+
if currentFrame == 3 then
1890+
1891+
end
1892+
if currentFrame == 4 then
1893+
end
1894+
1895+
17791896
-- convert mouse position to ansi text coordinates
17801897
local mouse = {
17811898
x = math.floor(love.mouse.getX()/8)+1,
@@ -2160,6 +2277,8 @@ function love.keypressed(key, scancode, isrepeat)
21602277
end
21612278

21622279

2280+
2281+
21632282
function love.mousepressed( x, y, button, istouch, presses )
21642283

21652284
-- convert mouse position to ansi text coordinates
@@ -2168,6 +2287,33 @@ function love.mousepressed( x, y, button, istouch, presses )
21682287
y = math.floor(love.mouse.getY()/16)+1
21692288
}
21702289

2290+
-- Visualizer area detection
2291+
if (mouse.x >= 1 and mouse.x <= 80) and (mouse.y >= 32 and mouse.y <= 43)then
2292+
VIZ.mouseX = mouse.x
2293+
VIZ.mouseY = mouse.y-31
2294+
else
2295+
VIZ.mouseX = 0
2296+
VIZ.mouseY = 0
2297+
end
2298+
2299+
-- Visualizer Page changing
2300+
if mouse.x == 19 and mouse.y == 31 then
2301+
-- change to page 1
2302+
game.selected["vizPage"] = 1
2303+
end
2304+
if mouse.x == 23 and mouse.y == 31 then
2305+
-- change to page 2
2306+
game.selected["vizPage"] = 2
2307+
end
2308+
if mouse.x == 27 and mouse.y == 31 then
2309+
-- change to page 1
2310+
game.selected["vizPage"] = 3
2311+
end
2312+
if mouse.x == 31 and mouse.y == 31 then
2313+
-- change to page 1
2314+
game.selected["vizPage"] = 4
2315+
end
2316+
21712317
-- Melody Instrument
21722318
if mouse.x >= 13 and mouse.x <= 19 and mouse.y == 5 then
21732319
if mouse.x == 13 then -- A clicked

game/xtui/0-visualizer-bottom.xtui

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"c",[0.5,0.5,0.5,1],"o",[0.5,0.5,0.5,1],"l",[0.5,0.5,0.5,1],"o",[0.5,0.5,0.5,1],"r",[0.5,0.5,0.5,1],":",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"1",[0.5,0.5,0.5,1]," ",[0.5,0,0,1],"2",[0.5,0.5,0.5,1]," ",[0.5,0.5,0,1],"3",[0.5,0.5,0.5,1]," ",[0,0.5,0,1],"4",[0.5,0.5,0.5,1]," ",[0,0.5,0.5,1],"5",[0.5,0.5,0.5,1]," ",[0,0,0.5,1],"6",[0.5,0.5,0.5,1]," ",[0.5,0,0.5,1],"7",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"8",[0.5,0.5,0.5,1]," ",[1,0,0,1],"9",[0.5,0.5,0.5,1]," ",[1,1,0,1],"1",[1,1,0,1],"0",[0.5,0.5,0.5,1]," ",[0,1,0,1],"1",[0,1,0,1],"1",[0.5,0.5,0.5,1]," ",[0,1,1,1],"1",[0,1,1,1],"2",[0.5,0.5,0.5,1]," ",[0,0,1,1],"1",[0,0,1,1],"3",[0.5,0.5,0.5,1]," ",[1,0,1,1],"1",[1,0,1,1],"4",[0.5,0.5,0.5,1]," ",[1,1,1,1],"1",[1,1,1,1],"5",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"c",[0.5,0.5,0.5,1],"o",[0.5,0.5,0.5,1],"p",[0.5,0.5,0.5,1],"y",[0.5,0.5,0.5,1],":",[0.5,0.5,0.5,1]," ",[0,0.5,0.5,1],"1",[0.5,0.5,0.5,1]," ",[0,0.5,0.5,1],"2",[0.5,0.5,0.5,1]," ",[0,0.5,0.5,1],"3",[0.5,0.5,0.5,1]," ",[0,0.5,0.5,1],"4",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0,0.5,0.5,1],"@",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0.5,0.5,0.5,1]," ",[0,0.5,0.5,1],"s",[0,0.5,0.5,1],"a",[0,0.5,0.5,1],"v",[0,0.5,0.5,1],"e",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─\n"]

game/xtui/0-visualizer-top.xtui

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0.5,0.5,0.5,1]," ",[0,1,0,1],"V",[0,1,0,1],"i",[0,1,0,1],"s",[0,1,0,1],"u",[0,1,0,1],"a",[0,1,0,1],"l",[0,1,0,1],"i",[0,1,0,1],"z",[0,1,0,1],"e",[0,1,0,1],"r",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0,0.5,0.5,1],"1",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0,0.5,0.5,1],"2",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0,0.5,0.5,1],"3",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0,0.5,0.5,1],"4",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0.5,0.5,0.5,1]," ",[0,0.5,0.5,1],"c",[0,0.5,0.5,1],"l",[0,0.5,0.5,1],"e",[0,0.5,0.5,1],"a",[0,0.5,0.5,1],"r",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0.5,0.5,0.5,1]," ",[0,0.5,0.5,1],"p",[0,0.5,0.5,1],"l",[0,0.5,0.5,1],"a",[0,0.5,0.5,1],"y",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0.5,0.5,0.5,1]," ",[0,0.5,0.5,1],"s",[0,0.5,0.5,1],"t",[0,0.5,0.5,1],"o",[0,0.5,0.5,1],"p",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"─",[0.5,0.5,0.5,1],"[",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"l",[0.5,0.5,0.5,1],"n",[0.5,0.5,0.5,1],":",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"c",[0.5,0.5,0.5,1],"o",[0.5,0.5,0.5,1],"l",[0.5,0.5,0.5,1],":",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1]," ",[0.5,0.5,0.5,1],"]",[0.5,0.5,0.5,1],"─\n"]

resources/wireframe-visualizer.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ the middle of a piano. <5 ║ │ │ │ ║
2828
<3 ║ │ │ │ ║ │ │ │ ║ │ │ │ ║ │ │ │
2929
<2 ║ │ │ │ ║ │ │ │ ║ │ │ │ ║ │ │ │
3030
<1 ║ │ │ │ ║ │ │ │ ║ │ │ │ ║ │ │ │
31-
+-[ Visualizer ]-[1]-[2]-[3]-[4]-[ clear ]-[ play ]- [ stop ]--[ ln:99 col:99 ]-+-[MML Preview]----------------------------------------------------------------+
31+
+-[ Visualizer ]-[1]-[2]-[3]-[4]-[ clear ]-[ play ]-[ stop ]---[ ln:99 col:99 ]-+-[MML Preview]----------------------------------------------------------------+
3232
| | |
3333
| | t999 |
3434
| | |

0 commit comments

Comments
 (0)