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

Use mpc idle instead of polling #28

Open
Ram-Z opened this issue Jul 23, 2014 · 3 comments
Open

Use mpc idle instead of polling #28

Ram-Z opened this issue Jul 23, 2014 · 3 comments

Comments

@Ram-Z
Copy link

Ram-Z commented Jul 23, 2014

Would it be possible to use mpc idle or mpc idleloop to update the status instead of polling it every update_interval?

The idea is to reduce the number of useless connections created to mpd. Connections would only needed to be made when something has actually changed on the mpd side and to get the current time when the mouse hovers over the widget.

I could even have a look at it myself, if I find a way to execute functions when mpc idleloop has new output.

@alexander-yakushev
Copy link
Owner

I don't have enough time to do it now, but you are welcome to try.

If you were to implement this you'd probably have to use asyncshell.lua to avoid locking whole Awesome while the code awaits for shell command to complete. For the same reason idleloop wouldn't probably fit as it never completes.

On a sidenote, I have some uncommitted changes with on-screen widget. That code obviously requires constant polling as widget stays on the screen permanently. So I'm not sure in the end this implementation will fit all the usecases.

firefish5000 added a commit to firefish5000/awesompd that referenced this issue Jul 24, 2015
Incorperated updates from
https://github.com/alexander-yakushev/awesomerc/blob/master/awesompd/awesompd.lua

Made slight alterations & bugfixes
(escape formated string -> format escaped string)

Added a protect_strings() which is capable of escaping & returning
stiring lists.

TODO
Store os.time when track_passed is stored. Can be used to keep a
relitivly accurate track position on osd and notify without calling
update_track.
Try implementing alexander-yakushev#28 (mpc idle/idleloop instead of update_track). should
give near instant track change(play/pause/stop/next/prev) notifications
regardless of means of changing track (track ended, mpc or ario client
request)
@firefish5000
Copy link
Contributor

I saw this within an hour of merging. If your still interested, I seem to have working code, though it could use a look over from someone who knows what asyncshell.lua is doing.
I also added recalculate_track, track_update_time, calc_track_passed, and calc_track_progress. Which use difference in os.time to calculate the current track position and progress, probably the main reason for constant polling.
If their isn't a problem using async (like perl and ithreads, which must be compiled in), it may be a better option than smart_update (catches changes from other mpd clients instantly, automatic mpd track change as well).
(I've exhausted all forms of entertainment other than listening to music, coding, and blogging in comments/commits)

firefish5000 added a commit to firefish5000/awesompd that referenced this issue Jul 25, 2015
idle_update() handles running update_track on track change, pause, play,
stop, next, and prev events. It should run near instantly regardless of
what clients are used.
recalculate_track calculates track_position and track_progress based on
how much time has passed since last update_track. Usefull for keeping
an osd up to date without excessive calls to update_track.

Implements alexander-yakushev#28
@firefish5000
Copy link
Contributor

I didnt mean to reference this in the first commit. (didn't know I could)
I'm still testing it, but it seems to work rather well. And I believe the relative code is smaller than smart_update.

Recalculate_track currently sets 'calc_' prefixed vars, meaning non calc_ ones wont using this functionality. Made this while working with the onscreen widget version. Some status_text related things got included since removal looked time-consuming. (wondering why your holding it back, its great! Updates without flickering! if it had ontop =true and x/y pos set relative to mouse on the text widgets mouse::enter event, it may even double as a beautiful notify. )

You may want to bump update_interval up, I set mine to 60 since it shouldn't be necessary(except for syncing time in case mpd plays faster/slower than os.time, which should take a while to be noticeable).

It shouldn't hurt to change mouse::enter's update_track to a recalculate_track and set notify_track to use calc_track time and pos. Though having fallback may be a good idea. (I think I'm avoiding writing my English paper the wrong way)

Let me know if your interested in any of it, have suggestions or complaints.

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

3 participants