@@ -7,7 +7,7 @@ use iced::{
77} ;
88
99use crate :: {
10- audio:: { get_volume_at, interpolate, interpolation_factor, AudioTime , WavFileReader } ,
10+ audio:: { get_volume_at, interpolate, interpolation_factor, AudioTime , CutInfo , WavFileReader } ,
1111 song:: Song ,
1212} ;
1313
@@ -21,11 +21,13 @@ const MARKER_COLOR: Color = Palette::GRUVBOX_DARK.primary;
2121
2222pub struct Plot {
2323 data : Vec < Point > ,
24- _song_before : Option < Song > ,
25- _song_after : Option < Song > ,
24+ song_before : Option < Song > ,
25+ song_after : Option < Song > ,
2626 start : AudioTime ,
2727 end : AudioTime ,
2828 cut_time : AudioTime ,
29+ finished_cut_before : bool ,
30+ finished_cut_after : bool ,
2931}
3032
3133impl Plot {
@@ -48,11 +50,13 @@ impl Plot {
4850 . collect ( ) ;
4951 Self {
5052 data,
51- _song_before : song_before,
52- _song_after : song_after,
53+ song_before,
54+ song_after,
5355 start,
5456 end,
5557 cut_time,
58+ finished_cut_before : false ,
59+ finished_cut_after : false ,
5660 }
5761 }
5862
@@ -64,16 +68,34 @@ impl Plot {
6468 WIDTH * interpolation_factor ( self . start , self . end , time) as f32
6569 }
6670
67- pub fn get_plot_path ( & self ) -> Path {
71+ pub fn get_plot_path ( & self , data : & [ Point ] ) -> Path {
6872 let mut path = Builder :: new ( ) ;
6973
70- path. move_to ( self . data [ 0 ] ) ;
71- for point in self . data . iter ( ) {
72- path. line_to ( * point) ;
74+ if data. len ( ) > 0 {
75+ path. move_to ( data[ 0 ] ) ;
76+ for point in data. iter ( ) {
77+ path. line_to ( * point) ;
78+ }
7379 }
7480 path. build ( )
7581 }
7682
83+ /// Return the path left of the marker and the path right
84+ /// of the marker, so they can be colored individually.
85+ pub fn get_plot_paths ( & self ) -> ( Path , Path ) {
86+ let cutoff = self
87+ . data
88+ . iter ( )
89+ . enumerate ( )
90+ . find ( |( _, p) | self . pos_to_time ( * * p) > self . cut_time )
91+ . map ( |( i, _) | i)
92+ . unwrap_or ( self . data . len ( ) - 1 ) ;
93+ (
94+ self . get_plot_path ( & self . data [ ..=cutoff] ) ,
95+ self . get_plot_path ( & self . data [ cutoff..] ) ,
96+ )
97+ }
98+
7799 pub fn get_marker_path ( & self ) -> Path {
78100 let mut path = Builder :: new ( ) ;
79101 let x = self . time_to_pos ( self . cut_time ) ;
@@ -84,6 +106,17 @@ impl Plot {
84106
85107 pub fn set_cut_position ( & mut self , time : AudioTime ) {
86108 self . cut_time = time;
109+ self . finished_cut_before = false ;
110+ self . finished_cut_after = false ;
111+ }
112+
113+ pub fn update_on_finished_cut ( & mut self , cut_song : & CutInfo ) {
114+ if self . song_before . as_ref ( ) == Some ( & cut_song. cut . song ) {
115+ self . finished_cut_before = true ;
116+ }
117+ if self . song_after . as_ref ( ) == Some ( & cut_song. cut . song ) {
118+ self . finished_cut_after = true ;
119+ }
87120 }
88121}
89122
@@ -126,12 +159,25 @@ impl Program<PlotMarkerMoved> for Plot {
126159 ) -> Vec < Geometry > {
127160 let mut frame = Frame :: new ( renderer, bounds. size ( ) ) ;
128161
129- let plot = self . get_plot_path ( ) ;
162+ let ( plot_before, plot_after) = self . get_plot_paths ( ) ;
163+ let color = |finished_cutting| {
164+ if finished_cutting {
165+ Color :: from_rgb ( 0.0 , 0.8 , 0.0 )
166+ } else {
167+ PLOT_COLOR
168+ }
169+ } ;
170+ frame. stroke (
171+ & plot_before,
172+ Stroke :: default ( )
173+ . with_width ( PLOT_STROKE_WIDTH )
174+ . with_color ( color ( self . finished_cut_before ) ) ,
175+ ) ;
130176 frame. stroke (
131- & plot ,
177+ & plot_after ,
132178 Stroke :: default ( )
133179 . with_width ( PLOT_STROKE_WIDTH )
134- . with_color ( PLOT_COLOR ) ,
180+ . with_color ( color ( self . finished_cut_after ) ) ,
135181 ) ;
136182 let marker = self . get_marker_path ( ) ;
137183 frame. stroke (
0 commit comments