Skip to content

Commit

Permalink
#800 Unlock relative-control glue elements if transformation produces…
Browse files Browse the repository at this point in the history
… relative values
  • Loading branch information
helgoboss committed Oct 30, 2024
1 parent 71db67e commit e89ead8
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion main/lib/helgoboss-learn
16 changes: 10 additions & 6 deletions main/src/application/mapping_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 0 additions & 1 deletion main/src/domain/accelerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
3 changes: 1 addition & 2 deletions main/src/domain/audio_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions main/src/domain/control_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P> = helgoboss_learn::ControlEvent<P, ControlEventTimestamp>;

Expand Down
1 change: 0 additions & 1 deletion main/src/domain/control_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
41 changes: 23 additions & 18 deletions main/src/domain/eel_transformation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AdditionalTransformationInput>,
Expand All @@ -52,6 +54,10 @@ impl Script for () {
false
}

fn produces_relative_values(&self) -> bool {
false
}

fn evaluate(
&self,
input: TransformationInput<AdditionalTransformationInput>,
Expand All @@ -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<AdditionalTransformationInput>,
) -> Result<TransformationOutput, &'static str> {
self.transform(input)
}

// fn evaluate(
// &self,
// input: TransformationInput<UnitValue>,
// output_value: UnitValue,
// additional_input: AdditionalTransformationInput,
// ) -> Result<TransformationOutput<ControlValue>, &'static str> {
// self.transform_continuous(input, output_value, additional_input)
// }
}

impl EelTransformation {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions main/src/domain/main_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion main/src/infrastructure/plugin/backbone_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion main/src/infrastructure/plugin/helgobox_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e89ead8

Please sign in to comment.