From 2c2bbea0c6dcff9aca2c25bdca749d7c1306a081 Mon Sep 17 00:00:00 2001 From: Maiko Date: Sun, 25 Jun 2023 18:56:39 +0900 Subject: [PATCH 01/12] wip track color --- OpenUtau/Controls/TrackHeader.axaml | 21 ++++---- OpenUtau/OpenUtau.csproj | 3 ++ OpenUtau/Views/PianoRollWindow.axaml | 2 + OpenUtau/Views/TrackColorDialog.axaml | 67 ++++++++++++++++++++++++ OpenUtau/Views/TrackColorDialog.axaml.cs | 10 ++++ 5 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 OpenUtau/Views/TrackColorDialog.axaml create mode 100644 OpenUtau/Views/TrackColorDialog.axaml.cs diff --git a/OpenUtau/Controls/TrackHeader.axaml b/OpenUtau/Controls/TrackHeader.axaml index a4777e691..f7b374516 100644 --- a/OpenUtau/Controls/TrackHeader.axaml +++ b/OpenUtau/Controls/TrackHeader.axaml @@ -14,8 +14,9 @@ - - + + + @@ -26,10 +27,10 @@ Text="{Binding TrackNo}" Foreground="White" VerticalAlignment="Center"/> - - - - - - - + diff --git a/OpenUtau/OpenUtau.csproj b/OpenUtau/OpenUtau.csproj index ca6c323e4..330342be0 100644 --- a/OpenUtau/OpenUtau.csproj +++ b/OpenUtau/OpenUtau.csproj @@ -82,6 +82,9 @@ TrackSettingsDialog.axaml + + TrackColorDialog.axaml + diff --git a/OpenUtau/Views/PianoRollWindow.axaml b/OpenUtau/Views/PianoRollWindow.axaml index fb5cfb214..0837cbf83 100644 --- a/OpenUtau/Views/PianoRollWindow.axaml +++ b/OpenUtau/Views/PianoRollWindow.axaml @@ -17,6 +17,7 @@ + @@ -504,5 +505,6 @@ + diff --git a/OpenUtau/Views/TrackColorDialog.axaml b/OpenUtau/Views/TrackColorDialog.axaml new file mode 100644 index 000000000..1dacaed85 --- /dev/null +++ b/OpenUtau/Views/TrackColorDialog.axaml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OpenUtau/Views/TrackColorDialog.axaml.cs b/OpenUtau/Views/TrackColorDialog.axaml.cs new file mode 100644 index 000000000..929bddf67 --- /dev/null +++ b/OpenUtau/Views/TrackColorDialog.axaml.cs @@ -0,0 +1,10 @@ +using Avalonia.Controls; +using Avalonia.Media; + +namespace OpenUtau.App.Views { + public partial class TrackColorDialog : Window { + public TrackColorDialog() { + InitializeComponent(); + } + } +} From f8bba47775713748681cfcad5bbbde7df6539a73 Mon Sep 17 00:00:00 2001 From: Maiko Date: Sat, 1 Jul 2023 17:29:09 +0900 Subject: [PATCH 02/12] wip track color --- OpenUtau.Core/Commands/TrackCommands.cs | 13 ++++ OpenUtau.Core/OpenUtau.Core.csproj | 1 + OpenUtau.Core/Ustx/UTrack.cs | 1 + OpenUtau/Controls/TrackHeader.axaml | 16 ++++- OpenUtau/Controls/TrackHeaderCanvas.cs | 3 +- OpenUtau/Strings/Strings.axaml | 1 + OpenUtau/ThemeManager.cs | 43 +++++++++++- OpenUtau/ViewModels/LyricsViewModel.cs | 1 + OpenUtau/ViewModels/NotesViewModel.cs | 13 ++++ OpenUtau/ViewModels/TrackColorViewModel.cs | 30 ++++++++ OpenUtau/ViewModels/TrackHeaderViewModel.cs | 15 ++++ OpenUtau/Views/LyricsDialog.axaml | 12 +++- OpenUtau/Views/PianoRollWindow.axaml | 2 +- OpenUtau/Views/PianoRollWindow.axaml.cs | 1 + OpenUtau/Views/TrackColorDialog.axaml | 78 +++++++-------------- OpenUtau/Views/TrackColorDialog.axaml.cs | 29 +++++++- 16 files changed, 201 insertions(+), 58 deletions(-) create mode 100644 OpenUtau/ViewModels/TrackColorViewModel.cs diff --git a/OpenUtau.Core/Commands/TrackCommands.cs b/OpenUtau.Core/Commands/TrackCommands.cs index 7b9ce3449..7d2eb1718 100644 --- a/OpenUtau.Core/Commands/TrackCommands.cs +++ b/OpenUtau.Core/Commands/TrackCommands.cs @@ -100,6 +100,19 @@ public RenameTrackCommand(UProject project, UTrack track, string name) { public override void Unexecute() => track.TrackName = oldName; } + public class ChangeTrackColorCommand : TrackCommand { + readonly string newName, oldName; + public ChangeTrackColorCommand(UProject project, UTrack track, string colorName) { + this.project = project; + this.track = track; + newName = colorName; + oldName = track.TrackColor; + } + public override string ToString() => "Change track color"; + public override void Execute() => track.TrackColor = newName; + public override void Unexecute() => track.TrackColor = oldName; + } + public class TrackChangeSingerCommand : TrackCommand { readonly USinger newSinger, oldSinger; public TrackChangeSingerCommand(UProject project, UTrack track, USinger newSinger) { diff --git a/OpenUtau.Core/OpenUtau.Core.csproj b/OpenUtau.Core/OpenUtau.Core.csproj index 306b5e2e0..c3c631028 100644 --- a/OpenUtau.Core/OpenUtau.Core.csproj +++ b/OpenUtau.Core/OpenUtau.Core.csproj @@ -23,6 +23,7 @@ + diff --git a/OpenUtau.Core/Ustx/UTrack.cs b/OpenUtau.Core/Ustx/UTrack.cs index c2e915bb4..d210c1992 100644 --- a/OpenUtau.Core/Ustx/UTrack.cs +++ b/OpenUtau.Core/Ustx/UTrack.cs @@ -88,6 +88,7 @@ public USinger Singer { [YamlIgnore] public string SingerName => Singer != null ? Singer.DisplayName : "[No Singer]"; [YamlIgnore] public int TrackNo { set; get; } public string TrackName { get; set; } = "New Track"; + public string TrackColor { get; set; } = "Pink"; [YamlIgnore] public bool Muted { set; get; } public bool Mute { get; set; } public bool Solo { get; set; } diff --git a/OpenUtau/Controls/TrackHeader.axaml b/OpenUtau/Controls/TrackHeader.axaml index f7b374516..5635ade56 100644 --- a/OpenUtau/Controls/TrackHeader.axaml +++ b/OpenUtau/Controls/TrackHeader.axaml @@ -12,10 +12,21 @@ + - + @@ -133,7 +144,8 @@ - + + diff --git a/OpenUtau/Controls/TrackHeaderCanvas.cs b/OpenUtau/Controls/TrackHeaderCanvas.cs index 374dc5eb2..658dc5171 100644 --- a/OpenUtau/Controls/TrackHeaderCanvas.cs +++ b/OpenUtau/Controls/TrackHeaderCanvas.cs @@ -92,7 +92,8 @@ public TrackHeaderCanvas() { header.ViewModel.ManuallyRaise(); } } - }); MessageBus.Current.Listen() + }); + MessageBus.Current.Listen() .Subscribe(e => { foreach (var (track, header) in trackHeaders) { if (header.ViewModel != null) { diff --git a/OpenUtau/Strings/Strings.axaml b/OpenUtau/Strings/Strings.axaml index 14f86bde9..533b1c198 100644 --- a/OpenUtau/Strings/Strings.axaml +++ b/OpenUtau/Strings/Strings.axaml @@ -398,6 +398,7 @@ General Rename track Select Renderer Select Singer + Select track color Segoe UI,San Francisco,Helvetica Neue Microsoft YaHei,Simsun,苹方-简,宋体-简 diff --git a/OpenUtau/ThemeManager.cs b/OpenUtau/ThemeManager.cs index 40322415d..45f3996b9 100644 --- a/OpenUtau/ThemeManager.cs +++ b/OpenUtau/ThemeManager.cs @@ -1,4 +1,6 @@ -using Avalonia; +using System.Collections.Generic; +using System.Linq; +using Avalonia; using Avalonia.Controls; using Avalonia.Media; using Avalonia.Styling; @@ -48,6 +50,24 @@ class ThemeManager { public static IBrush ExpActiveBrush = Brushes.Black; public static IBrush ExpActiveNameBrush = Brushes.White; + public static List TrackColors = new List(){ + new TrackColor("Red", "#EF5350", "#F44336", "#E57373"), + new TrackColor("Pink", "#F06292", "#EC407A", "#F48FB1"), + new TrackColor("Deep Orange", "#FF7043", "#FF5722", "#FF8A65"), + new TrackColor("Orange", "#FFA726", "#FF9800", "#FFB74D"), + new TrackColor("Yellow", "#FBC02D", "#F9A825", "#FDD835"), + new TrackColor("Lime", "#C0CA33", "#AFB42B", "#CDDC39"), + new TrackColor("Light Green", "#9CCC65", "#8BC34A", "#AED581"), + new TrackColor("Green", "#81C784", "#66BB6A", "#A5D6A7"), + new TrackColor("Teal", "#4DB6AC", "#26A69A", "#80CBC4"), + new TrackColor("Cyan", "#00BCD4", "#00ACC1", "#26C6DA"), + new TrackColor("Light Blue", "#4FC3F7", "#29B6F6", "#81D4FA"), + new TrackColor("Blue", "#4EA6EA", "#42A5F5", "#90CAF9"), + new TrackColor("Indigo", "#7986CB", "#5C6BC0", "#9FA8DA"), + new TrackColor("Deep Purple", "#9575CD", "#7E57C2", "#B39DDB"), + new TrackColor("Purple", "#BA68C8", "#AB47BC", "#CE93D8") + }; + public static void LoadTheme() { if (Application.Current == null) { return; @@ -159,5 +179,26 @@ public static string GetString(string key) { } return key; } + + public static TrackColor GetTrackColor(string name) { + if (TrackColors.Any(c => c.Name == name)) { + return TrackColors.First(c => c.Name == name); + } + return TrackColors.First(c => c.Name == "Blue"); + } + } + + public class TrackColor { + public string Name { get; set; } = ""; + public SolidColorBrush AccentColor { get; set; } + public SolidColorBrush AccentColorDark { get; set; } // Pressed + public SolidColorBrush AccentColorLight { get; set; } // PointerOver + + public TrackColor(string name, string accentColor, string darkColor, string lightColor) { + Name = name; + AccentColor = SolidColorBrush.Parse(accentColor); + AccentColorDark = SolidColorBrush.Parse(darkColor); + AccentColorLight = SolidColorBrush.Parse(lightColor); + } } } diff --git a/OpenUtau/ViewModels/LyricsViewModel.cs b/OpenUtau/ViewModels/LyricsViewModel.cs index c7c079f0d..5b60cb1c2 100644 --- a/OpenUtau/ViewModels/LyricsViewModel.cs +++ b/OpenUtau/ViewModels/LyricsViewModel.cs @@ -16,6 +16,7 @@ class LyricsViewModel : ViewModelBase { [Reactive] public int TotalCount { get; set; } [Reactive] public int MaxCount { get; set; } [Reactive] public bool LivePreview { get; set; } + public TrackColor TrackColor { get; set; } = ThemeManager.GetTrackColor("Blue"); private UVoicePart? part; private UNote[]? notes; diff --git a/OpenUtau/ViewModels/NotesViewModel.cs b/OpenUtau/ViewModels/NotesViewModel.cs index 3751b884e..f1965bc93 100644 --- a/OpenUtau/ViewModels/NotesViewModel.cs +++ b/OpenUtau/ViewModels/NotesViewModel.cs @@ -74,6 +74,7 @@ public class NotesViewModel : ViewModelBase, ICmdSubscriber { [Reactive] public Bitmap? Portrait { get; set; } [Reactive] public IBrush? PortraitMask { get; set; } [Reactive] public string WindowTitle { get; set; } = "Piano Roll"; + [Reactive] public TrackColor TrackColor { get; set; } = ThemeManager.GetTrackColor("Blue"); public double ViewportTicks => viewportTicks.Value; public double ViewportTracks => viewportTracks.Value; public double SmallChangeX => smallChangeX.Value; @@ -374,6 +375,7 @@ private void LoadPart(UPart part, UProject project) { OnPartModified(); LoadPortrait(part, project); LoadWindowTitle(part, project); + LoadTrackColor(part, project); } private void LoadPortrait(UPart? part, UProject? project) { @@ -435,6 +437,14 @@ private void LoadWindowTitle(UPart? part, UProject? project) { WindowTitle = project.tracks[part.trackNo].TrackName + " - " + part.DisplayName; } + private void LoadTrackColor(UPart? part, UProject? project) { + if (part == null || project == null) { + TrackColor = ThemeManager.GetTrackColor("Blue"); + return; + } + TrackColor = ThemeManager.GetTrackColor(project.tracks[part.trackNo].TrackColor); + } + private void UnloadPart() { DeselectNotes(); Part = null; @@ -868,6 +878,9 @@ public void OnNext(UCommand cmd, bool isUndo) { if (cmd is RenameTrackCommand) { LoadWindowTitle(Part, Project); return; + } else if (cmd is ChangeTrackColorCommand) { + LoadTrackColor(Part, Project); + return; } else if (cmd is RemoveTrackCommand removeTrack) { if (Part != null && removeTrack.removedParts.Contains(Part)) { UnloadPart(); diff --git a/OpenUtau/ViewModels/TrackColorViewModel.cs b/OpenUtau/ViewModels/TrackColorViewModel.cs new file mode 100644 index 000000000..aa8512c19 --- /dev/null +++ b/OpenUtau/ViewModels/TrackColorViewModel.cs @@ -0,0 +1,30 @@ +using System.Collections.ObjectModel; +using System.Drawing; +using System.Linq; +using Avalonia.Controls; +using OpenUtau.Core; +using OpenUtau.Core.Ustx; +using OpenUtau.Core.Util; +using ReactiveUI.Fody.Helpers; + +namespace OpenUtau.App.ViewModels { + public class TrackColorViewModel : ViewModelBase { + public ObservableCollection TrackColors { get; } = new ObservableCollection(ThemeManager.TrackColors); + [Reactive] public TrackColor SelectedColor { get; set; } + private UTrack track; + + public TrackColorViewModel(UTrack track) { + SelectedColor = TrackColors.FirstOrDefault(c => c.Name == track.TrackColor) ?? TrackColors.First(c => c.Name == "Blue"); + this.track = track; + } + + public void Finish() { + if(SelectedColor.Name != track.TrackColor) { + DocManager.Inst.StartUndoGroup(); + DocManager.Inst.ExecuteCmd(new ChangeTrackColorCommand(DocManager.Inst.Project, track, SelectedColor.Name)); + DocManager.Inst.EndUndoGroup(); + } + + } + } +} diff --git a/OpenUtau/ViewModels/TrackHeaderViewModel.cs b/OpenUtau/ViewModels/TrackHeaderViewModel.cs index 7f85a51cb..b341ecd56 100644 --- a/OpenUtau/ViewModels/TrackHeaderViewModel.cs +++ b/OpenUtau/ViewModels/TrackHeaderViewModel.cs @@ -6,8 +6,11 @@ using System.Reactive.Disposables; using System.Reactive.Linq; using Avalonia; +using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Media; using Avalonia.Media.Imaging; +using Avalonia.Styling; using OpenUtau.Api; using OpenUtau.App.Views; using OpenUtau.Core; @@ -31,6 +34,7 @@ public class TrackHeaderViewModel : ViewModelBase, IActivatableViewModel { public IReadOnlyList? RenderersMenuItems { get; set; } public ReactiveCommand SelectRendererCommand { get; } [Reactive] public string TrackName { get; set; } = string.Empty; + [Reactive] public TrackColor TrackColor { get; set; } = ThemeManager.GetTrackColor("Blue"); [Reactive] public double Volume { get; set; } [Reactive] public double Pan { get; set; } [Reactive] public bool Muted { get; set; } @@ -128,6 +132,7 @@ public TrackHeaderViewModel(UTrack track) { }); TrackName = track.TrackName; + TrackColor = ThemeManager.GetTrackColor(track.TrackColor); Volume = track.Volume; Pan = track.Pan; Muted = track.Muted; @@ -328,6 +333,16 @@ public void Rename() { } } + public async void SelectTrackColor() { + var dialog = new TrackColorDialog(); + dialog.DataContext = new TrackColorViewModel(track); + + if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop && desktop.MainWindow != null) { + await dialog.ShowDialog(desktop.MainWindow); + TrackColor = ThemeManager.GetTrackColor(track.TrackColor); + } + } + public void Duplicate() { DocManager.Inst.StartUndoGroup(); //TODO diff --git a/OpenUtau/Views/LyricsDialog.axaml b/OpenUtau/Views/LyricsDialog.axaml index 53a6b7437..4cdd73831 100644 --- a/OpenUtau/Views/LyricsDialog.axaml +++ b/OpenUtau/Views/LyricsDialog.axaml @@ -8,10 +8,20 @@ Title="{StaticResource lyrics.caption}" KeyDown="OnKeyDown" Opened="OnOpened"> + + + + Text="{Binding Text}" Focusable="True"/> diff --git a/OpenUtau/Views/PianoRollWindow.axaml b/OpenUtau/Views/PianoRollWindow.axaml index 0837cbf83..076be59c2 100644 --- a/OpenUtau/Views/PianoRollWindow.axaml +++ b/OpenUtau/Views/PianoRollWindow.axaml @@ -17,7 +17,7 @@ - + diff --git a/OpenUtau/Views/PianoRollWindow.axaml.cs b/OpenUtau/Views/PianoRollWindow.axaml.cs index bddf56099..1e8c6e1da 100644 --- a/OpenUtau/Views/PianoRollWindow.axaml.cs +++ b/OpenUtau/Views/PianoRollWindow.axaml.cs @@ -110,6 +110,7 @@ void EditLyrics() { var vm = new LyricsViewModel(); var (notes, lyrics) = ViewModel.NotesViewModel.PrepareInsertLyrics(); vm.Start(ViewModel.NotesViewModel.Part, notes, lyrics); + vm.TrackColor = ViewModel.NotesViewModel.TrackColor; var dialog = new LyricsDialog() { DataContext = vm, }; diff --git a/OpenUtau/Views/TrackColorDialog.axaml b/OpenUtau/Views/TrackColorDialog.axaml index 1dacaed85..97eca3028 100644 --- a/OpenUtau/Views/TrackColorDialog.axaml +++ b/OpenUtau/Views/TrackColorDialog.axaml @@ -2,66 +2,42 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="150" - x:Class="OpenUtau.App.Views.TrackColorDialog" - Title="Track Color"> + mc:Ignorable="d" Width="500" Height="150" + x:Class="OpenUtau.App.Views.TrackColorDialog" WindowStartupLocation="CenterOwner" + Icon="/Assets/open-utau.ico" + Title="{StaticResource tracks.trackcolor}" + KeyDown="OnKeyDown"> - + - + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + IsChecked="{Binding Mute, Mode=OneWay}" Command="{Binding ToggleMute}"> + + + + + + + + + + + + + + +