Skip to content

Commit

Permalink
Merge branch 'master' of github.com:helgoboss/realearn
Browse files Browse the repository at this point in the history
# Conflicts:
#	main/src/domain/main_processor.rs
#	main/src/infrastructure/ui/mapping_header_panel.rs
  • Loading branch information
helgoboss committed Jun 16, 2022
2 parents 38f8605 + f35f80b commit cf886d5
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 42 deletions.
7 changes: 7 additions & 0 deletions api/src/persistence/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum Source {
MidiDeviceChanges(MidiDeviceChangesSource),
RealearnInstanceStart(RealearnInstanceStartSource),
Timer(TimerSource),
RealearnParameter(RealearnParameterSource),
// MIDI
MidiNoteVelocity(MidiNoteVelocitySource),
MidiNoteKeyNumber(MidiNoteKeyNumberSource),
Expand Down Expand Up @@ -335,6 +336,12 @@ mod reaper {
#[serde(deny_unknown_fields)]
pub struct RealearnInstanceStartSource;

#[derive(Default, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct RealearnParameterSource {
pub parameter_index: u32,
}

#[derive(Default, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct TimerSource {
Expand Down
2 changes: 1 addition & 1 deletion dialogs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn generate_dialog_files(rc_dir: impl AsRef<Path>, bindings_file: impl AsRef
let global_scope = {
Scope {
linux: {
let horizontal_scale = 1.75;
let horizontal_scale = 1.8;
let vertical_scale = 1.65;
OsSpecificSettings {
scaling: DialogScaling {
Expand Down
2 changes: 1 addition & 1 deletion main/src/application/mapping_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl MappingModel {
feedback_send_behavior: Default::default(),
activation_condition_model: Default::default(),
visible_in_projection: true,
source_model: Default::default(),
source_model: SourceModel::new(compartment),
mode_model: Default::default(),
target_model: TargetModel::default_for_compartment(compartment),
advanced_settings: None,
Expand Down
2 changes: 1 addition & 1 deletion main/src/application/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ impl Session {
let element = m.target_model.create_control_element();
let virtual_source =
CompoundMappingSource::Virtual(VirtualSource::new(element));
let mut virtual_model = SourceModel::default();
let mut virtual_model = SourceModel::new(Compartment::Main);
let _ = virtual_model.apply_from_source(&virtual_source);
Some(virtual_model)
} else {
Expand Down
53 changes: 36 additions & 17 deletions main/src/application/source_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use crate::application::{
Affected, Change, GetProcessingRelevance, MappingProp, ProcessingRelevance,
};
use crate::domain::{
BackboneState, Compartment, CompoundMappingSource, EelMidiSourceScript,
BackboneState, Compartment, CompartmentParamIndex, CompoundMappingSource, EelMidiSourceScript,
ExtendedSourceCharacter, FlexibleMidiSourceScript, KeySource, Keystroke, LuaMidiSourceScript,
MidiSource, ReaperSource, TimerSource, VirtualControlElement, VirtualControlElementId,
VirtualSource, VirtualTarget,
MidiSource, RealearnParameterSource, ReaperSource, TimerSource, VirtualControlElement,
VirtualControlElementId, VirtualSource, VirtualTarget,
};
use derive_more::Display;
use enum_iterator::IntoEnumIterator;
Expand Down Expand Up @@ -50,6 +50,7 @@ pub enum SourceCommand {
SetOscFeedbackArgs(Vec<String>),
SetReaperSourceType(ReaperSourceType),
SetTimerMillis(u64),
SetParameterIndex(CompartmentParamIndex),
SetKeystroke(Option<Keystroke>),
SetControlElementType(VirtualControlElementType),
SetControlElementId(VirtualControlElementId),
Expand Down Expand Up @@ -82,6 +83,7 @@ pub enum SourceProp {
ControlElementType,
ControlElementId,
TimerMillis,
ParameterIndex,
Keystroke,
}

Expand Down Expand Up @@ -201,6 +203,10 @@ impl<'a> Change<'a> for SourceModel {
self.timer_millis = v;
One(P::TimerMillis)
}
C::SetParameterIndex(v) => {
self.parameter_index = v;
One(P::ParameterIndex)
}
C::SetKeystroke(v) => {
self.keystroke = v;
One(P::Keystroke)
Expand All @@ -213,13 +219,14 @@ impl<'a> Change<'a> for SourceModel {
/// A model for creating sources
#[derive(Clone, Debug)]
pub struct SourceModel {
compartment: Compartment,
category: SourceCategory,
custom_character: SourceCharacter,
// MIDI
midi_source_type: MidiSourceType,
channel: Option<Channel>,
midi_message_number: Option<U7>,
parameter_number_message_number: Option<U14>,
custom_character: SourceCharacter,
midi_clock_transport_message: MidiClockTransportMessage,
is_registered: Option<bool>,
is_14_bit: Option<bool>,
Expand All @@ -239,16 +246,18 @@ pub struct SourceModel {
// REAPER
reaper_source_type: ReaperSourceType,
timer_millis: u64,
parameter_index: CompartmentParamIndex,
// Key
keystroke: Option<Keystroke>,
// Virtual
control_element_type: VirtualControlElementType,
control_element_id: VirtualControlElementId,
}

impl Default for SourceModel {
fn default() -> Self {
impl SourceModel {
pub fn new(compartment: Compartment) -> Self {
Self {
compartment,
category: SourceCategory::Never,
midi_source_type: Default::default(),
control_element_type: Default::default(),
Expand All @@ -274,12 +283,11 @@ impl Default for SourceModel {
osc_feedback_args: vec![],
reaper_source_type: Default::default(),
timer_millis: Default::default(),
parameter_index: Default::default(),
keystroke: None,
}
}
}

impl SourceModel {
pub fn category(&self) -> SourceCategory {
self.category
}
Expand Down Expand Up @@ -372,6 +380,10 @@ impl SourceModel {
self.reaper_source_type
}

pub fn parameter_index(&self) -> CompartmentParamIndex {
self.parameter_index
}

pub fn timer_millis(&self) -> u64 {
self.timer_millis
}
Expand Down Expand Up @@ -641,6 +653,9 @@ impl SourceModel {
MidiDeviceChanges => ReaperSource::MidiDeviceChanges,
RealearnInstanceStart => ReaperSource::RealearnInstanceStart,
Timer => ReaperSource::Timer(self.create_timer_source()),
RealearnParameter => {
ReaperSource::RealearnParameter(self.create_realearn_parameter_source())
}
};
CompoundMappingSource::Reaper(reaper_source)
}
Expand All @@ -658,6 +673,13 @@ impl SourceModel {
TimerSource::new(Duration::from_millis(self.timer_millis))
}

fn create_realearn_parameter_source(&self) -> RealearnParameterSource {
RealearnParameterSource {
compartment: self.compartment,
parameter_index: self.parameter_index,
}
}

fn display_spec(&self) -> DisplaySpec {
use DisplayType::*;
match self.display_type {
Expand Down Expand Up @@ -1137,6 +1159,9 @@ pub enum ReaperSourceType {
#[serde(rename = "timer")]
#[display(fmt = "Timer")]
Timer,
#[serde(rename = "realearn-parameter")]
#[display(fmt = "ReaLearn parameter")]
RealearnParameter,
}

impl Default for ReaperSourceType {
Expand All @@ -1152,6 +1177,7 @@ impl ReaperSourceType {
MidiDeviceChanges => Self::MidiDeviceChanges,
RealearnInstanceStart => Self::RealearnInstanceStart,
Timer(_) => Self::Timer,
RealearnParameter(_) => Self::RealearnParameter,
}
}
}
Expand All @@ -1171,17 +1197,10 @@ mod tests {
#[test]
fn create_source() {
// Given
let m = SourceModel::default();
let m = SourceModel::new(Compartment::Main);
// When
let s = m.create_source();
// Then
assert_eq!(
s,
CompoundMappingSource::Midi(MidiSource::ControlChangeValue {
channel: None,
controller_number: None,
custom_character: SourceCharacter::RangeElement,
})
);
assert_eq!(s, CompoundMappingSource::Never);
}
}
30 changes: 23 additions & 7 deletions main/src/domain/main_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ use crate::domain::{
OrderedMappingMap, OscDeviceId, OscFeedbackTask, PluginParamIndex, PluginParams,
ProcessorContext, QualifiedClipMatrixEvent, QualifiedMappingId, QualifiedSource, RawParamValue,
RealFeedbackValue, RealTimeMappingUpdate, RealTimeTargetUpdate,
RealearnMonitoringFxParameterValueChangedEvent, ReaperMessage, ReaperTarget,
SharedInstanceState, SourceFeedbackValue, SourceReleasedEvent, SpecificCompoundFeedbackValue,
TargetValueChangedEvent, UpdatedSingleMappingOnStateEvent, VirtualControlElement,
VirtualSourceValue,
RealearnMonitoringFxParameterValueChangedEvent, RealearnParameterChangePayload, ReaperMessage,
ReaperTarget, SharedInstanceState, SourceFeedbackValue, SourceReleasedEvent,
SpecificCompoundFeedbackValue, TargetValueChangedEvent, UpdatedSingleMappingOnStateEvent,
VirtualControlElement, VirtualSourceValue,
};
use derive_more::Display;
use enum_map::EnumMap;
use helgoboss_learn::{
AbsoluteValue, ControlValue, GroupInteraction, MidiSourceValue, MinIsMaxBehavior,
ModeControlOptions, ModeControlResult, RawMidiEvent, Target, BASE_EPSILON,
AbsoluteValue, AbstractTimestamp, ControlValue, GroupInteraction, MidiSourceValue,
MinIsMaxBehavior, ModeControlOptions, ModeControlResult, RawMidiEvent, Target, BASE_EPSILON,
};
use std::borrow::Cow;
use std::cell::RefCell;
Expand Down Expand Up @@ -960,6 +960,7 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
self.basics
.event_handler
.handle_event(DomainEvent::UpdatedSingleParameterValue { index, value });
// Determine and process activation effects
let compartment = Compartment::by_plugin_param_index(index);
let activation_effects: Vec<MappingActivationEffect> = self
.all_mappings_in_compartment(compartment)
Expand All @@ -972,6 +973,21 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
})
.collect();
self.process_activation_effects(compartment, activation_effects, true);
// Control ("ReaLearn parameter source")
let control_payload = RealearnParameterChangePayload {
compartment,
parameter_index: compartment.to_compartment_param_index(index),
value,
};
let control_msg = ReaperMessage::RealearnParameterChange(control_payload);
if self.basics.settings.real_input_logging_enabled {
self.log_incoming_message(&control_msg);
}
let control_event = ControlEvent::new(
MainSourceMessage::Reaper(&control_msg),
ControlEventTimestamp::now(),
);
self.process_incoming_message_internal(control_event);
}

fn process_activation_effects(
Expand Down Expand Up @@ -1056,7 +1072,7 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
target_updates,
unused_sources,
changed_mappings.into_iter(),
)
);
}

fn update_all_params(&mut self, params: PluginParams) {
Expand Down
48 changes: 47 additions & 1 deletion main/src/domain/reaper_source.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::domain::{Compartment, CompartmentParamIndex, RawParamValue};
use core::fmt;
use derive_more::Display;
use helgoboss_learn::{
Expand All @@ -15,6 +16,13 @@ pub enum ReaperSource {
MidiDeviceChanges,
RealearnInstanceStart,
Timer(TimerSource),
RealearnParameter(RealearnParameterSource),
}

#[derive(Copy, Clone, PartialEq, Debug)]
pub struct RealearnParameterSource {
pub compartment: Compartment,
pub parameter_index: CompartmentParamIndex,
}

#[derive(Copy, Clone, PartialEq, Debug)]
Expand Down Expand Up @@ -75,6 +83,12 @@ impl ReaperSource {
MidiDeviceChanges => vec![DetailedSourceCharacter::MomentaryOnOffButton],
RealearnInstanceStart => vec![DetailedSourceCharacter::MomentaryOnOffButton],
Timer(_) => vec![DetailedSourceCharacter::PressOnlyButton],
RealearnParameter(_) => vec![
DetailedSourceCharacter::RangeControl,
DetailedSourceCharacter::MomentaryVelocitySensitiveButton,
DetailedSourceCharacter::MomentaryOnOffButton,
DetailedSourceCharacter::PressOnlyButton,
],
}
}

Expand All @@ -88,7 +102,13 @@ impl ReaperSource {
}

pub fn character(&self) -> SourceCharacter {
SourceCharacter::MomentaryButton
use ReaperSource::*;
match self {
MidiDeviceChanges | RealearnInstanceStart | Timer(_) => {
SourceCharacter::MomentaryButton
}
RealearnParameter(_) => SourceCharacter::RangeElement,
}
}

pub fn poll(&mut self) -> Option<ControlValue> {
Expand Down Expand Up @@ -116,6 +136,14 @@ impl ReaperSource {
}
_ => return None,
},
RealearnParameterChange(c) => match self {
ReaperSource::RealearnParameter(s)
if c.compartment == s.compartment && c.parameter_index == s.parameter_index =>
{
ControlValue::AbsoluteContinuous(UnitValue::new_clamped(c.value as f64))
}
_ => return None,
},
};
Some(control_value)
}
Expand All @@ -128,6 +156,24 @@ pub enum ReaperMessage {
#[display(fmt = "MidiDevicesDisconnected ({})", _0)]
MidiDevicesDisconnected(MidiDeviceChangePayload),
RealearnInstanceStarted,
RealearnParameterChange(RealearnParameterChangePayload),
}

#[derive(PartialEq, Debug)]
pub struct RealearnParameterChangePayload {
pub compartment: Compartment,
pub parameter_index: CompartmentParamIndex,
pub value: RawParamValue,
}

impl Display for RealearnParameterChangePayload {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(
f,
"Parameter {} with value {}",
self.parameter_index, self.value
)
}
}

#[derive(PartialEq, Debug)]
Expand Down
5 changes: 5 additions & 0 deletions main/src/infrastructure/api/convert/from_data/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ pub fn convert_source(
Timer => persistence::Source::Timer(persistence::TimerSource {
duration: data.timer_millis,
}),
RealearnParameter => {
persistence::Source::RealearnParameter(persistence::RealearnParameterSource {
parameter_index: data.parameter_index.get(),
})
}
}
}
Virtual => {
Expand Down
8 changes: 7 additions & 1 deletion main/src/infrastructure/api/convert/to_data/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ pub fn convert_source(s: Source) -> ConversionResult<SourceModelData> {
Timer(t) => t.duration,
_ => Default::default(),
},
parameter_index: match &s {
RealearnParameter(s) => s.parameter_index.try_into()?,
_ => Default::default(),
},
};
Ok(data)
}
Expand All @@ -140,7 +144,9 @@ fn convert_category(s: &Source) -> SourceCategory {
use Source::*;
match s {
NoneSource => SourceCategory::Never,
MidiDeviceChanges(_) | RealearnInstanceStart(_) | Timer(_) => SourceCategory::Reaper,
MidiDeviceChanges(_) | RealearnInstanceStart(_) | Timer(_) | RealearnParameter(_) => {
SourceCategory::Reaper
}
MidiNoteVelocity(_)
| MidiNoteKeyNumber(_)
| MidiPolyphonicKeyPressureAmount(_)
Expand Down

0 comments on commit cf886d5

Please sign in to comment.