Skip to content

Commit

Permalink
Track header layout adjustment and volume and Pan values can now be e…
Browse files Browse the repository at this point in the history
…ntered
  • Loading branch information
rokujyushi committed Jul 10, 2023
1 parent 8fa24a8 commit b52d3d0
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 54 deletions.
98 changes: 44 additions & 54 deletions OpenUtau/Controls/TrackHeader.axaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<UserControl xmlns="https://github.com/avaloniaui"
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"
xmlns:vm="using:OpenUtau.App.ViewModels"
mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="104"
x:Class="OpenUtau.App.Controls.TrackHeader" Width="300" TrackNo="{Binding TrackNo}">
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"
xmlns:vm="using:OpenUtau.App.ViewModels" mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="104" x:Class="OpenUtau.App.Controls.TrackHeader" Width="300" TrackNo="{Binding TrackNo}">
<Design.DataContext>
<vm:TrackHeaderViewModel/>
</Design.DataContext>
Expand All @@ -16,23 +14,15 @@
<Border Margin="1,1,1,1" BorderThickness="1" BorderBrush="{DynamicResource NeutralAccentBrushSemi}" CornerRadius="2">
<Grid Background="Transparent" RowDefinitions="20,20,20,20,20,*" ColumnDefinitions="Auto,1,*,20" VerticalAlignment="Top" ClipToBounds="True">
<Grid Grid.Row="0" Grid.RowSpan="6" Grid.Column="0" VerticalAlignment="Top">
<Border BorderThickness="0,0,1,1" Height="101" Width="101" VerticalAlignment="Top" CornerRadius="0,0,2,0"
BorderBrush="{DynamicResource NeutralAccentBrushSemi}" ClipToBounds="True">
<Border BorderThickness="0,0,1,1" Height="101" Width="101" VerticalAlignment="Top" CornerRadius="0,0,2,0" BorderBrush="{DynamicResource NeutralAccentBrushSemi}" ClipToBounds="True">
<Image Source="{Binding Avatar}" Stretch="UniformToFill" VerticalAlignment="Top" ToolTip.Tip="{Binding Singer}"/>
</Border>
<Border Background="{DynamicResource NeutralAccentBrushSemi}" Height="16" Width="22" CornerRadius="1,0,2,0"
HorizontalAlignment="Left" VerticalAlignment="Top">
<TextBlock TextAlignment="Center" FontWeight="Bold"
Text="{Binding TrackNo}" Foreground="White" VerticalAlignment="Center"/>
<Border Background="{DynamicResource NeutralAccentBrushSemi}" Height="16" Width="22" CornerRadius="1,0,2,0" HorizontalAlignment="Left" VerticalAlignment="Top">
<TextBlock TextAlignment="Center" FontWeight="Bold" Text="{Binding TrackNo}" Foreground="White" VerticalAlignment="Center"/>
</Border>
</Grid>
<Button Classes="clear" Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2" Margin="1" Padding="2,1,0,0" Height="18"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Focusable="False"
Content="{Binding TrackName}" Click="TrackNameButtonClicked"/>
<Button Classes="clear" Grid.Row="1" Grid.Column="2" Margin="1" Padding="2,1,0,0" Height="18"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Focusable="False"
Content="{Binding Singer, TargetNullValue={StaticResource tracks.selectsinger}}" Click="SingerButtonClicked" ContextRequested="SingerButtonContextRequested"
ToolTip.Tip="{Binding Singer}">
<Button Classes="clear" Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2" Margin="1" Padding="2,1,0,0" Height="18" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Focusable="False" Content="{Binding TrackName}" Click="TrackNameButtonClicked"/>
<Button Classes="clear" Grid.Row="1" Grid.Column="2" Margin="1" Padding="2,1,0,0" Height="18" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Focusable="False" Content="{Binding Singer, TargetNullValue={StaticResource tracks.selectsinger}}" Click="SingerButtonClicked" ContextRequested="SingerButtonContextRequested" ToolTip.Tip="{Binding Singer}">
<Button.ContextMenu>
<ContextMenu Classes="context" Name="SingersMenu" PlacementMode="Bottom" HorizontalOffset="-3" ItemsSource="{Binding SingerMenuItems}">
<ContextMenu.Styles>
Expand All @@ -46,10 +36,7 @@
</ContextMenu>
</Button.ContextMenu>
</Button>
<Button Classes="clear" Grid.Row="2" Grid.Column="2" Margin="1" Padding="2,1,0,0" Height="18"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Focusable="False"
Content="{Binding PhonemizerTag}" Click="PhonemizerButtonClicked" ContextRequested="PhonemizerButtonContextRequested"
ToolTip.Tip="{Binding Phonemizer}">
<Button Classes="clear" Grid.Row="2" Grid.Column="2" Margin="1" Padding="2,1,0,0" Height="18" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Focusable="False" Content="{Binding PhonemizerTag}" Click="PhonemizerButtonClicked" ContextRequested="PhonemizerButtonContextRequested" ToolTip.Tip="{Binding Phonemizer}">
<Button.ContextMenu>
<ContextMenu Classes="context" Name="PhonemizersMenu" PlacementMode="Bottom" HorizontalOffset="-3" ItemsSource="{Binding PhonemizerMenuItems}">
<ContextMenu.Styles>
Expand All @@ -63,10 +50,7 @@
</ContextMenu>
</Button.ContextMenu>
</Button>
<Button Classes="clear" Grid.Row="3" Grid.Column="2" Margin="1" Padding="2,1,0,0" Height="18"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Focusable="False"
Content="{Binding Renderer}" Click="RendererButtonClicked" ContextRequested="RendererButtonContextRequested"
ToolTip.Tip="{DynamicResource tracks.selectrenderer}">
<Button Classes="clear" Grid.Row="3" Grid.Column="2" Margin="1" Padding="2,1,0,0" Height="18" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Focusable="False" Content="{Binding Renderer}" Click="RendererButtonClicked" ContextRequested="RendererButtonContextRequested" ToolTip.Tip="{DynamicResource tracks.selectrenderer}">
<Button.ContextMenu>
<ContextMenu Classes="context" Name="RenderersMenu" PlacementMode="Bottom" HorizontalOffset="-3" ItemsSource="{Binding RenderersMenuItems}">
<ContextMenu.Styles>
Expand All @@ -80,9 +64,7 @@
</ContextMenu>
</Button.ContextMenu>
</Button>
<ToggleButton Grid.Row="1" Grid.Column="3" Margin="1" Padding="0" Height="18"
HorizontalAlignment="Stretch"
IsChecked="{Binding Mute, Mode=OneWay}" Command="{Binding ToggleMute}">
<ToggleButton Grid.Row="1" Grid.Column="3" Margin="1" Padding="0" Height="18" HorizontalAlignment="Stretch" IsChecked="{Binding Mute, Mode=OneWay}" Command="{Binding ToggleMute}">
<TextBlock Text="M" TextAlignment="Center"/>
<ToggleButton.ContextMenu>
<ContextMenu>
Expand All @@ -93,9 +75,7 @@
</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}">
<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>
Expand All @@ -105,11 +85,8 @@
</ContextMenu>
</ToggleButton.ContextMenu>
</ToggleButton>
<Button Grid.Row="3" Grid.Column="3" Margin="1" Padding="0" Height="18" Background="Transparent"
HorizontalAlignment="Stretch" Click="TrackSettingsButtonClicked">
<Path Classes="clear" Width="24" Height="24"
Data="M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z"
Fill="{StaticResource NeutralAccentBrush}">
<Button Grid.Row="3" Grid.Column="3" Margin="1" Padding="0" Height="18" Background="Transparent" HorizontalAlignment="Stretch" Click="TrackSettingsButtonClicked">
<Path Classes="clear" Width="24" Height="24" Data="M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z" Fill="{StaticResource NeutralAccentBrush}">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX=".67" ScaleY=".67"/>
Expand All @@ -118,28 +95,41 @@
</Path.RenderTransform>
</Path>
</Button>
<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" IsEnabled="{Binding !Muted}"/>
<TextBlock Margin="106,3,0,0" Width="36" HorizontalAlignment="Left" FontSize="9" FontFamily="monospace" >
<TextBlock.Text>
<Grid Grid.Row="4" Grid.Column="2" Grid.ColumnSpan="2" ColumnDefinitions="70,40,40,40" Height="24">
<Slider Name="VolumeSlider" Margin="0,0,0,0" Grid.Column="0" HorizontalAlignment="Stretch" Classes="fader" Minimum="-24" Maximum="12" Value="{Binding Volume}" PointerPressed="VolumeFaderPointerPressed" ContextRequested="VolumeFaderContextRequested" IsEnabled="{Binding !Muted}"/>
<Button Classes="clear" Name="VolumeButton" Margin="0,0,0,0" Grid.Column="1" HorizontalAlignment="Stretch" FontSize="9" FontFamily="monospace" Click="ButtonClicked">
<TextBlock TextAlignment="Left">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:+#00.0;-#00.0}">
<Binding Path="Volume"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Button>
<TextBox Name="VolumeTextBox" Grid.Column="1" Width="10" FontFamily="monospace" KeyDown="TextBoxEnter" PointerExited="TextBoxLeave" IsVisible="False">
<TextBox.Text>
<MultiBinding StringFormat="{}{0:+#00.0;-#00.0}">
<Binding Path="Volume"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<Slider Margin="134,0,0,0" Width="36" HorizontalAlignment="Left"
Classes="fader" Minimum="-100" Maximum="100" Value="{Binding Pan}"
PointerPressed="PanFaderPointerPressed"
ContextRequested="PanFaderContextRequested" IsEnabled="{Binding !Muted}"/>
<TextBlock Margin="0,3,4,0" HorizontalAlignment="Right" FontSize="9" FontFamily="monospace" IsHitTestVisible="False">
<TextBlock.Text>
</TextBox.Text>
</TextBox>
<Slider Name="PanSlider" Margin="0,0,0,0" Grid.Column="2" HorizontalAlignment="Stretch" Classes="fader" Minimum="-100" Maximum="100" Value="{Binding Pan}" PointerPressed="PanFaderPointerPressed" ContextRequested="PanFaderContextRequested" IsEnabled="{Binding !Muted}"/>
<Button Classes="clear" Name="PanButton" Margin="0,0,0,0" Grid.Column="3" HorizontalAlignment="Stretch" FontSize="9" FontFamily="monospace" Click="ButtonClicked">
<TextBlock TextAlignment="Left">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:00R;00L;C}">
<Binding Path="Pan"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Button>
<TextBox Name="PanTextBox" Grid.Column="3" Width="10" FontFamily="monospace" KeyDown="TextBoxEnter" PointerExited="TextBoxLeave" IsVisible="False">
<TextBox.Text>
<MultiBinding StringFormat="{}{0:00R;00L;C}">
<Binding Path="Pan"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</TextBox.Text>
</TextBox>
</Grid>
<Grid.ContextMenu>
<ContextMenu>
Expand Down
52 changes: 52 additions & 0 deletions OpenUtau/Controls/TrackHeader.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,58 @@ void TrackSettingsButtonClicked(object sender, RoutedEventArgs args) {
}
}

void ButtonClicked(object sender, RoutedEventArgs args) {
if (sender is Button button) {
if (button.Name != null) {
if (button.Name.Equals("VolumeButton") && ViewModel != null) {
VolumeTextBox.Text = ViewModel.Volume.ToString();
VolumeButton.IsVisible = false;
VolumeTextBox.IsVisible = true;
args.Handled = true;
} else if (button.Name.Equals("PanButton") && ViewModel != null) {
PanTextBox.Text = ViewModel.Pan.ToString();
PanButton.IsVisible = false;
PanTextBox.IsVisible = true;
args.Handled = true;
}
}
}
}
void TextBoxEnter(object sender, KeyEventArgs args) {
if (sender is TextBox textBox) {
if (textBox.Name != null) {
if (args.Key == Key.Enter) {
if (textBox.Name.Equals("VolumeTextBox") && ViewModel != null) {
if (double.TryParse(VolumeTextBox.Text, out double number)) {
number = number > VolumeSlider.Minimum ? number < VolumeSlider.Maximum ? number : VolumeSlider.Maximum : VolumeSlider.Minimum;
ViewModel.Volume = number;
}
VolumeButton.IsVisible = true;
VolumeTextBox.IsVisible = false;
args.Handled = true;
} else if (textBox.Name.Equals("PanTextBox") && ViewModel != null) {
if (int.TryParse(PanTextBox.Text, out int number)) {
number = (int)(number > PanSlider.Minimum ? number < PanSlider.Maximum ? number : PanSlider.Maximum : PanSlider.Minimum);
ViewModel.Pan = number;
}
PanButton.IsVisible = true;
PanTextBox.IsVisible = false;
args.Handled = true;
}
}
}
}
}

void TextBoxLeave(object sender, PointerEventArgs args) {
if (sender is TextBox textBox) {
VolumeButton.IsVisible = true;
PanButton.IsVisible = true;
textBox.IsVisible = false;
args.Handled = true;
}
}

public void Dispose() {
unbinds.ForEach(u => u.Dispose());
unbinds.Clear();
Expand Down

0 comments on commit b52d3d0

Please sign in to comment.