Skip to content

Commit

Permalink
fix: 修复合并错误
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYunPlayer committed Feb 6, 2025
1 parent c8036a5 commit 3771a40
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 44 deletions.
45 changes: 2 additions & 43 deletions TuneLab/Data/AudioPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,53 +86,12 @@ public Waveform GetWaveform(int channelIndex)
return mWaveforms[channelIndex];
}

public async void Reload()
{
mAudioData = null;
mWaveforms = [];
mAudioChanged.Invoke();
IAudioData? audioData = null;
Waveform[]? waveforms = null;
await Task.Run(() =>
{
try
{
int sampleRate = AudioEngine.SampleRate.Value;
var data = AudioUtils.Decode(Path, ref sampleRate);
switch (data.Length)
{
case 1:
audioData = new MonoAudioData(data[0]);
waveforms = [new(data[0])];
break;
case 2:
audioData = new StereoAudioData(data[0], data[1]);
waveforms = [new(data[0]), new(data[1])];
break;
}
}
catch (Exception ex)
{
audioData = null;
waveforms = null;
Log.Error($"Failed to load audio data from {Path}: {ex.Message}");
}
});

if (audioData == null || waveforms == null)
return;

mAudioData = audioData;
mWaveforms = waveforms;
mAudioChanged.Invoke();
}

protected override int SampleCount()
{
return mAudioData == null ? 0 : Math.Min(base.SampleCount(), mAudioData.Count);
}

async void Reload()
public async void Reload()
{
if (mLoadCancelTokenSource != null)
{
Expand All @@ -157,7 +116,7 @@ await Task.Run(() =>
{
path = System.IO.Path.Combine(BaseDirectory.Value, path[3..]);
}
int samplingRate = AudioEngine.SamplingRate;
int samplingRate = AudioEngine.SampleRate.Value;
var data = AudioUtils.Decode(path, ref samplingRate);
switch (data.Length)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ protected override void OnRender(DrawingContext context)
xp += gap;
xs.Add(xp);
double time = tempoManager.GetTime(TickAxis.X2Tick(xp));
positions.Add((time - startTime) * ((IAudioSource)audioPart).SamplingRate);
positions.Add((time - startTime) * ((IAudioSource)audioPart).SampleRate);
}
while (xp < maxX);

Expand Down

0 comments on commit 3771a40

Please sign in to comment.