Skip to content

Commit 3641b23

Browse files
committed
extracted Control & Alt seek speed control to audio.rs handle_seek_system
1 parent 5f00bb1 commit 3641b23

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/audio.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,24 @@ fn handle_seek_system(
112112
handle: Res<InstanceHandle>,
113113
mut audio_instances: ResMut<Assets<AudioInstance>>,
114114
mut events: EventReader<SeekEvent>,
115+
keyboard: Res<ButtonInput<KeyCode>>,
115116
) {
116117
if let Some(instance) = audio_instances.get_mut(&handle.0) {
117118
for event in events.read() {
119+
// holding Control will seek faster and holding Alt will seek slower
120+
let mut factor = 1.0;
121+
if keyboard.pressed(KeyCode::ControlLeft) {
122+
factor *= 2.0;
123+
}
124+
if keyboard.pressed(KeyCode::AltLeft) {
125+
factor /= 2.0;
126+
}
118127
match instance.state() {
119128
PlaybackState::Paused { position }
120129
| PlaybackState::Pausing { position }
121130
| PlaybackState::Playing { position }
122131
| PlaybackState::Stopping { position } => {
123-
instance.seek_to((position as f32 + event.0).max(0.0).into());
132+
instance.seek_to((position as f32 + event.0 * factor).max(0.0).into());
124133
}
125134
PlaybackState::Queued | PlaybackState::Stopped => {}
126135
}

src/timing.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,27 @@ impl Plugin for TimingPlugin {
3535
.add_event::<SeekEvent>()
3636
.add_systems(Update, space_pause_resume_control.run_if(project_loaded()))
3737
.add_systems(Update, progress_control_system.run_if(project_loaded()))
38-
.add_systems(Update, scroll_progress_control_system.run_if(project_loaded()));
38+
.add_systems(
39+
Update,
40+
scroll_progress_control_system.run_if(project_loaded()),
41+
);
3942
}
4043
}
4144

42-
/// Use ArrowLeft and ArrowRight to control the progress. Holding Control will seek faster and holding Alt will seek slower
45+
/// Use ArrowLeft and ArrowRight to control the progress
4346
fn progress_control_system(
4447
keyboard: Res<ButtonInput<KeyCode>>,
4548
mut events: EventWriter<SeekEvent>,
4649
) {
47-
let mut factor = 1.0;
48-
if keyboard.pressed(KeyCode::ControlLeft) {
49-
factor *= 2.0;
50-
}
51-
if keyboard.pressed(KeyCode::AltLeft) {
52-
factor /= 2.0;
53-
}
5450
if keyboard.pressed(KeyCode::ArrowLeft) {
55-
events.send(SeekEvent(-0.02 * factor));
51+
events.send(SeekEvent(-0.02));
5652
}
5753
if keyboard.pressed(KeyCode::ArrowRight) {
58-
events.send(SeekEvent(0.02 * factor));
54+
events.send(SeekEvent(0.02));
5955
}
6056
}
6157

62-
/// Scroll on the timeline to control the progress. Holding Control will seek faster and holding Alt will seek slower
58+
/// Scroll on the timeline to control the progress
6359
fn scroll_progress_control_system(
6460
mut wheel_events: EventReader<MouseWheel>,
6561
mut events: EventWriter<SeekEvent>,

0 commit comments

Comments
 (0)