The session hands the subtitle lane the rate a project does not know
Browse files at this commit6a02fb1e36a9e195c5536d756a5eea139131e209Parent: 79d449c- feat
- the session hands the subtitle lane the rate a project does not know
1 changed file +77 -4
crates/engine/src/playback.rsmodified+77 -4
| @@ -26,7 +26,7 @@ use crate::colorspace::ColorDescription; | |||
| 26 | use crate::decode::{Backend, BackendCell, DecodeSession, Frame, Worker}; | 26 | use crate::decode::{Backend, BackendCell, DecodeSession, Frame, Worker}; |
| 27 | use crate::demux::{Codec, Demuxer, VideoMeta}; | 27 | use crate::demux::{Codec, Demuxer, VideoMeta}; |
| 28 | use crate::eq::EqParams; | 28 | use crate::eq::EqParams; |
| 29 | -use crate::project::{Clip, Edge, Lane, LaneKind, Project, Rate, Source, Span, Speed}; | 29 | +use crate::project::{Clip, Edge, Lane, LaneKind, Project, Rate, Source, Span, Speed, SubClip}; |
| 30 | use crate::scale::{Composer, FitPolicy}; | 30 | use crate::scale::{Composer, FitPolicy}; |
| 31 | 31 | ||
| 32 | /// How long the feeder waits out a full ring. The ring holds a second, so this | 32 | /// How long the feeder waits out a full ring. The ring holds a second, so this |
| @@ -1207,15 +1207,19 @@ impl PlaybackSession { | |||
| 1207 | /// own remove goes through, the way [`import_subtitles`]( | 1207 | /// own remove goes through, the way [`import_subtitles`]( |
| 1208 | /// Self::import_subtitles) is the door that puts one on. Refused in | 1208 | /// Self::import_subtitles) is the door that puts one on. Refused in |
| 1209 | /// [`Project::remove_subtitles`]'s words for a row this timeline does not | 1209 | /// [`Project::remove_subtitles`]'s words for a row this timeline does not |
| 1210 | - /// have. | 1210 | + /// have, and for one a caption on a subtitle lane still plays -- delete |
| 1211 | + /// those placements first, or the words under them would change. | ||
| 1211 | /// | 1212 | /// |
| 1212 | /// Nothing playable changes and no worker was opened against a cue, so | 1213 | /// Nothing playable changes and no worker was opened against a cue, so |
| 1213 | /// unlike [`remove_source`](Self::remove_source) this does not reseek. Rows | 1214 | /// unlike [`remove_source`](Self::remove_source) this does not reseek. Rows |
| 1214 | /// past `idx` move down by one: a caller holding a picked row (the export's | 1215 | /// past `idx` move down by one: a caller holding a picked row (the export's |
| 1215 | - /// subtitle pick) has to fix it up or drop it. Not an undo step, for the | 1216 | + /// subtitle pick) has to fix it up or drop it; the placements on the lanes |
| 1217 | + /// are walked down with it and need no fixing. Not an undo step, for the | ||
| 1216 | /// reason [`Project::remove_subtitles`] gives -- the way back is | 1218 | /// reason [`Project::remove_subtitles`] gives -- the way back is |
| 1217 | /// [`import_subtitles`](Self::import_subtitles), which reads a file's | 1219 | /// [`import_subtitles`](Self::import_subtitles), which reads a file's |
| 1218 | - /// subtitles and touches nothing else on the timeline. | 1220 | + /// subtitles and touches nothing else on the timeline -- and it *empties* |
| 1221 | + /// the undo history, because the steps in it name the tracks by the indexes | ||
| 1222 | + /// this call just changed. | ||
| 1219 | pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> { | 1223 | pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> { |
| 1220 | self.project.remove_subtitles(idx) | 1224 | self.project.remove_subtitles(idx) |
| 1221 | } | 1225 | } |
| @@ -1696,6 +1700,75 @@ impl PlaybackSession { | |||
| 1696 | Some(moved) | 1700 | Some(moved) |
| 1697 | } | 1701 | } |
| 1698 | 1702 | ||
| 1703 | + /// The subtitle lanes in display order -- `S1..Sn`, the rows a front-end | ||
| 1704 | + /// lays out beside the picture and sound ones | ||
| 1705 | + /// ([`Project::subtitle_lanes`]). Empty until something adds one, which is | ||
| 1706 | + /// [`add_lane`](Self::add_lane) with [`LaneKind::Subtitle`], and they come | ||
| 1707 | + /// off, move and reorder through the very same doors every other lane does. | ||
| 1708 | + pub fn subtitle_lanes(&self) -> Vec<Lane> { | ||
| 1709 | + self.project.subtitle_lanes() | ||
| 1710 | + } | ||
| 1711 | + | ||
| 1712 | + /// What is placed on one subtitle lane, in timeline order: what a front-end | ||
| 1713 | + /// draws as clips, each naming the palette row it plays | ||
| 1714 | + /// ([`Self::subtitles`]) and the window of it it keeps | ||
| 1715 | + /// ([`Project::sub_lane`]). | ||
| 1716 | + pub fn sub_lane(&self, lane: Lane) -> &[SubClip] { | ||
| 1717 | + self.project.sub_lane(lane) | ||
| 1718 | + } | ||
| 1719 | + | ||
| 1720 | + /// Places a stretch of a subtitle track on `lane` at timeline frame `at` | ||
| 1721 | + /// ([`Project::place_sub`], whose words a refusal is shown in). One undo | ||
| 1722 | + /// step. | ||
| 1723 | + /// | ||
| 1724 | + /// No reseek and no invalidation, which is what the whole wrapper layer is | ||
| 1725 | + /// here for: cues are drawn from [`sub_lane_cues`](Self::sub_lane_cues) | ||
| 1726 | + /// over whatever picture is on screen, so nothing already decoded stops | ||
| 1727 | + /// being right. | ||
| 1728 | + pub fn place_sub(&mut self, lane: Lane, at: u32, sub: SubClip) -> crate::Result<()> { | ||
| 1729 | + self.project.place_sub(lane, at, sub) | ||
| 1730 | + } | ||
| 1731 | + | ||
| 1732 | + /// Drags a placement to another subtitle lane or another frame | ||
| 1733 | + /// ([`Project::move_sub`]). One undo step, and `Ok` with none for a drop | ||
| 1734 | + /// that changed nothing. | ||
| 1735 | + pub fn move_sub(&mut self, from: Lane, idx: usize, to: Lane, start: u32) -> crate::Result<()> { | ||
| 1736 | + self.project.move_sub(from, idx, to, start) | ||
| 1737 | + } | ||
| 1738 | + | ||
| 1739 | + /// Drags one edge of a placement to timeline frame `to` | ||
| 1740 | + /// ([`Project::trim_sub`]), **at this timeline's own frame rate** -- a | ||
| 1741 | + /// placement's position is in frames while its words are in microseconds, | ||
| 1742 | + /// and the rate that joins them is the one thing a [`Project`] does not | ||
| 1743 | + /// know. That is why a front-end trims through this door and never converts | ||
| 1744 | + /// a cue's microseconds itself. One undo step. | ||
| 1745 | + pub fn trim_sub(&mut self, lane: Lane, idx: usize, edge: Edge, to: u32) -> crate::Result<()> { | ||
| 1746 | + self.project.trim_sub(lane, idx, edge, to, self.meta.frame_rate) | ||
| 1747 | + } | ||
| 1748 | + | ||
| 1749 | + /// How far that edge may travel, `(first, last)` timeline frame inclusive | ||
| 1750 | + /// ([`Project::trim_sub_room`]) -- what a front-end drawing the box during | ||
| 1751 | + /// a drag asks, at this timeline's rate. | ||
| 1752 | + pub fn trim_sub_room(&self, lane: Lane, idx: usize, edge: Edge) -> Option<(u32, u32)> { | ||
| 1753 | + self.project.trim_sub_room(lane, idx, edge, self.meta.frame_rate) | ||
| 1754 | + } | ||
| 1755 | + | ||
| 1756 | + /// Takes one placement off a subtitle lane, leaving a gap | ||
| 1757 | + /// ([`Project::lift_sub`]). One undo step; the palette row it played stays | ||
| 1758 | + /// on this timeline's list. | ||
| 1759 | + pub fn lift_sub(&mut self, lane: Lane, idx: usize) -> bool { | ||
| 1760 | + self.project.lift_sub(lane, idx) | ||
| 1761 | + } | ||
| 1762 | + | ||
| 1763 | + /// What that subtitle lane shows on *this* timeline, in start order | ||
| 1764 | + /// ([`Project::sub_lane_cues`] at this timeline's rate) -- the placed-clip | ||
| 1765 | + /// counterpart of [`timeline_cues`](Self::timeline_cues), which carries a | ||
| 1766 | + /// whole palette track through the spans that play its media. Pure, so a | ||
| 1767 | + /// front-end may ask it per repaint. | ||
| 1768 | + pub fn sub_lane_cues(&self, lane: Lane) -> Vec<crate::subtitle::Cue> { | ||
| 1769 | + self.project.sub_lane_cues(lane, self.meta.frame_rate) | ||
| 1770 | + } | ||
| 1771 | + | ||
| 1699 | /// Splits every lane at `timeline_secs`, so the two sides become two | 1772 | /// Splits every lane at `timeline_secs`, so the two sides become two |
| 1700 | /// groups. Metadata only: a split never changes the timeline->source | 1773 | /// groups. Metadata only: a split never changes the timeline->source |
| 1701 | /// mapping, so the running decoder stays correct and playback does not | 1774 | /// mapping, so the running decoder stays correct and playback does not |