diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index c8e75b3e7..87d70bfc0 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -1131,25 +1131,21 @@ void Pane::_ControlWarningBellHandler(const winrt::Windows::Foundation::IInspect if (WI_IsFlagSet(_profile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Audible)) { // Audible is set, play the sound - // const auto soundAlias = reinterpret_cast(SND_ALIAS_SYSTEMHAND); - // PlaySound(soundAlias, NULL, SND_ALIAS_ID | SND_ASYNC | SND_SENTRY); + auto sounds{ _profile.BellSound() }; + if (sounds && sounds.Size() > 0) + { + winrt::Windows::Foundation::Uri uri{ sounds.GetAt(rand() % sounds.Size()) }; + auto source{ winrt::Windows::Media::Core::MediaSource::CreateFromUri(uri) }; + auto item{ winrt::Windows::Media::Playback::MediaPlaybackItem(source) }; + p.Source(item); + p.Play(); + } + else + { + const auto soundAlias = reinterpret_cast(SND_ALIAS_SYSTEMHAND); + PlaySound(soundAlias, NULL, SND_ALIAS_ID | SND_ASYNC | SND_SENTRY); - winrt::Windows::Foundation::Uri honks[]{ - winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk1.mp3"), - winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk2.mp3"), - winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk3.mp3"), - winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk4.mp3"), - winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk-muffled1.mp3"), - winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk-muffled2.mp3"), - winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk-muffled3.mp3"), - }; - - auto uri{ honks[rand() % ARRAYSIZE(honks)] }; - auto source{ winrt::Windows::Media::Core::MediaSource::CreateFromUri(uri) }; - - auto item{ winrt::Windows::Media::Playback::MediaPlaybackItem(source) }; - p.Source(item); - p.Play(); + } } if (WI_IsFlagSet(_profile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Window)) diff --git a/src/cascadia/TerminalSettingsModel/Profile.cpp b/src/cascadia/TerminalSettingsModel/Profile.cpp index 287ce8970..b3a89b720 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.cpp +++ b/src/cascadia/TerminalSettingsModel/Profile.cpp @@ -45,6 +45,7 @@ static constexpr std::string_view AntialiasingModeKey{ "antialiasingMode" }; static constexpr std::string_view TabColorKey{ "tabColor" }; static constexpr std::string_view BellStyleKey{ "bellStyle" }; static constexpr std::string_view UnfocusedAppearanceKey{ "unfocusedAppearance" }; +static constexpr std::string_view BellSoundKey{ "bellSound" }; Profile::Profile(guid guid) noexcept : _Guid(guid) @@ -134,6 +135,7 @@ winrt::com_ptr Profile::CopySettings() const profile->_SnapOnInput = _SnapOnInput; profile->_AltGrAliasing = _AltGrAliasing; profile->_BellStyle = _BellStyle; + profile->_BellSound = _BellSound; profile->_ConnectionType = _ConnectionType; profile->_Origin = _Origin; profile->_FontInfo = *fontInfo; @@ -221,6 +223,7 @@ void Profile::LayerJson(const Json::Value& json) JsonUtils::GetValueForKey(json, AntialiasingModeKey, _AntialiasingMode); JsonUtils::GetValueForKey(json, TabColorKey, _TabColor); JsonUtils::GetValueForKey(json, BellStyleKey, _BellStyle); + JsonUtils::GetValueForKey(json, BellSoundKey, _BellSound); if (json.isMember(JsonKey(UnfocusedAppearanceKey))) { @@ -374,6 +377,7 @@ Json::Value Profile::ToJson() const JsonUtils::SetValueForKey(json, AntialiasingModeKey, _AntialiasingMode); JsonUtils::SetValueForKey(json, TabColorKey, _TabColor); JsonUtils::SetValueForKey(json, BellStyleKey, _BellStyle); + JsonUtils::SetValueForKey(json, BellSoundKey, _BellSound); // Font settings const auto fontInfoImpl = winrt::get_self(_FontInfo); diff --git a/src/cascadia/TerminalSettingsModel/Profile.h b/src/cascadia/TerminalSettingsModel/Profile.h index f69471332..a690ee961 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.h +++ b/src/cascadia/TerminalSettingsModel/Profile.h @@ -140,6 +140,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation INHERITABLE_SETTING(Model::Profile, Model::IAppearanceConfig, UnfocusedAppearance, nullptr); + INHERITABLE_SETTING(Model::Profile, Windows::Foundation::Collections::IVector, BellSound); + private: Model::IAppearanceConfig _DefaultAppearance{ winrt::make(weak_ref(*this)) }; Model::FontConfig _FontInfo{ winrt::make(weak_ref(*this)) }; diff --git a/src/cascadia/TerminalSettingsModel/Profile.idl b/src/cascadia/TerminalSettingsModel/Profile.idl index 670303ff1..27670a0ef 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.idl +++ b/src/cascadia/TerminalSettingsModel/Profile.idl @@ -81,5 +81,7 @@ namespace Microsoft.Terminal.Settings.Model INHERITABLE_PROFILE_SETTING(Boolean, SnapOnInput); INHERITABLE_PROFILE_SETTING(Boolean, AltGrAliasing); INHERITABLE_PROFILE_SETTING(BellStyle, BellStyle); + + INHERITABLE_PROFILE_SETTING(Windows.Foundation.Collections.IVector, BellSound); } }