Skip to content

Commit

Permalink
Merge pull request #848 from lottev1991/SetPortraitHeight
Browse files Browse the repository at this point in the history
[character.yaml] Option to set portrait height (width will be relative)
  • Loading branch information
stakira authored Sep 18, 2023
2 parents c5d3568 + d93b889 commit 68d2c7f
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions OpenUtau.Core/Classic/ClassicSinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ClassicSinger : USinger {
public override byte[] AvatarData => avatarData;
public override string Portrait => voicebank.Portrait == null ? null : Path.Combine(Location, voicebank.Portrait);
public override float PortraitOpacity => voicebank.PortraitOpacity;
public override int PortraitHeight => voicebank.PortraitHeight;
public override string DefaultPhonemizer => voicebank.DefaultPhonemizer;
public override Encoding TextFileEncoding => voicebank.TextFileEncoding;
public override IList<USubbank> Subbanks => subbanks;
Expand Down
3 changes: 3 additions & 0 deletions OpenUtau.Core/Classic/VoiceBank.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using OpenUtau.Core.Ustx;

Expand All @@ -10,6 +11,7 @@ public class Voicebank {
public string Image;
public string Portrait;
public float PortraitOpacity;
public int PortraitHeight;
public string Author;
public string Voice;
public string Web;
Expand All @@ -27,6 +29,7 @@ public void Reload() {
Image = null;
Portrait = null;
PortraitOpacity = 0;
PortraitHeight = 0;
Author = null;
Voice = null;
Web = null;
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Classic/VoicebankConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class VoicebankConfig {
public string Image;
public string Portrait;
public float PortraitOpacity = 0.67f;
public int PortraitHeight = 800;
public string Author;
public string Voice;
public string Web;
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Classic/VoicebankLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public static void ApplyConfig(Voicebank bank, VoicebankConfig bankConfig) {
if (!string.IsNullOrWhiteSpace(bankConfig.Portrait)) {
bank.Portrait = bankConfig.Portrait;
bank.PortraitOpacity = bankConfig.PortraitOpacity;
bank.PortraitHeight = bankConfig.PortraitHeight;
}
if (!string.IsNullOrWhiteSpace(bankConfig.Author)) {
bank.Author = bankConfig.Author;
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Enunu/EnunuSinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class EnunuSinger : USinger {
public override byte[] AvatarData => avatarData;
public override string Portrait => voicebank.Portrait == null ? null : Path.Combine(Location, voicebank.Portrait);
public override float PortraitOpacity => voicebank.PortraitOpacity;
public override int PortraitHeight => voicebank.PortraitHeight;
public override string DefaultPhonemizer => voicebank.DefaultPhonemizer;
public override Encoding TextFileEncoding => voicebank.TextFileEncoding;
public override IList<USubbank> Subbanks => subbanks;
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Ustx/USinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public class USinger : INotifyPropertyChanged {
public virtual byte[] AvatarData { get; }
public virtual string Portrait { get; }
public virtual float PortraitOpacity { get; }
public virtual int PortraitHeight { get; }
public virtual string DefaultPhonemizer { get; }
public virtual Encoding TextFileEncoding => Encoding.UTF8;
public virtual IList<USubbank> Subbanks { get; }
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Vogen/VogenSinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class VogenSinger : USinger {
public override byte[] AvatarData => avatarData;
public override string Portrait => meta.portrait;
public override float PortraitOpacity => meta.portraitOpacity;
public override int PortraitHeight => meta.portraitHeight;
public override string DefaultPhonemizer => "OpenUtau.Core.Vogen.VogenMandarinPhonemizer";
public override Encoding TextFileEncoding => Encoding.UTF8;
public override IList<USubbank> Subbanks => subbanks;
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Vogen/VogenSingerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class VogenMeta {
public string avatar;
public string portrait;
public float portraitOpacity = 0.67f;
public int portraitHeight = 800;
public string web;
public string misc;
}
Expand Down
2 changes: 2 additions & 0 deletions OpenUtau.Test/Classic/VoicebankConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public VoicebankConfigTest(ITestOutputHelper output) {
static VoicebankConfig CreateConfig() {
return new VoicebankConfig() {
PortraitOpacity = 0.75f,
PortraitHeight = 675,
SymbolSet = new SymbolSet() {
Preset = SymbolSetPreset.hiragana,
},
Expand Down Expand Up @@ -53,6 +54,7 @@ public void SerializationTest() {

//"" evaluates to " in verbatim string literals
Assert.Equal(@"portrait_opacity: 0.75
portrait_height: 675
symbol_set:
preset: hiragana
head: '-'
Expand Down
5 changes: 4 additions & 1 deletion OpenUtau/ViewModels/NotesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,12 @@ private void LoadPortrait(UPart? part, UProject? project) {
} else {
using (var stream = new MemoryStream(data)) {
var portrait = new Bitmap(stream);
if (portrait.Size.Height > 800) {
if (portrait.Size.Height > 800 && singer.PortraitHeight == 0) {
int width = (int)Math.Round(800 * portrait.Size.Width / portrait.Size.Height);
portrait = portrait.CreateScaledBitmap(new PixelSize(width, 800));
} else {
int width = (int)Math.Round(singer.PortraitHeight * portrait.Size.Width / portrait.Size.Height);
portrait = portrait.CreateScaledBitmap(new PixelSize(width, singer.PortraitHeight));
}
Portrait = portrait;
portraitSource = singer.Portrait;
Expand Down

0 comments on commit 68d2c7f

Please sign in to comment.