Files
simple-multimidia-track-aud…/src/application/use_cases/adjust_sync.rs
T
Felipe 1ef47b3a07 feat: add AdjustExistingTrackDrift use case to adjust drift scale of existing tracks
- Implemented AdjustExistingTrackDrift struct with execute method to modify drift scale of existing tracks in a project.
- Added tests for adjusting drift scale, handling non-existent track IDs, and invalid scale values.
- Updated MediaTrackInfo and AudioTrack entities to include drift_scale field.
- Enhanced Project entity with needs_mkvmerge method to determine if mkvmerge is required based on drift scale.
- Integrated drift scale adjustments into existing track list UI, allowing users to modify drift values.
- Updated various use cases and UI components to support drift scale functionality, including add audio/subtitle forms and batch processing.
- Implemented mkvmerge availability check and integrated it into the application workflow for conditional processing.
2026-03-01 12:01:39 -03:00

62 lines
1.9 KiB
Rust

use crate::domain::entities::Project;
use crate::domain::value_objects::{SyncOffset, TrackId};
use anyhow::{Result, anyhow};
/// Ajusta o offset de sincronização de uma faixa externa existente pelo TrackId.
#[allow(dead_code)]
pub struct AdjustSync;
impl AdjustSync {
#[allow(dead_code)]
pub fn execute(project: &mut Project, id: TrackId, offset: SyncOffset) -> Result<()> {
let track = project
.find_track_mut(id)
.ok_or_else(|| anyhow!("Faixa não encontrada: {:?}", id))?;
track.set_offset(offset);
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::application::use_cases::add_audio_track::AddAudioTrack;
use crate::domain::entities::{MkvOutput, Project, VideoFile};
use crate::domain::value_objects::{FilePath, TrackLanguage};
#[test]
fn ajusta_offset_existente() {
let mut project = Project::new(
VideoFile::new(FilePath::from("input.mkv")),
MkvOutput::new(FilePath::from("output.mkv")),
)
.unwrap();
let lang = TrackLanguage::new("por").unwrap();
AddAudioTrack::execute(
&mut project,
FilePath::from("audio.aac"),
SyncOffset::default(),
lang,
false,
String::new(),
1.0,
)
.unwrap();
let id = project.tracks[0].id();
AdjustSync::execute(&mut project, id, SyncOffset::from_ms(1200)).unwrap();
assert_eq!(project.tracks[0].offset().as_ms(), 1200);
}
#[test]
fn erro_se_id_inexistente() {
let mut project = Project::new(
VideoFile::new(FilePath::from("input.mkv")),
MkvOutput::new(FilePath::from("output.mkv")),
)
.unwrap();
let result = AdjustSync::execute(&mut project, TrackId::new(99), SyncOffset::from_ms(500));
assert!(result.is_err());
}
}