@@ -3,7 +3,7 @@ use std::sync::Arc;
33use notation_bevy_utils:: prelude:: { DoLayoutEvent , GridData , LayoutData , ShapeOp } ;
44use notation_midi:: prelude:: PlayControlEvent ;
55use notation_model:: prelude:: {
6- LaneEntry , PlayState , PlayingState , Position , Tab , TabBarProps , TickResult ,
6+ LaneEntry , PlayState , PlayingState , Position , Tab , TickResult ,
77} ;
88
99use bevy:: prelude:: * ;
@@ -51,9 +51,9 @@ impl PlayPlugin {
5151 commands : & mut Commands ,
5252 theme : & NotationTheme ,
5353 entity : Entity ,
54- tab : & Tab ,
54+ tab : & Arc < Tab > ,
5555 ) {
56- let bar_data = BarIndicatorData :: new ( ) ;
56+ let bar_data = BarIndicatorData :: new ( tab . clone ( ) ) ;
5757 bar_data. create ( commands, & theme, entity) ;
5858 let pos_data = PosIndicatorData :: new ( tab. bar_units ( ) ) ;
5959 pos_data. create ( commands, & theme, entity) ;
@@ -73,21 +73,24 @@ fn update_indicators(
7373 & LayoutData ,
7474 & Arc < GridData > ,
7575 ) > ,
76- bar_props : TabBarProps ,
76+ bar_playing : & BarPlaying ,
7777 bar_layout : LayoutData ,
7878) {
79- for ( entity, mut data) in bar_indicator_query. iter_mut ( ) {
80- data. bar_props = bar_props;
81- data. bar_layout = bar_layout;
82- data. update ( commands, & theme, entity) ;
83- }
79+ let bar_props = bar_playing. bar_props ;
80+ let mut in_bar_pos = None ;
8481 for ( entity, mut data) in pos_indicator_query. iter_mut ( ) {
8582 data. bar_props = bar_props;
8683 data. bar_layout = bar_layout;
8784 data. update ( commands, & theme, entity) ;
8885 settings
8986 . layout
9087 . focus_bar ( commands, theme, tab_bars_query, & data) ;
88+ in_bar_pos = Some ( data. bar_position . in_bar_pos ) ;
89+ }
90+ for ( entity, mut data) in bar_indicator_query. iter_mut ( ) {
91+ data. bar_props = bar_props;
92+ data. bar_layout = bar_layout;
93+ data. update_data ( commands, theme, entity, bar_props, bar_layout, in_bar_pos) ;
9194 }
9295}
9396
@@ -136,7 +139,7 @@ fn on_tab_resized(
136139 & mut bar_indicator_query,
137140 & mut pos_indicator_query,
138141 & mut tab_bars_query,
139- playing. bar_props ,
142+ playing,
140143 layout. clone ( ) ,
141144 ) ;
142145 }
@@ -167,7 +170,7 @@ fn on_bar_playing_changed(
167170 & mut bar_indicator_query,
168171 & mut pos_indicator_query,
169172 & mut tab_bars_query,
170- playing. bar_props ,
173+ playing,
171174 layout. clone ( ) ,
172175 ) ;
173176 break ;
@@ -218,6 +221,7 @@ fn on_tick(
218221 commands : & mut Commands ,
219222 theme : & NotationTheme ,
220223 settings : & mut NotationSettings ,
224+ bar_indicator_query : & mut Query < ( Entity , & mut BarIndicatorData ) , With < BarIndicatorData > > ,
221225 pos_indicator_query : & mut Query < ( Entity , & mut PosIndicatorData ) , With < PosIndicatorData > > ,
222226 bar_playing_query : & mut Query < ( Entity , & mut BarPlaying ) , With < BarPlaying > > ,
223227 entry_playing_query : & mut Query <
@@ -247,25 +251,28 @@ fn on_tick(
247251 if * stopped {
248252 tab_state. set_play_state ( commands, state_entity, PlayState :: Stopped ) ;
249253 } else {
250- if let Some ( pos_data) =
251- PosIndicatorData :: update_pos ( commands, theme, pos_indicator_query, * new_position)
252- {
253- if settings. layout . mode == LayoutMode :: Line && pos_data. is_synced ( ) {
254- settings
255- . layout
256- . focus_bar ( commands, theme, tab_bars_query, & pos_data) ;
257- }
258- }
259254 let playing_bar_ordinal = new_position. bar . bar_ordinal ;
260255 BarPlaying :: update ( bar_playing_query, tab_state, playing_bar_ordinal) ;
261- ChordPlaying :: update ( chord_playing_query, tab_state, new_position) ;
262256 EntryPlaying :: update_with_pos (
263257 entry_playing_query,
264258 tab_state,
265259 new_position,
266260 * end_passed,
267261 * jumped,
268262 ) ;
263+ let chord_changed = ChordPlaying :: update ( chord_playing_query, tab_state, new_position) ;
264+ if let Some ( pos_data) =
265+ PosIndicatorData :: update_pos ( commands, theme, pos_indicator_query, * new_position)
266+ {
267+ if settings. layout . mode == LayoutMode :: Line && pos_data. is_synced ( ) {
268+ settings
269+ . layout
270+ . focus_bar ( commands, theme, tab_bars_query, & pos_data) ;
271+ }
272+ if chord_changed > 0 {
273+ BarIndicatorData :: update_pos ( commands, theme, bar_indicator_query, pos_data. bar_props , pos_data. bar_position . in_bar_pos ) ;
274+ }
275+ }
269276 }
270277}
271278
@@ -275,6 +282,7 @@ fn on_play_control_evt(
275282 mut settings : ResMut < NotationSettings > ,
276283 mut evts : EventReader < PlayControlEvent > ,
277284 mut tab_state_query : Query < ( Entity , & mut TabState ) > ,
285+ mut bar_indicator_query : Query < ( Entity , & mut BarIndicatorData ) , With < BarIndicatorData > > ,
278286 mut pos_indicator_query : Query < ( Entity , & mut PosIndicatorData ) , With < PosIndicatorData > > ,
279287 mut bar_playing_query : Query < ( Entity , & mut BarPlaying ) , With < BarPlaying > > ,
280288 mut entry_playing_query : Query <
@@ -304,6 +312,7 @@ fn on_play_control_evt(
304312 & mut commands,
305313 & theme,
306314 & mut settings,
315+ & mut bar_indicator_query,
307316 & mut pos_indicator_query,
308317 & mut bar_playing_query,
309318 & mut entry_playing_query,
0 commit comments