Skip to content

Commit

Permalink
#1308 Add source "ReaLearn compartment loaded"
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Nov 5, 2024
1 parent 5bfd82b commit 2c0104b
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 11 deletions.
1 change: 1 addition & 0 deletions api/src/persistence/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub enum Source {
// REAPER
MidiDeviceChanges,
RealearnInstanceStart,
RealearnCompartmentLoaded,
Timer(TimerSource),
RealearnParameter(RealearnParameterSource),
Speech,
Expand Down
23 changes: 20 additions & 3 deletions main/src/application/source_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,11 @@ impl SourceModel {
RealearnParameter(p) => {
self.parameter_index = p.parameter_index;
}
MidiDeviceChanges | RealearnInstanceStart | Timer(_) | Speech(_) => {}
MidiDeviceChanges
| RealearnInstanceStart
| RealearnCompartmentLoaded
| Timer(_)
| Speech(_) => {}
}
}
StreamDeck(s) => {
Expand Down Expand Up @@ -760,6 +764,7 @@ impl SourceModel {
let reaper_source = match self.reaper_source_type {
MidiDeviceChanges => ReaperSource::MidiDeviceChanges,
RealearnUnitStart => ReaperSource::RealearnInstanceStart,
RealearnCompartmentLoaded => ReaperSource::RealearnCompartmentLoaded,
Timer => ReaperSource::Timer(self.create_timer_source()),
RealearnParameter => {
ReaperSource::RealearnParameter(self.create_realearn_parameter_source())
Expand Down Expand Up @@ -1314,6 +1319,9 @@ pub enum ReaperSourceType {
#[serde(rename = "realearn-instance-start")]
#[display(fmt = "ReaLearn unit start")]
RealearnUnitStart,
#[serde(rename = "realearn-compartment-loaded")]
#[display(fmt = "ReaLearn compartment loaded")]
RealearnCompartmentLoaded,
#[serde(rename = "timer")]
#[display(fmt = "Timer")]
Timer,
Expand All @@ -1331,6 +1339,7 @@ impl ReaperSourceType {
match source {
MidiDeviceChanges => Self::MidiDeviceChanges,
RealearnInstanceStart => Self::RealearnUnitStart,
RealearnCompartmentLoaded => Self::RealearnCompartmentLoaded,
Timer(_) => Self::Timer,
RealearnParameter(_) => Self::RealearnParameter,
Speech(_) => Self::Speech,
Expand All @@ -1340,15 +1349,23 @@ impl ReaperSourceType {
pub fn supports_control(self) -> bool {
use ReaperSourceType::*;
match self {
MidiDeviceChanges | RealearnUnitStart | Timer | RealearnParameter => true,
MidiDeviceChanges
| RealearnUnitStart
| RealearnCompartmentLoaded
| Timer
| RealearnParameter => true,
Speech => false,
}
}

pub fn supports_feedback(self) -> bool {
use ReaperSourceType::*;
match self {
MidiDeviceChanges | RealearnUnitStart | Timer | RealearnParameter => false,
MidiDeviceChanges
| RealearnUnitStart
| RealearnCompartmentLoaded
| Timer
| RealearnParameter => false,
Speech => true,
}
}
Expand Down
6 changes: 6 additions & 0 deletions main/src/application/unit_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2283,6 +2283,12 @@ impl UnitModel {
}
self.reset_parameters(compartment);
self.notify_everything_has_changed();
self.notify_compartment_loaded(compartment);
}

pub fn notify_compartment_loaded(&self, compartment: CompartmentKind) {
self.normal_main_task_sender
.send_complaining(NormalMainTask::NotifyRealearnCompartmentLoaded(compartment));
}

fn reset_parameters(&self, compartment: CompartmentKind) {
Expand Down
8 changes: 8 additions & 0 deletions main/src/domain/main_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,12 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
let evt = ControlEvent::new(&ReaperMessage::RealearnUnitStarted, timestamp);
self.process_reaper_message(evt);
}
NotifyRealearnCompartmentLoaded(kind) => {
debug!("NotifyRealearnCompartmentLoaded received");
let message = ReaperMessage::RealearnCompartmentLoaded(kind);
let evt = ControlEvent::new(&message, timestamp);
self.process_reaper_message(evt);
}
HitTarget { id, value } => {
self.hit_target(id, value);
}
Expand Down Expand Up @@ -2879,6 +2885,8 @@ pub enum NormalMainTask {
},
/// Invokes the "ReaLearn instance started" source.
NotifyRealearnUnitStarted,
/// Invokes the "ReaLearn compartment loaded" source.
NotifyRealearnCompartmentLoaded(CompartmentKind),
/// Instructs the main processor to hit the target directly.
///
/// This doesn't invoke group interaction because it's meant to totally skip the mode.
Expand Down
3 changes: 2 additions & 1 deletion main/src/domain/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,8 @@ impl<'a> MainSourceMessage<'a> {
MidiDevicesConnected(_)
| MidiDevicesDisconnected(_)
| StreamDeckDevicesConnected(_)
| RealearnUnitStarted => return None,
| RealearnUnitStarted
| RealearnCompartmentLoaded(_) => return None,
RealearnParameterChange(payload) => {
MessageCaptureResult::RealearnParameter(*payload)
}
Expand Down
17 changes: 15 additions & 2 deletions main/src/domain/reaper_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::time::{Duration, Instant};
pub enum ReaperSource {
MidiDeviceChanges,
RealearnInstanceStart,
RealearnCompartmentLoaded,
Timer(TimerSource),
RealearnParameter(RealearnParameterSource),
Speech(SpeechSource),
Expand Down Expand Up @@ -150,6 +151,7 @@ impl ReaperSource {
match self {
MidiDeviceChanges => vec![DetailedSourceCharacter::MomentaryOnOffButton],
RealearnInstanceStart => vec![DetailedSourceCharacter::MomentaryOnOffButton],
RealearnCompartmentLoaded => vec![DetailedSourceCharacter::Trigger],
Timer(_) => vec![DetailedSourceCharacter::Trigger],
RealearnParameter(_) => vec![
DetailedSourceCharacter::RangeControl,
Expand All @@ -173,7 +175,7 @@ impl ReaperSource {
pub fn character(&self) -> SourceCharacter {
use ReaperSource::*;
match self {
MidiDeviceChanges | RealearnInstanceStart | Timer(_) => {
MidiDeviceChanges | RealearnInstanceStart | RealearnCompartmentLoaded | Timer(_) => {
SourceCharacter::MomentaryButton
}
RealearnParameter(_) => SourceCharacter::RangeElement,
Expand Down Expand Up @@ -214,6 +216,12 @@ impl ReaperSource {
}
_ => return None,
},
RealearnCompartmentLoaded(kind) => match self {
ReaperSource::RealearnCompartmentLoaded if *kind == compartment => {
ControlValue::AbsoluteContinuous(UnitValue::MAX)
}
_ => return None,
},
RealearnParameterChange(c) => match self {
ReaperSource::RealearnParameter(s)
if c.compartment == compartment && c.parameter_index == s.parameter_index =>
Expand All @@ -229,7 +237,11 @@ impl ReaperSource {
pub fn feedback(&self, feedback_value: &FeedbackValue) -> Option<ReaperSourceFeedbackValue> {
use ReaperSource::*;
match self {
MidiDeviceChanges | RealearnInstanceStart | Timer(_) | RealearnParameter(_) => None,
MidiDeviceChanges
| RealearnInstanceStart
| RealearnCompartmentLoaded
| Timer(_)
| RealearnParameter(_) => None,
Speech(s) => Some(ReaperSourceFeedbackValue::Speech(
s.feedback(feedback_value),
)),
Expand Down Expand Up @@ -262,6 +274,7 @@ pub enum ReaperMessage {
#[display(fmt = "MidiDevicesDisconnected ({_0})")]
MidiDevicesDisconnected(MidiDeviceChangePayload),
RealearnUnitStarted,
RealearnCompartmentLoaded(CompartmentKind),
RealearnParameterChange(RealearnParameterChangePayload),
StreamDeckDevicesConnected(StreamDeckDevicePayload),
}
Expand Down
1 change: 1 addition & 0 deletions main/src/infrastructure/api/convert/from_data/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub fn convert_source(
match data.reaper_source_type {
MidiDeviceChanges => persistence::Source::MidiDeviceChanges,
RealearnUnitStart => persistence::Source::RealearnInstanceStart,
RealearnCompartmentLoaded => persistence::Source::RealearnCompartmentLoaded,
Timer => persistence::Source::Timer(persistence::TimerSource {
duration: data.timer_millis,
}),
Expand Down
10 changes: 7 additions & 3 deletions main/src/infrastructure/api/convert/to_data/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub fn convert_source(s: Source) -> ConversionResult<SourceModelData> {
Source::RealearnInstanceStart => ReaperSourceType::RealearnUnitStart,
Source::Timer(_) => ReaperSourceType::Timer,
Source::RealearnParameter(_) => ReaperSourceType::RealearnParameter,
Source::RealearnCompartmentLoaded => ReaperSourceType::RealearnCompartmentLoaded,
_ => Default::default(),
},
timer_millis: match &s {
Expand All @@ -166,9 +167,12 @@ fn convert_category(s: &Source) -> SourceCategory {
use Source::*;
match s {
None => SourceCategory::Never,
MidiDeviceChanges | RealearnInstanceStart | Timer(_) | RealearnParameter(_) | Speech => {
SourceCategory::Reaper
}
MidiDeviceChanges
| RealearnInstanceStart
| RealearnCompartmentLoaded
| Timer(_)
| RealearnParameter(_)
| Speech => SourceCategory::Reaper,
MidiNoteVelocity(_)
| MidiNoteKeyNumber(_)
| MidiPolyphonicKeyPressureAmount(_)
Expand Down
2 changes: 2 additions & 0 deletions main/src/infrastructure/data/unit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ impl UnitData {
}
// Notify
session.notify_everything_has_changed();
session.notify_compartment_loaded(CompartmentKind::Main);
session.notify_compartment_loaded(CompartmentKind::Controller);
Ok(())
}

Expand Down
7 changes: 5 additions & 2 deletions main/src/infrastructure/ui/stream_deck_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub fn create_stream_deck_compartment_reflecting_toolbar(
// Those don't ever send feedback because there's no current value, and as such there's also no feedback value
// and the screen stays as it is.
// TODO-high CONTINUE Toolbar images should be slided, not faded
// TODO-high CONTINUE "ReaLearn Unit Start" should be replaced with "ReaLearn Compartment load"
let button_mappings = items.enumerate().map(|(i, item)| {
let action = Reaper::get()
.main_section()
Expand Down Expand Up @@ -76,6 +75,7 @@ pub fn create_stream_deck_compartment_reflecting_toolbar(
..Default::default()
},
ActionCharacter::Trigger => Glue {
// TODO-high CONTINUE This is obsolete for Trigger as soon as the feedback prob is solved
button_filter: Some(ButtonFilter::PressOnly),
..Default::default()
},
Expand All @@ -91,6 +91,9 @@ pub fn create_stream_deck_compartment_reflecting_toolbar(
};
Some(cmd)
},
// TODO-high CONTINUE This should be Trigger for trigger-like actions, as soon as the feedback prob is solved
// TODO-high CONTINUE It might be a problem in general that non-trigger actions are not retriggerable.
// Because the value can't usually be relied on! Only in case of toggle actions.
invocation: Some(ActionInvocationKind::Absolute7Bit),
..Default::default()
};
Expand All @@ -104,7 +107,7 @@ pub fn create_stream_deck_compartment_reflecting_toolbar(
});
let set_brightness_to_max_mapping = Mapping {
name: Some("Set brightness to max".to_string()),
source: Some(Source::RealearnInstanceStart),
source: Some(Source::RealearnCompartmentLoaded),
target: Some(Target::StreamDeckBrightness(Default::default())),
..Default::default()
};
Expand Down

0 comments on commit 2c0104b

Please sign in to comment.