New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cycle-values fix/enhancement #5772

Closed
wjtk4444 opened this Issue Apr 27, 2018 · 5 comments

Comments

Projects
None yet
2 participants
@wjtk4444

wjtk4444 commented Apr 27, 2018

cycle-values should either be fixed/enhanced, or another input command should be added

As of now, neither cycle nor cycle-values allows for toggling a multi-state value (more than 2 possible values) correctly. Consider the following example:

input.conf:
c cycle-values keep-open yes no

case 1:
mpv --keep-open=no - values will be cycled properly - yes, no, yes, no, etc.

case 2:
mpv --keep-open=yes - values won't be cycled properly - yes, yes, no, yes, etc.

I'd like to see either cycle-values 'fixed' (I'm not sure if current behaviour is desired), or a new input command that wound prevent choosing the same value twice in a row.

I wrote a workaround script for that, but I think that it should be a built-in mpv input command. It's probably really simple to implement, but I don't know whether I should make it a new input command or change the behaviour of existing one, nor I have any experience in contributing to mpv. Here's the script, if anyone is interested:

-- -----------------------------------------------------------
--
-- Description:
--
--  Allows you to toggle any property between two states
--  if current state is different from both specified states, 
--  first one is used and additional message is displayed.
--
-- -----------------------------------------------------------


local mp = require 'mp'

function toggle_property(name, val1, val2)
	local val = mp.get_property(name)
	if(val == val1) then
		mp.set_property(name, val2)
		mp.osd_message(name .. ': ' .. val2)
	elseif(val == val2) then
		mp.set_property(name, val1)
		mp.osd_message(name .. ': ' .. val1)
	else
		mp.set_property(name, val1)
		mp.osd_message(name .. ': ' .. val .. ' => ' .. val1)
	end
end


-- Bind this via input.conf. Example:
-- c script_message toggle_property keep-open yes no
-- l script_message toggle_property loop-file no yes
mp.register_script_message('toggle_property', toggle_property)
@wm4

This comment has been minimized.

Contributor

wm4 commented Apr 27, 2018

The current behavior is pretty much due to options like "aspect", which tend to introduce some rounding etc., which would break cycle-values if it behaved like you wanted it to behave. Not sure if this could be hacked around by now.

@wjtk4444

This comment has been minimized.

wjtk4444 commented Apr 27, 2018

If I understand it right, adding a new input command, say, cycle-values-without-repeating (which is not the best name, but that's not the point) that would implement the same logic as my script has would work just fine.

I updated my script so that it works exactly how I'd like cycle-values-without-repeating to work.
If I misundestood what You said and it's not possible to add such input binding - sorry. You are free to close this issue (and share my script in the mpv wiki in case if someone looks for a solution to the similar problem).

-- -----------------------------------------------------------
--
-- Description:
--
--  Allows you to cycle trough values for any
--  property without the risk of repeating the same
--  value twice in a row (like cycle-values can do)
--  If current value is different from any of the 
--  specified ones, first from the list will be used 
--  and additional message will be displayed.
--
-- -----------------------------------------------------------


local mp = require 'mp'

function cycle_values(name, ...)
	local values = {...}
	local old_value = mp.get_property(name)
	local value_count = #values
	local value_found = false
	
	-- sanity check
	if value_count == 0 then
		mp.osd_message('[cycle_values]: you need to specify at least one allowed value in input.conf')
		return
	end
	
	-- loop trough the allowed values
	for index, value in ipairs(values) do
		--find old value within them
		if (old_value == value) then
			value_found = true
			-- set new value
			if(index < value_count) then -- to the next one from the list
				mp.set_property(name, values[index + 1])
				mp.osd_message(name .. ': ' .. values[index + 1])
			else -- index == value_count -- or the first one from the list 
				mp.set_property(name, values[1])
				mp.osd_message(name .. ': ' .. values[1])
			end
		end
	end
	
	-- if old value wasn't found in the allowed values
	if not value_found then -- set new value to the first one from the list
		mp.set_property(name, values[1])
		mp.osd_message(name .. ': ' .. old_value .. ' => ' .. values[1])
	end
end

-- Bind this via input.conf. Example:
-- key script_message cycle_values property-name value1 value2 ... valueN 
--
-- c script_message cycle_values keep-open yes no always
-- l script_message cycle_values loop-file no yes 1 2 3 4 5
mp.register_script_message('cycle_values', cycle_values)

On the side note, where can I ask a question regarding mpv? I tried looking trough issues, reading manual and even asking on /g/mpv - I couldn't find the answer to my question so far. Since I already went this far, I'll post the qestion here (I can delete this part of my comment after I'll get an answer - either to my question, or to where should I ask it instead). Sorry for completely offtopic talk in the issue comments, but I'm all out of ideas where to ask instead. Opening a new issue just to ask a question seems like even worse idea.

Is it possible to either call a function from one script in another while reusing the instance, or call a script's function by command line arguments? Example below.

script.lua:

local result = something_complex_that_takes_lots_of_time_to_complete()

function do_stuff_that_takes_almost_no_time_to_complete()
    --do stuff using result (without modifying it's value)
end

mp.register_event('some_event', do_stuff_that_takes_almost_no_time_to_complete)

call_a_function_from_script.lua

script = ... ?
script.do_stuff_that_takes_almost_no_time_to_complete()

command line args:

mpv --call_function="script/do_stuff_that_takes_almost_no_time_to_complete"
@wm4

This comment has been minimized.

Contributor

wm4 commented Apr 27, 2018

Questions normally go on IRC. See: https://mpv.io/community/

Scripts are completely isolated from each other. They can only talk via the script-messageandscript-message-to`` commands and associated events (I think lua has some helpers too, not sure). In theory they also could use OS mechanisms, but that would be even messier.

There's no way to call script functions from command lines. But there's --script-opts, which can be read as property by scripts or via the mp.options Lua helper.

@wm4

This comment has been minimized.

Contributor

wm4 commented Apr 27, 2018

Also I'll probably take a look again at changing cycle-values to something that's generally more expected.

@wjtk4444

This comment has been minimized.

wjtk4444 commented Apr 27, 2018

Thank You very much for your answer. I'll move with my next questions to IRC. Let me know If I should remove the offtopic part of my previous comment. It's most certainly not related to this issue, but I'm generally against deleting anything anywhere - someone may make use of those informations. For instance, I had no idea that mpv has it's own IRC channel.

Regarding the issue - it's definitely not something of a high priority, especially since I made a script that solves the problem for now. I'll leave the decision whether to close the issue to You, probably this will be my last comment on this topic.

@jeeb jeeb closed this in 7dd69ef Apr 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment