Skip to content

add play_queue total_time - #1309

Merged
flyingmutant merged 3 commits into
cmus:masterfrom
Lagrang3:play_queue_total_time
Sep 29, 2024
Merged

flyingmutant merged 3 commits into
cmus:masterfrom
Lagrang3:play_queue_total_time

Conversation

@Lagrang3

@Lagrang3 Lagrang3 commented Feb 9, 2024

Copy link
Copy Markdown
Contributor

The format option "total" will display the total time in the library or the current playing list, but if the queue is active it should instead display the total time of the queue.

@gavtroy

gavtroy commented Feb 27, 2024

Copy link
Copy Markdown
Collaborator

It could benefit from further consideration in update(), otherwise the code looks fine. But I wonder if it would be better to add it as a separate format option instead, if what you're really interested in is how low the queue is running.

I'm playing around with how we present the information in #1317 but a %{queue_total} or similar could be a complimentary change (and perhaps a %{queue_nr_tracks}).

@Lagrang3

Lagrang3 commented Feb 27, 2024 •

Copy link
Copy Markdown
Contributor Author

As a user I have format_statusline = ... %{total} .... To me this means total play time but the context is missing.
If I am on the queue, total should stand for the total time on the queue, if I am playing a playlist total means the total time on the list, if I am playing from the library or tree view, then the total time of the library.
That's my interpretation.

As a matter of fact the old line
fopt_set_time(&track_fopts[TF_TOTAL], play_library ? lib_editable.total_time : pl_playing_total_time(), 0);
is also supporting that interpretation. total time is either the library total time or the playlist total time depending on which is playing. There isn't an option total_pl_time.

I am just adding total time is either the library total time or the playlist total time or the queue time depending on which is playing.

@Lagrang3

Lagrang3 commented Feb 27, 2024 •

Copy link
Copy Markdown
Contributor Author

If I add an explicit queue_total option, would I need to format my status line with a condition, kind of
if playing queue, then show queue_total, else show total?

@gavtroy

gavtroy commented Feb 28, 2024

Copy link
Copy Markdown
Collaborator

If I am on the queue

Incidentally since the queue isn't "active" until the first track gets pulled from it, it might make more sense to set that condition as (!queue_empty || queue_active).

The queue feels different to library vs playlist because it's a temporary state and there isn't a good indication of whether it's "active". But I'm not opposing your proposal, just wondering what works best for the use case. What you're suggesting is probably fine. If it was a separate format option then depending on the implementation you could have something like
... %{total}%{?queue_total? (%{queue_total} enqueued)} ... or
... %{?queue_total?%{queue_total}?%{total}} ....

Either way if you expect it to be used in the statusline, you need to extend the redraw condition in update()

cmus/ui_curses.c

Lines 1966 to 1972 in 23afab3

/* total time changed? */
if (play_library) {
needs_status_update += lib_editable.shared->win->changed;
lib_editable.shared->win->changed = 0;
} else {
needs_status_update += pl_needs_redraw();
}

@Lagrang3

Lagrang3 commented Mar 7, 2024 •

Copy link
Copy Markdown
Contributor Author

I think this is meant to indicate when the queue is active

cmus/cmus.c

Line 547 in 23afab3

bool cmus_queue_active(void) {

I am using this change already locally, and it feels fine to me.

The only issue that I have, now that you mention it, is that the queue is active whenever there is at least one element there no matter if I am currently playing a track from a playlist or a the library; the next track will always be the one on the top of the queue. But that is not up to me.

@Lagrang3

Lagrang3 commented Mar 7, 2024

Copy link
Copy Markdown
Contributor Author

At the end of the day I just want to extend the meaning of {total}. If I play from the library total will show the total time on the library, if I play from a playlist total will show the total time on the playlist. Therefore, one might expect that if I play from the queue total would show the total time on the queue.
That's all I want to do.

@gavtroy

gavtroy commented Mar 8, 2024

Copy link
Copy Markdown
Collaborator

The logical behavior is subjective (and I'm not sure how useful the existing %{total} is in the first place...) but I don't think anyone would be upset by this change.

I am using this change already locally, and it feels fine to me.

With regards to what I'm saying about update(), try adding something to the queue while cmus is paused/stopped. You'll see the statusbar isn't redrawn until it has a reason to be. If cmus is playing then it will redraw every second, so you might not notice this quirk.

@Lagrang3

Lagrang3 commented Mar 8, 2024

Copy link
Copy Markdown
Contributor Author

True, I haven't noticed the update condition for the status bar. Now added a quick fix 8ea3b84.
It was fun reviewing the update() function. Thanks for the suggestion.

Comment thread ui_curses.c
/* total time changed? */
if (play_library) {
if (cmus_queue_active()) {
needs_status_update += queue_needs_redraw();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to clear changed to 0 when you read it similar to what's done for lib_editable, otherwise it'll still be set on every loop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the same problem with the playlist view then. pl_needs_redraw checks on pl_editable_shared.win->changed, but changed is only set to 0 after pl_draw is called. So that means the status bar redraws on every loop if playing from the playlist but pl_draw is not called, eg. if on another view.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking to set all changed flags to 0 in post_update. Would that make sense? I will propose it for the play queue, and later it could be also extended to the playlists and library.

@Lagrang3 Lagrang3 Mar 15, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a check, and it wouldn't work resetting the changed flag in post_update().
I would get a frozen queue while on the queue view, for example after typing :clear.
I am not sure why.

Instead I clear the flag at the end of the update() function and that seems to work 13f7980.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I hadn't noticed that about playlist updates, but I guess you can just ignore it if you want.

I would get a frozen queue while on the queue view

The queue view shouldn't freeze since it doesn't use changed as far as I see. But you probably meant playlist view since pl_draw() does check changed (although this optimization is probably not worth the headache).

Comment thread ui_curses.c
/* total time changed? */
if (play_library) {
if (cmus_queue_active()) {
needs_status_update += queue_needs_redraw();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I hadn't noticed that about playlist updates, but I guess you can just ignore it if you want.

I would get a frozen queue while on the queue view

The queue view shouldn't freeze since it doesn't use changed as far as I see. But you probably meant playlist view since pl_draw() does check changed (although this optimization is probably not worth the headache).

@pgaskin

pgaskin commented Sep 16, 2024 •

Copy link
Copy Markdown
Member

How does this change relate to bad9b0c from #1317 @gavtroy?

Unless I'm misunderstanding the intention of this PR, it's now obsolete, right?

Nevermind, I see the difference now; this one is for the global TF_TOTAL.

@pgaskin pgaskin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works, makes sense.

The queue_post_update thing seems out of scope for this PR at first, but the existence of the lib_editable.shared->win->changed = 0; line earlier in the function (which has a similar purpose, but for the library/playlist views) kind of justifies this change being part of the PR (since otherwise the logic wouldn't be the same for the queue). It's a bit hacky, but no worse than what's already done.

Comment thread ui_curses.c
}

/* Reset changed flags */
queue_post_update();

@pgaskin pgaskin Sep 20, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took a while to understand why this is needed, but basically:

  • Usually, the changed flag is cleared by update_window.
  • That function is called by do_update_view in update if any view's changed flag is set.
  • The do_update_view only calls update_window for the currently visible view, even if other views bad the changed flag set.
  • Thus, all views should have their changed flag cleared after the entire update is done since all views which should be visible have already been updated.
  • There is already a workaround for this for library/playlist earlier in the update function where the editable changed flag is reset if playing from the library.

The comment above this line is a little bit vague, if not misleading. Also, to match the way the rest of the update function is written (specifically the parts which check the changed flag on all the views), the flags of all views should be cleared here.

This is fine for now though.

Comment thread play_queue.c

void queue_post_update(void)
{
pq_editable.shared->win->changed = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I don't think this function should exist; it's good for encapsulation, but it's inconsistent with the rest of cmus, where the changed flags on the views are directly manipulated by the update function.

@pgaskin

pgaskin commented Sep 20, 2024

Copy link
Copy Markdown
Member

@flyingmutant, probably merge this as a rebase to keep the changes separate.

@pgaskin

pgaskin commented Sep 24, 2024

Copy link
Copy Markdown
Member

@flyingmutant, do you plan to merge this, or are you still reviewing it?

The format option "total" will display the total time in the library or
the current playing list, but if the queue is active it should instead
display the total time of the queue.
The update condition for the status bar now takes into account changes
to the queue. This is needed for example if queue values, like total
time, are displayed in the status bar.
@flyingmutant
flyingmutant merged commit c04bf04 into cmus:master Sep 29, 2024
@flyingmutant

Copy link
Copy Markdown
Member

Merged, finally! Thanks a lot for the PR.

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

Successfully merging this pull request may close these issues.

4 participants