Skip to content

Commit

Permalink
Merge pull request #772 from rokujyushi/Text-box-direct
Browse files Browse the repository at this point in the history
For fine control of volume and panning.
  • Loading branch information
stakira committed Jul 13, 2023
2 parents c2110b0 + 7662b95 commit be25074
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 16 deletions.
45 changes: 29 additions & 16 deletions OpenUtau/Controls/TrackHeader.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,41 @@
</Path.RenderTransform>
</Path>
</Button>
<Grid Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="2">
<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,45,35" Height="24" IsEnabled="{Binding !Muted}">
<Slider Margin="0,0,0,0" Grid.Column="0" HorizontalAlignment="Stretch" Classes="fader" Minimum="-24" Maximum="12" Value="{Binding Volume}" PointerPressed="VolumeFaderPointerPressed" ContextRequested="VolumeFaderContextRequested"/>
<Button Classes="clear" Margin="0,0,0,0" Grid.Column="1" HorizontalAlignment="Stretch" FontSize="9" FontFamily="monospace" Click="VolumeButtonClicked">
<TextBlock TextAlignment="Left">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:+#00.0;-#00.0}">
<Binding Path="Volume"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Button>
<TextBox Grid.Column="1" Width="10" FontSize="9" FontFamily="monospace" KeyDown="VolumeTextBoxEnter" 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 Margin="0,0,0,0" Grid.Column="2" HorizontalAlignment="Stretch" Classes="fader" Minimum="-100" Maximum="100" Value="{Binding Pan}" PointerPressed="PanFaderPointerPressed" ContextRequested="PanFaderContextRequested"/>
<Button Classes="clear" Margin="0,0,0,0" Grid.Column="3" HorizontalAlignment="Stretch" FontSize="9" FontFamily="monospace" Click="PanButtonClicked">
<TextBlock TextAlignment="Left">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:00R;00L;C}">
<Binding Path="Pan"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Button>
<TextBox Grid.Column="3" Width="10" FontSize="9" FontFamily="monospace" KeyDown="PanTextBoxEnter" 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
79 changes: 79 additions & 0 deletions OpenUtau/Controls/TrackHeader.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,85 @@ void TrackSettingsButtonClicked(object sender, RoutedEventArgs args) {
}
}

void VolumeButtonClicked(object sender, RoutedEventArgs args) {
if (sender is Button button && ViewModel != null) {
if (button.Parent is Grid parentGrid) {
if (parentGrid.Children[2] is TextBox volumeTextBox) {
volumeTextBox.Text = ViewModel.Volume.ToString();
volumeTextBox.IsVisible = true;
button.IsVisible = false;
args.Handled = true;
}
}
}
}
void PanButtonClicked(object sender, RoutedEventArgs args) {
if (sender is Button button && ViewModel != null) {
if (button.Parent is Grid parentGrid) {
if (parentGrid.Children[5] is TextBox panTextBox) {
panTextBox.Text = ViewModel.Pan.ToString();
panTextBox.IsVisible = true;
button.IsVisible = false;
args.Handled = true;
}
}
}
}
void VolumeTextBoxEnter(object sender, KeyEventArgs args) {
if (sender is TextBox textBox && ViewModel != null && Key.Enter.Equals(args.Key)) {
if (textBox.Parent is Grid parentGrid) {
if (parentGrid.Children[0] is Slider volumeSlider) {
if (double.TryParse(textBox.Text, out double number)) {
number = number > volumeSlider.Minimum ? number < volumeSlider.Maximum ? number : volumeSlider.Maximum : volumeSlider.Minimum;
ViewModel.Volume = number;
}

} else
if (parentGrid.Children[1] is Button volumeButton) {
textBox.IsVisible = false;
volumeButton.IsVisible = true;
args.Handled = true;
}
}
}
}
void PanTextBoxEnter(object sender, KeyEventArgs args) {
if (sender is TextBox textBox && ViewModel != null && Key.Enter.Equals(args.Key)) {
if (textBox.Parent is Grid parentGrid) {
if (parentGrid.Children[3] is Slider panSlider) {
if (double.TryParse(textBox.Text, out double number)) {
number = number > panSlider.Minimum ? number < panSlider.Maximum ? number : panSlider.Maximum : panSlider.Minimum;
ViewModel.Pan = number;
}

} else
if (parentGrid.Children[4] is Button panButton) {
textBox.IsVisible = false;
panButton.IsVisible = true;
args.Handled = true;
}
}
}
}

void TextBoxLeave(object sender, PointerEventArgs args) {
if (sender is TextBox textBox) {
if (textBox.Parent is Grid parentGrid) {
if (parentGrid.Children[1] is Button volumeButton) {
textBox.IsVisible = false;
volumeButton.IsVisible = true;
args.Handled = true;
}
if (parentGrid.Children[4] is Button panButton) {
textBox.IsVisible = false;
panButton.IsVisible = true;
args.Handled = true;
}
}
}
}


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

0 comments on commit be25074

Please sign in to comment.