Skip to content

Commit

Permalink
fix: Slide SFX
Browse files Browse the repository at this point in the history
  • Loading branch information
LeZi9916 committed Aug 15, 2024
1 parent a736e5c commit a101091
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Components/ComponentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void Menu_New_Click(object sender, RoutedEventArgs e)
}
}

private void Menu_Open_Click(object sender, RoutedEventArgs e)
private async void Menu_Open_Click(object sender, RoutedEventArgs e)
{
if (!isSaved)
if (!AskSave())
Expand All @@ -119,7 +119,7 @@ private void Menu_Open_Click(object sender, RoutedEventArgs e)
if ((bool)openFileDialog.ShowDialog()!)
{
var fileInfo = new FileInfo(openFileDialog.FileName);
initFromFile(fileInfo.DirectoryName!);
await initFromFile(fileInfo.DirectoryName!);
}
}

Expand Down
15 changes: 8 additions & 7 deletions MainWindowCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,15 @@ private async Task ReadSetting()
if (!File.Exists(path))
return;

using var stream = File.OpenRead(path);
var setting = await JsonSerializer.DeserializeAsync<MajSetting>(stream);

LevelSelector.SelectedIndex = setting!.LastEditDiff;
selectedDifficulty = setting.LastEditDiff;
SetBgmPosition(setting.LastEditTime);
using (var stream = File.OpenRead(path))
{
var setting = await JsonSerializer.DeserializeAsync<MajSetting>(stream);
LevelSelector.SelectedIndex = setting!.LastEditDiff;
selectedDifficulty = setting.LastEditDiff;
await SetBgmPosition(setting.LastEditTime);

AudioManager.ReadSetting(setting);
AudioManager.ReadSetting(setting);
}

await SaveSetting(); // 覆盖旧版本setting
}
Expand Down
32 changes: 19 additions & 13 deletions SubWindow/SoundSetting.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class SoundSetting : Window
private readonly MainWindow MainWindow;
private readonly Dictionary<Slider, Label> SliderValueBindingMap = new(); // Slider和ValueLabel的绑定关系

private readonly Timer UpdateLevelTimer = new(1);
CancellationTokenSource source = new();

public SoundSetting()
{
Expand Down Expand Up @@ -45,39 +45,46 @@ private void SoundSettingWindow_Loaded(object sender, RoutedEventArgs e)
SetSlider(Judge_Slider, ChannelType.TapJudge);
SetSlider(Break_Slider, ChannelType.Break, ChannelType.BreakJudge);
SetSlider(BreakSlide_Slider, ChannelType.BreakSlideEnd, ChannelType.BreakSlideJudge);
SetSlider(Slide_Slider, ChannelType.BreakSlideStart, ChannelType.BreakSlideStart);
SetSlider(Slide_Slider, ChannelType.Slide, ChannelType.BreakSlideStart);
SetSlider(EX_Slider, ChannelType.ExJudge);
SetSlider(Touch_Slider, ChannelType.Touch);
SetSlider(Hanabi_Slider, ChannelType.Hanabi, ChannelType.HoldRiser);


UpdateLevelTimer.AutoReset = true;
UpdateLevelTimer.Elapsed += UpdateLevelTimer_Elapsed;
UpdateLevelTimer.Start();
UpdateDBLevel();
}

private void UpdateLevelTimer_Elapsed(object? sender, ElapsedEventArgs e)
async void UpdateDBLevel()
{
Dispatcher.Invoke(() =>
while(true)
{
if (source.IsCancellationRequested)
break;
UpdateProgressBar(BGM_Level, ChannelType.BGM, ChannelType.TrackStart, ChannelType.APSFX, ChannelType.Clock);
UpdateProgressBar(Answer_Level, ChannelType.Answer);
UpdateProgressBar(Judge_Level, ChannelType.TapJudge);
UpdateProgressBar(Break_Level, ChannelType.Break, ChannelType.BreakJudge);
UpdateProgressBar(BreakSlide_Level, ChannelType.BreakSlideEnd, ChannelType.BreakSlideJudge);
UpdateProgressBar(Slide_Level, ChannelType.BreakSlideStart, ChannelType.BreakSlideStart);
UpdateProgressBar(Slide_Level, ChannelType.Slide, ChannelType.BreakSlideStart);
UpdateProgressBar(EX_Level, ChannelType.ExJudge);
UpdateProgressBar(Touch_Level, ChannelType.Touch);
UpdateProgressBar(Hanabi_Level, ChannelType.Hanabi, ChannelType.HoldRiser);
});
await Task.Delay(16);
}
}

/// <summary>
/// 更新对应Channel的响度
/// </summary>
/// <param name="bar"></param>
/// <param name="channels"></param>
private void UpdateProgressBar(ProgressBar bar, params ChannelType[] channels)
{
var values = new double[channels.Length];
var ampLevel = 0f;
for (var i = 0; i < channels.Length; i++)
{
ampLevel = AudioManager.GetVolume(channels[i]);
values[i] = AudioManager.GetChannelDB(channels[i]);
}

var value = values.Max();
if (!double.IsNaN(value) && !double.IsInfinity(value)) bar.Value = value * ampLevel;
Expand Down Expand Up @@ -108,8 +115,7 @@ void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e

private void SoundSettingWindow_Closing(object sender, CancelEventArgs e)
{
UpdateLevelTimer.Stop();
UpdateLevelTimer.Dispose();
source.Cancel();
}

private void BtnSetDefault_Click(object sender, RoutedEventArgs e)
Expand Down
36 changes: 18 additions & 18 deletions Utils/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,23 @@ public static class AudioManager

public static void Init()
{
answerStream = Bass.BASS_StreamCreateFile(SFX_PATH + "answer.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
judgeStream = Bass.BASS_StreamCreateFile(SFX_PATH + "judge.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
judgeBreakStream = Bass.BASS_StreamCreateFile(SFX_PATH + "judge_break.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
judgeExStream = Bass.BASS_StreamCreateFile(SFX_PATH + "judge_ex.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
breakStream = Bass.BASS_StreamCreateFile(SFX_PATH + "break.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
hanabiStream = Bass.BASS_StreamCreateFile(SFX_PATH + "hanabi.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
holdRiserStream = Bass.BASS_StreamCreateFile(SFX_PATH + "touchHold_riser.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
trackStartStream = Bass.BASS_StreamCreateFile(SFX_PATH + "track_start.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
slideStream = Bass.BASS_StreamCreateFile(SFX_PATH + "slide.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
touchStream = Bass.BASS_StreamCreateFile(SFX_PATH + "touch.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
allperfectStream = Bass.BASS_StreamCreateFile(SFX_PATH + "all_perfect.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
fanfareStream = Bass.BASS_StreamCreateFile(SFX_PATH + "fanfare.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
clockStream = Bass.BASS_StreamCreateFile(SFX_PATH + "clock.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
breakSlideStartStream =
Bass.BASS_StreamCreateFile(SFX_PATH + "break_slide_start.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
breakSlideStream = Bass.BASS_StreamCreateFile(SFX_PATH + "break_slide.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
judgeBreakSlideStream =
Bass.BASS_StreamCreateFile(SFX_PATH + "judge_break_slide.wav", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
answerStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "answer.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
judgeStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "judge.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
judgeBreakStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "judge_break.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
judgeExStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "judge_ex.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
breakStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "break.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
hanabiStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "hanabi.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
holdRiserStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "touchHold_riser.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
trackStartStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "track_start.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
slideStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "slide.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
touchStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "touch.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
allperfectStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "all_perfect.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
fanfareStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "fanfare.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
clockStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "clock.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
breakSlideStartStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "break_slide_start.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
breakSlideStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "break_slide.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
judgeBreakSlideStream = Bass.BASS_StreamCreateFile(Path.Combine(SFX_PATH, "judge_break_slide.wav"), 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);

}
public static BASS_CHANNELINFO? LoadBGM(string path)
{
Expand Down Expand Up @@ -192,6 +191,7 @@ public static int GetChannelId(in ChannelType type)
ChannelType.TapJudge => judgeStream,
ChannelType.Touch => touchStream,
ChannelType.TrackStart => trackStartStream,
ChannelType.Slide => slideStream,
_ => -1
};
}
Expand Down

0 comments on commit a101091

Please sign in to comment.