Skip to content

Instantly share code, notes, and snippets.

@Jip-Hop
Created July 10, 2019 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jip-Hop/75fe128091e82938836ab565066f2a27 to your computer and use it in GitHub Desktop.
Save Jip-Hop/75fe128091e82938836ab565066f2a27 to your computer and use it in GitHub Desktop.
-- PLAY key menu
-- Use PLAY button to toggle RAW video preferences
require("config")
play_key_timestamp = nil
currently_selected_preset = nil
last_run_preset = nil
before_last_run_preset = nil
-- TODO: find a better way to set resolution in "RAW video" submenu
-- Currently the mlv_rec module isn't Lua friendly
-- There's no way to use menu.set to choose a specific resolution from the dropdown
-- I can basically only follow the approach in Danne's cine.lua script,
-- which makes a choice from the dropdown by simulating multiple key presses
-- The good thing is that, when the resolution is set to it's max, it will default
-- to the highest possible resolution in all modes.
-- Alternatively, when the resolution has never been chosen,
-- it also defaults to the highest possible resolution.
-- One way would be to clear the related settings in mlv_lite.cfg and reboot the camera
-- But that's not quick either.
start_playback_mode = function()
-- Quickly get out of here
key.press(KEY.MENU)
-- Needs to run after MENU key has been handled
task.create(
function()
camera.gui.play = true
end
)
-- TODO set preset_menu_playback_key as the default selected key when opening the preset_menu next time
end
preset_menu_playback_key =
menu.new {
parent = "Presets",
name = "Open Playback menu",
select = start_playback_mode
}
-- close_menu = function()
-- -- It's a bit slow, but most reliable way to close ML menu
-- -- Simulating MENU key presses didn't work this time
-- -- Closing it in a background task can cause conflicts
-- -- It really needs to be closed before we call lv.pause()
-- menu.close();
-- end
refresh_live_view = function()
-- With lv.stop() we exit live view immediately, so we don't need to first close ML menu (which is slow)
-- Also the regs will be refreshed when we call lv.start() again
-- For cameras other than EOS M maybe lv.pause() would work better, but then we first need to close ML menu
-- In that case uncomment close_menu() in do_for_each_preset()
lv.stop()
lv.start()
task.create(
function()
-- Wait a bit until RAW video resolution has been updated
sleep(1)
display.notify_box(currently_selected_preset.name .. " " .. menu.get("Movie", "RAW video"))
end
)
end
do_for_each_preset = function()
-- close_menu();
if currently_selected_preset.submenu ~= nil then
-- Loop over all entries in the submenu
-- And apply the ones that match
for k,v in pairs(currently_selected_preset.submenu) do
-- If the name of this entry starts with specified string (index starts at 1)
if string.find(k, "bitdepth") == 1 then
menu.set("Crop mode", "bitdepth", v.value)
end
end
end
menu.set("Crop mode", "ratios", menu.get("Presets", "Ratio"))
menu.set("Crop mode", "set 25fps", menu.get("Presets", "FPS"))
end
run_if_opened_with_play_key = function(this)
-- Only handle in movie mode
if (camera.mode ~= MODE.MOVIE) then
return true
end
-- If opened with the PLAY key, run function
-- Else allow to edit submenu when opened with SET key
if play_key_timestamp == nil or (dryos.ms_clock - play_key_timestamp) > 2000 then
return true
end
task.create(
function()
do_for_each_preset()
currently_selected_preset.select()
refresh_live_view()
end
)
before_last_run_preset = last_run_preset
last_run_preset = currently_selected_preset
-- Handle key event only once
play_key_timestamp = nil
return false
end
store_currently_selected_preset = function(this)
if (this.selected) then
currently_selected_preset = this
end
return true
end
preset_menu_ratio =
menu.new {
parent = "Presets",
name = "Ratio",
max = 2,
choices = {"16:9", "2.39:1", "2.35:1"},
help = "Aspect ratio to apply to each preset.",
depends_on = DEPENDS_ON.MOVIE_MODE
}
preset_menu_fps =
menu.new {
parent = "Presets",
name = "FPS",
max = 1,
choices = {"OFF", "25fps"},
help = "Sets 2.39:1, 2.35:1 and 16:9 modes to 25fps.",
depends_on = DEPENDS_ON.MOVIE_MODE
}
preset_menu_a =
menu.new {
parent = "Presets",
name = "HD",
help = "Press SET to edit, press PLAY to apply preset.",
select = function(this)
menu.set("Crop mode", "x3crop", 0)
menu.set("Movie", "Crop mode", "mv1080p MCM rewire")
end,
update = store_currently_selected_preset,
submenu = {
{
name = "bitdepth a",
max = 4,
choices = {"OFF", "8 bit", "9 bit", "10 bit", "12 bit"},
help = "Alter bitdepth. OFF defaults to 14 bit.",
update = run_if_opened_with_play_key
}
},
depends_on = DEPENDS_ON.MOVIE_MODE
}
preset_menu_b =
menu.new {
parent = "Presets",
name = "HD crop",
help = "Press SET to edit, press PLAY to apply preset.",
select = function(this)
menu.set("Crop mode", "x3crop", 1)
menu.set("Movie", "Crop mode", "mv1080p MCM rewire")
end,
update = store_currently_selected_preset,
submenu = {
{
name = "bitdepth b",
max = 4,
choices = {"OFF", "8 bit", "9 bit", "10 bit", "12 bit"},
help = "Alter bitdepth. OFF defaults to 14 bit.",
update = run_if_opened_with_play_key
}
},
depends_on = DEPENDS_ON.MOVIE_MODE
}
-- With ratios set to off the 2.5K 2520x1418 mode has greater hight.
-- 2.5K 1:1 centered records max 2520x1080.
-- 2.5K 2520x1418 records in 2520x1416.
-- In 16:9 aspect ratio 2.5K 1:1 centered records max 1920x1080.
-- 2.5K 2520x1418 records in 2192x1234.
-- So not only greater hight, but also greater width.
-- In 2.39:1 ratio both record in 2520x1054.
-- In 2.35:1 ratio both record in 2520x1072.
preset_menu_c =
menu.new {
parent = "Presets",
name = "TWOK",
help = "Press SET to edit, press PLAY to apply preset.",
select = function(this)
menu.set("Crop mode", "x3crop", 0)
menu.set("Movie", "Crop mode", "2.5K 2520x1418")
end,
update = store_currently_selected_preset,
submenu = {
{
name = "bitdepth c",
max = 4,
choices = {"OFF", "8 bit", "9 bit", "10 bit", "12 bit"},
help = "Alter bitdepth. OFF defaults to 14 bit.",
update = run_if_opened_with_play_key
}
},
depends_on = DEPENDS_ON.MOVIE_MODE
}
preset_menu_d =
menu.new {
parent = "Presets",
name = "FOURK",
help = "Press SET to edit, press PLAY to apply preset.",
select = function(this)
menu.set("Crop mode", "x3crop", 0)
menu.set("Movie", "Crop mode", "4K anamorphic rewired")
end,
update = store_currently_selected_preset,
submenu = {
{
name = "bitdepth d",
max = 4,
choices = {"OFF", "8 bit", "9 bit", "10 bit", "12 bit"},
help = "Alter bitdepth. OFF defaults to 14 bit.",
update = run_if_opened_with_play_key
}
},
depends_on = DEPENDS_ON.MOVIE_MODE
}
open_preset_menu = function()
currently_selected_preset = before_last_run_preset
menu.select("Presets", before_last_run_preset.name)
menu.open()
end
-- Why doesn't this work?
-- Currently there's no state between reboots
-- Script starts with errors if I uncomment these lines:
-- config.create_from_menu(preset_menu_ratio)
-- config.create_from_menu(preset_menu_fps)
-- config.create_from_menu(preset_menu_a)
-- config.create_from_menu(preset_menu_b)
-- config.create_from_menu(preset_menu_c)
-- config.create_from_menu(preset_menu_d)
last_selected_preset = preset_menu_a
last_run_preset = preset_menu_a
before_last_run_preset = preset_menu_b
event.keypress = function(k)
-- Check if PLAY key is pressed
if k == KEY.PLAY then
play_key_timestamp = dryos.ms_clock
if camera.gui.play == true or camera.gui.menu == true or menu.visible == true then
-- Don't trigger my menu when already in ML menu or Canon menu or Play menu
return true
else
-- Camera locks up if not calling with task.create...
task.create(open_preset_menu)
return false
end
else
-- Pressed other key
play_key_timestamp = nil
end
return true
end
console.hide()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment