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

Library controls color selector #13077

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

aqw42
Copy link
Contributor

@aqw42 aqw42 commented Apr 9, 2024

Add [Library], track_color_selector

Follows #13066 and #2541

Tested on Debian :
-> Using developer mode, messing with the controls values
-> Using a MIDI controller, mapping each of the controls to a push button or a rotary encoder
Everything worked fine.

New controls list (note to myself for the future manual addition)

  • [ChannelN], track_color_prev - push button
  • [ChannelN], track_color_next - push button
  • [ChannelN], track_color_selector - encoder
  • [Library], track_color_prev - push button
  • [Library], track_color_next - push button
  • [Library], track_color_selector - encoder <-- new

src/library/librarycontrol.cpp Outdated Show resolved Hide resolved
Comment on lines 1089 to 1096
while (steps != 0) {
if (steps > 0) {
pActiveView->assignNextTrackColor();
steps--;
} else {
pActiveView->assignPreviousTrackColor();
steps++;
}
Copy link
Member

@Swiftb0y Swiftb0y Apr 16, 2024

Choose a reason for hiding this comment

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

Is this possible without the while? It's not very efficient and could cause visual artifacts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your review.
colorPalette.nextColor() only handles color codes, the actual QT event is thrown with track->setColor().
So I think no visual artifacts or performance issue can be caused by this.
Another code using this have been push last week (see #13066)

Copy link
Member

Choose a reason for hiding this comment

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

I think @Swiftb0y is referring to the Track::colorUpdated(color) signal that is fired for each color change whic causes repaint calls everywhere that track (or many tracks) is loaded (tracks view, decks), and with the selector color changes can indeed occur at high rates.
Didn't think of that during my previous review 👍

Copy link
Member

Choose a reason for hiding this comment

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

So ideally the color selector would be moved to the track itself, find the desired color and assign it right away.
IIUC that only refers to the situation when we have select steps buffered, e.g. from MIDI, and LibraryControl is going to do one by one. Because 'quick' color switch may also happen when triggering color_next/_prev quickly.

Copy link
Member

Choose a reason for hiding this comment

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

causes repaint calls everywhere that track (or many tracks)

okay, WTrackTableView::assignNextTrackColor acts only on the first selected track.

Copy link
Member

Choose a reason for hiding this comment

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

So ideally the color selector would be moved to the track itself

nope, to ColorPalette::nextColor: find the Nth next/prev color (incl. palette wrap-around), return, apply to track.

Copy link
Member

Choose a reason for hiding this comment

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

causes repaint calls everywhere

Yes. thats what I was referring to.

IIUC that only refers to the situation when we have select steps buffered,

That seems like an ugly workaround. Ideally the API would just be changed so you can just set n'th next color directly.

from MIDI, and LibraryControl is going to do one by one.

If the user quickly cycles through colors by pressing the next/prev button quickly, thats fine. Especially since there is quite a lot of delay between the individual presses (which is not true for a programmed loop).

Copy link
Member

Choose a reason for hiding this comment

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

To clarify:
"IIUC that only refers to the situation when we have select steps buffered"
was meant like
"IIUC that only affects the situation when we have select steps buffered" ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I was looking at the wrong patch when I first replied (the one in basetrackplayer)
So I updated this one following your advice, what do you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test result :
With this version, setting [library], track_color_selector to 5 display one time this message :
"debug [Main] BaseTrackCache(0x562e25698fb0) updateIndexWithQuery took 0 ms"
With the old version (while loop in librarycontrol), the same manipulation triggers it once too.
Both are functionally the same.
Is there any other debug message I could use to check the repaint call ?

@github-actions github-actions bot added the ui label Apr 17, 2024
Comment on lines 425 to 433
while (steps != 0) {
if (steps > 0) {
color = colorPalette.nextColor(color);
steps--;
} else {
color = colorPalette.previousColor(color);
steps++;
}
}
Copy link
Member

@Swiftb0y Swiftb0y Apr 17, 2024

Choose a reason for hiding this comment

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

this solution still does a lot of searching. we can go one step further

Suggested change
while (steps != 0) {
if (steps > 0) {
color = colorPalette.nextColor(color);
steps--;
} else {
color = colorPalette.previousColor(color);
steps++;
}
}
const int currentColorIdx = colorPalette.indexOf(color);
const int newColorIndex = rem_euclid(currentColorIdx + steps, colorPalette.size());
color = colorPalette.at(newColorIndex);

rem_euclid is a euclidean remainder/modulo which you'll have to implement in util/math.h. There are plenty of solutions to this online that are reasonably fast (remember % is terribly slow, solutions using three modulos in a row are likely suboptimal).

You might also want to consider to implement this as nextNthColor in ColorPalette directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion !
But i'm not sure the modulo efficiency is relevant here

Copy link
Member

Choose a reason for hiding this comment

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

Here probably not, no, but if we add it as a general function to math, we should still make sure its within reasonable limits.

Copy link
Member

Choose a reason for hiding this comment

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

What about simply moving this to colorpalette so it is available elsewhere?
ColorPalette::getNthColor()

Copy link
Contributor Author

@aqw42 aqw42 Apr 17, 2024

Choose a reason for hiding this comment

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

I simply moved the while loop to getNthColor, as suggested by @ronso0 because there are too many individual cases that are already handled in nextColor and previousColor (for example index -1 is no color, and you need to cycle through it too).

I felt that trying to be overefficient here would damage readability and not gain execution time given the nature of the color change (only manual changes of a few steps can happen).

I called this function in the per deck track_color_selector too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test results:
The steps maximum value is 99, min is -99. (is it hardcoded in the control definition ?)
It takes 0ms to execute and there are no visual artifacts.
I made sure we really cycle through the palette, even with big values.
Works for Library and Channel.

Copy link
Member

@Swiftb0y Swiftb0y Apr 18, 2024

Choose a reason for hiding this comment

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

yup, the visual artifact problem should be solved, 0ms doesn't mean its very efficient though (milliseconds is wayy too large of a timescale). At least add a TODO at the loop location please.

Comment on lines 1084 to 1135
LibraryView* pActiveView = m_pLibraryWidget->getActiveView();
if (!pActiveView) {
Copy link
Member

Choose a reason for hiding this comment

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

FWIW I have a WIP branch that makes use of WLibrary::getCurrentTrackTableView(). This allows to remove many virtual methods from libraryview.h and library features (DlgMissing etc.) which essentially just redirect calls to their own WTrackTableView (which you didn't do here, which means the color controls don't work in AutoDJ, Missing and Hidden?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry, my knowledge of the codebase is clearly insufficient to understand this comment.

I cannot find the getCurrentTrackTableView method anywhere.
Why would AutoDJ need these features ?
How does he access them ?

Can you clarify or point me to the relevant files ?

Copy link
Member

Choose a reason for hiding this comment

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

sorry, I was knee-deep into it when I wrote this.

Like the color select slots, many control slots in LibraryControl call methods of the 'active view'. This can be anything that inherits LibraryView: a pure WTrackTableView, a html root view (top-level item of Crates and Playlists), or some controls row + table view (Auto DJ, Recording, Analysis).

So, until now, a virtual function in libraryview.h needs to be overriden not just in WTrackTableView but in every view/feature where a certain control should be availble. "Until now" because I opened #13335 earlier today which makes use of WLibrary::getCurrentTrackTableView() to get rid of all the virtuals and overrides (see what I removed there).
That's why AutoDJ doesn't need it, but you probably want the color controls to work in the AutoDJ and Recording table, too.

I cannot find the getCurrentTrackTableView method anywhere.

Probably because your branch is based on an older version of main that doesn't have it, yet, not sure.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW I've been using the Github code search a ot lately, very handy:
https://github.com/search?q=repo%3Amixxxdj%2Fmixxx%20%22searchterm%22&type=code
I have a search accelerator (shortcut) and I wrap the term in quotes " (%22) so I use search terms with whitespaces.

@aqw42 aqw42 force-pushed the library-controls-color-selector branch from 23ad535 to 7bd68a8 Compare June 6, 2024 17:06
@ronso0
Copy link
Member

ronso0 commented Jun 18, 2024

#13335 has been merged, please fix the conflicts (switch to getCurrentTrackTableView())

Copy link

This PR is marked as stale because it has been open 90 days with no activity.

@github-actions github-actions bot added the stale Stale issues that haven't been updated for a long time. label Sep 17, 2024
@daschuer daschuer marked this pull request as draft September 17, 2024 09:28
@github-actions github-actions bot removed the stale Stale issues that haven't been updated for a long time. label Sep 19, 2024
@ronso0
Copy link
Member

ronso0 commented Sep 20, 2024

@aqw42 do you intend to finish this, or should someone else jump in?

If yes:

#13335 has been merged, please fix the conflicts (switch to getCurrentTrackTableView())

Thanks!

@aqw42
Copy link
Contributor Author

aqw42 commented Sep 21, 2024

@aqw42 do you intend to finish this, or should someone else jump in?

If yes:

#13335 has been merged, please fix the conflicts (switch to getCurrentTrackTableView())

Thanks!

I'm on it, thanks for the reminder

@aqw42 aqw42 force-pushed the library-controls-color-selector branch from 7bd68a8 to 6d46304 Compare September 22, 2024 12:25
Fix codestyle issue
@aqw42 aqw42 force-pushed the library-controls-color-selector branch from 6d46304 to 561ab07 Compare September 22, 2024 12:42
@aqw42 aqw42 marked this pull request as ready for review September 22, 2024 13:45
@ronso0 ronso0 mentioned this pull request Sep 23, 2024

void LibraryControl::slotTrackColorNext(double v) {
if (!m_pLibraryWidget || v <= 0) {
LibraryView* pActiveView = m_pLibraryWidget->getCurrentTrackTableView();
Copy link
Member

Choose a reason for hiding this comment

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

Please change to WTrackTableView

Suggested change
LibraryView* pActiveView = m_pLibraryWidget->getCurrentTrackTableView();
WTrackTableView* pTrackTableView = m_pLibraryWidget->getCurrentTrackTableView();

and use pTrackTableView below.

Switch to ptracktableview
@JoergAtGithub
Copy link
Member

Please resolve the merge conflict, otherwise the CI builds will not start.

@ronso0
Copy link
Member

ronso0 commented Sep 29, 2024

@aqw42 Please ammend the last fixup commit in to the 'merge branch main' commits.
All commits should build, so we can use git bisect for debugging.

So please also check all the previous commits build.
Thank you!

Co-authored-by: ronso0 <ronso0@mixxx.org>
@aqw42 aqw42 force-pushed the library-controls-color-selector branch from cd29890 to e70da63 Compare September 29, 2024 15:30
src/widget/wtracktableview.h Outdated Show resolved Hide resolved
src/library/libraryview.h Outdated Show resolved Hide resolved
src/library/librarycontrol.cpp Outdated Show resolved Hide resolved
src/library/librarycontrol.cpp Outdated Show resolved Hide resolved
Comment on lines +43 to +44
// TODO : Use rem_euclid modulo function instead of a loop
while (steps) {
Copy link
Member

Choose a reason for hiding this comment

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

we should address this in this PR IMO. The repeated calls to nextColor/previousColor which in turn call indexOf are highly suboptimal (in terms of wasted computations).

@aqw42
Copy link
Contributor Author

aqw42 commented Oct 1, 2024

@Swiftb0y these comments are mostly unimportant or details that we already discussed 4 month ago.
I feel that you are making me lose my time, please resolve them yourself, as you already did in your suggestions.

@ronso0
Copy link
Member

ronso0 commented Oct 1, 2024

@aqw42 I don't think this is the appropriate tone, considering the delay of 4 months stems from the fact that you missed my reminder in June. (and none of the contributors, me included, gave this high prio considering more important 2.4/2.5 fixes that had to be done).

Let's fix/polish this and get it merged soonish.

@Swiftb0y
Copy link
Member

Swiftb0y commented Oct 1, 2024

these comments are mostly unimportant or details that we already discussed 4 month ago.

sure these comments are certainly nitpicks to a degree, but I feel like they're important enough to raise. The fact that I brought them up even though we've already discussed them should emphasize their importance as well as the fact that they have not yet been addressed. Trust me, I want to do anything but to waste your time, but largescale software development requires careful consideration of each change, otherwise the result will become a large mess that nobody wants to work on anymore.

So please bear with me when I ask for a little bit of polish. It helps you to improve your code and us all to improve mixxx. Thank you.

Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com>
src/library/libraryview.h Outdated Show resolved Hide resolved
src/widget/wtracktableview.h Outdated Show resolved Hide resolved
@ronso0
Copy link
Member

ronso0 commented Oct 3, 2024

Just some cleanup..

@ronso0
Copy link
Member

ronso0 commented Oct 5, 2024

@Swiftb0y Have your concerns all been addressed?

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

Successfully merging this pull request may close these issues.

4 participants