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.
This commit is contained in:
2026-03-01 12:01:39 -03:00
parent 285f22e2d1
commit 1ef47b3a07
31 changed files with 1081 additions and 62 deletions
+85
View File
@@ -0,0 +1,85 @@
use crate::domain::entities::Project;
use crate::domain::value_objects::TrackId;
use anyhow::{Result, anyhow};
/// Ajusta o fator de escala temporal (drift) de uma faixa externa pelo TrackId.
///
/// Um `scale != 1.0` indica que o projeto precisará usar o pipeline mkvmerge.
#[allow(dead_code)]
pub struct AdjustDrift;
impl AdjustDrift {
#[allow(dead_code)]
pub fn execute(project: &mut Project, id: TrackId, scale: f64) -> Result<()> {
if scale <= 0.0 {
return Err(anyhow!("O fator de escala deve ser maior que zero: {}", scale));
}
let track = project
.find_track_mut(id)
.ok_or_else(|| anyhow!("Faixa não encontrada: {:?}", id))?;
track.set_drift_scale(scale);
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::application::use_cases::add_audio_track::AddAudioTrack;
use crate::domain::entities::{MkvOutput, VideoFile};
use crate::domain::value_objects::{FilePath, SyncOffset, TrackLanguage};
fn make_project() -> Project {
Project::new(
VideoFile::new(FilePath::from("input.mkv")),
MkvOutput::new(FilePath::from("output.mkv")),
)
.unwrap()
}
#[test]
fn ajusta_drift_existente() {
let mut p = make_project();
let lang = TrackLanguage::new("por").unwrap();
AddAudioTrack::execute(
&mut p,
FilePath::from("audio.aac"),
SyncOffset::default(),
lang,
false,
String::new(),
1.0,
)
.unwrap();
let id = p.tracks[0].id();
AdjustDrift::execute(&mut p, id, 0.99983).unwrap();
assert!((p.tracks[0].drift_scale() - 0.99983).abs() < 1e-9);
}
#[test]
fn erro_se_id_inexistente() {
let mut p = make_project();
let result = AdjustDrift::execute(&mut p, TrackId::new(99), 0.99983);
assert!(result.is_err());
}
#[test]
fn erro_se_scale_zero() {
let mut p = make_project();
let lang = TrackLanguage::new("por").unwrap();
AddAudioTrack::execute(
&mut p,
FilePath::from("audio.aac"),
SyncOffset::default(),
lang,
false,
String::new(),
1.0,
)
.unwrap();
let id = p.tracks[0].id();
let result = AdjustDrift::execute(&mut p, id, 0.0);
assert!(result.is_err());
}
}