Skip to content

Commit

Permalink
#800 Make "y_type = 1;" change output type to relative-discrete
Browse files Browse the repository at this point in the history
no adjustment of GUI yet (display of relative controls)
  • Loading branch information
helgoboss committed Oct 26, 2024
1 parent 139f5f0 commit 5152967
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion main/lib/helgoboss-learn
21 changes: 13 additions & 8 deletions main/src/domain/eel_transformation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct EelUnit {
x: eel::Variable,
y: eel::Variable,
y_last: eel::Variable,
y_type: eel::Variable,
rel_time: Option<eel::Variable>,
}

Expand Down Expand Up @@ -104,6 +105,7 @@ impl EelTransformation {
let x = vm.register_variable("x");
let y = vm.register_variable("y");
let y_last = vm.register_variable("y_last");
let y_type = vm.register_variable("y_type");
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 @@ -119,6 +121,7 @@ impl EelTransformation {
x,
y,
y_last,
y_type,
rel_time,
};
let transformation = EelTransformation {
Expand All @@ -143,7 +146,7 @@ impl Transformation for EelTransformation {
output_value: f64,
additional_input: AdditionalTransformationInput,
) -> Result<TransformationOutput<f64>, &'static str> {
let v = unsafe {
let (raw_output, raw_output_type) = unsafe {
use OutputVariable::*;
let eel_unit = &*self.eel_unit;
let (input_var, output_var) = match self.output_var {
Expand All @@ -157,26 +160,28 @@ impl Transformation for EelTransformation {
rel_time_var.set(input.meta_data.rel_time.as_millis() as _);
}
eel_unit.program.execute();
output_var.get()
(output_var.get(), self.eel_unit.y_type.get())
};
let (out_val, instruction) = if v == STOP {
let (out_val, instruction) = if raw_output == STOP {
// Stop only
(None, Some(TransformationInstruction::Stop))
} else if v == NONE {
} else if raw_output == NONE {
// Neither control nor stop
(None, None)
} else if (CONTROL_AND_STOP_MAGIC..=CONTROL_AND_STOP_MAGIC + 1.0).contains(&v) {
} else if (CONTROL_AND_STOP_MAGIC..=CONTROL_AND_STOP_MAGIC + 1.0).contains(&raw_output) {
// Both control and stop
(
Some(v - CONTROL_AND_STOP_MAGIC),
Some(raw_output - CONTROL_AND_STOP_MAGIC),
Some(TransformationInstruction::Stop),
)
} else {
// Control only
(Some(v), None)
(Some(raw_output), None)
};
let raw_output_type = raw_output_type.round() as u8;
let produced_kind = ControlValueKind::try_from(raw_output_type).unwrap_or_default();
let output = TransformationOutput {
produced_kind: ControlValueKind::AbsoluteContinuous,
produced_kind,
value: out_val,
instruction,
};
Expand Down

0 comments on commit 5152967

Please sign in to comment.