Skip to content

Some improvements to Cue handling - #1406

Merged
flyingmutant merged 9 commits into
cmus:masterfrom
ihy123:cue
Sep 9, 2025
Merged

flyingmutant merged 9 commits into
cmus:masterfrom
ihy123:cue

Conversation

@ihy123

@ihy123 ihy123 commented Feb 12, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@ihy123
ihy123 marked this pull request as draft February 12, 2025 20:20
@ihy123
ihy123 force-pushed the cue branch 2 times, most recently from b4ed28c to b578c52 Compare February 15, 2025 16:35
@ihy123

ihy123 commented Feb 15, 2025

Copy link
Copy Markdown
Contributor Author

I suspect that #1397 will be fixed by this pull request. Can't say for sure because there's no Cue file attached to it.

@ihy123
ihy123 marked this pull request as ready for review February 15, 2025 16:44
@gavtroy

gavtroy commented Feb 15, 2025

Copy link
Copy Markdown
Collaborator

I only lightly reviewed but it looks sane. One part that that needs consideration is how .cue files are now added directly instead of magically substituted when another format with a matching filename is added. I do like adding the .cue directly but you probably need to keep and invert the "matching filename" logic to instead exclude the media file. Otherwise :add ~/Music will also add the un-cut-up .flac (or whatever).

@ihy123

ihy123 commented Feb 15, 2025

Copy link
Copy Markdown
Contributor Author

Yeah, I think the only way to correctly add a directory with Cue files is to

  1. add all Cue files and exclude audio files which were mentioned in these
  2. add all remaining files

I checked Audacious source and they implement it in the same way.

Also, am I right that playlist files (.pl, .m3u) don't need this special treatment?

@BoostCookie

Copy link
Copy Markdown

I suspect that #1397 will be fixed by this pull request. Can't say for sure because there's no Cue file attached to it.

Hello. I opened this issue.
I just tried out your merge request and unfortunately the problem still persists.
In the attachments you can find my two example cue files and the ffprobe output of the corresponding mka file. One has TrueHD audio with Atmos, the other one has DTS. If you send me an email I can provide you with the mka files.
examples.zip

@ihy123

ihy123 commented Feb 16, 2025

Copy link
Copy Markdown
Contributor Author

I tried this on a directory with 100+ Cue files in different subdirs and it worked, so it's ready for review

@BoostCookie

Copy link
Copy Markdown

Hello,
in my issue
#1397
I have a suggestion that would fix it.

Suggestion: When going from track n to track n+1, and both tracks are in the same file, then cmus should not seek the start of track n+1, but instead continue playing the file.

Otherwise to get accurate seeks one would need to

  1. Seek to the time timestamp that is right before the specified time in the cue sheet
  2. Use the sampling rate to calculate the exact number of frames one needs to go forward from there, including the consideration that the timestamp is rounded.
  3. Play from this exact frame.

What do you think?

@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.

Seems fine to me. I only really looked at the scan logic, as I'm not qualified to test or review the cue stuff (and someone else has already tried it), and since the scanning works, the impact on other formats is minimal.

@pgaskin

pgaskin commented Aug 20, 2025

Copy link
Copy Markdown
Member

@flyingmutant rebase merge?

@flyingmutant
flyingmutant force-pushed the cue branch 2 times, most recently from 2f36931 to 6d0cd8f Compare August 25, 2025 15:43
@flyingmutant

Copy link
Copy Markdown
Member

I am almost sure associated_cue mechanism that 791d190 removes served some real purpose, but it has been a long time since I've used cue files in any form. Anyone actively using cue care to weight in?

@flyingmutant

Copy link
Copy Markdown
Member

@ihy123 can you please explain the logic behind 6d0cd8f?

@ihy123

ihy123 commented Aug 30, 2025

Copy link
Copy Markdown
Contributor Author

I am almost sure associated_cue mechanism that 791d190 removes served some real purpose, but it has been a long time since I've used cue files in any form. Anyone actively using cue care to weight in?

This comment explains its purpose well #1406 (comment)
But 5b98d29 + 6d0cd8f remove the need for it

@ihy123

ihy123 commented Aug 30, 2025

Copy link
Copy Markdown
Contributor Author

@ihy123 can you please explain the logic behind 6d0cd8f?

Sure:
From add_dir() we call:

  • dir_list_recursive() to do just that
  • ptr_array_sort(), ptr_array_unique() to
    • remove duplicates. Don't remember why exactly (something with symlinks?), might be unnecessary
    • for binary search that handle_cue_files() does
  • handle_cue_files() to remove files that are mentioned in cues from the whole list

This is not an elegant solution, but I don't know of a better one yet. My main goal was to remove the associated cue mechanism, because it's counter-intuitive (see commit message of a87da7e)

@flyingmutant

Copy link
Copy Markdown
Member

I am almost sure associated_cue mechanism that 791d190 removes served some real purpose, but it has been a long time since I've used cue files in any form. Anyone actively using cue care to weight in?

This comment explains its purpose well #1406 (comment) But 5b98d29 + 6d0cd8f remove the need for it

If I have a folder with a bunch of music podcast MP3's + CUE files for them, and I just :add the whole folder, I would have separate entries for each MP3 and each CUE item for each MP3, right?

1. Multiple FILEs are now allowed.
Multiple FILE directives with same file name are treated as different files.

2. Track numbers may not start at 1 and may not be sequential, but still
must be ordered (this is just to make program simpler).
Example:
3, 6, 7 - correct;
3, 2, 7 - incorrect;
1, 1 - incorrect.
PREGAP and POSTGAP directives tell how much silence (that is not present
in the audio file) to add to the track.
This definitely should be handled in input plugin instead of the parser.
When cue sheet is written for a lossy audio source, ip_duration may
return an estimation. We shouldn't take it as end_offset.
Now Cue file can be added like `:add file.cue`
Imagine we have a directory with these files:
test.cue
test.wav
cd.wav

test.cue content:
FILE "cd.wav" WAVE
  TRACK 01 AUDIO

When we do `:add test.wav`, cd.wav is added to the library instead of
test.wav. Obviously it wasn't user's intention.

I think if the user wants to add a Cue file, then they would just write
`:add test.cue`. This 'associated cue' mechanism seems obsolete.
@ihy123

ihy123 commented Sep 3, 2025

Copy link
Copy Markdown
Contributor Author

mp3 files mentioned in cues will be added as cue items, standalone files will be added as standalone files.

@BoostCookie

Copy link
Copy Markdown

My issue #1397 was fixed by #1444, btw.

@flyingmutant

Copy link
Copy Markdown
Member

I am conflicted about changing the handling of .cue files. I am not a huge fan of how it was done, but the previous behavior had an important property: :add ~/Music is more DWIM. Adding two entries for MP3-by-itself and MP3-from-cue is IMO rarely what one wants: when CUE sheet exists, information in it is usually a strict superset of what is in the music file itself. I am open to changing my mind here, but whatever the solution is, it should be consistent with DWIM :add ~/Music spirit, whatever DWIM is.

@ihy123

ihy123 commented Sep 8, 2025

Copy link
Copy Markdown
Contributor Author

There's been a misunderstanding. Everything works same as before except that cue files can be added directly now. Associated cue stuff was needed to not include same audio file twice (as standalone file and cue entry), now this is accomplished by reading FILE directives from cue and not adding these files the second time after they have been added as cue entries. This also allows to support cue files with multiple FILE directives, for example:

TITLE album
FILE "track1.flac" WAVE
  TRACK 01 AUDIO
    TITLE track1
    INDEX 01 00:00:00
FILE "track2.flac" WAVE
  TRACK 02 AUDIO
    TITLE track2
    INDEX 01 00:00:00

@flyingmutant
flyingmutant merged commit 0788a07 into cmus:master Sep 9, 2025
@flyingmutant

Copy link
Copy Markdown
Member

Thanks a lot!

@ihy123
ihy123 deleted the cue branch September 9, 2025 15:14
@BrewTestBot BrewTestBot mentioned this pull request Oct 28, 2026
1 task done
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Nov 2, 2026
https://build.opensuse.org/request/show/1394501
by user mia + anag_factory
- Update to 2.13.0
  * Set the minimum requested AAudio buffer capacity
    gh#cmus/cmus#1386
  * Check for libavutil pkg-config
    gh#cmus/cmus#1388
  * Add sort by duration
    gh#cmus/cmus#1440
  * Respect scroll_offset setting when resizing window
    gh#cmus/cmus#1413
  * Try to fallback to any plugin upon failure to init output
    plugin
    gh#cmus/cmus#1416
  * PulseAudio bugfixes and APPLICATION_ID
    gh#cmus/cmus#1405
  * ip/ffmpeg fixes and ffmpeg 8.0 support
    gh#cmus/cmus#1444
  * CUE handling improvements and replaygain/genre support
    gh#cmus/cmus#1406
  * Fix for missing Icecast streaming bitrate display.
    gh#cmus/cmus#1451
  * op/mixer_alsa: alsamixer's volume scale; setting mixer control
    like aplay does it
    gh#cmus/cmus#1445
  * ip/ffmpeg: fix seeking and
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.

5 participants