Skip to content

Commit

Permalink
Playtime: Distinguish between fixed and dynamic section
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Nov 2, 2023
1 parent 7d163a4 commit c2db1a2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
2 changes: 1 addition & 1 deletion main/src/domain/targets/clip_management_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl RealearnTarget for ClipManagementTarget {
return Ok(HitResponse::ignored());
}
self.with_matrix(context, |matrix| {
matrix.adjust_slot_section_length(self.slot_coordinates, a.factor)?;
matrix.adjust_slot_dynamic_section_length(self.slot_coordinates, a.factor)?;
Ok(HitResponse::processed_with_effect())
})?
}
Expand Down
6 changes: 2 additions & 4 deletions main/src/infrastructure/data/clip_legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ pub(super) fn create_clip_matrix_from_legacy_slots(
looped: desc.descriptor.repeat,
volume: api::Db::new(0.0).unwrap(),
color: api::ClipColor::PlayTrackColor,
section: api::Section {
start_pos: api::PositiveSecond::new(0.0).unwrap(),
length: None,
},
dynamic_section: Default::default(),
fixed_section: Default::default(),
audio_settings: Default::default(),
midi_settings: Default::default(),
};
Expand Down
2 changes: 0 additions & 2 deletions main/src/infrastructure/plugin/realearn_editor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::infrastructure::ui::MainPanel;

use reaper_high::Reaper;
use reaper_low::firewall;
use reaper_low::raw::HWND;
use slog::debug;

use std::os::raw::c_void;

Expand Down
39 changes: 38 additions & 1 deletion playtime-api/src/persistence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::cmp;
use std::error::Error;
use std::ops::Add;
use std::path::PathBuf;

// TODO-medium Add start time detection
Expand Down Expand Up @@ -985,8 +986,20 @@ pub struct Clip {
/// Color of the clip.
// TODO-clip-implement
pub color: ClipColor,
/// A more variable kind of section within the main section.
///
/// Intended for playing with section bounds as a part of the performance *without* destroying
/// the original section.
#[serde(default)]
pub dynamic_section: Section,
/// Defines which portion of the original source should be played.
pub section: Section,
///
/// This section is especially important for the way that Playtime records audio clips: It
/// records the count-in phase as well and more samples than actually necessary at the end.
/// It then sets this section to the portion that actually matters. Once set, this section
/// rarely changes.
#[serde(alias = "section")]
pub fixed_section: Section,
pub audio_settings: ClipAudioSettings,
pub midi_settings: ClipMidiSettings,
// /// Defines the total amount of time this clip should consume and where within that range the
Expand Down Expand Up @@ -1154,6 +1167,18 @@ pub struct Section {
pub length: Option<PositiveSecond>,
}

impl Section {
pub fn combine_with_inner(&self, inner: Section) -> Section {
Section {
start_pos: self.start_pos + inner.start_pos,
length: match (self.length, inner.length) {
(Some(l), None) => Some(l.saturating_sub(inner.start_pos)),
(_, l) => l,
},
}
}
}

#[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "kind")]
pub enum AudioCacheBehavior {
Expand Down Expand Up @@ -1330,6 +1355,10 @@ impl PositiveSecond {
pub const fn get(&self) -> f64 {
self.0
}

pub fn saturating_sub(&self, rhs: Self) -> Self {
Self(0.0f64.max(self.0 - rhs.0))
}
}

impl TryFrom<f64> for PositiveSecond {
Expand All @@ -1340,6 +1369,14 @@ impl TryFrom<f64> for PositiveSecond {
}
}

impl Add for PositiveSecond {
type Output = Self;

fn add(self, rhs: Self) -> Self::Output {
Self(self.0 + rhs.0)
}
}

#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema)]
pub struct PositiveBeat(f64);

Expand Down
2 changes: 1 addition & 1 deletion playtime-clip-engine

0 comments on commit c2db1a2

Please sign in to comment.