Skip to content
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

controls doesn't work #777

Closed
hooke007 opened this issue Nov 7, 2023 · 19 comments
Closed

controls doesn't work #777

hooke007 opened this issue Nov 7, 2023 · 19 comments

Comments

@hooke007
Copy link
Contributor

hooke007 commented Nov 7, 2023

controls = cycle:developer_board_off:hwdec:no=developer_board_off/yes=memory/auto-copy=developer_board?test

It doesn't work in current git version.

@tomasklaen
Copy link
Owner

Can you describe how is it not working? Because I don't see an issue:

hwdec

@hooke007
Copy link
Contributor Author

hooke007 commented Nov 7, 2023

load a video and click the button.
The video could only change its hwdec mode once.

@tomasklaen
Copy link
Owner

Works fine for me even for videos. And on the gif above you can see that uosc is triggering proper commands. So whatever the issue is, it doesn't seem to be uosc related.

@hooke007
Copy link
Contributor Author

hooke007 commented Nov 7, 2023

test
git version

update:
release 5.0 broke too

@hooke007
Copy link
Contributor Author

hooke007 commented Nov 7, 2023

release 4.7 works well
test2

@hooke007
Copy link
Contributor Author

hooke007 commented Nov 7, 2023

And on the gif above you can see that uosc is triggering proper commands.

I don't see your console is switching hwdec mode. [vd] Using ....

@tomasklaen
Copy link
Owner

That looks more like a cursor events issue. Does something like toggle:shuffle:shuffle work? Or does it freeze after first click too?

I don't see your console is switching hwdec mode. [vd] Using ....

It's a static paused image with --quiet enabled. One of those variables is why the output is clean. I get VO: changes on videos and observing hwdec reports changes correctly.

@hooke007
Copy link
Contributor Author

hooke007 commented Nov 7, 2023

That looks more like a cursor events issue.

I tried cycle:developer_board_off:hue:10=developer_board_off/20=memory/30=developer_board?test and it works. So it looks like something else.

Or does it freeze after first click too

No freezing, it just does not respond my click.

@hooke007
Copy link
Contributor Author

hooke007 commented Nov 7, 2023

@tomasklaen
Copy link
Owner

Can you report what is this logging?

diff --git a/src/uosc/elements/CycleButton.lua b/src/uosc/elements/CycleButton.lua
index 6059849..6d5ca85 100644
--- a/src/uosc/elements/CycleButton.lua
+++ b/src/uosc/elements/CycleButton.lua
@@ -24,6 +24,7 @@ function CycleButton:init(id, props)
 	self.on_click = function()
 		local new_state = self.states[self.current_state_index + 1] or self.states[1]
 		local new_value = new_state.value
+		print('current:', self.states[self.current_state_index].value, 'next:', new_value)
 		if self.owner then
 			mp.commandv('script-message-to', self.owner, 'set', self.prop, new_value)
 		elseif is_state_prop then

@hooke007
Copy link
Contributor Author

hooke007 commented Nov 7, 2023

@tomasklaen
Copy link
Owner

Yeah I though this was gonna be the issue. Now to figure out why is it failing to set or select next state for you.

Can you screenshot the result of this too?:

print('current:', self.states[self.current_state_index].value, 'next:', new_value, 'real:', mp.get_property_native('hwdec'))

@hooke007
Copy link
Contributor Author

hooke007 commented Nov 7, 2023

But in this case, we should observe hwdec-current instead https://mpv.io/manual/master/#command-interface-hwdec-current

@tomasklaen
Copy link
Owner

Oh my god. How do we handle this now? There's one property for reading, and another for setting? Jesus. And why does it work for me and not for you?

@hooke007
Copy link
Contributor Author

hooke007 commented Nov 7, 2023

#777 (comment)
But there must be sth happened in this commit right?

@tomasklaen
Copy link
Owner

Does this work for you?

diff --git a/src/uosc/elements/CycleButton.lua b/src/uosc/elements/CycleButton.lua
index 6059849..475f2e5 100644
--- a/src/uosc/elements/CycleButton.lua
+++ b/src/uosc/elements/CycleButton.lua
@@ -1,5 +1,9 @@
 local Button = require('elements/Button')
 
+local writer_reader_map = {
+	hwdec = 'hwdec-current'
+}
+
 ---@alias CycleState {value: any; icon: string; active?: boolean}
 ---@alias CycleButtonProps {prop: string; states: CycleState[]; anchor_id?: string; tooltip?: string}
 
@@ -52,7 +56,7 @@ function CycleButton:init(id, props)
 		self['on_prop_' .. self.prop] = function(self, value) handle_change(self.prop, value) end
 		handle_change(self.prop, state[self.prop])
 	else
-		self:observe_mp_property(self.prop, handle_change)
+		self:observe_mp_property(writer_reader_map[self.prop] or self.prop, handle_change)
 	end
 end

But there must be sth happened in this commit right?

I'll try to look.

@hooke007
Copy link
Contributor Author

hooke007 commented Nov 7, 2023

Does this work for you?

No, because I think hwdec-current reflects the name of hwdec.

Snipaste_2023-11-07_17-47-53

@tomasklaen
Copy link
Owner

Try this? 😬

diff --git a/src/uosc/elements/CycleButton.lua b/src/uosc/elements/CycleButton.lua
index 6059849..61cd666 100644
--- a/src/uosc/elements/CycleButton.lua
+++ b/src/uosc/elements/CycleButton.lua
@@ -52,7 +52,7 @@ function CycleButton:init(id, props)
 		self['on_prop_' .. self.prop] = function(self, value) handle_change(self.prop, value) end
 		handle_change(self.prop, state[self.prop])
 	else
-		self:observe_mp_property(self.prop, handle_change)
+		self:observe_mp_property(self.prop, 'string', handle_change)
 	end
 end
 
diff --git a/src/uosc/elements/Element.lua b/src/uosc/elements/Element.lua
index 3e3f458..733d63e 100644
--- a/src/uosc/elements/Element.lua
+++ b/src/uosc/elements/Element.lua
@@ -182,9 +182,12 @@ end
 
 -- Automatically registers disposer for the observer.
 ---@param name string
----@param callback fun(name: string, value: any)
-function Element:observe_mp_property(name, callback)
-	mp.observe_property(name, 'native', callback)
+---@param type_or_callback string|fun(name: string, value: any)
+---@param callback_maybe nil|fun(name: string, value: any)
+function Element:observe_mp_property(name, type_or_callback, callback_maybe)
+	local callback = type(type_or_callback) == 'function' and type_or_callback or callback_maybe
+	local prop_type = type(type_or_callback) == 'string' and type_or_callback or 'native'
+	mp.observe_property(name, prop_type, callback)
 	self:register_disposer(function() mp.unobserve_property(callback) end)
 end

@hooke007
Copy link
Contributor Author

hooke007 commented Nov 7, 2023

Yes, it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants