From c2db1a2be7354e1011a70cccb37d6d59846e5bab Mon Sep 17 00:00:00 2001 From: Benjamin Klum Date: Thu, 2 Nov 2023 16:00:26 +0100 Subject: [PATCH] Playtime: Distinguish between fixed and dynamic section --- .../domain/targets/clip_management_target.rs | 2 +- main/src/infrastructure/data/clip_legacy.rs | 6 +-- .../infrastructure/plugin/realearn_editor.rs | 2 - playtime-api/src/persistence/mod.rs | 39 ++++++++++++++++++- playtime-clip-engine | 2 +- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/main/src/domain/targets/clip_management_target.rs b/main/src/domain/targets/clip_management_target.rs index 9f12da481..91f7eec42 100644 --- a/main/src/domain/targets/clip_management_target.rs +++ b/main/src/domain/targets/clip_management_target.rs @@ -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()) })? } diff --git a/main/src/infrastructure/data/clip_legacy.rs b/main/src/infrastructure/data/clip_legacy.rs index 74a2f3ca5..f6b74957f 100644 --- a/main/src/infrastructure/data/clip_legacy.rs +++ b/main/src/infrastructure/data/clip_legacy.rs @@ -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(), }; diff --git a/main/src/infrastructure/plugin/realearn_editor.rs b/main/src/infrastructure/plugin/realearn_editor.rs index e2ea922a5..5054be006 100644 --- a/main/src/infrastructure/plugin/realearn_editor.rs +++ b/main/src/infrastructure/plugin/realearn_editor.rs @@ -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; diff --git a/playtime-api/src/persistence/mod.rs b/playtime-api/src/persistence/mod.rs index 6db77a428..16d4bba82 100644 --- a/playtime-api/src/persistence/mod.rs +++ b/playtime-api/src/persistence/mod.rs @@ -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 @@ -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 @@ -1154,6 +1167,18 @@ pub struct Section { pub length: Option, } +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 { @@ -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 for PositiveSecond { @@ -1340,6 +1369,14 @@ impl TryFrom 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); diff --git a/playtime-clip-engine b/playtime-clip-engine index dd0f6fb2c..04054dde8 160000 --- a/playtime-clip-engine +++ b/playtime-clip-engine @@ -1 +1 @@ -Subproject commit dd0f6fb2c2af6c877f11cf2ed29d01c13f162074 +Subproject commit 04054dde80bd53cc2bc4f89e706821f7a51e07ce