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

Trim overlaps #50

Closed
wants to merge 3 commits into from
Closed

Conversation

mooseyboots
Copy link

i had a crack at implementing trimming overlapping subtitles and thought i would share what i came up with.

as per rndusr's recommendations, it includes

  • customize option to ask to trim on load
  • customize option to always trim on save
  • custom options and prefix args to trim by:
    • any number of milliseconds
    • the value of subed-subtitle-spacing, or
    • 1 millisecond
  • customize option to either trim end of current or start of next sub.

personally i only have experience with .srt subtitle files, so that is all i have used this with. i also don't know the codebase super well. but thought i would share my efforts nonetheless.

mousebot added 3 commits December 21, 2021 18:49
- option to check and ask to trim on load
- option to always trim on save
- trim end of current or start of next subtitle
- custom or prefix args to trim by:
  - any number of milliseconds
  - the value of subed-subtitle-spacing, or
  - 1 millisecond
whitespace
@sachac
Copy link
Owner

sachac commented Dec 21, 2021 via email

@mooseyboots
Copy link
Author

mooseyboots commented Dec 25, 2021

hey s, sure that's a good idea. i'm a silly noob with testing but am slowly getting the hang of it on another project. i'll just take a while to nut it out.

reference: #6

@sachac
Copy link
Owner

sachac commented Dec 26, 2021 via email

@sachac
Copy link
Owner

sachac commented Dec 29, 2021

Worked on some tests tonight and rewrote it to use the functions for adjusting time stop/start. Haven't pushed my changes yet, as I want to take another look when I'm less sleepy. :) I'm a little unsure about having all the options for controlling it. Are you okay if I simplify it to just use either msecs as a numeric argument or subed-subtitle-spacing, instead of having another way to control whether subed-subtitle-spacing is used? People can set subed-subtitle-spacing to 1 if they want stop times and start times to be at least 1 msec apart, or have a function that calls it with an arg. (I'll probably change my config to that, actually.) Would that still work for your use case?

@mooseyboots
Copy link
Author

hey, that's great to hear! it would have taken me days and days of work. i'm also happy if you modify what i proposed, i'm sure you'll improve it. in my use case, i just tend to use 1ms. i really just need to blast away all overlaps before i start editing, so the gap isn't that crucial for me. i kind of wrote what i wanted but then expanded it to fit rndusr's suggestions. it was also a way for me to start learning what (interactive) is capable of and how to tame it. it's great for me that you took a look at it, as i learn stuff when more experienced people edit my hacks.

sachac added a commit that referenced this pull request Dec 30, 2021
You can now trim subtitle overlaps with ~M-x subed-trim-overlaps~. By
default, this adjusts the stop time of overlapping subtitles to
~subed-subtitle-spacing~ milliseconds before the next subtitle
starts. Use ~M-x customize-group~ ~subed~ to configure trimming
to happen automatically when buffers are loaded or saved, which
time is adjusted, and how much time to leave between subtitles.

* README.org (Features): Document M-x subed-trim-overlaps.
* subed/subed-common.el:
(subed-trim-overlaps): New command that trims overlapping subtitles in
the current buffer.
(subed-trim-overlap-stop): New command that adjusts the stop time of
the current subtitle so that it stops before the next subtitle starts.
(subed-trim-overlap-next-start): New command that adjusts the start
time of the next subtitle so that it starts after the current subtitle
stops.
(subed-trim-overlap-check, subed-trim-overlap-maybe-sanitize,
subed-trim-overlap-maybe-check, subed-trim-overlap-stop, subed--identify-overlaps): New function.
* subed/subed-common.el (subed-sanitize-functions): Add
subed-trim-overlap-maybe-sanitize.
(subed-validate-functions): Add subed-trim-overlap-maybe-check.
* subed/subed-config.el (subed-trim-overlap-on-save,
subed-trim-overlap-check-on-save, subed-trim-overlap-check-on-load,
subed-trim-overlap-use-start): New user options.

Co-authored-by: mooseyboots / mousebot <mousebot@riseup.net>
Based on #50 with some
simplification and reuse.
@sachac
Copy link
Owner

sachac commented Dec 30, 2021

Okay, I think I've mostly gotten things sorted out with tests and stuff at a97a9e5 . I promise I didn't rename and fiddle with things just to be ornery. =) I wanted functions to be mostly discoverable with M-x, so I gave them (mostly) the subed-trim-overlap prefix. Customization options tend to be grouped alphabetically too, so I renamed them to be close together. I wanted to reuse the subed-adjust-subtitle-time-stop and -start functions because they seemed to have a fair bit of thought put into the logic. And then I ended up also tweaking how the sanitizing and validation functions were called so that we could have generic validation functions without having to add them to each of the specific validation functions...

Would you consider trying out this version and seeing if it works for you? It seems to pass the tests and it works interactively for me.

(Sorry for the somewhat heavy touch editing the code; I'm learning my way around maintaining subed too!)

@mooseyboots
Copy link
Author

hey, s, no probs, happy to defer to your hands.

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.

2 participants