1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-19 09:01:15 +02:00

Move AudacityProject::DoTrackMute and DoTrackSolo...

... also fixed the bug that muting and soloing from the mixer board did not
update accessibility.
This commit is contained in:
Paul Licameli
2018-10-27 20:32:58 -04:00
parent 51c3541716
commit 50f8579475
6 changed files with 116 additions and 123 deletions

View File

@@ -575,6 +575,107 @@ void DoRemoveTracks( AudacityProject &project )
trackPanel->Refresh(false);
}
void DoTrackMute(AudacityProject &project, Track *t, bool exclusive)
{
auto &tracks = *project.GetTracks();
auto &trackPanel = *project.GetTrackPanel();
// Whatever t is, replace with lead channel
t = *tracks.FindLeader(t);
// "exclusive" mute means mute the chosen track and unmute all others.
if (exclusive) {
for (auto leader : tracks.Leaders<PlayableTrack>()) {
const auto group = TrackList::Channels(leader);
bool chosen = (t == leader);
for (auto channel : group)
channel->SetMute( chosen ),
channel->SetSolo( false );
}
}
else {
// Normal click toggles this track.
auto pt = dynamic_cast<PlayableTrack *>( t );
if (!pt)
return;
bool wasMute = pt->GetMute();
for (auto channel : TrackList::Channels(pt))
channel->SetMute( !wasMute );
if (project.IsSoloSimple() || project.IsSoloNone())
{
// We also set a solo indicator if we have just one track / stereo pair playing.
// in a group of more than one playable tracks.
// otherwise clear solo on everything.
auto range = tracks.Leaders<PlayableTrack>();
auto nPlayableTracks = range.size();
auto nPlaying = (range - &PlayableTrack::GetMute).size();
for (auto track : tracks.Any<PlayableTrack>())
// will set both of a stereo pair
track->SetSolo( (nPlaying==1) && (nPlayableTracks > 1 ) && !track->GetMute() );
}
}
project.ModifyState(true);
trackPanel.UpdateAccessibility();
trackPanel.Refresh(false);
}
void DoTrackSolo(AudacityProject &project, Track *t, bool exclusive)
{
auto &tracks = *project.GetTracks();
auto &trackPanel = *project.GetTrackPanel();
// Whatever t is, replace with lead channel
t = *tracks.FindLeader(t);
const auto pt = dynamic_cast<PlayableTrack *>( t );
if (!pt)
return;
bool bWasSolo = pt->GetSolo();
bool bSoloMultiple = !project.IsSoloSimple() ^ exclusive;
// Standard and Simple solo have opposite defaults:
// Standard - Behaves as individual buttons, shift=radio buttons
// Simple - Behaves as radio buttons, shift=individual
// In addition, Simple solo will mute/unmute tracks
// when in standard radio button mode.
if ( bSoloMultiple )
{
for (auto channel : TrackList::Channels(pt))
channel->SetSolo( !bWasSolo );
}
else
{
// Normal click solo this track only, mute everything else.
// OR unmute and unsolo everything.
for (auto leader : tracks.Leaders<PlayableTrack>()) {
const auto group = TrackList::Channels(leader);
bool chosen = (t == leader);
for (auto channel : group) {
if (chosen) {
channel->SetSolo( !bWasSolo );
if( project.IsSoloSimple() )
channel->SetMute( false );
}
else {
channel->SetSolo( false );
if( project.IsSoloSimple() )
channel->SetMute( !bWasSolo );
}
}
}
}
project.ModifyState(true);
trackPanel.UpdateAccessibility();
trackPanel.Refresh(false);
}
void DoRemoveTrack(AudacityProject &project, Track * toRemove)
{
auto &tracks = *project.GetTracks();
@@ -1234,7 +1335,7 @@ void OnTrackMute(const CommandContext &context)
const auto track = trackPanel->GetFocusedTrack();
if (track) track->TypeSwitch( [&](PlayableTrack *t) {
project.DoTrackMute(t, false);
DoTrackMute(project, t, false);
});
}
@@ -1245,7 +1346,7 @@ void OnTrackSolo(const CommandContext &context)
const auto track = trackPanel->GetFocusedTrack();
if (track) track->TypeSwitch( [&](PlayableTrack *t) {
project.DoTrackSolo(t, false);
DoTrackSolo(project, t, false);
});
}