From e89ead8d4c5477b345416adfdc4f7a13c3acd5b5 Mon Sep 17 00:00:00 2001 From: Benjamin Klum Date: Wed, 30 Oct 2024 17:50:11 +0100 Subject: [PATCH] #800 Unlock relative-control glue elements if transformation produces relative values --- main/lib/helgoboss-learn | 2 +- main/src/application/mapping_model.rs | 16 +++++--- main/src/domain/accelerator.rs | 1 - main/src/domain/audio_hook.rs | 3 +- main/src/domain/control_event.rs | 3 +- main/src/domain/control_surface.rs | 1 - main/src/domain/eel_transformation.rs | 41 +++++++++++-------- main/src/domain/main_processor.rs | 4 +- .../infrastructure/plugin/backbone_shell.rs | 2 +- .../infrastructure/plugin/helgobox_plugin.rs | 1 - 10 files changed, 39 insertions(+), 35 deletions(-) diff --git a/main/lib/helgoboss-learn b/main/lib/helgoboss-learn index 9759b17c1..ce0bff7dd 160000 --- a/main/lib/helgoboss-learn +++ b/main/lib/helgoboss-learn @@ -1 +1 @@ -Subproject commit 9759b17c1f9585d55d21b2a4328a86625cf22121 +Subproject commit ce0bff7ddebf4f94a2dc0bc22a8c049bd1317d8c diff --git a/main/src/application/mapping_model.rs b/main/src/application/mapping_model.rs index 51db8b6fd..f65078e8f 100644 --- a/main/src/application/mapping_model.rs +++ b/main/src/application/mapping_model.rs @@ -486,16 +486,20 @@ impl MappingModel { } pub fn base_mode_applicability_check_input(&self) -> ModeApplicabilityCheckInput { + let transformation = + EelTransformation::compile_for_control(self.mode_model.eel_control_transformation()); ModeApplicabilityCheckInput { target_is_virtual: self.target_model.is_virtual(), // TODO-high-discrete Enable (also taking source into consideration!) target_supports_discrete_values: false, - control_transformation_uses_time: { - let transformation = EelTransformation::compile_for_control( - self.mode_model.eel_control_transformation(), - ); - transformation.map(|t| t.uses_time()).unwrap_or(false) - }, + control_transformation_uses_time: transformation + .as_ref() + .map(|t| t.uses_time()) + .unwrap_or(false), + control_transformation_produces_relative_values: transformation + .as_ref() + .map(|t| t.produces_relative_values()) + .unwrap_or(false), is_feedback: false, make_absolute: self.mode_model.make_absolute(), use_textual_feedback: self.mode_model.feedback_type().is_textual(), diff --git a/main/src/domain/accelerator.rs b/main/src/domain/accelerator.rs index 74db7e814..3b647152e 100644 --- a/main/src/domain/accelerator.rs +++ b/main/src/domain/accelerator.rs @@ -2,7 +2,6 @@ use crate::domain::{ Backbone, ControlEvent, ControlEventTimestamp, DomainEventHandler, KeyMessage, Keystroke, SharedMainProcessors, }; -use helgoboss_learn::AbstractTimestamp; use reaper_high::Reaper; use reaper_low::raw; use reaper_medium::{ diff --git a/main/src/domain/audio_hook.rs b/main/src/domain/audio_hook.rs index 1a3ab31ac..cfa0ddbca 100644 --- a/main/src/domain/audio_hook.rs +++ b/main/src/domain/audio_hook.rs @@ -7,7 +7,7 @@ use crate::domain::{ use base::byte_pattern::{BytePattern, PatternByte}; use base::metrics_util::{measure_time, record_duration}; use base::non_blocking_lock; -use helgoboss_learn::{AbstractTimestamp, MidiSourceValue, RawMidiEvent, RawMidiEvents}; +use helgoboss_learn::{MidiSourceValue, RawMidiEvent, RawMidiEvents}; use helgoboss_midi::{DataEntryByteOrder, RawShortMessage, ShortMessage, ShortMessageType}; use helgobox_allocator::*; use reaper_common_types::DurationInSeconds; @@ -18,7 +18,6 @@ use reaper_medium::{ }; use smallvec::SmallVec; use std::fmt::{Display, Formatter}; -use std::sync::atomic::{AtomicU32, AtomicU64, Ordering}; use std::sync::{Arc, Mutex, MutexGuard, OnceLock}; use std::time::{Duration, Instant}; use tinyvec::ArrayVec; diff --git a/main/src/domain/control_event.rs b/main/src/domain/control_event.rs index eb586cca3..c62854066 100644 --- a/main/src/domain/control_event.rs +++ b/main/src/domain/control_event.rs @@ -3,8 +3,7 @@ use helgoboss_learn::AbstractTimestamp; use reaper_common_types::{DurationInSeconds, Hz}; use std::fmt::{Display, Formatter}; use std::ops::Sub; -use std::sync::LazyLock; -use std::time::{Duration, Instant}; +use std::time::Duration; pub type ControlEvent

= helgoboss_learn::ControlEvent; diff --git a/main/src/domain/control_surface.rs b/main/src/domain/control_surface.rs index e14b787fb..413a0a5ec 100644 --- a/main/src/domain/control_surface.rs +++ b/main/src/domain/control_surface.rs @@ -9,7 +9,6 @@ use crate::domain::{ }; use base::{metrics_util, Global, NamedChannelSender, SenderToNormalThread}; use crossbeam_channel::Receiver; -use helgoboss_learn::AbstractTimestamp; use reaper_high::{ ChangeDetectionMiddleware, ChangeEvent, ControlSurfaceEvent, ControlSurfaceMiddleware, FutureMiddleware, Fx, FxParameter, MainTaskMiddleware, Project, Reaper, diff --git a/main/src/domain/eel_transformation.rs b/main/src/domain/eel_transformation.rs index 8e2518fa5..9b8061de4 100644 --- a/main/src/domain/eel_transformation.rs +++ b/main/src/domain/eel_transformation.rs @@ -41,6 +41,8 @@ pub enum OutputVariable { pub trait Script { fn uses_time(&self) -> bool; + fn produces_relative_values(&self) -> bool; + fn evaluate( &self, input: TransformationInput, @@ -52,6 +54,10 @@ impl Script for () { false } + fn produces_relative_values(&self) -> bool { + false + } + fn evaluate( &self, input: TransformationInput, @@ -76,21 +82,21 @@ impl Script for EelTransformation { self.wants_to_be_polled() } + fn produces_relative_values(&self) -> bool { + let input = TransformationInput::default(); + let Ok(output) = self.transform(input) else { + return false; + }; + // For now, we only support relative-discrete + output.produced_kind == ControlValueKind::RelativeDiscrete + } + fn evaluate( &self, input: TransformationInput, ) -> Result { self.transform(input) } - - // fn evaluate( - // &self, - // input: TransformationInput, - // output_value: UnitValue, - // additional_input: AdditionalTransformationInput, - // ) -> Result, &'static str> { - // self.transform_continuous(input, output_value, additional_input) - // } } impl EelTransformation { @@ -237,7 +243,7 @@ const CONTROL_AND_STOP_MAGIC: f64 = 8965019.0; mod tests { use super::*; use bytesize::ByteSize; - use helgoboss_learn::TransformationInputMetaData; + use helgoboss_learn::TransformationInputEvent; use sysinfo::ProcessRefreshKind; #[test] @@ -291,15 +297,14 @@ mod tests { .map(|i| { let code = format!("y = x * {i}"); let transformation = EelTransformation::compile_for_control(&code).unwrap(); - let input = TransformationInput::new( - 0.5, - TransformationInputMetaData { - rel_time: Default::default(), + let input = TransformationInput { + event: TransformationInputEvent { + input_value: 0.5, + ..Default::default() }, - ); - transformation - .transform(input, 0.5, AdditionalTransformationInput::default()) - .unwrap(); + ..Default::default() + }; + transformation.transform(input).unwrap(); transformation }) .collect() diff --git a/main/src/domain/main_processor.rs b/main/src/domain/main_processor.rs index 445ae4d27..907c26b82 100644 --- a/main/src/domain/main_processor.rs +++ b/main/src/domain/main_processor.rs @@ -25,8 +25,8 @@ use crate::domain::{ use derive_more::Display; use enum_map::EnumMap; use helgoboss_learn::{ - AbsoluteValue, AbstractTimestamp, ControlValue, GroupInteraction, MidiSourceValue, - MinIsMaxBehavior, ModeControlOptions, RawMidiEvent, Target, BASE_EPSILON, + AbsoluteValue, ControlValue, GroupInteraction, MidiSourceValue, MinIsMaxBehavior, + ModeControlOptions, RawMidiEvent, Target, BASE_EPSILON, }; use std::borrow::Cow; use std::cell::RefCell; diff --git a/main/src/infrastructure/plugin/backbone_shell.rs b/main/src/infrastructure/plugin/backbone_shell.rs index 9bc77eadb..22049d4ad 100644 --- a/main/src/infrastructure/plugin/backbone_shell.rs +++ b/main/src/infrastructure/plugin/backbone_shell.rs @@ -91,7 +91,7 @@ use std::collections::{HashMap, HashSet}; use std::error::Error; use std::future::Future; use std::rc::{Rc, Weak}; -use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, Ordering}; +use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::thread::JoinHandle; use std::time::Duration; diff --git a/main/src/infrastructure/plugin/helgobox_plugin.rs b/main/src/infrastructure/plugin/helgobox_plugin.rs index 12eb0c2e4..e9e0a5346 100644 --- a/main/src/infrastructure/plugin/helgobox_plugin.rs +++ b/main/src/infrastructure/plugin/helgobox_plugin.rs @@ -30,7 +30,6 @@ use crate::infrastructure::plugin::helgobox_plugin_editor::HelgoboxPluginEditor; use crate::infrastructure::plugin::instance_shell::InstanceShell; use crate::infrastructure::ui::instance_panel::InstancePanel; use anyhow::{anyhow, Context}; -use helgoboss_learn::AbstractTimestamp; use std::convert::TryInto; use std::ptr::null_mut; use std::rc::Rc;