Set timestamp on newline
This commit is contained in:
parent
eddf56ae64
commit
31d59fd0ee
|
@ -101,6 +101,18 @@ impl Controls {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the current position of the playhead
|
||||||
|
///
|
||||||
|
/// If there was an error, this will be `None`. In all other cases, this will return
|
||||||
|
/// `Some`.
|
||||||
|
pub fn position(&self) -> Option<Duration> {
|
||||||
|
if let NoError { player, .. } = &self.error_state {
|
||||||
|
Some(player.position())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Program<Message> for (&Controls, Theme) {
|
impl Program<Message> for (&Controls, Theme) {
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl Editor {
|
||||||
self.lyrics.insert_text(text);
|
self.lyrics.insert_text(text);
|
||||||
}
|
}
|
||||||
pub fn handle_lyric_event(&mut self, line_no: usize, kind: LyricEvent) {
|
pub fn handle_lyric_event(&mut self, line_no: usize, kind: LyricEvent) {
|
||||||
self.lyrics.handle_event(line_no, kind)
|
self.lyrics.handle_event(line_no, kind, || self.controls.position())
|
||||||
}
|
}
|
||||||
pub fn current_line_mut(&mut self) -> (usize, &mut Lyric) {
|
pub fn current_line_mut(&mut self) -> (usize, &mut Lyric) {
|
||||||
self.lyrics.current_line_mut()
|
self.lyrics.current_line_mut()
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl Lyrics {
|
||||||
self.lines[line_no + n_pieces].select();
|
self.lines[line_no + n_pieces].select();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_event(&mut self, line_no: usize, kind: LyricEvent) {
|
pub fn handle_event(&mut self, line_no: usize, kind: LyricEvent, timestamp: impl Fn() -> Option<Duration>) {
|
||||||
match kind {
|
match kind {
|
||||||
LyricEvent::LyricChanged(newval) => {
|
LyricEvent::LyricChanged(newval) => {
|
||||||
self.update_line(newval, line_no)
|
self.update_line(newval, line_no)
|
||||||
|
@ -79,7 +79,7 @@ impl Lyrics {
|
||||||
self.lines[line_no].timestamp_update(newval)
|
self.lines[line_no].timestamp_update(newval)
|
||||||
},
|
},
|
||||||
LyricEvent::LineAdvanced => {
|
LyricEvent::LineAdvanced => {
|
||||||
self.advance_line(line_no)
|
self.advance_line(line_no, timestamp())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ impl Lyrics {
|
||||||
self.lines[line_no].value = new_content;
|
self.lines[line_no].value = new_content;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn advance_line(&mut self, current_line: usize) {
|
pub fn advance_line(&mut self, current_line: usize, timestamp: Option<Duration>) {
|
||||||
let new_line = current_line + 1;
|
let new_line = current_line + 1;
|
||||||
|
|
||||||
let line = if new_line == self.lines.len() {
|
let line = if new_line == self.lines.len() {
|
||||||
|
@ -100,9 +100,11 @@ impl Lyrics {
|
||||||
|
|
||||||
line.select();
|
line.select();
|
||||||
|
|
||||||
self.lines.get_mut(current_line)
|
let previous_line = self.lines.get_mut(current_line).unwrap();
|
||||||
.unwrap()
|
previous_line.deselect();
|
||||||
.deselect();
|
if let Some(timestamp) = timestamp {
|
||||||
|
previous_line.set_timestamp(timestamp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_line(&mut self, index: usize, content: Option<String>) -> &mut Lyric {
|
pub fn insert_line(&mut self, index: usize, content: Option<String>) -> &mut Lyric {
|
||||||
|
@ -245,6 +247,15 @@ impl Lyric {
|
||||||
self.timestamp_state.unfocus();
|
self.timestamp_state.unfocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_timestamp(&mut self, timestamp: Duration) {
|
||||||
|
self.timestamp = timestamp;
|
||||||
|
let seconds = timestamp.as_secs();
|
||||||
|
let minutes = seconds / 60;
|
||||||
|
let seconds = seconds % 60;
|
||||||
|
let millis = timestamp.as_millis() % 1000;
|
||||||
|
self.timestamp_raw = format!("{}:{:02}.{:03}", minutes, seconds, millis);
|
||||||
|
}
|
||||||
|
|
||||||
pub (crate) fn timestamp_update(&mut self, newval: String) {
|
pub (crate) fn timestamp_update(&mut self, newval: String) {
|
||||||
if let Some((shift, validated)) = Self::clean_timestamp(newval) {
|
if let Some((shift, validated)) = Self::clean_timestamp(newval) {
|
||||||
self.timestamp = dbg!(Self::parse_validated_timestamp(&validated));
|
self.timestamp = dbg!(Self::parse_validated_timestamp(&validated));
|
||||||
|
|
Loading…
Reference in a new issue