Skip to content

Commit

Permalink
Merge pull request #1146 from maiko3tattun/240518_FirstSetParamLinkage
Browse files Browse the repository at this point in the history
First linkage with setparam
  • Loading branch information
stakira authored Jun 9, 2024
2 parents 3e5ed7b + fa39ab2 commit 304faa8
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 2 deletions.
22 changes: 22 additions & 0 deletions OpenUtau.Core/Classic/Ust.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,5 +459,27 @@ public static (List<UNote>, List<UNote>) ParsePlugin(
.ToList();
return (toRemove, toAdd);
}

public static void WriteForSetParam(UProject project, string filePath, List<UOto> otos) {
using (var writer = new StreamWriter(filePath, false, Encoding.GetEncoding("shift_jis"))) {
writer.WriteLine("[#SETTING]");
writer.WriteLine($"Tempo=120");
writer.WriteLine("Tracks=1");
if (project.Saved) {
writer.WriteLine($"Project={project.FilePath.Replace(".ustx", ".ust")}");
}
writer.WriteLine($"VoiceDir={Path.GetDirectoryName(otos[0].File)}");
writer.WriteLine($"CacheDir={PathManager.Inst.CachePath}");
writer.WriteLine("Mode2=True");

for (int i = 0; i < otos.Count; i++) {
UOto oto = otos[i];
writer.WriteLine($"[#{i:D4}]");
writer.WriteLine($"Length=480");
writer.WriteLine($"Lyric={oto.Alias}");
writer.WriteLine($"NoteNum=60");
}
}
}
}
}
1 change: 1 addition & 0 deletions OpenUtau.Core/Util/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public class SerializablePreferences {
public bool LyricsHelperBrackets = false;
public int OtoEditor = 0;
public string VLabelerPath = string.Empty;
public string SetParamPath = string.Empty;
public bool Beta = false;
public bool RememberMid = false;
public bool RememberUst = true;
Expand Down
3 changes: 3 additions & 0 deletions OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ Warning: this option removes custom presets.</system:String>
<system:String x:Key="prefs.on">On</system:String>
<system:String x:Key="prefs.otoeditor">Oto Editor</system:String>
<system:String x:Key="prefs.otoeditor.select">Default Oto Editor</system:String>
<system:String x:Key="prefs.otoeditor.setparampath">setParam Path</system:String>
<system:String x:Key="prefs.paths">Paths</system:String>
<system:String x:Key="prefs.paths.addlsinger">Additional Singer Path</system:String>
<system:String x:Key="prefs.paths.addlsinger.install">Install to Additional Singer Path</system:String>
Expand Down Expand Up @@ -433,13 +434,15 @@ Warning: this option removes custom presets.</system:String>
<system:String x:Key="progress.waitingrendering">Waiting Rendering</system:String>

<system:String x:Key="singers.caption">Singers</system:String>
<system:String x:Key="singers.editoto.editinsetparam">Edit In setParam</system:String>
<system:String x:Key="singers.editoto.editinvlabeler">Edit In vLabeler</system:String>
<system:String x:Key="singers.editoto.gotosource">Goto Source File</system:String>
<system:String x:Key="singers.editoto.regenfrq">Regenerate FRQ</system:String>
<system:String x:Key="singers.editoto.regenfrq.regenerating">Regenerating FRQ</system:String>
<system:String x:Key="singers.editoto.reset">Reset Otos</system:String>
<system:String x:Key="singers.editoto.save">Save Otos</system:String>
<system:String x:Key="singers.editoto.searchalias">Search Alias</system:String>
<system:String x:Key="singers.editoto.setsetparampath">Download setParam (v4.0b or higher) from http://nwp8861.blog92.fc2.com/ and set setParam path in Preferences first!</system:String>
<system:String x:Key="singers.editoto.setvlabelerpath">Download vLabeler (1.0.0-beta1 or higher) from https://github.com/sdercolin/vlabeler and set vLabeler path in Preferences first!</system:String>
<system:String x:Key="singers.errorreport">Generate Singer Error Report</system:String>
<system:String x:Key="singers.location">Location</system:String>
Expand Down
5 changes: 4 additions & 1 deletion OpenUtau/Strings/Strings.ja-JP.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@
<system:String x:Key="prefs.on">オン</system:String>
<system:String x:Key="prefs.otoeditor">原音設定</system:String>
<system:String x:Key="prefs.otoeditor.select">デフォルトの原音設定エディタ</system:String>
<system:String x:Key="prefs.otoeditor.setparampath">setParamの場所</system:String>
<system:String x:Key="prefs.paths">ファイルの場所</system:String>
<system:String x:Key="prefs.paths.addlsinger">シンガーの場所(追加)</system:String>
<system:String x:Key="prefs.paths.addlsinger.install">シンガーの場所(追加)にインストール</system:String>
Expand Down Expand Up @@ -431,14 +432,16 @@
<system:String x:Key="progress.waitingrendering">レンダリング中</system:String>

<system:String x:Key="singers.caption">シンガー</system:String>
<system:String x:Key="singers.editoto.editinsetparam">setParamで編集</system:String>
<system:String x:Key="singers.editoto.editinvlabeler">vLabelerで編集</system:String>
<system:String x:Key="singers.editoto.gotosource">原音の場所を開く</system:String>
<system:String x:Key="singers.editoto.regenfrq">周波数表を再生成</system:String>
<system:String x:Key="singers.editoto.regenfrq.regenerating">周波数表を再生成中</system:String>
<system:String x:Key="singers.editoto.reset">原音設定をリセット</system:String>
<system:String x:Key="singers.editoto.save">原音設定を保存</system:String>
<system:String x:Key="singers.editoto.searchalias">エイリアス検索</system:String>
<!--<system:String x:Key="singers.editoto.setvlabelerpath">Download vLabeler (1.0.0-beta1 or higher) from https://github.com/sdercolin/vlabeler and set vLabeler path in Preferences first!</system:String>-->
<system:String x:Key="singers.editoto.setsetparampath">先にsetParam(v4.0b以降)をダウンロードし、環境設定でパスを設定してください! http://nwp8861.blog92.fc2.com/</system:String>
<system:String x:Key="singers.editoto.setvlabelerpath">先にvLabeler(1.0.0-beta1以降)をダウンロードし、環境設定でパスを設定してください! https://github.com/sdercolin/vlabeler</system:String>
<system:String x:Key="singers.errorreport">シンガーのError Reportを出力</system:String>
<system:String x:Key="singers.location">ファイルの場所</system:String>
<system:String x:Key="singers.otoview.moveleft">左へ移動</system:String>
Expand Down
7 changes: 7 additions & 0 deletions OpenUtau/ViewModels/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public AudioOutputDevice? AudioOutputDevice {
[Reactive] public bool ShowGhostNotes { get; set; }
[Reactive] public int OtoEditor { get; set; }
public string VLabelerPath => Preferences.Default.VLabelerPath;
public string SetParamPath => Preferences.Default.SetParamPath;
[Reactive] public bool ClearCacheOnQuit { get; set; }
public int LogicalCoreCount {
get => Environment.ProcessorCount;
Expand Down Expand Up @@ -374,5 +375,11 @@ public void SetVLabelerPath(string path) {
Preferences.Save();
this.RaisePropertyChanged(nameof(VLabelerPath));
}

public void SetSetParamPath(string path) {
Preferences.Default.SetParamPath = path;
Preferences.Save();
this.RaisePropertyChanged(nameof(SetParamPath));
}
}
}
10 changes: 10 additions & 0 deletions OpenUtau/Views/PreferencesDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
<ComboBox SelectedIndex="{Binding OtoEditor}">
<ComboBoxItem Content="OpenUtau"/>
<ComboBoxItem Content="vLabeler"/>
<ComboBoxItem Content="setParam"/>
</ComboBox>
<TextBlock Text="{DynamicResource prefs.advanced.vlabelerpath}" Margin="0,10,0,0"/>
<TextBlock HorizontalAlignment="Stretch" Margin="4"
Expand All @@ -224,6 +225,15 @@
<Button Grid.Column="2" Content="{DynamicResource prefs.paths.select}"
HorizontalAlignment="Stretch" Click="SelectVLabelerPath"/>
</Grid>
<TextBlock Text="{DynamicResource prefs.otoeditor.setparampath}" Margin="0,10,0,0"/>
<TextBlock HorizontalAlignment="Stretch" Margin="4"
TextWrapping="Wrap" FontSize="11" Text="{Binding SetParamPath}"/>
<Grid HorizontalAlignment="Stretch" ColumnDefinitions="*,10,*">
<Button Grid.Column="0" Content="{DynamicResource prefs.paths.reset}"
HorizontalAlignment="Stretch" Click="ResetSetParamPath"/>
<Button Grid.Column="2" Content="{DynamicResource prefs.paths.select}"
HorizontalAlignment="Stretch" Click="SelectSetParamPath"/>
</Grid>
</StackPanel>
</HeaderedContentControl>
<HeaderedContentControl Classes="groupbox" Header="{DynamicResource prefs.advanced}">
Expand Down
14 changes: 14 additions & 0 deletions OpenUtau/Views/PreferencesDialog.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,19 @@ async void SelectVLabelerPath(object sender, RoutedEventArgs e) {
((PreferencesViewModel)DataContext!).SetVLabelerPath(path);
}
}

void ResetSetParamPath(object sender, RoutedEventArgs e) {
((PreferencesViewModel)DataContext!).SetSetParamPath(string.Empty);
}

async void SelectSetParamPath(object sender, RoutedEventArgs e) {
var path = await FilePicker.OpenFile(this, "prefs.otoeditor.setparampath", FilePicker.EXE);
if (string.IsNullOrEmpty(path)) {
return;
}
if (File.Exists(path)) {
((PreferencesViewModel)DataContext!).SetSetParamPath(path);
}
}
}
}
5 changes: 4 additions & 1 deletion OpenUtau/Views/SingersDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
IsVisible="{Binding IsClassic}" IsEnabled="{Binding Singer.OtoDirty}"/>
<Button Margin="0" Content="{DynamicResource singers.editoto.editinvlabeler}"
IsVisible="{Binding IsClassic}" Click="OnEditInVLabeler"/>
<!-- <Button Margin="0" Content="{DynamicResource singers.editoto.editinsetparam}"
IsVisible="{Binding IsClassic}" Click="OnEditInSetParam"/>-->
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="2" Spacing="10" Margin="0,0,10,0" Height="20"
Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom">
Expand All @@ -171,9 +173,10 @@
SelectionChanged="OnSelectedOtoChanged"
BeginningEdit="OnBeginningEdit" CellEditEnded="OnCellEditEnded">
<DataGrid.ContextMenu>
<ContextMenu>
<ContextMenu IsVisible="{Binding IsClassic}">
<MenuItem Header="{DynamicResource singers.editoto.gotosource}" Click="GotoSourceFile"/>
<MenuItem Header="{DynamicResource singers.editoto.editinvlabeler}" Click="GotoVLabelerOto"/>
<MenuItem Header="{DynamicResource singers.editoto.editinsetparam}" Click="GotoSetParamOto"/>
<MenuItem Header="{DynamicResource singers.editoto.regenfrq}">
<MenuItem Header="DIO" Click="RegenFrq" Tag="dio"/>
<MenuItem Header="DIO(5x)" Click="RegenFrq" Tag="dioss"/>
Expand Down
54 changes: 54 additions & 0 deletions OpenUtau/Views/SingersDialog.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand All @@ -10,6 +11,7 @@
using NAudio.Wave;
using NWaves.Audio;
using OpenUtau.App.ViewModels;
using OpenUtau.Classic;
using OpenUtau.Core;
using OpenUtau.Core.Format;
using OpenUtau.Core.Ustx;
Expand Down Expand Up @@ -224,6 +226,58 @@ private void OpenInVLabeler(USinger singer, UOto? oto) {
}
}

void GotoSetParamOto(object sender, RoutedEventArgs args) {
var viewModel = (DataContext as SingersViewModel)!;
if (viewModel.Singer == null) {
return;
}
var oto = OtoGrid?.SelectedItem as UOto;
if (oto == null) {
return;
}
if (viewModel.Singer != null) {
OpenInSetParam(viewModel.Singer, oto);
}
}

/*void OnEditInVSetParam(object sender, RoutedEventArgs args) {
var viewModel = (DataContext as SingersViewModel)!;
if (viewModel.Singer != null) {
OpenInSetParam(viewModel.Singer, null);
}
}*/

private void OpenInSetParam(USinger singer, UOto oto) {
string path = Core.Util.Preferences.Default.SetParamPath;
if (string.IsNullOrEmpty(path) || !File.Exists(path)) {
MessageBox.Show(
this,
ThemeManager.GetString("singers.editoto.setsetparampath"),
ThemeManager.GetString("errors.caption"),
MessageBox.MessageBoxButtons.Ok);
return;
}
try {
var tempFile = Path.Combine(PathManager.Inst.CachePath, "temp.tmp");
Ust.WriteForSetParam(DocManager.Inst.Project, tempFile, new List<UOto> { oto });

var startInfo = new ProcessStartInfo() {
FileName = path,
Arguments = $"\"{tempFile}\"",
WorkingDirectory = Path.GetDirectoryName(path)
};
using (var process = Process.Start(startInfo)) {
process!.WaitForExit();
}
} catch (Exception e) {
MessageBox.Show(
this,
e.ToString(),
ThemeManager.GetString("errors.caption"),
MessageBox.MessageBoxButtons.Ok);
}
}

void OnOpenReadme(object sender, RoutedEventArgs e) {
var viewModel = (DataContext as SingersViewModel)!;
if (viewModel.Singer != null) {
Expand Down

0 comments on commit 304faa8

Please sign in to comment.