-
Notifications
You must be signed in to change notification settings - Fork 685
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
Support offset values for adding tracks relative to current track #1999
base: main
Are you sure you want to change the base?
Conversation
I was in a hurry and didn't actually run the tests locally, figuring it would be fine. It appears I've got some more work to do on understanding how the tracklist works 😊 |
4595084
to
e16f009
Compare
Two points:
Are there other cases we should have "shortcuts" for? Start of tracklist, end and after current are the obvious ones that come to mind. |
e16f009
to
3d31c21
Compare
I added a constant for this.
I'll add that once this PR gets merged.
Start of tracklist is easy: just supply |
This is out of scope for this PR and a bit niche but what happens (and what should happen) when you use this, or the old 2-call manual method, at a point in time near the end of the current track's playback? Will our gapless stuff have already loaded the old next track so you won't get the new one you just inserted? |
Right now, there's a small window of time (even smaller with this new approach) where if the current track's playback ends after the index has been retrieved but before the first new track is added, you won't hear the tracks you've just added. As long as the first new track gets added before playback of the current track ends, you'll hear all of the tracks you added. As for what should happen, I have no idea. I'm not sure there is a good solution. I think a more pressing problem is "play next" functionality when random is turned on. Right now, the track you've just selected to play next won't actually play next (regardless of whether or not this new approach is used). Has any thought been given to this in the past? |
If random is on then you cannot control what is played next without an excplicit call to EDIT:
And for the record I couldn't trigger this happening with a few casual attempts. The time period between |
I suspect it could happen, but that you'd never be able to reliably reproduce it. |
54e74b1
to
6ea3414
Compare
I've updated this PR to utilise an enum for the new behaviour. This also allowed me to more easily add "constants" for the start and end of the tracklist, as @adamcik suggested. The new system shouldn't have any issues with backwards-compatibility, and I've added a test to confirm that negative integer position values work. |
mopidy/core/tracklist.py
Outdated
class AddAtPosition(enum.Enum): | ||
START = enum.auto() | ||
AFTER_CURRENT = enum.auto() | ||
END = enum.auto() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a string Enum:
class AddAtPosition(enum.Enum): | |
START = enum.auto() | |
AFTER_CURRENT = enum.auto() | |
END = enum.auto() | |
class AddAtPosition(str, enum.Enum): | |
START = "START" | |
AFTER_CURRENT = "AFTER_CURRENT" | |
END = "END" |
Then you could accept strings to the at_position
argument and check if they're valid with simply at_position in AddAtPosition
, and the strings could be converted to enum values with just AddAtPosition(at_position)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deliberately didn't want to use a string Enum because I feel like you lose the benefits of using an Enum from a type checking point of view. I've seen them used before and they've always felt like a kludge.
6d1d766
to
7c926ea
Compare
I've updated the PR. I also added a few more tests while I was there. |
MPD now also supports this thanks to @djmattyg007's feature request. Perhaps we should also implement complete support for relative insertion indexes here. |
@djmattyg007 are you happy with this as is or do you want to support the relative insertion with +/-OFFSET ? |
I'd prefer to re-work this to instead use the MPD offset syntax. |
Similarly to #2007 I'm going to work on updating this so we can utilise support for it in a |
d0e8b69
to
76ce691
Compare
59910ab
to
27fbc78
Compare
27fbc78
to
68ce4e0
Compare
@jodal @kingosticks This is finally ready for review once more :) Flake8 is complaining about line length because of a couple of long strings, but it's not something black is complaining about. What are your thoughts? What's the preferred approach for breaking long strings over multiple lines? |
Oh, I noticed that offset values are now supported in MPD for a couple of other operations. I'll take a deeper look at this tomorrow 👍 |
Yes, it's totally random which methods support it. It appears to be done on request. |
I think they’re all related to adding tracks to the tracklist though, so hopefully this is the only new functionality required in Mopidy’s core to make it all possible. |
With this change, you can add tracks directly before or after the currently playing track without first having to retrieve the position of the currently playing track value yourself. When used over Mopidy's HTTP interfaces, this reduces the chance that the tracks you're adding will accidentally be skipped over between your two requests. The syntax for the offset strings matches MPD's support that was implemented as part of 0.23. I noticed there were no existing tests for the at_position argument, so I added some at the same time to handle other existing cases in addition to the new cases.
68ce4e0
to
7648949
Compare
Rebased and passed CI on |
With this change, you can add tracks directly before or after the currently playing track without first having to retrieve the position of the currently playing track value yourself. When used over Mopidy's HTTP interfaces, this reduces the chance that the tracks you're adding will accidentally be skipped over between your two requests.
The syntax for the offset strings matches MPD's support that was implemented as part of 0.23.
I noticed there were no existing tests for the at_position argument, so I added some at the same time to handle other existing cases in addition to the new cases.