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

Add sample thumbnails #7366

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

khoidauminh
Copy link
Contributor

@khoidauminh khoidauminh commented Jul 4, 2024

This is an attempt in adding sample thumbnails in order to speed up rendering (mainly) in the song editor and other places (currently being Audio File Processor, SlicerT and the Automation editor).

Brief summary of the PR and explanation of names:

  • SampleThumbnailBit: a thumbnail sample, here being a struct whose fields are max min and rms.
  • SampleThumbnail: a thumbnail.
  • SampleThumbnailList: a vector of thumbnails. All thumbnails in this list come from the same sample.
  • SharedSampleThumbnailList: shared_ptr to a thumbnail list, used to track the usage of the thumbnail list.
  • SampleThumbnailListManager: class to manage the operations of creating, deleting, selecting and rendering thumbnails/thumbnail lists.
  • SampleThumbnailVisualizeParameters: contains information for rendering. See comments in SampleThumbnail.h for documentation.

SAMPLE_THUMBNAIL_LIST_MAP is an std::map with keys being the sample file path and the value being a SharedSampleThumbnailList. All thumbnail lists are stored here. This variable exists as a private static member of SampleThumbnailListManager.

This implementation assumes that a unique sample has a unique full file path. If this is violated or the file path is just the file name, the implementation may break completely.

When a sample is loaded into the song editor, the constructor of SampleThumbnailListManager looks into SAMPLE_THUMBNAIL_LIST_MAP to find the thumbnail list for this sample. If the sample is new, it proceeds to generate a new thumbnail list for this sample and insert it into the map. In other places like AFP, SlicerT, when loading a preexisting preset or project, the thumbnail lists might not be generated until you open the plugin GUI, which triggers the paintEvents.

The SampleThumbnailListManager class contains a non-static member list of type SharedSampleThumbnailList. The class attaches itself to classes that uses thumbnails, such as SampleClipView. This ensures that thumbnail list that is being used will have a use_count() of 2 or more (one in the std::map and others in the objects) . A use_count() of 1 indicates the sample is out of use and the thumbnail list will be deleted. Cleaning operations is done when loading new samples or closing LMMS.

This implementation uses powers of 32 for thumbnail size with the largest being 32768, and minimum being 1.

@Rossmaxx
Copy link
Contributor

Rossmaxx commented Jul 4, 2024

This implementation assumes that a unique sample has a unique full file path. If this is violated or the file path is relative, the implementation may break completely.

Factory samples would like to have a word with you

@khoidauminh
Copy link
Contributor Author

khoidauminh commented Jul 4, 2024

This implementation assumes that a unique sample has a unique full file path. If this is violated or the file path is relative, the implementation may break completely.

Factory samples would like to have a word with you

As long as the factory sample paths remain unique for each sample (which I believe they do) then it won't break.

I'm mostly concerned with when the sample name is just the filename.

(also changed the PR description a bit)

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.

None yet

2 participants