Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MikiraSora committed Dec 18, 2023
2 parents 133f335 + 2e38f8c commit e90922a
Show file tree
Hide file tree
Showing 32 changed files with 601 additions and 204 deletions.
12 changes: 12 additions & 0 deletions OngekiFumenEditor/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="OngekiFumenEditor.Properties.AudioSetting" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="OngekiFumenEditor.Properties.OptionGeneratorToolsSetting" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="OngekiFumenEditor.Properties.ProgramSetting" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="OngekiFumenEditor.Properties.LogSetting" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
Expand All @@ -10,6 +11,17 @@
</sectionGroup>
</configSections>
<userSettings>
<OngekiFumenEditor.Properties.AudioSetting>
<setting name="SoundFolderPath" serializeAs="String">
<value>.\Resources\sounds\</value>
</setting>
<setting name="AudioOutputType" serializeAs="String">
<value>1</value>
</setting>
<setting name="AudioSampleRate" serializeAs="String">
<value>48000</value>
</setting>
</OngekiFumenEditor.Properties.AudioSetting>
<OngekiFumenEditor.Properties.OptionGeneratorToolsSetting>
<setting name="LastLoadedGameFolder" serializeAs="String">
<value />
Expand Down
24 changes: 14 additions & 10 deletions OngekiFumenEditor/Base/Collections/BulletPalleteList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public class BulletPalleteList : IReadOnlyList<BulletPallete>, INotifyCollection

public static int ConvertIdToInt(string id)
{
return id.Reverse().Select((x, i) => (int)Math.Pow(ALPHABET.Count, i) * (ALPHABET.TryGetValue(x, out var d) ? d : 0)).Sum();
return id
.ToUpperInvariant()
.Reverse()
.Select((x, i) => (int)Math.Pow(ALPHABET.Count, i) * (ALPHABET.TryGetValue(x, out var d) ? d : 0))
.Sum();
}

public static string ConvertIntToId(int val)
Expand All @@ -33,15 +37,15 @@ public static string ConvertIntToId(int val)
val = val / ALPHABET_REV.Count;
}

return str;
return str.ToUpperInvariant();
}

private Dictionary<string, BulletPallete> palleteMap = new();
private Dictionary<int, BulletPallete> palleteMap = new();
private string cacheCurrentMaxId = null;

public int Count => palleteMap.Count;
public BulletPallete this[int index] => this[ConvertIntToId(index)];
public BulletPallete this[string strId] => palleteMap.TryGetValue(strId, out var r) ? r : default;
public BulletPallete this[int index] => this[index];
public BulletPallete this[string strId] => palleteMap.TryGetValue(ConvertIdToInt(strId), out var r) ? r : default;

public event NotifyCollectionChangedEventHandler CollectionChanged;

Expand All @@ -55,17 +59,17 @@ public void AddPallete(BulletPallete pallete)
if (palleteMap.Count == 0)
cacheCurrentMaxId = "9Z";
else
cacheCurrentMaxId = ConvertIntToId(palleteMap.Keys.Select(ConvertIdToInt).OrderBy(x => x).LastOrDefault());
cacheCurrentMaxId = ConvertIntToId(palleteMap.Keys.OrderBy(x => x).LastOrDefault());
}

if (string.IsNullOrWhiteSpace(pallete.StrID))
{
//分配一个新的StrId
//分配一个新的StrId
pallete.StrID = ConvertIntToId(ConvertIdToInt(cacheCurrentMaxId) + 1);
}

var addable = true;
if (palleteMap.TryGetValue(pallete.StrID, out var old))
if (palleteMap.TryGetValue(ConvertIdToInt(pallete.StrID), out var old))
{
if (old == pallete)
addable = false; //重复添加,那就忽略了
Expand All @@ -78,7 +82,7 @@ public void AddPallete(BulletPallete pallete)

if (addable)
{
palleteMap[pallete.StrID] = pallete;
palleteMap[ConvertIdToInt(pallete.StrID)] = pallete;

pallete.PropertyChanged += OnPalletePropChanged;
cacheCurrentMaxId = Comparer<string>.Default.Compare(pallete.StrID, cacheCurrentMaxId) > 0 ? pallete.StrID : cacheCurrentMaxId;
Expand All @@ -89,7 +93,7 @@ public void AddPallete(BulletPallete pallete)

public void RemovePallete(BulletPallete pallete)
{
if (palleteMap.Remove(pallete.StrID))
if (palleteMap.Remove(ConvertIdToInt(pallete.StrID)))
{
pallete.PropertyChanged -= OnPalletePropChanged;
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
Expand Down
13 changes: 13 additions & 0 deletions OngekiFumenEditor/Base/IBulletPalleteChangable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OngekiFumenEditor.Base
{
public interface IBulletPalleteChangable
{
public string SetStrID { get; set; }
}
}
19 changes: 19 additions & 0 deletions OngekiFumenEditor/Base/OngekiFumen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,25 @@ private void OnOngekiObjectModify(object sender, PropertyChangedEventArgs e)
}
}
break;
case nameof(IBulletPalleteChangable.SetStrID):
if (sender is IBulletPalleteReferencable bullet)
{
var beforeStrId = bullet.ReferenceBulletPallete?.StrID;
var afterStrId = bullet.SetStrID;
if (!string.IsNullOrWhiteSpace(afterStrId))
{
if (BulletPalleteList[afterStrId] is BulletPallete newPallete)
{
bullet.ReferenceBulletPallete = newPallete;
Log.LogInfo($"Change IBulletPalleteReferencable object {bullet} ref pallete from {beforeStrId} to {afterStrId}.");
}
else
{
Log.LogWarn($"Change IBulletPalleteReferencable object {bullet} ref pallete failed, new ref strId={afterStrId} not found.");
}
}
}
break;
default:
break;
}
Expand Down
14 changes: 14 additions & 0 deletions OngekiFumenEditor/Base/OngekiObjects/Bell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ private void ReferenceBulletPallete_PropertyChanged(object sender, System.Compon
[ObjectPropertyBrowserShow]
public string StrID => ReferenceBulletPallete?.StrID;

private string setStrID;
[ObjectPropertyBrowserShow]
[ObjectPropertyBrowserTipText("改变此值可以改变此物件对应的子弹模板")]
[ObjectPropertyBrowserAlias("SetStrID")]
public string SetStrID
{
get => setStrID;
set
{
Set(ref setStrID, value);
setStrID = default;
}
}

[ObjectPropertyBrowserAlias("BPL." + nameof(PlaceOffset))]
[ObjectPropertyBrowserShow]
public int PlaceOffset => ReferenceBulletPallete?.PlaceOffset ?? default;
Expand Down
16 changes: 15 additions & 1 deletion OngekiFumenEditor/Base/OngekiObjects/Bullet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,21 @@ public BulletDamageType BulletDamageTypeValue

[ObjectPropertyBrowserAlias("BPL." + nameof(StrID))]
[ObjectPropertyBrowserShow]
public string StrID => ReferenceBulletPallete?.StrID;
public string StrID => ReferenceBulletPallete?.StrID ?? string.Empty;

private string setStrID;
[ObjectPropertyBrowserShow]
[ObjectPropertyBrowserTipText("改变此值可以改变此物件对应的子弹模板")]
[ObjectPropertyBrowserAlias("SetStrID")]
public string SetStrID
{
get => setStrID;
set
{
Set(ref setStrID, value);
setStrID = default;
}
}

[ObjectPropertyBrowserAlias("BPL." + nameof(PlaceOffset))]
[ObjectPropertyBrowserShow]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace OngekiFumenEditor.Base.OngekiObjects
{
public interface IBulletPalleteReferencable : IDisplayableObject, IHorizonPositionObject, ITimelineObject, INotifyPropertyChanged
public interface IBulletPalleteReferencable : IDisplayableObject, IHorizonPositionObject, ITimelineObject, INotifyPropertyChanged, IBulletPalleteChangable
{
BulletPallete ReferenceBulletPallete { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using OngekiFumenEditor.Base;
using OngekiFumenEditor.Base.OngekiObjects;
using OngekiFumenEditor.Base.OngekiObjects.Beam;
using OngekiFumenEditor.Kernel.Audio.NAudioImpl.Sound;
using OngekiFumenEditor.Modules.FumenVisualEditor;
using OngekiFumenEditor.Modules.FumenVisualEditor.ViewModels;
using OngekiFumenEditor.Properties;
Expand Down Expand Up @@ -50,7 +51,7 @@ public float Volume
}

private Dictionary<SoundControl, ISoundPlayer> cacheSounds = new();
private Task loadTask;
private Task<bool> loadTask;

public DefaultFumenSoundPlayer()
{
Expand All @@ -59,7 +60,7 @@ public DefaultFumenSoundPlayer()

private async void InitSounds()
{
var source = new TaskCompletionSource();
var source = new TaskCompletionSource<bool>();
loadTask = source.Task;
var audioManager = IoC.Get<IAudioManager>();

Expand All @@ -69,6 +70,8 @@ private async void InitSounds()
var msg = $"因为音效文件夹不存在,无法加载音效";
MessageBox.Show(msg);
Log.LogError(msg);
source.SetResult(false);
return;
}
else
Log.LogInfo($"SoundFolderPath : {soundFolderPath} , fullpath : {Path.GetFullPath(soundFolderPath)}");
Expand All @@ -90,6 +93,7 @@ async Task load(SoundControl sound, string fileName)
}
}

cacheSounds.Clear();
await load(SoundControl.Tap, "tap.wav");
await load(SoundControl.Bell, "bell.wav");
await load(SoundControl.CriticalTap, "extap.wav");
Expand All @@ -106,9 +110,13 @@ async Task load(SoundControl sound, string fileName)
await load(SoundControl.BeamEnd, "beamend.wav");

if (!noError)
{
MessageBox.Show("部分音效并未加载成功,详情可查看日志");
source.SetResult(false);
return;
}

source.SetResult();
source.SetResult(true);
}

public async Task Prepare(FumenVisualEditorViewModel editor, IAudioPlayer player)
Expand Down Expand Up @@ -488,5 +496,11 @@ public void SetVolume(SoundControl sound, float volume)
}
}
}

public async Task<bool> ReloadSoundFiles()
{
InitSounds();
return await loadTask;
}
}
}
2 changes: 2 additions & 0 deletions OngekiFumenEditor/Kernel/Audio/IFumenSoundPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public interface IFumenSoundPlayer
float? GetVolume(SoundControl sound);
void SetVolume(SoundControl sound, float volume);
void Seek(TimeSpan msec, bool pause);

Task<bool> ReloadSoundFiles();
}
}
15 changes: 15 additions & 0 deletions OngekiFumenEditor/Kernel/Audio/NAudioImpl/AudioOutputType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OngekiFumenEditor.Kernel.Audio.NAudioImpl
{
public enum AudioOutputType
{
WaveOut,
Wasapi,
Asio
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using NAudio.Wave;
using System.Runtime.InteropServices;

namespace OngekiFumenEditor.Kernel.Audio.NAudioImpl.Music
{
internal class BufferWaveStream : WaveStream, IWaveProvider, ISampleProvider
{
private readonly byte[] waveBuffer;
private readonly WaveFormat format;

public BufferWaveStream(byte[] buffer, WaveFormat format)
{
waveBuffer = buffer;
this.format = format;
}

public override WaveFormat WaveFormat => format;

public override long Length => waveBuffer.LongLength;

public override long Position { get; set; } = 0;

public override int Read(byte[] buffer, int offset, int count)
{
var beforePosition = Position;
for (int i = 0; i < count && Position < waveBuffer.Length; i++)
buffer[offset + i] = waveBuffer[Position++];
return (int)(Position - beforePosition);
}

public int Read(float[] buffer, int offset, int count)
{
var floatBuffer = MemoryMarshal.Cast<byte, float>(waveBuffer);

var floatPosition = (int)(Position / sizeof(float));
var floatLength = waveBuffer.Length / sizeof(float);

var beforePosition = floatPosition;
for (int i = 0; i < count && floatPosition < floatLength; i++)
buffer[offset + i] = floatBuffer[floatPosition++];
var read = floatPosition - beforePosition;
Position = floatPosition * sizeof(float);
return read;
}
}
}
Loading

0 comments on commit e90922a

Please sign in to comment.