From 135010b3c4c0d924a78dcbcdc681e90dde04b3b4 Mon Sep 17 00:00:00 2001 From: Benjamin Klum Date: Sat, 7 Dec 2024 16:45:03 +0100 Subject: [PATCH] Complain when attempting to add Playtime matrix to Helgobox instance if REAPER version too old --- main/src/domain/instance.rs | 14 +++++++++++++- main/src/infrastructure/plugin/backbone_shell.rs | 10 +++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/main/src/domain/instance.rs b/main/src/domain/instance.rs index 8022f564f..8a6bf0769 100644 --- a/main/src/domain/instance.rs +++ b/main/src/domain/instance.rs @@ -268,7 +268,9 @@ impl Instance { #[cfg(feature = "playtime")] mod playtime_impl { use crate::domain::instance::NO_CLIP_MATRIX_SET; - use crate::domain::{Instance, QualifiedClipMatrixEvent}; + use crate::domain::{ + err_if_reaper_version_too_low_for_playtime, Instance, QualifiedClipMatrixEvent, + }; use anyhow::Context; use base::NamedChannelSender; use reaper_high::OrCurrentProject; @@ -346,6 +348,7 @@ mod playtime_impl { if self.playtime.clip_matrix.is_some() { return Ok(false); } + err_if_reaper_version_too_low_for_playtime()?; let track = self.processor_context.track() .context("Sorry, Playtime is not intended to be used from the monitoring FX chain! If you have a really good use case for that, please write to info@helgoboss.org and we will see what we can do.")?; let matrix = @@ -475,3 +478,12 @@ pub enum PotStateChangedEvent { #[cfg(feature = "playtime")] const NO_CLIP_MATRIX_SET: &str = "no Playtime matrix set for this instance"; + +#[cfg(feature = "playtime")] +pub fn err_if_reaper_version_too_low_for_playtime() -> anyhow::Result<()> { + const MIN_REAPER_VERSION: &str = "7"; + if reaper_high::Reaper::get().version().revision() < MIN_REAPER_VERSION { + anyhow::bail!("Please update REAPER to version {MIN_REAPER_VERSION} to access Playtime!"); + } + Ok(()) +} diff --git a/main/src/infrastructure/plugin/backbone_shell.rs b/main/src/infrastructure/plugin/backbone_shell.rs index 4c4fdd7b2..bc8d5f643 100644 --- a/main/src/infrastructure/plugin/backbone_shell.rs +++ b/main/src/infrastructure/plugin/backbone_shell.rs @@ -2980,9 +2980,10 @@ pub struct NewInstanceOutcome { #[cfg(feature = "playtime")] mod playtime_impl { + use crate::domain::err_if_reaper_version_too_low_for_playtime; use crate::infrastructure::data::LicenseManager; use crate::infrastructure::plugin::{BackboneShell, NewInstanceOutcome}; - use anyhow::{bail, Context}; + use anyhow::Context; use base::metrics_util::{record_duration, record_occurrence}; use camino::Utf8PathBuf; use playtime_api::persistence::PlaytimeSettings; @@ -2990,7 +2991,6 @@ mod playtime_impl { use reaper_high::{GroupingBehavior, Project, Reaper}; use reaper_medium::{GangBehavior, InputMonitoringMode, RecordingInput}; use std::fs; - use crate::infrastructure::plugin::backbone_shell::MIN_REAPER_VERSION_FOR_PLAYTIME; impl BackboneShell { pub(crate) fn read_playtime_settings() -> Option { @@ -3008,9 +3008,7 @@ mod playtime_impl { } async fn add_and_show_playtime() -> anyhow::Result<()> { - if Reaper::get().version().revision() < MIN_REAPER_VERSION_FOR_PLAYTIME { - bail!("Please update REAPER to version 7 to access Playtime!"); - } + err_if_reaper_version_too_low_for_playtime()?; let project = Reaper::get().current_project(); create_new_instance_in_project(project, "Playtime").await?; enable_playtime_for_first_helgobox_instance_and_show_it()?; @@ -3167,5 +3165,3 @@ struct MatchingSourceOutcome { mapping: SharedMapping, source_is_learnable: bool, } - -const MIN_REAPER_VERSION_FOR_PLAYTIME: &str = "7"; \ No newline at end of file