Skip to content

Commit

Permalink
#1294 Add control transformation variable realearn_last_feedback_value
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Oct 28, 2024
1 parent 34d862e commit 7c4f170
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ path-slash = "0.2.1"
pathdiff = "0.2.1"
open = "5.0.1"
url = "2.5.2"
atomic = "0.6.0"

[profile.release]
# This is important for having line numbers in bug reports.
Expand Down
2 changes: 2 additions & 0 deletions main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ auto_impl.workspace = true
palette.workspace = true
# For parsing/formatting enum-like target values from/to a stable and ID-like representation
serde_plain.workspace = true
# For sharing variables between main thread and real-time threads
atomic.workspace = true

[target.'cfg(any(target_os = "windows", target_os = "macos"))'.dependencies]
# For speech source
Expand Down
15 changes: 15 additions & 0 deletions main/src/domain/eel_transformation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use helgoboss_learn::{
};
use std::os::raw::c_void;

use atomic::Atomic;
use reaper_medium::reaper_str;
use std::sync::atomic::Ordering;
use std::sync::Arc;

#[derive(Default)]
Expand All @@ -25,6 +27,7 @@ struct EelUnit {
y: eel::Variable,
y_last: eel::Variable,
y_type: eel::Variable,
last_feedback_value: eel::Variable,
rel_time: Option<eel::Variable>,
}

Expand Down Expand Up @@ -66,6 +69,7 @@ impl Script for () {
pub struct EelTransformation {
// Arc because EelUnit is not cloneable
eel_unit: Arc<EelUnit>,
shared_last_feedback_value: Arc<Atomic<f64>>,
output_var: OutputVariable,
wants_to_be_polled: bool,
}
Expand Down Expand Up @@ -94,6 +98,11 @@ impl EelTransformation {
EelTransformation::compile(eel_script, OutputVariable::X)
}

pub fn set_last_feedback_value(&self, value: f64) {
self.shared_last_feedback_value
.store(value, Ordering::SeqCst);
}

// Compiles the given script and creates an appropriate transformation.
fn compile(eel_script: &str, result_var: OutputVariable) -> Result<EelTransformation, String> {
if eel_script.trim().is_empty() {
Expand All @@ -106,6 +115,7 @@ impl EelTransformation {
let y = vm.register_variable("y");
let y_last = vm.register_variable("y_last");
let y_type = vm.register_variable("y_type");
let last_feedback_value = vm.register_variable("realearn_last_feedback_value");
let rel_time_var_name = "rel_time";
let uses_rel_time = eel_script.contains(rel_time_var_name);
let rel_time = if uses_rel_time {
Expand All @@ -122,10 +132,12 @@ impl EelTransformation {
y,
y_last,
y_type,
last_feedback_value,
rel_time,
};
let transformation = EelTransformation {
eel_unit: Arc::new(eel_unit),
shared_last_feedback_value: Arc::new(Atomic::new(-1.0)),
output_var: result_var,
wants_to_be_polled: uses_rel_time,
};
Expand Down Expand Up @@ -155,6 +167,9 @@ impl Transformation for EelTransformation {
};
input_var.set(input.value);
output_var.set(output_value);
eel_unit
.last_feedback_value
.set(self.shared_last_feedback_value.load(Ordering::SeqCst));
eel_unit.y_last.set(additional_input.y_last);
if let Some(rel_time_var) = eel_unit.rel_time {
rel_time_var.set(input.meta_data.rel_time.as_millis() as _);
Expand Down
10 changes: 10 additions & 0 deletions main/src/domain/main_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3751,6 +3751,16 @@ impl<EH: DomainEventHandler> Basics<EH> {
if let Some(final_feedback_value) =
feedback_collector.process(preliminary_feedback_value)
{
if let Some(t) = &m.mode().settings().control_transformation
{
if let Some(numeric_fb_value) =
value.feedback_value().to_numeric()
{
t.set_last_feedback_value(
numeric_fb_value.value.to_unit_value().get(),
);
}
}
self.send_direct_feedback(
feedback_reason,
feedback_value.cause,
Expand Down
2 changes: 1 addition & 1 deletion playtime-clip-engine

0 comments on commit 7c4f170

Please sign in to comment.