Overview
Audio clips represent instances of audio files placed on the timeline. Each clip contains a reference to the audio data, waveform visualization, and timing information.AudioClip Class
TheAudioClip class (~/workspace/source/Lumix/Clips/AudioClips/AudioClip.cs:10) extends the base Clip class to provide audio-specific functionality.
Key Properties
| Property | Type | Description |
|---|---|---|
Clip | AudioClipData | Reference to the underlying audio data |
WaveFormImage | IntPtr | Cached waveform visualization |
StartTick | long | Timeline position in ticks |
DurationTicks | long | Clip duration in ticks |
StartMarker | long | Trimmed portion from start (in ticks) |
EndMarker | long | Trimmed portion from end (in ticks) |
Name | string | Clip name (derived from filename) |
Color | Vector4 | Clip color (inherited from track) |
Enabled | bool | Whether the clip is active |
Construction
AudioClipData Class
TheAudioClipData class (~/workspace/source/Lumix/Clips/AudioClips/AudioClipData.cs:5) wraps the audio file reader and wave channel.
Properties
- AudioFileReader: NAudio’s file reader for decoding audio
- Wave32: 32-bit wave channel for processing
Clip Timing
Clips use a sophisticated timing system based on both ticks and musical time.Time Formats
Clip Width Calculation
- Audio file duration in seconds
- Converted to ticks based on tempo
- Multiplied by current zoom level (pixels per tick)
Waveform Visualization
Each clip displays a visual representation of its audio waveform.Waveform Data Structure
- samples: Raw audio sample data
- peaks: Maximum values for each pixel column
- valleys: Minimum values for each pixel column
Rendering
Dynamic Resizing
Waveform data is recalculated when zoom changes:Waveform data is cached and only regenerated when the clip width changes, optimizing performance during playback.
Clip Operations
Positioning
Clips snap to grid when positioned:Duplication
Clips can be duplicated with Ctrl+D:Moving Between Tracks
Clips can be dragged between tracks:Splitting (Planned Feature)
The clip splitting functionality is implemented but currently commented out:Clip States
Enable/Disable
Clips can be individually enabled or disabled:- Enabled: Clip plays normally with full color
- Disabled: Clip is skipped during playback, rendered in grayscale
Selection
Multiple clips can be selected for batch operations:- Click to select single clip
- Shift+Click to add to selection
- Time selection area to select all clips in range
Playback Integration
When a clip needs to play:- Creating a new
AudioFileReaderinstance - Seeking to the start offset
- Creating a sample provider with proper duration
- Adding to the mixer
Clip Menu Options
Right-click on a clip to access:| Action | Shortcut | Description |
|---|---|---|
| Cut | Ctrl+X | Cut clip to clipboard |
| Copy | Ctrl+C | Copy clip to clipboard |
| Duplicate | Ctrl+D | Create a copy |
| Delete | Del | Remove clip |
| Split | Ctrl+E | Split at playhead |
| Rename | Ctrl+R | Change clip name |
| Activate/Deactivate | 0 | Toggle enabled state |
| Color Picker | - | Change clip color |
Clip Markers and Trimming
Clips support non-destructive trimming:- StartMarker: Trims audio from the beginning
- EndMarker: Trims audio from the end
Visual Feedback
Hover Effects
When hovering over a clip’s menu bar:- Cursor changes to a hand icon
- Clip can be dragged
- Double-click to open in editor (when implemented)
Dragging
While dragging:- Clip follows mouse position
- Snaps to grid based on quantization settings
- Visual feedback shows new position
Selection Highlighting
Selected clips are rendered with a distinct selection color:Performance Considerations
Waveform Caching
Waveform Caching
Waveform peak data is calculated once and cached. Only recalculated when zoom changes significantly.
Audio File Instances
Audio File Instances
Each clip holds a single
AudioClipData reference. New AudioFileReader instances are created only during playback.Rendering Optimization
Rendering Optimization
Clips are rendered using ImGui child windows for efficient clipping and input handling.
Best Practices
Organization
- Use meaningful clip names
- Color-code related clips
- Keep clips organized on appropriate tracks
Editing
- Use markers for non-destructive trimming
- Duplicate before making major changes
- Use time selection for precise operations
Performance
- Disable unused clips instead of deleting
- Use consolidation for complex arrangements
- Monitor waveform cache size on long sessions
Workflow
- Double-click clips to open editor
- Use keyboard shortcuts for faster editing
- Group related clips using time selection
Related Components
- Base Clip Class:
~/workspace/source/Lumix/Clips/Clip.cs - Waveform Renderer: Used for visualization
- TimeLineV2: Timing and conversion utilities
Next Steps
Audio Tracks
Understand how tracks manage clips
Audio Engine
Learn about audio playback and processing