Skip to content

Commit 19664d8

Browse files
committed
use up and down key to move a whole row
1 parent d7c5058 commit 19664d8

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

apps/notation_viewer/assets/kb/en-US/usage.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
- *Page Down* jump to the first bar of next section
1414
- *Left* jump to last bar
1515
- *Right* jump to next bar
16-
- *Down* play one guitar note (same as clicking on guitar fretboard)
16+
- *Up* jump to last row
17+
- *Down* jump to next row
18+
- *\`* play one guitar note (same as clicking on guitar fretboard)
1719

1820
# Keyboard Shortcuts - Play Control
1921
- *Space* play or pause

apps/notation_viewer/assets/kb/zh-CN/usage.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
- *Page Down* 跳转到下一段落的第一个小节
1414
- *Left* 跳转到上一小节
1515
- *Right* 跳转到下一小节
16-
- *Down* 触发一个吉他音符 (也可以鼠标单击吉他指板)
16+
- *Up* 跳转到上一行
17+
- *Down* 跳转到下一行
18+
- *\`* 触发一个吉他音符 (也可以鼠标单击吉他指板)
1719

1820
# 快捷键 - 播放控制
1921
- *Space* 开始或暂停

apps/notation_viewer/src/viewer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl NotationViewer {
5757
mut play_control_evts: EventWriter<PlayControlEvent>,
5858
mut window_resized_evts: EventWriter<WindowResizedEvent>,
5959
mut jump_to_bar_evts: EventWriter<JumpToBarEvent>,
60+
tab_bars_query: Query<(&TabBars, &GridData), With<TabBars>>,
6061
) {
6162
if egui_ctx.ctx().wants_keyboard_input() {
6263
return;
@@ -98,7 +99,11 @@ impl NotationViewer {
9899
MidiControl::jump_to_prev_bar(&midi_state, &mut jump_to_bar_evts);
99100
} else if keyboard_input.just_released(KeyCode::Right) {
100101
MidiControl::jump_to_next_bar(&midi_state, &mut jump_to_bar_evts);
102+
} else if keyboard_input.just_released(KeyCode::Up) {
103+
MidiControl::jump_to_prev_row(&midi_state, &mut jump_to_bar_evts, &tab_bars_query);
101104
} else if keyboard_input.just_released(KeyCode::Down) {
105+
MidiControl::jump_to_next_row(&midi_state, &mut jump_to_bar_evts, &tab_bars_query);
106+
} else if keyboard_input.just_released(KeyCode::Grave) {
102107
MidiControl::seek_forward(&midi_settings, &mut midi_state, &mut play_control_evts);
103108
} else if keyboard_input.just_released(KeyCode::Minus) {
104109
Control::toggle_layout_mode(&mut app_state, &mut settings, &mut theme);

crates/notation_bevy/src/midi/midi_control.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use std::sync::Arc;
22

33
use bevy::prelude::*;
4+
use notation_bevy_utils::prelude::GridData;
45
use notation_midi::prelude::{MidiSettings, MidiState};
56
use notation_model::play::play_control::TickResult;
67
use notation_model::prelude::{JumpToBarEvent, PlayControlEvent, BarPosition, Tab, Units};
78
use notation_model::tab_bar::TabBar;
89

10+
use crate::tab::tab_bars::TabBars;
911
use crate::tab::tab_plugin::{TabPlugin};
1012

1113
use crate::prelude::{NotationSettings};
@@ -221,6 +223,42 @@ impl MidiControl {
221223
None
222224
});
223225
}
226+
pub fn get_grid_cols(
227+
tab_bars_query: &Query<(&TabBars, &GridData), With<TabBars>>,
228+
) -> usize {
229+
for (_tab_bars, grid_data) in tab_bars_query.iter() {
230+
return grid_data.cols;
231+
}
232+
2
233+
}
234+
pub fn jump_to_prev_row(
235+
midi_state: &MidiState,
236+
jump_to_bar_evts: &mut EventWriter<JumpToBarEvent>,
237+
tab_bars_query: &Query<(&TabBars, &GridData), With<TabBars>>,
238+
) {
239+
Self::jump_to_bar(midi_state, jump_to_bar_evts, &|tab, pos| {
240+
let cols = Self::get_grid_cols(tab_bars_query);
241+
if pos.bar_ordinal > cols {
242+
tab.get_bar_of_ordinal(pos.bar_ordinal - cols)
243+
} else {
244+
tab.get_bar_of_ordinal(0)
245+
}
246+
});
247+
}
248+
pub fn jump_to_next_row(
249+
midi_state: &MidiState,
250+
jump_to_bar_evts: &mut EventWriter<JumpToBarEvent>,
251+
tab_bars_query: &Query<(&TabBars, &GridData), With<TabBars>>,
252+
) {
253+
Self::jump_to_bar(midi_state, jump_to_bar_evts, &|tab, pos| {
254+
let cols = Self::get_grid_cols(tab_bars_query);
255+
if pos.bar_ordinal < tab.bars.len() - cols {
256+
tab.get_bar_of_ordinal(pos.bar_ordinal + cols)
257+
} else {
258+
tab.get_bar_of_ordinal(tab.bars.len() - 1)
259+
}
260+
});
261+
}
224262
pub fn send_begin_end_evt(
225263
midi_state: &mut MidiState,
226264
play_control_evts: &mut EventWriter<PlayControlEvent>,

0 commit comments

Comments
 (0)