Skip to content

Commit

Permalink
Change unused source detection to not clone complete source
Browse files Browse the repository at this point in the history
because the clone would now be incomplete ...
and it's also unnecessary as it turns out
  • Loading branch information
helgoboss committed Nov 16, 2023
1 parent 9d09d99 commit 1ed0503
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions main/src/domain/main_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use crate::domain::{
MessageCaptureEvent, MessageCaptureResult, MidiControlInput, MidiDestination, MidiScanResult,
NormalRealTimeTask, OrderedMappingIdSet, OrderedMappingMap, OscDeviceId, OscFeedbackTask,
PluginParamIndex, PluginParams, ProcessorContext, ProjectOptions, ProjectionFeedbackValue,
QualifiedMappingId, QualifiedSource, RawParamValue, RealTimeMappingUpdate,
RealTimeTargetUpdate, RealearnMonitoringFxParameterValueChangedEvent,
RealearnParameterChangePayload, ReaperConfigChange, ReaperMessage, ReaperSourceFeedbackValue,
ReaperTarget, SharedInstanceState, SourceReleasedEvent, SpecificCompoundFeedbackValue,
TargetControlEvent, TargetValueChangedEvent, UpdatedSingleMappingOnStateEvent,
VirtualControlElement, VirtualSourceValue,
QualifiedMappingId, RawParamValue, RealTimeMappingUpdate, RealTimeTargetUpdate,
RealearnMonitoringFxParameterValueChangedEvent, RealearnParameterChangePayload,
ReaperConfigChange, ReaperMessage, ReaperSourceFeedbackValue, ReaperTarget,
SharedInstanceState, SourceReleasedEvent, SpecificCompoundFeedbackValue, TargetControlEvent,
TargetValueChangedEvent, UpdatedSingleMappingOnStateEvent, VirtualControlElement,
VirtualSourceValue,
};
use derive_more::Display;
use enum_map::EnumMap;
Expand Down Expand Up @@ -2058,7 +2058,7 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
compartment: Compartment,
mapping_updates: Vec<RealTimeMappingUpdate>,
target_updates: Vec<RealTimeTargetUpdate>,
unused_sources: HashMap<CompoundMappingSourceAddress, QualifiedSource>,
unused_sources: UnusedSources,
changed_mappings: impl Iterator<Item = MappingId>,
) {
// Send feedback
Expand Down Expand Up @@ -2314,24 +2314,37 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
.collect()
}

/// Returns a hash map where each key is the source address of a source whose mapping
/// emits feedback and the value is the "off feedback" message.
///
/// This will be used to check which sources are not in use anymore and then send the
/// "off feedback" message accordingly.
fn currently_feedback_enabled_sources(
&self,
compartment: Compartment,
include_virtual: bool,
) -> HashMap<CompoundMappingSourceAddress, QualifiedSource> {
) -> UnusedSources {
if include_virtual {
self.all_mappings_in_compartment(compartment)
.filter(|m| m.feedback_is_effectively_on())
.filter_map(|m| {
Some((m.source().extract_feedback_address()?, m.qualified_source()))
Some((
m.source().extract_feedback_address()?,
m.qualified_source()
.off_feedback(&self.basics.source_context)?,
))
})
.collect()
} else {
self.collections.mappings[compartment]
.values()
.filter(|m| m.feedback_is_effectively_on())
.filter_map(|m| {
Some((m.source().extract_feedback_address()?, m.qualified_source()))
Some((
m.source().extract_feedback_address()?,
m.qualified_source()
.off_feedback(&self.basics.source_context)?,
))
})
.collect()
}
Expand All @@ -2340,7 +2353,7 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
fn handle_feedback_after_having_updated_all_mappings(
&mut self,
compartment: Compartment,
now_unused_sources: HashMap<CompoundMappingSourceAddress, QualifiedSource>,
now_unused_sources: UnusedSources,
) {
self.send_feedback(
FeedbackReason::Normal,
Expand All @@ -2357,7 +2370,7 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
fn handle_feedback_after_having_updated_particular_mappings(
&mut self,
compartment: Compartment,
now_unused_sources: HashMap<CompoundMappingSourceAddress, QualifiedSource>,
now_unused_sources: UnusedSources,
mapping_ids: impl Iterator<Item = MappingId>,
) {
self.send_feedback(
Expand All @@ -2373,15 +2386,9 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
}

/// Indicate via off feedback the sources which are not in use anymore.
fn send_off_feedback_for_unused_sources(
&self,
now_unused_sources: HashMap<CompoundMappingSourceAddress, QualifiedSource>,
) {
for s in now_unused_sources.into_values() {
self.send_feedback(
FeedbackReason::ClearUnusedSource,
s.off_feedback(&self.basics.source_context),
);
fn send_off_feedback_for_unused_sources(&self, now_unused_sources: UnusedSources) {
for feedback_value in now_unused_sources.into_values() {
self.send_feedback(FeedbackReason::ClearUnusedSource, Some(feedback_value));
}
}

Expand Down Expand Up @@ -4354,3 +4361,5 @@ pub struct KeyProcessingResult {
/// Whether this message should be filtered out from the keyboard processing chain.
pub filter_out_event: bool,
}

type UnusedSources = HashMap<CompoundMappingSourceAddress, CompoundFeedbackValue>;

0 comments on commit 1ed0503

Please sign in to comment.