Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
xasopheno committed Jun 23, 2023
1 parent b2e64d8 commit de0f8c0
Show file tree
Hide file tree
Showing 22 changed files with 689 additions and 183 deletions.
13 changes: 12 additions & 1 deletion ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct FunDef {
#[derive(Clone, PartialEq, Debug, Hash)]
pub enum Op {
AsIs,
Out,
Id(String),
Tag(String),
//
Expand All @@ -24,6 +25,9 @@ pub enum Op {
scales: Vec<Scale>,
},
//
FMOsc {
defs: Vec<FmOscDef>,
},
Lowpass {
hash: String,
cutoff_frequency: Rational64,
Expand Down Expand Up @@ -125,7 +129,13 @@ pub enum Op {
},
}

#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Ord, PartialOrd, Hash, Eq)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Hash, Ord, PartialOrd, Eq)]
pub struct FmOscDef {
pub fm: Rational64,
pub depth: Rational64,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Hash, Ord, PartialOrd, Eq)]
/// Oscillator Type
pub enum OscType {
None,
Expand All @@ -134,6 +144,7 @@ pub enum OscType {
Square { width: Option<Rational64> },
Noise,
Saw,
Fm { defs: Vec<FmOscDef> },
}

impl OscType {
Expand Down
1 change: 1 addition & 0 deletions ast/src/datagen/mod_1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub fn eeg_datum_to_point_op(
osc_type: OscType::None,
names: nameset,
filters: vec![],
is_out: false,
}
}

Expand Down
2 changes: 1 addition & 1 deletion ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod nameset;
pub mod operations;
pub mod term;
pub use crate::{
ast::{FunDef, Op, Op::*, OscType, ASR},
ast::{FmOscDef, FunDef, Op, Op::*, OscType, ASR},
datagen::Scale,
generator::{
coefs::{Coef, Coefs},
Expand Down
2 changes: 2 additions & 0 deletions ast/src/operations/get_length_ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ impl GetLengthRatio<Term> for Op {
) -> Result<Rational64, Error> {
match self {
Op::AsIs {}
| Op::Out {}
| Op::Lowpass { .. }
| Op::FMOsc { .. }
| Op::Highpass { .. }
| Op::Bandpass { .. }
| Op::AD { .. }
Expand Down
3 changes: 3 additions & 0 deletions ast/src/operations/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub fn pad_length(
osc_type: OscType::None,
names: NameSet::new(),
filters: vec![],
is_out: false,
});
}
}
Expand Down Expand Up @@ -114,6 +115,7 @@ pub fn join_sequence(mut l: NormalForm, mut r: NormalForm) -> NormalForm {
osc_type: OscType::None,
names: NameSet::new(),
filters: vec![],
is_out: false,
}])
}
}
Expand All @@ -134,6 +136,7 @@ pub fn join_sequence(mut l: NormalForm, mut r: NormalForm) -> NormalForm {
osc_type: OscType::None,
names: NameSet::new(),
filters: vec![],
is_out: false,
}])
}
}
Expand Down
17 changes: 13 additions & 4 deletions ast/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub struct PointOp {
pub names: NameSet,
/// Filters
pub filters: Vec<BiquadFilterDef>,
/// Should fade out to nothing
pub is_out: bool,
}

impl Default for PointOp {
Expand All @@ -69,6 +71,7 @@ impl Default for PointOp {
osc_type: OscType::None,
names: NameSet::new(),
filters: vec![],
is_out: false,
}
}
}
Expand Down Expand Up @@ -229,6 +232,7 @@ impl Mul<PointOp> for PointOp {
.chain(&other.filters)
.map(|f| f.to_owned())
.collect(),
is_out: other.is_out,
}
}
}
Expand All @@ -252,9 +256,9 @@ impl<'a, 'b> Mul<&'b PointOp> for &'a PointOp {
other.reverb
},
osc_type: if other.osc_type.is_none() {
self.osc_type
self.osc_type.clone()
} else {
other.osc_type
other.osc_type.clone()
},
attack: self.attack * other.attack,
decay: self.decay * other.decay,
Expand All @@ -267,6 +271,7 @@ impl<'a, 'b> Mul<&'b PointOp> for &'a PointOp {
.chain(&other.filters)
.map(|f| f.to_owned())
.collect(),
is_out: other.is_out,
}
}
}
Expand All @@ -288,7 +293,7 @@ impl MulAssign for PointOp {
other.reverb
},
osc_type: if other.osc_type == OscType::None {
self.osc_type
self.osc_type.clone()
} else {
other.osc_type
},
Expand All @@ -303,6 +308,7 @@ impl MulAssign for PointOp {
.chain(&other.filters)
.map(|f| f.to_owned())
.collect(),
is_out: other.is_out,
}
}
}
Expand Down Expand Up @@ -334,7 +340,7 @@ impl PointOp {
other.reverb
},
osc_type: if other.osc_type.is_none() {
self.osc_type
self.osc_type.clone()
} else {
other.osc_type
},
Expand All @@ -349,6 +355,7 @@ impl PointOp {
.chain(&other.filters)
.map(|f| f.to_owned())
.collect(),
is_out: other.is_out,
}
}

Expand All @@ -368,6 +375,7 @@ impl PointOp {
osc_type: OscType::None,
names: NameSet::new(),
filters: vec![],
is_out: false,
}
}
pub fn init_silent() -> PointOp {
Expand All @@ -386,6 +394,7 @@ impl PointOp {
osc_type: OscType::None,
names: NameSet::new(),
filters: vec![],
is_out: false,
}
}

Expand Down
14 changes: 14 additions & 0 deletions ast/src/operations/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ impl Normalize<Term> for Op {
) -> Result<(), Error> {
match self {
Op::AsIs => {}
Op::Out => {
input.fmap_mut(|op| {
op.is_out = true;
op.fm = Ratio::new(0, 1);
op.fa = Ratio::new(0, 1);
op.g = Ratio::new(0, 1);
op.l = Ratio::new(0, 1)
});
}
Op::Lambda {
term,
input_name,
Expand All @@ -37,6 +46,11 @@ impl Normalize<Term> for Op {
handle_id_error(id, defs)?.apply_to_normal_form(input, defs)?;
}

Op::FMOsc { defs } => input.fmap_mut(|op| {
op.osc_type = OscType::Fm {
defs: defs.to_owned(),
}
}),
Op::Lowpass {
hash,
cutoff_frequency,
Expand Down

0 comments on commit de0f8c0

Please sign in to comment.