Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ standalone = [
embedded = ["dep:maolan-engine", "maolan-engine?/audio"]

[dependencies]
maolan-engine = { version = "0.4.22", optional = true }
maolan-engine = { version = "0.4.24", optional = true }
oxideav-core = { version = "0.1.43", optional = true }
oxideav-basic = { version = "0.0.12", optional = true }
oxideav-flac = { version = "0.0.13", optional = true }
Expand All @@ -45,7 +45,6 @@ serde = { version = "1.0", features = ["derive"] }
rubato = "5.1.0"
serde_json = "1.0.154"
tokio = { version = "1.54.1", features = ["sync", "time"] }
toml = "1.2.1"

[target.'cfg(target_os = "linux")'.dependencies]
alsa = { version = "0.12.1", optional = true }
Expand Down
54 changes: 38 additions & 16 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::io::{
};
use crate::io::{document_status, load_audio_buffer};
use crate::markers::detect_markers;
#[cfg(target_os = "freebsd")]
use crate::preferences::EditorPreferences;
use crate::transport::{
play_standalone, prepare_document_track, refresh_standalone_playhead, reset_after_close,
Expand Down Expand Up @@ -637,7 +638,7 @@ fn update_message(app: &mut EditApp, message: Message) -> Task<Message> {
app.status = document_status(&audio);
app.playing = false;
app.playhead_samples = 0;
app.waveform_view = None;
app.waveform_view = initial_waveform_view(&audio);
app.engine_clip_path = None;
app.selection_anchor_samples = None;
app.selection_samples = None;
Expand Down Expand Up @@ -974,13 +975,21 @@ fn update_message(app: &mut EditApp, message: Message) -> Task<Message> {
};
app.setup.output_device = dialog.output_device.clone();
app.setup.input_device = dialog.input_device.clone();
let preferences = EditorPreferences {
default_output_device_id: dialog.output_device.map(|device| device.id),
default_input_device_id: dialog.input_device.map(|device| device.id),
};
match preferences.save() {
Ok(()) => app.status = String::from("Preferences saved."),
Err(err) => app.status = format!("Failed to save preferences: {err}"),
#[cfg(target_os = "freebsd")]
{
let mut preferences = EditorPreferences::default();
preferences
.set_default_output_device_id(dialog.output_device.map(|device| device.id));
preferences
.set_default_input_device_id(dialog.input_device.map(|device| device.id));
match crate::preferences::save(&preferences) {
Ok(()) => app.status = String::from("Preferences saved."),
Err(err) => app.status = format!("Failed to save preferences: {err}"),
}
}
#[cfg(not(target_os = "freebsd"))]
{
app.status = String::from("Audio preferences apply to this session only.");
}
Task::none()
}
Expand Down Expand Up @@ -1085,6 +1094,15 @@ fn set_selection_boundary(app: &mut EditApp, value: &str, is_start: bool) -> Tas
Task::none()
}

fn initial_waveform_view(audio: &AudioDocument) -> Option<(f32, f32)> {
const INITIAL_VIEW_SECONDS: f64 = 5.0 * 60.0;
let duration = audio.frames() as f64 / audio.sample_rate.max(1) as f64;
(duration > INITIAL_VIEW_SECONDS).then(|| {
let visible = (INITIAL_VIEW_SECONDS / duration) as f32;
(0.0, visible.clamp(f32::EPSILON, 1.0))
})
}

fn nearest_zero_crossing(audio: &crate::document::AudioDocument, target: usize) -> Option<usize> {
let channels = audio.channels.max(1);
let frames = audio.preview_samples.len() / channels;
Expand Down Expand Up @@ -1186,6 +1204,8 @@ fn materialize_edits(audio: &mut crate::document::AudioDocument) {
mod tests {
use super::*;
use crate::document::test_document;
#[cfg(not(target_os = "freebsd"))]
use crate::preferences::EditorPreferences;

fn app_with_markers(markers: Vec<(usize, String)>, frames: usize) -> EditApp {
let mut audio = test_document(vec![0.0f32; frames], 1);
Expand Down Expand Up @@ -1243,14 +1263,16 @@ mod tests {
fn waveform_zoom_out_clamps_to_full_document() {
let mut app = app_with_markers(Vec::new(), 100);
app.waveform_view = Some((0.25, 0.5));
let _ = update(
&mut app,
Message::WaveformZoom {
delta_y: -10.0,
cursor_ratio: 0.5,
viewport_width: 100.0,
},
);
for _ in 0..3 {
let _ = update(
&mut app,
Message::WaveformZoom {
delta_y: -10.0,
cursor_ratio: 0.5,
viewport_width: 100.0,
},
);
}
assert_eq!(app.waveform_view, None);
}

Expand Down
24 changes: 11 additions & 13 deletions src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ impl StartupSetup {
) -> Self {
let audio_engine = AudioEngineOption::default();
let output_device = preferences
.default_output_device_id
.as_deref()
.default_output_device_id()
.and_then(|id| {
output_devices
.iter()
Expand All @@ -161,8 +160,7 @@ impl StartupSetup {
})
.or_else(|| output_devices.first().cloned());
let input_device = preferences
.default_input_device_id
.as_deref()
.default_input_device_id()
.and_then(|id| input_devices.iter().find(|device| device.id == id).cloned())
.or_else(|| input_devices.first().cloned());
let mut setup = Self {
Expand All @@ -187,7 +185,7 @@ impl StartupSetup {

impl Default for StartupSetup {
fn default() -> Self {
let preferences = EditorPreferences::load();
let preferences = crate::preferences::load();
let audio_engine = AudioEngineOption::default();
let output_devices = discover_output_audio_devices(audio_engine);
let input_devices = discover_input_audio_devices(audio_engine);
Expand Down Expand Up @@ -776,10 +774,10 @@ mod tests {

#[test]
fn startup_setup_with_preferences_selects_saved_devices() {
let preferences = EditorPreferences {
default_output_device_id: Some(String::from("out2")),
default_input_device_id: Some(String::from("in2")),
};
let preferences = EditorPreferences::from_toml_str(
"default_output_device_id = \"out2\"\ndefault_input_device_id = \"in2\"\n",
)
.unwrap();
let output_devices = vec![
AudioDeviceOption::with_supported_caps("out1", "Out One", vec![32], vec![48_000]),
AudioDeviceOption::with_supported_caps("out2", "Out Two", vec![32], vec![48_000]),
Expand All @@ -803,10 +801,10 @@ mod tests {

#[test]
fn startup_setup_with_preferences_falls_back_to_first_device() {
let preferences = EditorPreferences {
default_output_device_id: Some(String::from("missing")),
default_input_device_id: Some(String::from("missing")),
};
let preferences = EditorPreferences::from_toml_str(
"default_output_device_id = \"missing\"\ndefault_input_device_id = \"missing\"\n",
)
.unwrap();
let output_devices = vec![AudioDeviceOption::with_supported_caps(
"out1",
"Out One",
Expand Down
Loading
Loading