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 ability to trim audio clips from start position #3291

Draft
wants to merge 17 commits into
base: community
Choose a base branch
from

Conversation

m0nkmaster
Copy link

@m0nkmaster m0nkmaster commented Jan 16, 2025

Add ability to trim audio clips from their start position

Feature Description

Adds the ability to trim audio clips from their start position in Audio Clip View, similar to the existing end-position trimming functionality. This gives users more control over audio sample editing directly from the grid interface.

Currently to trim the beginning of an audio clip you need a workaround by reversing the clip, see:
https://www.youtube.com/watch?v=iWhVUsx40Mg&t=108s&ab_channel=RonCavagnaro

Implementation Details

  • Added start marker functionality in AudioClipView that mirrors existing end marker behaviour
  • Added changeUnderlyingSampleStart() method to handle start position adjustments
  • Modified pad action handling to support start marker selection and adjustment
  • Added runtime feature flag TrimFromStartOfAudioClip to control availability of this feature

Changes

  • Added start marker visual feedback (green blinking column) when selecting start position
  • Start marker can be toggled by tapping the first column of the audio clip
  • Changing the start marker adjusts the clip's start position while maintaining end position
  • Sample length is automatically recalculated based on new start position
  • Changes are tracked in action history for undo/redo support

Acceptance Criteria

  • Start marker should be toggleable by tapping first column of clip
  • Start marker should blink green when active
  • Pressing a pad to the right should trim from start of clip
  • Changes should be undoable/redoable
  • Reversed samples should maintain correct behavior
  • Minimum clip length of 1 tick should be enforced
  • Feature should be toggleable via community settings
  • Visual feedback should be clear and consistent with existing UI patterns7
  • Is non destructive - reversing audio will allow you to re-introduce trimmed start audio

Testing Notes

  • Test with both normal and reversed samples
  • Check interaction with existing end marker functionality
  • Verify undo/redo behaviour
  • Test with various sample lengths and clip settings spanning multiple bars
  • Test on both OLED and 7SEG display devices
  • Reversing audio will allows you to re-introduce trimmed start audio

Demo

https://youtu.be/9S2BkhaB50c

- Adjusted visibility logic for start and end markers to enhance user interaction.
- Updated rendering logic to differentiate between blinking and static marker states.
- Improved comments for clarity and maintenance.
- Implemented non-destructive start trimming functionality, allowing for better audio editing.
- Fixed minor issues related to marker toggling and display updates.

This commit builds upon the initial implementation of start trimming and enhances the overall user experience in the audio clip view.
Copy link
Contributor

github-actions bot commented Jan 16, 2025

Test Results

107 tests  ±0   107 ✅ ±0   0s ⏱️ -1s
 16 suites ±0     0 💤 ±0 
 16 files   ±0     0 ❌ ±0 

Results for commit e499b93. ± Comparison against base commit c3c3918.

♻️ This comment has been updated with latest results.

…s, allowing for more flexible audio editing.

- Fixed issues related to marker toggling.

TODO - Currently trimming from the start results in the prior audio becoming hidden and the new play head moves to column one. Should change this so the new playhead does not move and the hidden audio is greyed out.
@m0nkmaster m0nkmaster changed the title Audio trimming at start Add ability to trim audio clips from start position Jan 17, 2025
@m0nkmaster
Copy link
Author

This is the first iteration. Ideally I would like to change the behaviour slightly so that when you trigger Start Trimming Mode and click a new column to the right, the view doesn't jump to make that new start column one. Instead you'd see the columns to the left greyed out - the same behaviour as when editing the end. But it's a little bit tricky to work out how that would affect playback. It introduces the concept of columns before the start of playback i.e. minus (<0) columns. I need to think about that. I know that the green column always jumping to be col one is a bit of a jaunting experience.

However, as undo is implemented, it's pretty natural to quickly step back if you've cropped too much audio.

Copy link
Collaborator

@stellar-aria stellar-aria left a comment

Choose a reason for hiding this comment

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

Not a true review, just some little style and QoL things I saw on a quick browse

}

// Or if yes Sample...
else {
AudioClip* clip = getCurrentAudioClip();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If clip is assumed to be valid (i.e. not nullptr) after this point, it should be a reference.

Suggested change
AudioClip* clip = getCurrentAudioClip();
AudioClip& clip = *getCurrentAudioClip();

Note that all uses of it will need to be changed from arrow syntax to dot syntax

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it needs to be checked before making a reference - we shouldn't end up here without the current clip being an audio clip but it's probably possible, in which case getCurrentAudioClip returns a nullptr

Copy link
Author

Choose a reason for hiding this comment

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

I'm not super familiar with C++, I've given it a go updating to use references where possible and ensure we have checked for null, see what you think.

src/deluge/gui/views/audio_clip_view.cpp Outdated Show resolved Hide resolved
src/deluge/gui/views/audio_clip_view.cpp Outdated Show resolved Hide resolved
src/deluge/gui/views/audio_clip_view.cpp Outdated Show resolved Hide resolved
src/deluge/gui/views/audio_clip_view.cpp Outdated Show resolved Hide resolved
src/deluge/gui/views/audio_clip_view.cpp Outdated Show resolved Hide resolved
src/deluge/gui/views/audio_clip_view.cpp Outdated Show resolved Hide resolved
src/deluge/gui/views/audio_clip_view.cpp Show resolved Hide resolved
src/deluge/gui/views/audio_clip_view.cpp Outdated Show resolved Hide resolved
src/deluge/gui/views/audio_clip_view.cpp Outdated Show resolved Hide resolved
@m0nkmaster
Copy link
Author

Recommended changes implemented

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.

3 participants