Skip to content

Commit

Permalink
Merge pull request #762 from maiko3tattun/0701_SoloMute
Browse files Browse the repository at this point in the history
Fix solo and mute
  • Loading branch information
stakira authored Jul 3, 2023
2 parents b4bb869 + f05f4b2 commit 2c2e87f
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 39 deletions.
1 change: 0 additions & 1 deletion OpenUtau.Core/PlaybackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ private PlaybackManager() {
public Audio.IAudioOutput AudioOutput { get; set; } = new Audio.DummyAudioOutput();
public bool Playing => AudioOutput.PlaybackState == PlaybackState.Playing;
public bool StartingToPlay { get; private set; }
public bool SoloTrackExist { get; set; } = false;

public void PlayTestSound() {
masterMix = null;
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Ustx/UProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class UProject {
public List<UTempo> tempos;
public List<UTrack> tracks;
[YamlIgnore] public List<UPart> parts;
public bool SoloTrackExist { get => tracks.Any(t => t.Solo); }

/// <summary>
/// Transient field used for serialization.
Expand Down
4 changes: 1 addition & 3 deletions OpenUtau.Core/Ustx/UTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ public void AfterLoad(UProject project) {
};
}
TrackNo = project.tracks.IndexOf(this);
if (Solo) {
PlaybackManager.Inst.SoloTrackExist = true;
} else if (Mute) {
if (!Solo && Mute) {
Muted = true;
}
}
Expand Down
21 changes: 18 additions & 3 deletions OpenUtau/Controls/TrackHeader.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,28 @@
</Button>
<ToggleButton Grid.Row="1" Grid.Column="3" Margin="1" Padding="0" Height="18"
HorizontalAlignment="Stretch"
IsChecked="{Binding Muted, Mode=OneWay}" Command="{Binding ToggleMute}">
IsChecked="{Binding Mute, Mode=OneWay}" Command="{Binding ToggleMute}">
<TextBlock Text="M" TextAlignment="Center"/>
<ToggleButton.ContextMenu>
<ContextMenu>
<MenuItem Classes="context" Header="{StaticResource tracks.mute}" Command="{Binding ToggleMute}"/>
<MenuItem Classes="context" Header="{StaticResource tracks.mute.only}" Command="{Binding MuteOnly}"/>
<MenuItem Classes="context" Header="{StaticResource tracks.mute.allothers}" Command="{Binding MuteAllOthers}"/>
<MenuItem Classes="context" Header="{StaticResource tracks.mute.unmuteall}" Command="{Binding UnmuteAll}"/>
</ContextMenu>
</ToggleButton.ContextMenu>
</ToggleButton>
<ToggleButton Grid.Row="2" Grid.Column="3" Margin="1" Padding="0" Height="18"
HorizontalAlignment="Stretch"
IsChecked="{Binding Solo, Mode=OneWay}" Command="{Binding ToggleSolo}">
<TextBlock Text="S" TextAlignment="Center"/>
<ToggleButton.ContextMenu>
<ContextMenu>
<MenuItem Classes="context" Header="{StaticResource tracks.solo.only}" Command="{Binding ToggleSolo}"/>
<MenuItem Classes="context" Header="{StaticResource tracks.solo.add}" Command="{Binding SoloAdditionally}"/>
<MenuItem Classes="context" Header="{StaticResource tracks.solo.unsoloall}" Command="{Binding UnsoloAll}"/>
</ContextMenu>
</ToggleButton.ContextMenu>
</ToggleButton>
<Button Grid.Row="3" Grid.Column="3" Margin="1" Padding="0" Height="18" Background="Transparent"
HorizontalAlignment="Stretch" Click="TrackSettingsButtonClicked">
Expand All @@ -106,7 +121,7 @@
<Grid Grid.Row="4" Grid.Column="2" Grid.ColumnSpan="2" Height="20">
<Slider Margin="1,0,0,0" Width="102" HorizontalAlignment="Left" Classes="fader" Minimum="-24" Maximum="12" Value="{Binding Volume}"
PointerPressed="VolumeFaderPointerPressed"
ContextRequested="VolumeFaderContextRequested"/>
ContextRequested="VolumeFaderContextRequested" IsEnabled="{Binding !Muted}"/>
<TextBlock Margin="106,3,0,0" Width="36" HorizontalAlignment="Left" FontSize="9" FontFamily="monospace" >
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:+#00.0;-#00.0}">
Expand All @@ -117,7 +132,7 @@
<Slider Margin="134,0,0,0" Width="36" HorizontalAlignment="Left"
Classes="fader" Minimum="-100" Maximum="100" Value="{Binding Pan}"
PointerPressed="PanFaderPointerPressed"
ContextRequested="PanFaderContextRequested"/>
ContextRequested="PanFaderContextRequested" IsEnabled="{Binding !Muted}"/>
<TextBlock Margin="0,3,4,0" HorizontalAlignment="Right" FontSize="9" FontFamily="monospace" IsHitTestVisible="False">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:00R;00L;C}">
Expand Down
30 changes: 13 additions & 17 deletions OpenUtau/Controls/TrackHeaderCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ public TrackHeaderCanvas() {
if (header.ViewModel == null) {
continue;
}
if (PlaybackManager.Inst.SoloTrackExist && !track.Solo) {
header.ViewModel.Muted = true;
}
header.ViewModel.JudgeMuted();
header.ViewModel.ManuallyRaise();
}
if (trackAdder != null) {
Expand All @@ -69,34 +67,32 @@ public TrackHeaderCanvas() {
foreach (var (track, header) in trackHeaders) {
if (header.ViewModel != null) {
if (e.solo) {
PlaybackManager.Inst.SoloTrackExist = true;
if (track.TrackNo == e.trackNo) {
header.ViewModel.Solo = true;
header.ViewModel.Muted = false;
} else {
} else if (!e.additionally) {
header.ViewModel.Solo = false;
header.ViewModel.Muted = true;
}
} else {
PlaybackManager.Inst.SoloTrackExist = false;
if (track.TrackNo == e.trackNo) {
if (track.TrackNo == e.trackNo || e.trackNo == -1) {
header.ViewModel.Solo = false;
}
if (track.Mute) {
header.ViewModel.Muted = true;
} else {
header.ViewModel.Muted = false;
}
}
}
}
foreach (var (track, header) in trackHeaders) {
if (header.ViewModel != null) {
header.ViewModel.JudgeMuted();
header.ViewModel.ManuallyRaise();
}
}
}); MessageBus.Current.Listen<TracksMuteEvent>()
});
MessageBus.Current.Listen<TracksMuteEvent>()
.Subscribe(e => {
foreach (var (track, header) in trackHeaders) {
if (header.ViewModel != null) {
if (track.TrackNo == e.trackNo) {
if(e.trackNo == -1) {
header.ViewModel.ToggleMute(e.allmute);
} else if (track.TrackNo == e.trackNo) {
header.ViewModel.ToggleMute();
}
}
Expand Down
7 changes: 7 additions & 0 deletions OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,17 @@ General
<system:String x:Key="tracks.more">More</system:String>
<system:String x:Key="tracks.movedown">Move Down</system:String>
<system:String x:Key="tracks.moveup">Move Up</system:String>
<system:String x:Key="tracks.mute">Mute</system:String>
<system:String x:Key="tracks.mute.allothers">Mute all others</system:String>
<system:String x:Key="tracks.mute.only">Mute this only</system:String>
<system:String x:Key="tracks.mute.unmuteall">Unmute all</system:String>
<system:String x:Key="tracks.remove">Remove</system:String>
<system:String x:Key="tracks.rename">Rename track</system:String>
<system:String x:Key="tracks.selectrenderer">Select Renderer</system:String>
<system:String x:Key="tracks.selectsinger">Select Singer</system:String>
<system:String x:Key="tracks.solo.add">Solo additionally (which not removes solo from other tracks)</system:String>
<system:String x:Key="tracks.solo.only">Solo this only (which removes solo from other tracks)</system:String>
<system:String x:Key="tracks.solo.unsoloall">Unsolo all</system:String>

<FontFamily x:Key="ui.fontfamily">Segoe UI,San Francisco,Helvetica Neue</FontFamily>
<FontFamily x:Key="ui.textbox.fontfamily">Microsoft YaHei,Simsun,苹方-简,宋体-简</FontFamily>
Expand Down
7 changes: 7 additions & 0 deletions OpenUtau/Strings/Strings.ja-JP.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,17 @@
<system:String x:Key="tracks.more">さらに表示</system:String>
<system:String x:Key="tracks.movedown">下へ</system:String>
<system:String x:Key="tracks.moveup">上へ</system:String>
<system:String x:Key="tracks.mute">ミュート</system:String>
<system:String x:Key="tracks.mute.allothers">このトラック以外をミュート</system:String>
<system:String x:Key="tracks.mute.only">このトラックだけミュート</system:String>
<system:String x:Key="tracks.mute.unmuteall">全トラックのミュートを解除</system:String>
<system:String x:Key="tracks.remove">削除</system:String>
<system:String x:Key="tracks.rename">トラックの名前を変更</system:String>
<system:String x:Key="tracks.selectrenderer">レンダラーを選択</system:String>
<system:String x:Key="tracks.selectsinger">シンガーを選択</system:String>
<system:String x:Key="tracks.solo.add">ソロ (他トラックのソロを解除しない)</system:String>
<system:String x:Key="tracks.solo.only">ソロ (他トラックのソロを解除)</system:String>
<system:String x:Key="tracks.solo.unsoloall">全トラックのソロを解除</system:String>

<FontFamily x:Key="ui.fontfamily">Meiryo UI,Hiragino Sans,Segoe UI,San Francisco,Helvetica Neue</FontFamily>
<!--<FontFamily x:Key="ui.textbox.fontfamily">Microsoft YaHei,Simsun,苹方-简,宋体-简</FontFamily>-->
Expand Down
65 changes: 56 additions & 9 deletions OpenUtau/ViewModels/TrackHeaderViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Media.Imaging;
Expand Down Expand Up @@ -33,6 +34,7 @@ public class TrackHeaderViewModel : ViewModelBase, IActivatableViewModel {
[Reactive] public string TrackName { get; set; } = string.Empty;
[Reactive] public double Volume { get; set; }
[Reactive] public double Pan { get; set; }
[Reactive] public bool Mute { get; set; }
[Reactive] public bool Muted { get; set; }
[Reactive] public bool Solo { get; set; }
[Reactive] public Bitmap? Avatar { get; set; }
Expand Down Expand Up @@ -130,6 +132,7 @@ public TrackHeaderViewModel(UTrack track) {
TrackName = track.TrackName;
Volume = track.Volume;
Pan = track.Pan;
Mute = track.Mute;
Muted = track.Muted;
Solo = track.Solo;
this.WhenAnyValue(x => x.Volume)
Expand All @@ -142,6 +145,10 @@ public TrackHeaderViewModel(UTrack track) {
track.Pan = pan;
DocManager.Inst.ExecuteCmd(new PanChangeNotification(track.TrackNo, pan));
});
this.WhenAnyValue(x => x.Mute)
.Subscribe(mute => {
track.Mute = mute;
});
this.WhenAnyValue(x => x.Muted)
.Subscribe(muted => {
track.Muted = muted;
Expand All @@ -156,20 +163,59 @@ public TrackHeaderViewModel(UTrack track) {
}

public void ToggleSolo() {
MessageBus.Current.SendMessage(new TracksSoloEvent(track.TrackNo, !track.Solo));
MessageBus.Current.SendMessage(new TracksSoloEvent(track.TrackNo, !track.Solo, false));
}

public void SoloAdditionally() {
MessageBus.Current.SendMessage(new TracksSoloEvent(track.TrackNo, !track.Solo, true));
}

public void UnsoloAll() {
MessageBus.Current.SendMessage(new TracksSoloEvent(-1, false, false));
}

public void ToggleMute() {
if (!track.Mute) {
track.Mute = true;
if (!Mute) {
Mute = true;
} else {
Mute = false;
}
this.RaisePropertyChanged(nameof(Mute));
JudgeMuted();
}
public void ToggleMute(bool mute) {
if (mute) {
Mute = true;
} else {
Mute = false;
}
this.RaisePropertyChanged(nameof(Mute));
JudgeMuted();
}

public void MuteOnly() {
MessageBus.Current.SendMessage(new TracksMuteEvent(-1, false));
ToggleMute();
}

public void MuteAllOthers() {
MessageBus.Current.SendMessage(new TracksMuteEvent(-1, true));
ToggleMute();
}

public void UnmuteAll() {
MessageBus.Current.SendMessage(new TracksMuteEvent(-1, false));
}

public void JudgeMuted() {
if (Solo) {
Muted = false;
} else if (Mute) {
Muted = true;
} else if (DocManager.Inst.Project.SoloTrackExist) {
Muted = true;
} else {
track.Mute = false;
if (PlaybackManager.Inst.SoloTrackExist) {
Muted = true;
} else {
Muted = false;
}
Muted = false;
}
this.RaisePropertyChanged(nameof(Muted));
}
Expand Down Expand Up @@ -280,6 +326,7 @@ public void ManuallyRaise() {
this.RaisePropertyChanged(nameof(Phonemizer));
this.RaisePropertyChanged(nameof(PhonemizerTag));
this.RaisePropertyChanged(nameof(Renderer));
this.RaisePropertyChanged(nameof(Mute));
this.RaisePropertyChanged(nameof(Muted));
this.RaisePropertyChanged(nameof(Solo));
this.RaisePropertyChanged(nameof(Volume));
Expand Down
8 changes: 6 additions & 2 deletions OpenUtau/ViewModels/TracksViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ public class TracksRefreshEvent { }
public class TracksSoloEvent {
public readonly int trackNo;
public readonly bool solo;
public TracksSoloEvent(int trackNo, bool solo) {
public readonly bool additionally;
public TracksSoloEvent(int trackNo, bool solo, bool additionally) {
this.trackNo = trackNo;
this.solo = solo;
this.additionally = additionally;
}
}
public class TracksMuteEvent {
public readonly int trackNo;
public TracksMuteEvent(int trackNo) {
public readonly bool allmute; // use only when track number is -1
public TracksMuteEvent(int trackNo, bool allmute) {
this.trackNo = trackNo;
this.allmute = allmute;
}
}
public class PartsSelectionEvent {
Expand Down
4 changes: 2 additions & 2 deletions OpenUtau/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,14 @@ void OnKeyDown(object sender, KeyEventArgs args) {
if (viewModel.TracksViewModel.SelectedParts.Count > 0) {
var part = viewModel.TracksViewModel.SelectedParts.First();
var track = DocManager.Inst.Project.tracks[part.trackNo];
MessageBus.Current.SendMessage(new TracksSoloEvent(part.trackNo, !track.Solo));
MessageBus.Current.SendMessage(new TracksSoloEvent(part.trackNo, !track.Solo, false));
}
break;
// mute
case Key.M:
if (viewModel.TracksViewModel.SelectedParts.Count > 0) {
var part = viewModel.TracksViewModel.SelectedParts.First();
MessageBus.Current.SendMessage(new TracksMuteEvent(part.trackNo));
MessageBus.Current.SendMessage(new TracksMuteEvent(part.trackNo, false));
}
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions OpenUtau/Views/PianoRollWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,14 +1202,14 @@ bool OnKeyExtendedHandler(KeyEventArgs args) {
// solo
if(isShift) {
var track = project.tracks[notesVm.Part.trackNo];
MessageBus.Current.SendMessage(new TracksSoloEvent(notesVm.Part.trackNo, !track.Solo));
MessageBus.Current.SendMessage(new TracksSoloEvent(notesVm.Part.trackNo, !track.Solo, false));
return true;
}
break;
case Key.M:
// mute
if (isShift) {
MessageBus.Current.SendMessage(new TracksMuteEvent(notesVm.Part.trackNo));
MessageBus.Current.SendMessage(new TracksMuteEvent(notesVm.Part.trackNo, false));
}
break;
case Key.F:
Expand Down

0 comments on commit 2c2e87f

Please sign in to comment.