Tidy up
This commit is contained in:
parent
444cfc4a15
commit
d6ee17292b
45
mosaic.lua
45
mosaic.lua
|
|
@ -1,3 +1,12 @@
|
||||||
|
-- 1. CONFIGURATION
|
||||||
|
|
||||||
|
screen_width = 1000 -- FIXME
|
||||||
|
aspect_ratio = 1.5 -- a good default for dragonframe's typical 1620x1080 exports
|
||||||
|
window_titlebar_height = 39
|
||||||
|
|
||||||
|
|
||||||
|
-- 2. UTILITY FUNCTIONS
|
||||||
|
|
||||||
function exec(cmd)
|
function exec(cmd)
|
||||||
local handle = io.popen(cmd)
|
local handle = io.popen(cmd)
|
||||||
local result = handle:read("*a")
|
local result = handle:read("*a")
|
||||||
|
|
@ -14,12 +23,15 @@ function linesToTable(s)
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- 3. GET FILE LIST
|
||||||
|
-- TODO: get these some other way that's easier to use...
|
||||||
|
-- maybe args passed in from an Automater script?
|
||||||
|
|
||||||
local cd = exec("pwd")
|
local cd = exec("pwd")
|
||||||
-- print("| "..cd.." |")
|
|
||||||
|
|
||||||
local files = exec('stat -f "%N" *.mp4')
|
local files = exec('stat -f "%N" *.mp4')
|
||||||
-- print("| "..files.." |")
|
|
||||||
|
|
||||||
|
-- Create a table containing the complete path to every video:
|
||||||
local filetable = linesToTable(files)
|
local filetable = linesToTable(files)
|
||||||
for k, file in ipairs(filetable) do
|
for k, file in ipairs(filetable) do
|
||||||
print("k "..k.." v "..file)
|
print("k "..k.." v "..file)
|
||||||
|
|
@ -27,33 +39,43 @@ for k, file in ipairs(filetable) do
|
||||||
print(filetable[k])
|
print(filetable[k])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- 4. PREP FOR PLAYING
|
||||||
|
|
||||||
-- FIXME:
|
-- FIXME:
|
||||||
if #filetable <= 9 then
|
if #filetable <= 9 then
|
||||||
cols = 3
|
cols = 3
|
||||||
rows = 3
|
rows = 3
|
||||||
end
|
end
|
||||||
|
|
||||||
-- FIXME:
|
|
||||||
screen_width = 1000
|
|
||||||
aspect_ratio = 1.5
|
|
||||||
video_width = screen_width // cols -- "floor division" returns an integer
|
video_width = screen_width // cols -- "floor division" returns an integer
|
||||||
video_height = video_width // aspect_ratio
|
video_height = video_width // aspect_ratio
|
||||||
window_titlebar_height = 39
|
|
||||||
|
|
||||||
|
-- 5. PLAY + POSITION VIDEOS
|
||||||
|
|
||||||
|
-- We're going to loop through the list of videos.
|
||||||
|
-- For each video we will:
|
||||||
|
-- 1. use AppleScript to open it, playing on loop
|
||||||
|
-- 2. move it to the appropriate position
|
||||||
|
|
||||||
current_col = 1
|
current_col = 1
|
||||||
current_row = 1
|
current_row = 1
|
||||||
for _, file in ipairs(filetable) do
|
for _, file in ipairs(filetable) do
|
||||||
print("opening "..file)
|
print("opening "..file)
|
||||||
print(string.format(" col: %s, row: %s", current_col, current_row))
|
print(string.format(" col: %s, row: %s", current_col, current_row))
|
||||||
|
|
||||||
|
-- Calculate position / dimensions
|
||||||
local x1 = (current_col * video_width) - video_width
|
local x1 = (current_col * video_width) - video_width
|
||||||
local y1 = (current_row * video_height) - video_height + (current_row * window_titlebar_height) - window_titlebar_height
|
local y1 = (current_row * video_height) - video_height + (current_row * window_titlebar_height) - window_titlebar_height
|
||||||
local x2 = x1 + video_width
|
local x2 = x1 + video_width
|
||||||
local y2 = y1 + video_height
|
local y2 = y1 + video_height
|
||||||
local bounds = string.format("{%d, %d, %d, %d}", x1, y1, x2, y2)
|
local bounds = string.format("{%d, %d, %d, %d}", x1, y1, x2, y2)
|
||||||
|
|
||||||
print(" "..bounds)
|
print(" "..bounds)
|
||||||
print()
|
print()
|
||||||
-- os.execute(string.format("open -a 'QuickTime Player' %s", file))
|
|
||||||
|
|
||||||
|
-- Open the video + play it on loop
|
||||||
os.execute(
|
os.execute(
|
||||||
string.format(
|
string.format(
|
||||||
[[osascript -e '
|
[[osascript -e '
|
||||||
|
|
@ -67,9 +89,10 @@ for _, file in ipairs(filetable) do
|
||||||
end tell'
|
end tell'
|
||||||
]], file))
|
]], file))
|
||||||
|
|
||||||
local cmd = string.format("osascript -e 'tell application \"%s\" to set the bounds of the front window to %s'", "QuickTime Player", bounds)
|
-- Move it to the correct spot on the screen
|
||||||
print(cmd)
|
os.execute(string.format("osascript -e 'tell application \"%s\" to set the bounds of the front window to %s'", "QuickTime Player", bounds))
|
||||||
os.execute(cmd)
|
|
||||||
|
-- Update grid positioning for the next iteration
|
||||||
current_col = current_col + 1
|
current_col = current_col + 1
|
||||||
if current_col > cols then
|
if current_col > cols then
|
||||||
current_col = 1
|
current_col = 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue