Skip to content

Commit

Permalink
#627 Play sound on feedback only if enabled for that mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Aug 31, 2022
1 parent fc3fa20 commit 5b7f163
Show file tree
Hide file tree
Showing 10 changed files with 422 additions and 53 deletions.
8 changes: 8 additions & 0 deletions api/src/persistence/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct Mapping {
#[serde(skip_serializing_if = "Option::is_none")]
pub target: Option<Target>,
#[serde(skip_serializing_if = "Option::is_none")]
pub success_audio_feedback: Option<SuccessAudioFeedback>,
#[serde(skip_serializing_if = "Option::is_none")]
pub unprocessed: Option<serde_json::Map<String, serde_json::Value>>,
}

Expand All @@ -60,6 +62,12 @@ pub enum RawMidiMessage {
ByteArray(Vec<u8>),
}

#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "kind")]
pub enum SuccessAudioFeedback {
Simple,
}

#[derive(PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "kind")]
pub enum ActivationCondition {
Expand Down
5 changes: 5 additions & 0 deletions dialogs/src/mapping_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,11 @@ pub fn create(context: ScopedContext, ids: &mut IdGenerator) -> Dialog {
) + ES_MULTILINE
+ ES_READONLY
+ WS_VSCROLL,
context.checkbox(
"Beep on success",
ids.named_id("IDC_BEEP_ON_SUCCESS_CHECK_BOX"),
rect(7, 516, 70, 10),
) + WS_TABSTOP,
ok_button(
ids.named_id("ID_MAPPING_PANEL_OK"),
context.rect(201, 514, 50, 14),
Expand Down
16 changes: 15 additions & 1 deletion main/src/application/mapping_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum MappingCommand {
SetFeedbackIsEnabled(bool),
SetFeedbackSendBehavior(FeedbackSendBehavior),
SetVisibleInProjection(bool),
SetBeepOnSuccess(bool),
ChangeActivationCondition(ActivationConditionCommand),
ChangeSource(SourceCommand),
ChangeMode(ModeCommand),
Expand All @@ -46,6 +47,7 @@ pub enum MappingProp {
FeedbackIsEnabled,
FeedbackSendBehavior,
VisibleInProjection,
BeepOnSuccess,
AdvancedSettings,
InActivationCondition(Affected<ActivationConditionProp>),
InSource(Affected<SourceProp>),
Expand All @@ -63,7 +65,8 @@ impl GetProcessingRelevance for MappingProp {
| P::FeedbackIsEnabled
| P::FeedbackSendBehavior
| P::VisibleInProjection
| P::AdvancedSettings => Some(ProcessingRelevance::ProcessingRelevant),
| P::AdvancedSettings
| P::BeepOnSuccess => Some(ProcessingRelevance::ProcessingRelevant),
P::InActivationCondition(p) => p.processing_relevance(),
P::InMode(p) => p.processing_relevance(),
P::InSource(p) => p.processing_relevance(),
Expand Down Expand Up @@ -92,6 +95,7 @@ pub struct MappingModel {
feedback_send_behavior: FeedbackSendBehavior,
pub activation_condition_model: ActivationConditionModel,
visible_in_projection: bool,
beep_on_success: bool,
pub source_model: SourceModel,
pub mode_model: ModeModel,
pub target_model: TargetModel,
Expand Down Expand Up @@ -161,6 +165,10 @@ impl<'a> Change<'a> for MappingModel {
self.visible_in_projection = v;
One(P::VisibleInProjection)
}
C::SetBeepOnSuccess(v) => {
self.beep_on_success = v;
One(P::BeepOnSuccess)
}
C::ChangeActivationCondition(cmd) => {
return self
.activation_condition_model
Expand Down Expand Up @@ -210,6 +218,7 @@ impl MappingModel {
feedback_send_behavior: Default::default(),
activation_condition_model: Default::default(),
visible_in_projection: true,
beep_on_success: false,
source_model: SourceModel::new(compartment),
mode_model: Default::default(),
target_model: TargetModel::default_for_compartment(compartment),
Expand Down Expand Up @@ -250,6 +259,10 @@ impl MappingModel {
self.visible_in_projection
}

pub fn beep_on_success(&self) -> bool {
self.beep_on_success
}

pub fn activation_condition_model(&self) -> &ActivationConditionModel {
&self.activation_condition_model
}
Expand Down Expand Up @@ -545,6 +558,7 @@ impl MappingModel {
control_is_enabled: group_data.control_is_enabled && self.control_is_enabled(),
feedback_is_enabled: group_data.feedback_is_enabled && self.feedback_is_enabled(),
feedback_send_behavior: self.feedback_send_behavior(),
beep_on_success: self.beep_on_success,
};
let mut merged_tags = group_data.tags;
merged_tags.extend_from_slice(&self.tags);
Expand Down
9 changes: 5 additions & 4 deletions main/src/domain/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub struct ProcessorMappingOptions {
pub control_is_enabled: bool,
pub feedback_is_enabled: bool,
pub feedback_send_behavior: FeedbackSendBehavior,
pub beep_on_success: bool,
}

impl ProcessorMappingOptions {
Expand Down Expand Up @@ -257,8 +258,8 @@ impl MainMapping {
}
}

pub fn success_celebration_enabled(&self) -> bool {
true
fn beep_on_success(&self) -> bool {
self.core.options.beep_on_success
}

/// This is for:
Expand Down Expand Up @@ -991,7 +992,7 @@ impl MainMapping {
new_target_value,
feedback_value: self.manual_feedback_because_of_target(new_target_value, context),
hit_instruction: first_hit_instruction,
celebrate_success: self.success_celebration_enabled(),
celebrate_success: self.beep_on_success(),
}
} else {
MappingControlResult {
Expand Down Expand Up @@ -1026,7 +1027,7 @@ impl MainMapping {
None
},
hit_instruction: first_hit_instruction,
celebrate_success: self.success_celebration_enabled(),
celebrate_success: self.beep_on_success(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions main/src/infrastructure/api/convert/from_data/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub fn convert_mapping(
},
glue: style.required_value(convert_glue(data.mode, style)?),
target: style.required_value(convert_target(data.target, style)?),
success_audio_feedback: data.success_audio_feedback,
unprocessed: style.optional_value(advanced.unprocessed),
};
Ok(mapping)
Expand Down
1 change: 1 addition & 0 deletions main/src/infrastructure/api/convert/to_data/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub fn convert_mapping(
visible_in_projection: m
.visible_in_projection
.unwrap_or(defaults::MAPPING_VISIBLE_IN_PROJECTION),
success_audio_feedback: m.success_audio_feedback,
};
Ok(v)
}
Expand Down
13 changes: 13 additions & 0 deletions main/src/infrastructure/data/mapping_model_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::infrastructure::data::{
ModeModelData, ModelToDataConversionContext, SourceModelData, TargetModelData,
};
use crate::infrastructure::plugin::App;
use realearn_api::persistence::SuccessAudioFeedback;
use semver::Version;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -73,6 +74,12 @@ pub struct MappingModelData {
pub advanced: Option<serde_yaml::mapping::Mapping>,
#[serde(default = "bool_true", skip_serializing_if = "is_bool_true")]
pub visible_in_projection: bool,
#[serde(
default,
deserialize_with = "deserialize_null_default",
skip_serializing_if = "is_default"
)]
pub success_audio_feedback: Option<SuccessAudioFeedback>,
}

impl MappingModelData {
Expand Down Expand Up @@ -107,6 +114,11 @@ impl MappingModelData {
),
advanced: model.advanced_settings().cloned(),
visible_in_projection: model.visible_in_projection(),
success_audio_feedback: if model.beep_on_success() {
Some(SuccessAudioFeedback::Simple)
} else {
None
},
}
}

Expand Down Expand Up @@ -241,6 +253,7 @@ impl MappingModelData {
model.change(P::SetFeedbackSendBehavior(feedback_send_behavior));
let _ = model.set_advanced_settings(self.advanced.clone());
model.change(P::SetVisibleInProjection(self.visible_in_projection));
model.change(P::SetBeepOnSuccess(self.success_audio_feedback.is_some()));
Ok(())
}
}
97 changes: 49 additions & 48 deletions main/src/infrastructure/ui/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub mod root {
pub const ID_CLEAR_SOURCE_FILTER_BUTTON: u32 = 30034;
pub const ID_FILTER_BY_TARGET_BUTTON: u32 = 30035;
pub const ID_CLEAR_TARGET_FILTER_BUTTON: u32 = 30036;
pub const ID_MAPPING_PANEL: u32 = 30194;
pub const ID_MAPPING_PANEL: u32 = 30195;
pub const ID_MAPPING_FEEDBACK_SEND_BEHAVIOR_COMBO_BOX: u32 = 30043;
pub const ID_MAPPING_SHOW_IN_PROJECTION_CHECK_BOX: u32 = 30044;
pub const ID_MAPPING_ADVANCED_BUTTON: u32 = 30045;
Expand Down Expand Up @@ -252,51 +252,52 @@ pub mod root {
pub const ID_MAPPING_HELP_APPLICABLE_TO_LABEL: u32 = 30189;
pub const ID_MAPPING_HELP_APPLICABLE_TO_COMBO_BOX: u32 = 30190;
pub const ID_MAPPING_HELP_CONTENT_LABEL: u32 = 30191;
pub const ID_MAPPING_PANEL_OK: u32 = 30192;
pub const IDC_MAPPING_ENABLED_CHECK_BOX: u32 = 30193;
pub const ID_MAPPING_ROW_PANEL: u32 = 30212;
pub const ID_MAPPING_ROW_MAPPING_LABEL: u32 = 30195;
pub const IDC_MAPPING_ROW_ENABLED_CHECK_BOX: u32 = 30196;
pub const ID_MAPPING_ROW_EDIT_BUTTON: u32 = 30197;
pub const ID_MAPPING_ROW_DUPLICATE_BUTTON: u32 = 30198;
pub const ID_MAPPING_ROW_REMOVE_BUTTON: u32 = 30199;
pub const ID_MAPPING_ROW_LEARN_SOURCE_BUTTON: u32 = 30200;
pub const ID_MAPPING_ROW_LEARN_TARGET_BUTTON: u32 = 30201;
pub const ID_MAPPING_ROW_CONTROL_CHECK_BOX: u32 = 30202;
pub const ID_MAPPING_ROW_FEEDBACK_CHECK_BOX: u32 = 30203;
pub const ID_MAPPING_ROW_SOURCE_LABEL_TEXT: u32 = 30204;
pub const ID_MAPPING_ROW_TARGET_LABEL_TEXT: u32 = 30205;
pub const ID_MAPPING_ROW_DIVIDER: u32 = 30206;
pub const ID_MAPPING_ROW_GROUP_LABEL: u32 = 30207;
pub const IDC_MAPPING_ROW_MATCHED_INDICATOR_TEXT: u32 = 30208;
pub const ID_UP_BUTTON: u32 = 30210;
pub const ID_DOWN_BUTTON: u32 = 30211;
pub const ID_MAPPING_ROWS_PANEL: u32 = 30215;
pub const ID_DISPLAY_ALL_GROUPS_BUTTON: u32 = 30213;
pub const ID_GROUP_IS_EMPTY_TEXT: u32 = 30214;
pub const ID_MESSAGE_PANEL: u32 = 30217;
pub const ID_MESSAGE_TEXT: u32 = 30216;
pub const ID_SHARED_GROUP_MAPPING_PANEL: u32 = 30233;
pub const ID_MAPPING_NAME_EDIT_CONTROL: u32 = 30219;
pub const ID_MAPPING_TAGS_EDIT_CONTROL: u32 = 30221;
pub const ID_MAPPING_CONTROL_ENABLED_CHECK_BOX: u32 = 30222;
pub const ID_MAPPING_FEEDBACK_ENABLED_CHECK_BOX: u32 = 30223;
pub const ID_MAPPING_ACTIVATION_TYPE_COMBO_BOX: u32 = 30225;
pub const ID_MAPPING_ACTIVATION_SETTING_1_LABEL_TEXT: u32 = 30226;
pub const ID_MAPPING_ACTIVATION_SETTING_1_BUTTON: u32 = 30227;
pub const ID_MAPPING_ACTIVATION_SETTING_1_CHECK_BOX: u32 = 30228;
pub const ID_MAPPING_ACTIVATION_SETTING_2_LABEL_TEXT: u32 = 30229;
pub const ID_MAPPING_ACTIVATION_SETTING_2_BUTTON: u32 = 30230;
pub const ID_MAPPING_ACTIVATION_SETTING_2_CHECK_BOX: u32 = 30231;
pub const ID_MAPPING_ACTIVATION_EDIT_CONTROL: u32 = 30232;
pub const ID_MAIN_PANEL: u32 = 30239;
pub const ID_MAIN_PANEL_STATUS_1_TEXT: u32 = 30235;
pub const ID_MAIN_PANEL_STATUS_2_TEXT: u32 = 30236;
pub const IDC_EDIT_TAGS_BUTTON: u32 = 30237;
pub const ID_MAIN_PANEL_VERSION_TEXT: u32 = 30238;
pub const ID_YAML_EDITOR_PANEL: u32 = 30244;
pub const ID_YAML_TEXT_EDITOR_BUTTON: u32 = 30240;
pub const ID_YAML_EDIT_CONTROL: u32 = 30241;
pub const ID_YAML_HELP_BUTTON: u32 = 30242;
pub const ID_YAML_EDIT_INFO_TEXT: u32 = 30243;
pub const IDC_BEEP_ON_SUCCESS_CHECK_BOX: u32 = 30192;
pub const ID_MAPPING_PANEL_OK: u32 = 30193;
pub const IDC_MAPPING_ENABLED_CHECK_BOX: u32 = 30194;
pub const ID_MAPPING_ROW_PANEL: u32 = 30213;
pub const ID_MAPPING_ROW_MAPPING_LABEL: u32 = 30196;
pub const IDC_MAPPING_ROW_ENABLED_CHECK_BOX: u32 = 30197;
pub const ID_MAPPING_ROW_EDIT_BUTTON: u32 = 30198;
pub const ID_MAPPING_ROW_DUPLICATE_BUTTON: u32 = 30199;
pub const ID_MAPPING_ROW_REMOVE_BUTTON: u32 = 30200;
pub const ID_MAPPING_ROW_LEARN_SOURCE_BUTTON: u32 = 30201;
pub const ID_MAPPING_ROW_LEARN_TARGET_BUTTON: u32 = 30202;
pub const ID_MAPPING_ROW_CONTROL_CHECK_BOX: u32 = 30203;
pub const ID_MAPPING_ROW_FEEDBACK_CHECK_BOX: u32 = 30204;
pub const ID_MAPPING_ROW_SOURCE_LABEL_TEXT: u32 = 30205;
pub const ID_MAPPING_ROW_TARGET_LABEL_TEXT: u32 = 30206;
pub const ID_MAPPING_ROW_DIVIDER: u32 = 30207;
pub const ID_MAPPING_ROW_GROUP_LABEL: u32 = 30208;
pub const IDC_MAPPING_ROW_MATCHED_INDICATOR_TEXT: u32 = 30209;
pub const ID_UP_BUTTON: u32 = 30211;
pub const ID_DOWN_BUTTON: u32 = 30212;
pub const ID_MAPPING_ROWS_PANEL: u32 = 30216;
pub const ID_DISPLAY_ALL_GROUPS_BUTTON: u32 = 30214;
pub const ID_GROUP_IS_EMPTY_TEXT: u32 = 30215;
pub const ID_MESSAGE_PANEL: u32 = 30218;
pub const ID_MESSAGE_TEXT: u32 = 30217;
pub const ID_SHARED_GROUP_MAPPING_PANEL: u32 = 30234;
pub const ID_MAPPING_NAME_EDIT_CONTROL: u32 = 30220;
pub const ID_MAPPING_TAGS_EDIT_CONTROL: u32 = 30222;
pub const ID_MAPPING_CONTROL_ENABLED_CHECK_BOX: u32 = 30223;
pub const ID_MAPPING_FEEDBACK_ENABLED_CHECK_BOX: u32 = 30224;
pub const ID_MAPPING_ACTIVATION_TYPE_COMBO_BOX: u32 = 30226;
pub const ID_MAPPING_ACTIVATION_SETTING_1_LABEL_TEXT: u32 = 30227;
pub const ID_MAPPING_ACTIVATION_SETTING_1_BUTTON: u32 = 30228;
pub const ID_MAPPING_ACTIVATION_SETTING_1_CHECK_BOX: u32 = 30229;
pub const ID_MAPPING_ACTIVATION_SETTING_2_LABEL_TEXT: u32 = 30230;
pub const ID_MAPPING_ACTIVATION_SETTING_2_BUTTON: u32 = 30231;
pub const ID_MAPPING_ACTIVATION_SETTING_2_CHECK_BOX: u32 = 30232;
pub const ID_MAPPING_ACTIVATION_EDIT_CONTROL: u32 = 30233;
pub const ID_MAIN_PANEL: u32 = 30240;
pub const ID_MAIN_PANEL_STATUS_1_TEXT: u32 = 30236;
pub const ID_MAIN_PANEL_STATUS_2_TEXT: u32 = 30237;
pub const IDC_EDIT_TAGS_BUTTON: u32 = 30238;
pub const ID_MAIN_PANEL_VERSION_TEXT: u32 = 30239;
pub const ID_YAML_EDITOR_PANEL: u32 = 30245;
pub const ID_YAML_TEXT_EDITOR_BUTTON: u32 = 30241;
pub const ID_YAML_EDIT_CONTROL: u32 = 30242;
pub const ID_YAML_HELP_BUTTON: u32 = 30243;
pub const ID_YAML_EDIT_INFO_TEXT: u32 = 30244;
}
21 changes: 21 additions & 0 deletions main/src/infrastructure/ui/mapping_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ impl MappingPanel {
);
view.invalidate_mode_controls();
}
P::BeepOnSuccess => {
view.invalidate_beep_on_success_checkbox();
}
P::IsEnabled => {
view.invalidate_mapping_enabled_check_box();
}
Expand Down Expand Up @@ -1244,6 +1247,14 @@ impl<'a> MutableMappingPanel<'a> {
);
}

fn update_beep_on_success(&mut self) {
let checked = self
.view
.require_control(root::IDC_BEEP_ON_SUCCESS_CHECK_BOX)
.is_checked();
self.change_mapping(MappingCommand::SetBeepOnSuccess(checked));
}

fn update_mapping_is_enabled(&mut self) {
let checked = self
.view
Expand Down Expand Up @@ -3007,6 +3018,7 @@ impl<'a> ImmutableMappingPanel<'a> {
fn invalidate_all_controls(&self) {
self.invalidate_window_title();
self.panel.mapping_header_panel.invalidate_controls();
self.invalidate_beep_on_success_checkbox();
self.invalidate_mapping_enabled_check_box();
self.invalidate_mapping_feedback_send_behavior_combo_box();
self.invalidate_mapping_visible_in_projection_check_box();
Expand Down Expand Up @@ -3172,6 +3184,12 @@ impl<'a> ImmutableMappingPanel<'a> {
.unwrap();
}

fn invalidate_beep_on_success_checkbox(&self) {
self.view
.require_control(root::IDC_BEEP_ON_SUCCESS_CHECK_BOX)
.set_checked(self.mapping.beep_on_success());
}

fn invalidate_mapping_enabled_check_box(&self) {
self.view
.require_control(root::IDC_MAPPING_ENABLED_CHECK_BOX)
Expand Down Expand Up @@ -6031,6 +6049,9 @@ impl View for MappingPanel {
fn button_clicked(self: SharedView<Self>, resource_id: u32) {
match resource_id {
// Mapping
root::IDC_BEEP_ON_SUCCESS_CHECK_BOX => {
self.write(|p| p.update_beep_on_success());
}
root::IDC_MAPPING_ENABLED_CHECK_BOX => {
self.write(|p| p.update_mapping_is_enabled());
}
Expand Down
Loading

0 comments on commit 5b7f163

Please sign in to comment.