Skip to content

Commit

Permalink
#664 Show in status bar if control and/or feedback disabled instance-…
Browse files Browse the repository at this point in the history
…wide

don't show it by greying out mappings anymore
  • Loading branch information
helgoboss committed Oct 14, 2022
1 parent ce7c00c commit 62ab9d9
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 19 deletions.
7 changes: 7 additions & 0 deletions main/src/application/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2424,6 +2424,13 @@ impl DomainEventHandler for WeakSession {
.borrow_mut()
.set_on_mappings(on_mappings);
}
GlobalControlAndFeedbackStateChanged(state) => {
session
.borrow()
.instance_state
.borrow_mut()
.set_global_control_and_feedback_state(state);
}
UpdatedSingleMappingOnState(event) => {
session
.borrow()
Expand Down
7 changes: 7 additions & 0 deletions main/src/domain/eventing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::fmt::Debug;
#[derive(Debug)]
pub enum DomainEvent<'a> {
CapturedIncomingMessage(MessageCaptureEvent),
GlobalControlAndFeedbackStateChanged(GlobalControlAndFeedbackState),
UpdatedOnMappings(HashSet<QualifiedMappingId>),
UpdatedSingleMappingOnState(UpdatedSingleMappingOnStateEvent),
UpdatedSingleParameterValue {
Expand All @@ -33,6 +34,12 @@ pub enum DomainEvent<'a> {
TimeForCelebratingSuccess,
}

#[derive(Copy, Clone, Eq, PartialEq, Debug, Default)]
pub struct GlobalControlAndFeedbackState {
pub control_active: bool,
pub feedback_active: bool,
}

#[derive(Clone, Debug)]
pub struct MessageCaptureEvent {
pub result: MessageCaptureResult,
Expand Down
21 changes: 19 additions & 2 deletions main/src/domain/instance_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use rxrust::prelude::*;

use crate::base::{NamedChannelSender, Prop, SenderToNormalThread, SenderToRealTimeThread};
use crate::domain::{
BackboneState, Compartment, FxDescriptor, FxInputClipRecordTask, GroupId,
HardwareInputClipRecordTask, InstanceId, MappingId, MappingSnapshotContainer,
BackboneState, Compartment, FxDescriptor, FxInputClipRecordTask, GlobalControlAndFeedbackState,
GroupId, HardwareInputClipRecordTask, InstanceId, MappingId, MappingSnapshotContainer,
NormalAudioHookTask, NormalRealTimeTask, QualifiedMappingId, Tag, TagScope, TrackDescriptor,
VirtualMappingSnapshotIdForLoad,
};
Expand Down Expand Up @@ -59,6 +59,8 @@ pub struct InstanceState {
/// - Completely derived from mappings, so it's redundant state.
/// - It's needed by both processing layer and layers above.
on_mappings: Prop<HashSet<QualifiedMappingId>>,
/// Whether control/feedback are globally active.
global_control_and_feedback_state: Prop<GlobalControlAndFeedbackState>,
/// All mapping tags whose mappings have been switched on via tag.
///
/// - Set by target "ReaLearn: Enable/disable mappings".
Expand Down Expand Up @@ -177,6 +179,7 @@ impl InstanceState {
active_mapping_by_group: Default::default(),
mapping_infos: Default::default(),
on_mappings: Default::default(),
global_control_and_feedback_state: Default::default(),
active_mapping_tags: Default::default(),
active_instance_tags: Default::default(),
copied_clip: None,
Expand Down Expand Up @@ -436,16 +439,30 @@ impl InstanceState {
self.on_mappings.get_ref().contains(&id)
}

pub fn global_control_and_feedback_state(&self) -> GlobalControlAndFeedbackState {
self.global_control_and_feedback_state.get()
}

pub fn on_mappings_changed(
&self,
) -> impl LocalObservable<'static, Item = (), Err = ()> + 'static {
self.on_mappings.changed()
}

pub fn global_control_and_feedback_state_changed(
&self,
) -> impl LocalObservable<'static, Item = (), Err = ()> + 'static {
self.global_control_and_feedback_state.changed()
}

pub fn set_on_mappings(&mut self, on_mappings: HashSet<QualifiedMappingId>) {
self.on_mappings.set(on_mappings);
}

pub fn set_global_control_and_feedback_state(&mut self, state: GlobalControlAndFeedbackState) {
self.global_control_and_feedback_state.set(state);
}

pub fn set_mapping_on(&mut self, id: QualifiedMappingId, is_on: bool) {
self.on_mappings.mut_in_place(|m| {
if is_on {
Expand Down
36 changes: 19 additions & 17 deletions main/src/domain/main_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use crate::domain::{
ControlMode, ControlOutcome, DeviceFeedbackOutput, DomainEvent, DomainEventHandler,
ExtendedProcessorContext, FeedbackAudioHookTask, FeedbackCollector, FeedbackDestinations,
FeedbackOutput, FeedbackRealTimeTask, FeedbackResolution, FeedbackSendBehavior,
FinalRealFeedbackValue, FinalSourceFeedbackValue, GroupId, HitInstructionContext,
HitInstructionResponse, InstanceContainer, InstanceOrchestrationEvent, InstanceStateChanged,
IoUpdatedEvent, KeyMessage, LimitedAsciiString, MainMapping, MainSourceMessage,
MappingActivationEffect, MappingControlResult, MappingId, MappingInfo, MessageCaptureEvent,
MessageCaptureResult, MidiControlInput, MidiDestination, MidiScanResult, NormalRealTimeTask,
OrderedMappingIdSet, OrderedMappingMap, OscDeviceId, OscFeedbackTask, PluginParamIndex,
PluginParams, ProcessorContext, ProjectOptions, ProjectionFeedbackValue,
FinalRealFeedbackValue, FinalSourceFeedbackValue, GlobalControlAndFeedbackState, GroupId,
HitInstructionContext, HitInstructionResponse, InstanceContainer, InstanceOrchestrationEvent,
InstanceStateChanged, IoUpdatedEvent, KeyMessage, LimitedAsciiString, MainMapping,
MainSourceMessage, MappingActivationEffect, MappingControlResult, MappingId, MappingInfo,
MessageCaptureEvent, MessageCaptureResult, MidiControlInput, MidiDestination, MidiScanResult,
NormalRealTimeTask, OrderedMappingIdSet, OrderedMappingMap, OscDeviceId, OscFeedbackTask,
PluginParamIndex, PluginParams, ProcessorContext, ProjectOptions, ProjectionFeedbackValue,
QualifiedClipMatrixEvent, QualifiedMappingId, QualifiedSource, RawParamValue,
RealTimeMappingUpdate, RealTimeTargetUpdate, RealearnMonitoringFxParameterValueChangedEvent,
RealearnParameterChangePayload, ReaperConfigChange, ReaperMessage, ReaperTarget,
Expand Down Expand Up @@ -1232,6 +1232,13 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
any_main_mapping_is_effectively_on,
project_options,
);
let event = GlobalControlAndFeedbackState {
control_active: self.basics.control_is_globally_enabled,
feedback_active: self.basics.feedback_is_globally_enabled,
};
self.basics
.event_handler
.handle_event_ignoring_error(DomainEvent::GlobalControlAndFeedbackStateChanged(event));
}

fn potentially_enable_or_disable_control(
Expand Down Expand Up @@ -2051,16 +2058,11 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
}

fn update_on_mappings(&self) {
let instance_is_enabled = self.basics.instance_control_is_effectively_enabled()
&& self.basics.instance_feedback_is_effectively_enabled();
let on_mappings = if instance_is_enabled {
self.all_mappings()
.filter(|m| m.is_effectively_on())
.map(MainMapping::qualified_id)
.collect()
} else {
HashSet::new()
};
let on_mappings = self
.all_mappings()
.filter(|m| m.is_effectively_on())
.map(MainMapping::qualified_id)
.collect();
self.basics
.event_handler
.handle_event_ignoring_error(DomainEvent::UpdatedOnMappings(on_mappings));
Expand Down
14 changes: 14 additions & 0 deletions main/src/infrastructure/ui/main_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ impl MainPanel {
);
let _ = write!(&mut text, " (on track {:.15})", instance_fx_track_label);
}
let control_and_feedback_state = instance_state.global_control_and_feedback_state();
if !control_and_feedback_state.control_active {
text.push_str(" | CONTROL off");
}
if !control_and_feedback_state.feedback_active {
text.push_str(" | FEEDBACK off");
}
let label = self.view.require_control(root::ID_MAIN_PANEL_STATUS_2_TEXT);
label.disable();
label.set_text(text.as_str());
Expand Down Expand Up @@ -256,6 +263,13 @@ impl MainPanel {
self.when(session.tags.changed().merge(session.id.changed()), |view| {
view.invalidate_status_1_text();
});
let instance_state = session.instance_state().borrow();
self.when(
instance_state.global_control_and_feedback_state_changed(),
|view| {
view.invalidate_status_2_text();
},
);
});
}

Expand Down

0 comments on commit 62ab9d9

Please sign in to comment.