Skip to content

Enable changing the bell sound#11511

Merged
16 commits merged intomainfrom
dev/migrie/fhl/honk
Jan 6, 2022
Merged

Enable changing the bell sound#11511
16 commits merged intomainfrom
dev/migrie/fhl/honk

Conversation

@zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented Oct 14, 2021

Summary of the Pull Request

Adds a per-profile setting for setting the audio sound for the bell. The setting is bellSound, it accepts a path. We'll use the file at that path as the sound for the bell. If it doesn't exist, then oh well, so sound for you.

It'll also secretly accept an array of paths. If you provide an array, it will pick one at random.

PR Checklist

Validation Steps Performed

I'm not suggesting that anyone go to this post and download a zip full of honk.mp3s. I'm definitely not suggesting you add it to your settings like

"bellSound": [
    "C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk1.mp3",
    "C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk2.mp3",
    "C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk3.mp3",
    "C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk4.mp3",
    "C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk-muffled1.mp3",
    "C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk-muffled2.mp3",
    "C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk-muffled3.mp3"
]

No, don't do that.

honk-001.mp4
  • It surprisingly works elevated
  • We should probably accept env vars in these paths
  • We may only want one MediaPlayer per terminal, rather than one per pane
  • We may want to validate the paths, and discard ones that don't exist.
    • alternatively, meh

@ghost ghost added Area-Settings Issues related to settings and customizability, for console or terminal Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels Oct 14, 2021
@zadjii-msft zadjii-msft changed the title it honks Enable changing the bell sound Oct 14, 2021
@DHowett
Copy link
Member

DHowett commented Oct 14, 2021

HEAK YEAH IT HONMK safely ignore me

Comment on lines 1137 to 1141
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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the URI points to a video file or stream?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omfg it's great.

Say you had a file that was no.mp4. If you set the path to "bellSound": "%~%\\Downloads\\memes\\no.mp4", then it'll just play the entirety of the audio of the mp4 file. It's great. If you emit another bell in the middle, then it'll just start it over.

There's a lot of possibilities here.

@WSLUser

This comment has been minimized.

@KalleOlaviNiemitalo

This comment has been minimized.

@zadjii-msft zadjii-msft self-assigned this Nov 1, 2021
  Somehow, this also causes an exception on teardown north of
  `Windows.Media.MediaControl.dll!AudioStateMonitorImpl::remove_SoundLevelChanged()`,
  which is in OS code somewhere. Not sure there's anything we can actually do
  about this. There are piles of bugs on that function in the OS repo.

  I think we're going to have to just end up avoiding this entirely.
@zadjii-msft zadjii-msft assigned DHowett and unassigned zadjii-msft Nov 16, 2021
@github-actions

This comment has been minimized.

@zadjii-msft zadjii-msft requested a review from DHowett January 4, 2022 16:13
@zadjii-msft zadjii-msft added the Needs-Second It's a PR that needs another sign-off label Jan 5, 2022
profile->_Hidden = _Hidden;
profile->_TabColor = _TabColor;
profile->_Padding = _Padding;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this random newline seems unnecessary but meh haha

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that actually seems to be the case with most of this file.

Comment on lines 1071 to 1072
auto source{ winrt::Windows::Media::Core::MediaSource::CreateFromUri(uri) };
auto item{ winrt::Windows::Media::Playback::MediaPlaybackItem(source) };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto source{ winrt::Windows::Media::Core::MediaSource::CreateFromUri(uri) };
auto item{ winrt::Windows::Media::Playback::MediaPlaybackItem(source) };
const auto source{ winrt::Windows::Media::Core::MediaSource::CreateFromUri(uri) };
const auto item{ winrt::Windows::Media::Playback::MediaPlaybackItem(source) };

nit

@carlos-zamora
Copy link
Member

Mind filing a follow-up issue for an update to the SUI?

@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jan 6, 2022
@ghost
Copy link

ghost commented Jan 6, 2022

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 9d7966a into main Jan 6, 2022
@ghost ghost deleted the dev/migrie/fhl/honk branch January 6, 2022 17:41
val.push_back(trait.FromJson(element));
}
}
else
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: this is the place I should just check for null and skip

@ghost ghost removed the Needs-Second It's a PR that needs another sign-off label Jan 27, 2022
@zadjii-msft zadjii-msft mentioned this pull request Jan 28, 2022
4 tasks
ghost pushed a commit that referenced this pull request Jan 31, 2022
Sorry for combining two fixes in one PR. I can separate if need be.

* [x] Closes #12276:
  - `"bellSound": null` didn't work. This one was easier, and is atomically in bcc2ca0. Basically, we would deserialize that as an array with a single empty string in it, which we'd try to then play. I think it's more idomatic to have that deserialized as an empty array, which correctly falls back to playing the default sound.
* [x] Closes #12258: 
  - This one is the majority of the rest of the PR. If you leave the MediaPlayer open, then the media keys will _affect the Terminal_. More importantly, once the bell sounds, they'd replay the bell, which is insane. So the fix is to re-create the media player when we need it. We do this per-pane for simpler lifetime tracking. I'm not worried about the overhead of creating a mediaplayer here, since we're already throttling bells.
* Originally added in #11511
* [x] Tested manually
  - Use [`no.mp4`](https://www.youtube.com/watch?v=x2w9TyCv2gk) for this since that's like, 17s long
  - Checked that closing panes / the terminal while a bell was playing didn't crash
  - Playing a bunch of bells at once works
  - closing a pane stops the bell it's playing
  - once the bell stops, the media keys went back to working for Spotify
* [x] I work here
@ghost
Copy link

ghost commented Feb 3, 2022

🎉Windows Terminal Preview v1.13.10336.0 has been released which incorporates this pull request.:tada:

Handy links:

@dark-swordsman
Copy link

dark-swordsman commented Jul 4, 2022

Can documentation be added to elaborate on where to put this into the JSON file? Or even better, can it be a UI item where you can just select the file you want to use?

Edit: For anyone else that comes across this, it's specifically profiles.list[].bellSound. It will warn you that it is not allowed, but it is allowed.
image

@zadjii-msft
Copy link
Member Author

DHowett pushed a commit that referenced this pull request Jul 5, 2022
DHowett pushed a commit that referenced this pull request Jul 5, 2022
As noted in #11511 (comment).

Missed in #13035

(cherry picked from commit 86dfefa)
Service-Card-Id: 83891742
Service-Version: 1.14
DHowett pushed a commit that referenced this pull request Jul 5, 2022
As noted in #11511 (comment).

Missed in #13035

(cherry picked from commit 86dfefa)
Service-Card-Id: 83891743
Service-Version: 1.15
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Settings Issues related to settings and customizability, for console or terminal AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specify an audio file for the audible bell

7 participants