Skip to content

Commit

Permalink
Handle bad notes in note container
Browse files Browse the repository at this point in the history
 * Fix deserialization of synth voice presets
  • Loading branch information
Ameobea committed Feb 1, 2025
1 parent 51ad5d9 commit 70d7ff3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions backend/src/models/synth_preset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub struct FilterParams {
pub q: Option<f64>,
#[serde(default)]
pub gain: f64,
#[serde(default)]
pub detune: f64,
}

Expand Down
3 changes: 3 additions & 0 deletions engine/note_container/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#![feature(vec_into_raw_parts)]

#[macro_use]
extern crate log;

pub mod exports;
pub mod note_container;
pub mod note_lines;
16 changes: 13 additions & 3 deletions engine/note_container/src/note_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,19 @@ impl NoteContainer {
}

pub fn add_note(&mut self, start_point: f64, note: Note) {
assert!(note.length.is_normal() && note.length > 0.);
assert!(start_point >= 0.);
println!("Inserting {:?} at {}", note, start_point);
debug_assert!(note.length.is_normal() && note.length > 0.);
if !note.length.is_normal() {
error!(
"Tried to add note with invalid length of {}; ignoring",
note.length
);
return;
}
debug_assert!(start_point >= 0.);
if start_point < 0. {
error!("Found note with invalid start point of {start_point}; ignoring");
return;
}

let end_point = start_point + note.length;
// We check to see if there are any notes intersecting the point we're trying to insert
Expand Down

0 comments on commit 70d7ff3

Please sign in to comment.