Skip to content

Commit

Permalink
Support triggering in the envelope modulator, read more presets, lega…
Browse files Browse the repository at this point in the history
…cy Aftertouch modulator
  • Loading branch information
softdevca committed Jun 8, 2023
1 parent 673bb25 commit fd011ea
Show file tree
Hide file tree
Showing 68 changed files with 780 additions and 333 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/target

# The Cargo lock file should not be tracked for libraries.
/Cargo.lock

# MacOS trash
**/.DS_Store

# A place to store your personal notes.
TODO.txt
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

Unreleased changes.

# 0.2.1 (2036-06-07)

* Successfully read more factory presets.
* Support triggering for the envelope modulator.
* Convert any legacy Aftertouch modulators to Pressure modulators.
* Add mod wheel and modulator output modulation sources.

# 0.2.0 (2023-06-05)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[package]
name = "synthahol-phase-plant"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
authors = ["Sheldon Young <sheldon@softdev.ca>"]
description = "Read and write Phase Plant presets"
Expand Down
20 changes: 14 additions & 6 deletions src/effect/bitcrush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use uom::si::f32::{Frequency, Ratio};
use uom::si::frequency::hertz;
use uom::si::ratio::percent;

use crate::SnapinId;

use super::super::io::*;
use super::{Effect, EffectMode};

Expand Down Expand Up @@ -105,9 +107,12 @@ impl EffectRead for Bitcrush {

reader.expect_u32(0, "bitcrush_unknown_1")?;
reader.expect_u32(0, "bitcrush_unknown_2")?;
if effect_version >= 1047 {
reader.expect_u32(0, "bitcrush_unknown_3")?;
}

let group_id = if effect_version >= 1047 {
reader.read_snapin_position()?
} else {
None
};

let effect = Box::new(Bitcrush {
frequency,
Expand All @@ -119,7 +124,7 @@ impl EffectRead for Bitcrush {
mix,
});

Ok(EffectReadReturn::new(effect, enabled, minimized))
Ok(EffectReadReturn::new(effect, enabled, minimized, group_id))
}
}

Expand All @@ -129,6 +134,7 @@ impl EffectWrite for Bitcrush {
writer: &mut PhasePlantWriter<W>,
enabled: bool,
minimized: bool,
group_id: Option<SnapinId>,
) -> io::Result<()> {
writer.write_bool32(enabled)?;
writer.write_hertz(self.frequency)?;
Expand All @@ -142,9 +148,11 @@ impl EffectWrite for Bitcrush {

writer.write_u32(0)?;
writer.write_u32(0)?;

if self.write_version() >= 1048 {
writer.write_u32(0)?;
writer.write_snapin_id(group_id)?;
}

Ok(())
}

Expand Down Expand Up @@ -197,7 +205,7 @@ mod test {
let snapin = &preset.lanes[0].snapins[0];
assert!(snapin.enabled);
assert!(!snapin.minimized);
assert_eq!(snapin.position, 1);
assert_eq!(snapin.id, 1);
let effect = snapin.effect.as_bitcrush().unwrap();
assert_relative_eq!(effect.frequency.get::<hertz>(), 6000.0, epsilon = 3.0);
assert_eq!(effect.quantize.get::<percent>(), 100.0);
Expand Down
11 changes: 8 additions & 3 deletions src/effect/carve_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use uom::si::frequency::hertz;
use uom::si::ratio::percent;

use crate::version::Version;
use crate::Decibels;
use crate::{Decibels, SnapinId};

use super::super::io::*;
use super::{Effect, EffectMode};
Expand Down Expand Up @@ -278,18 +278,19 @@ impl EffectRead for CarveEq {

let mut preset_path = vec![];
if version_b_major > 5 {
// if effect_version > 1022 {
preset_path = reader.read_path()?;
trace!("carve eq: preset path {preset_path:?}");
}

let preset_edited = reader.read_bool32()?;
trace!("carve eq: preset edited {preset_edited}");

reader.expect_u8(0, "carve_eq_path_1")?;

let mix = reader.read_ratio()?;
let enabled = reader.read_bool32()?;
let minimized = reader.read_bool32()?;
trace!("carve eq: mix {mix:?} enabled {enabled} minimized {minimized}");

let mut shape = [[0_f32; Self::BAND_COUNT]; Self::CHANNEL_COUNT];
for band_idx in 0..Self::BAND_COUNT {
Expand Down Expand Up @@ -333,11 +334,13 @@ impl EffectRead for CarveEq {
}

reader.expect_u32(0, "carve_eq_unknown_22")?;

let mut group_id = None;
if effect_version < 1023 {
reader.expect_u32(0, "carve_eq_unknown_23")?;
reader.expect_u32(0, "carve_eq_unknown_24")?;
} else if effect_version >= 1034 {
reader.expect_u32(0, "carve_eq_unknown_23")?;
group_id = reader.read_snapin_position()?;
}

let effect = Box::new(CarveEq {
Expand All @@ -351,6 +354,7 @@ impl EffectRead for CarveEq {
effect,
enabled,
minimized,
group_id,
metadata: Default::default(),
preset_name,
preset_path,
Expand All @@ -365,6 +369,7 @@ impl EffectWrite for CarveEq {
writer: &mut PhasePlantWriter<W>,
enabled: bool,
_minimized: bool,
_group_id: Option<SnapinId>,
) -> io::Result<()> {
writer.write_bool8(enabled)?; // FIXME: Duplicate
writer.write_u8(0)?;
Expand Down
12 changes: 9 additions & 3 deletions src/effect/channel_mixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use std::io;
use std::io::{Error, ErrorKind, Read, Seek, Write};
use std::ops::RangeInclusive;

use crate::SnapinId;

use super::super::io::*;
use super::{Effect, EffectMode};

Expand Down Expand Up @@ -107,7 +109,8 @@ impl EffectRead for ChannelMixer {

reader.expect_u32(0, "channel_mixer_unknown_1")?;
reader.expect_u32(0, "channel_mixer_unknown_2")?;
reader.expect_u32(0, "channel_mixer_unknown_3")?;

let group_id = reader.read_snapin_position()?;

Ok(EffectReadReturn::new(
Box::new(ChannelMixer {
Expand All @@ -118,6 +121,7 @@ impl EffectRead for ChannelMixer {
}),
enabled,
minimized,
group_id,
))
}
}
Expand All @@ -128,6 +132,7 @@ impl EffectWrite for ChannelMixer {
writer: &mut PhasePlantWriter<W>,
enabled: bool,
_minimized: bool,
group_id: Option<SnapinId>,
) -> io::Result<()> {
writer.write_bool32(enabled)?;
writer.write_f32(self.left_to_left)?;
Expand All @@ -137,7 +142,8 @@ impl EffectWrite for ChannelMixer {

writer.write_u32(0)?; // channel_mixer_unknown_1
writer.write_u32(0)?; // channel_mixer_unknown_2
writer.write_u32(0)?; // channel_mixer_unknown_3

writer.write_snapin_id(group_id)?;

Ok(())
}
Expand Down Expand Up @@ -180,7 +186,7 @@ mod test {
let snapin = &preset.lanes[0].snapins[0];
assert!(snapin.enabled);
assert!(!snapin.minimized);
assert_eq!(snapin.position, 1);
assert_eq!(snapin.id, 1);
let effect = snapin.effect.as_channel_mixer().unwrap();
assert_eq!(effect, &Default::default());
}
Expand Down
16 changes: 12 additions & 4 deletions src/effect/chorus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use uom::si::frequency::hertz;
use uom::si::ratio::percent;
use uom::si::time::millisecond;

use crate::SnapinId;

use super::super::io::*;
use super::{Effect, EffectMode};

Expand Down Expand Up @@ -103,9 +105,12 @@ impl EffectRead for Chorus {

reader.expect_u32(0, "chorus_unknown_1")?;
reader.expect_u32(0, "chorus_unknown_2")?;
if effect_version >= 1046 {
reader.expect_u32(0, "chorus_unknown_3")?;
}

let group_id = if effect_version >= 1046 {
reader.read_snapin_position()?
} else {
None
};

Ok(EffectReadReturn::new(
Box::new(Chorus {
Expand All @@ -118,6 +123,7 @@ impl EffectRead for Chorus {
}),
enabled,
minimized,
group_id,
))
}
}
Expand All @@ -128,6 +134,7 @@ impl EffectWrite for Chorus {
writer: &mut PhasePlantWriter<W>,
enabled: bool,
minimized: bool,
group_id: Option<SnapinId>,
) -> io::Result<()> {
writer.write_bool32(enabled)?;
writer.write_seconds(self.delay)?;
Expand All @@ -140,7 +147,8 @@ impl EffectWrite for Chorus {

writer.write_u32(0)?; // chorus_unknown_1
writer.write_u32(0)?; // chorus_unknown_2
writer.write_u32(0)?; // chorus_unknown_3

writer.write_snapin_id(group_id)?;

Ok(())
}
Expand Down
17 changes: 13 additions & 4 deletions src/effect/comb_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use uom::si::f32::{Frequency, Ratio};
use uom::si::frequency::hertz;
use uom::si::ratio::percent;

use crate::SnapinId;

use super::super::io::*;
use super::{Effect, EffectMode};

Expand Down Expand Up @@ -84,9 +86,12 @@ impl EffectRead for CombFilter {

reader.expect_u32(0, "comb_filter_unknown_1")?;
reader.expect_u32(0, "comb_filter_unknown_2")?;
if effect_version >= 1047 {
reader.expect_u32(0, "comb_filter_unknown_3")?;
}

let group_id = if effect_version >= 1047 {
reader.read_snapin_position()?
} else {
None
};

Ok(EffectReadReturn::new(
Box::new(CombFilter {
Expand All @@ -97,6 +102,7 @@ impl EffectRead for CombFilter {
}),
enabled,
minimized,
group_id,
))
}
}
Expand All @@ -107,6 +113,7 @@ impl EffectWrite for CombFilter {
writer: &mut PhasePlantWriter<W>,
enabled: bool,
minimized: bool,
group_id: Option<SnapinId>,
) -> io::Result<()> {
writer.write_bool32(enabled)?;
writer.write_f32(self.frequency.get::<hertz>())?;
Expand All @@ -117,9 +124,11 @@ impl EffectWrite for CombFilter {

writer.write_u32(0)?;
writer.write_u32(0)?;

if self.write_version() >= 1048 {
writer.write_u32(0)?;
writer.write_snapin_id(group_id)?;
}

Ok(())
}

Expand Down
15 changes: 10 additions & 5 deletions src/effect/compressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use uom::si::ratio::percent;
use uom::si::time::millisecond;

use crate::effect::SidechainMode;
use crate::Decibels;
use crate::{Decibels, SnapinId};

use super::super::io::*;
use super::{Effect, EffectMode};
Expand Down Expand Up @@ -115,9 +115,11 @@ impl EffectRead for Compressor {
reader.expect_u32(0, "compressor_unknown_1")?;
reader.expect_u32(0, "compressor_unknown_2")?;

if effect_version > 1039 {
reader.expect_u32(0, "compressor_unknown_3")?;
}
let group_id = if effect_version > 1039 {
reader.read_snapin_position()?
} else {
None
};

let sidechain_id = reader.read_u32()?;
let sidechain_mode_str = reader.read_string_and_length()?;
Expand All @@ -141,6 +143,7 @@ impl EffectRead for Compressor {
}),
enabled,
minimized,
group_id,
))
}
}
Expand All @@ -151,6 +154,7 @@ impl EffectWrite for Compressor {
writer: &mut PhasePlantWriter<W>,
enabled: bool,
minimized: bool,
group_id: Option<SnapinId>,
) -> io::Result<()> {
writer.write_bool32(enabled)?;
writer.write_seconds(self.attack)?;
Expand All @@ -161,10 +165,10 @@ impl EffectWrite for Compressor {
writer.write_ratio(self.makeup)?;
writer.write_bool32(minimized)?;

writer.write_u32(0)?;
writer.write_u32(0)?;
writer.write_u32(0)?;

writer.write_snapin_id(group_id)?;
writer.write_u32(self.sidechain_mode as u32)?;
writer.write_string_and_length(self.sidechain_mode.to_string())
}
Expand Down Expand Up @@ -216,6 +220,7 @@ mod test {
#[test]
fn init() {
for file in &[
"compressor-1.8.0.phaseplant",
"compressor-1.8.5.phaseplant",
"compressor-1.8.13.phaseplant",
"compressor-2.0.12.phaseplant",
Expand Down

0 comments on commit fd011ea

Please sign in to comment.