Skip to content

Commit

Permalink
Add serde feature
Browse files Browse the repository at this point in the history
  • Loading branch information
zeozeozeo committed Nov 29, 2023
1 parent a21fd9b commit 2baeaee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ edition = "2021"
[dependencies]
cpal = { version = "0.15.2", optional = true }
log = "0.4.20"
serde = { version = "1.0.193", features = ["derive"], optional = true }
symphonia = { version = "0.5.3", features = ["all"], optional = true }
thiserror = "1.0.50"

[features]
default = ["use-symphonia", "playback"]
use-symphonia = ["symphonia"] # Audio decoding support with [`symphonia`].
playback = ["cpal"] # Audio playback support with [`cpal`].
# Disable this if you want to use kittyaudio purely as an audio library.
# Disable this if you want to use kittyaudio purely as an audio library.
4 changes: 4 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ fn sine_in_out(t: f32) -> f32 {

/// Specifies what easing function to use.
#[derive(Debug, Copy, Clone, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Easing {
/// Linear easing.
#[default]
Expand Down Expand Up @@ -432,6 +433,7 @@ impl Easing {

/// Specifies what change to make to a [`crate::Sound`]. Used with [`Command`].
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Change {
/// Change volume value.
Volume(f32),
Expand All @@ -449,6 +451,7 @@ pub enum Change {
/// A command that specifies an action that is applied on a [`crate::Sound`]
/// with an optional tween.
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Command {
/// What variable to change.
pub change: Change,
Expand Down Expand Up @@ -516,6 +519,7 @@ impl Tweenable for usize {
/// A parameter (used in [`crate::Sound`]) that implements tweening the
/// underlying value.
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Parameter<T: Tweenable> {
/// Last tweened value. If no commands are running, this is the same as
/// the previous value.
Expand Down
2 changes: 2 additions & 0 deletions src/sound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use symphonia::core::{

/// Represents an audio sample. Stores a left and right channel.
#[derive(Debug, Copy, Clone, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Frame {
/// Left channel value. Float.
pub left: f32,
Expand Down Expand Up @@ -145,6 +146,7 @@ impl Neg for Frame {

/// Specifies how quickly the sound is played.
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PlaybackRate {
/// The sound is playing at a speed factor of the original sample rate.
///
Expand Down

0 comments on commit 2baeaee

Please sign in to comment.