Skip to content

Commit

Permalink
Handled null, changed ubuntu image to 22.04
Browse files Browse the repository at this point in the history
  • Loading branch information
EX3exp committed Oct 15, 2024
1 parent bb477e0 commit 2f2498b
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 23 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/release-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
VERSION: ${{ github.ref_name }}

runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
Expand All @@ -31,14 +31,7 @@ jobs:
dotnet-version: '8.x'

- name: Restore dependencies
run: |
sudo apt-get update -y
sudo apt-get install mono-complete -y
sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
mono /usr/local/bin/nuget.exe help
echo 'alias nuget="mono /usr/local/bin/nuget.exe"' >> ~/.bashrc
source ~/.bashrc
mono /usr/local/bin/nuget.exe restore
run: nuget restore

- name: Build and make appcast (Linux only)
run: python3 Mirivoice.Desktop/deploy.py 2>&1
Expand Down
101 changes: 88 additions & 13 deletions Mirivoice/Mirivoice.Core/Managers/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public TimeSpan GetAudioDuration(string audioFilePath)
return reader.TotalTime;
}
}


List<string> GetAllCacheFiles()
{
return Directory.GetFiles(MainManager.Instance.PathM.CachePath, "*.wav").ToList();
Expand All @@ -89,6 +91,8 @@ List<string> GetAllCacheFiles()
private double OffsetBeforePlay;
private int offset = 0;
private int currentLine;

public bool PlayingOneShot = false;
/// <summary>
/// Note that startIndex is same as lineNo (starts from 1, not 0)
/// </summary>
Expand All @@ -113,7 +117,11 @@ public async void PlayAllCacheFiles(int startIndex, bool exportOnlyAndDoNotPlay

int index = 0;
v.SingleTextBoxEditorEnabled = false;
v.CurrentEdit.IsEnabled = false;
if (v.CurrentEdit is not null)
{
v.CurrentEdit.IsEnabled = false;
}

var tasks = new List<Task>();

caches.Clear();
Expand All @@ -133,7 +141,7 @@ public async void PlayAllCacheFiles(int startIndex, bool exportOnlyAndDoNotPlay

if (i < startIndex - 1 || skipInference)
{
//Log.Debug($"[Skipping Cache Generation] Line {l.viewModel.LineNo} is before the start index.");
Log.Debug($"[Skipping Cache Generation] Line {l.viewModel.LineNo} is before the start index.");
continue;
}

Expand Down Expand Up @@ -200,7 +208,10 @@ public async void PlayAllCacheFiles(int startIndex, bool exportOnlyAndDoNotPlay
WaveFileWriter.CreateWaveFile(exportPath, resampler);
}
}
v.CurrentEdit.IsEnabled = true;
if (v.CurrentEdit is not null)
{
v.CurrentEdit.IsEnabled = true;
}
v.SingleTextBoxEditorEnabled = true;
v.MainWindowGetInput = true;
return;
Expand Down Expand Up @@ -230,7 +241,11 @@ public async void PlayAllCacheFiles(int startIndex, bool exportOnlyAndDoNotPlay
}
no++;
}
v.CurrentEdit.IsEnabled = true;
if (v.CurrentEdit is not null)
{
v.CurrentEdit.IsEnabled = true;
}

v.SingleTextBoxEditorEnabled = true;
v.MainWindowGetInput = true;
return;
Expand Down Expand Up @@ -270,7 +285,12 @@ public async void PlayAllCacheFiles(int startIndex, bool exportOnlyAndDoNotPlay
}
File.WriteAllText(exportPath, sb1.ToString());
File.WriteAllText(exportPathNamesSrt, sb2.ToString());
v.CurrentEdit.IsEnabled = true;

if (v.CurrentEdit is not null)
{
v.CurrentEdit.IsEnabled = true;
}

v.SingleTextBoxEditorEnabled = true;
v.MainWindowGetInput = true;
return;
Expand Down Expand Up @@ -302,15 +322,19 @@ public async void PlayAllCacheFiles(int startIndex, bool exportOnlyAndDoNotPlay
}
}
}
v.CurrentEdit.IsEnabled = true;
if (v.CurrentEdit is not null)
{
v.CurrentEdit.IsEnabled = true;
}
v.SingleTextBoxEditorEnabled = true;
v.MainWindowGetInput = true;
return;
}

audioPaths.Clear();
foreach (string cacheName in caches)
{
//Log.Debug($"[Collecting Cache] {cacheName}");
Log.Debug($"[Collecting Cache] {cacheName}");
audioPaths.Add(cacheName);


Expand All @@ -323,14 +347,49 @@ public async void PlayAllCacheFiles(int startIndex, bool exportOnlyAndDoNotPlay
v.LinesViewerOffset = new Avalonia.Vector(0, 104 * (startIndex - 1));
currentLine = startIndex - 1;

if (SelectedOnly)
{
PlayingOneShot = true;
if (_player is null)
{
_player = new Player();
_player.PlaybackFinished += OnPlaybackStopped;
}


if (!File.Exists(audioPaths[0]))
{

v.MainWindowGetInput = true;
if (v.CurrentEdit is not null)
{
v.CurrentEdit.IsEnabled = true;
}
v.SingleTextBoxEditorEnabled = true;

PlayNextFile();
}
else
{

await _player.Play(audioPaths[0]);

v.LineBoxCollection[currentLine].viewModel.IsSelected = true;

}

return;
}
else
{
PlayNextFile();
}


}

private async void PlayNextFile()
{

if (_currentFileIndex < audioPaths.Count)
{
Log.Information($"Playing cache file: {audioPaths[_currentFileIndex]}");
Expand All @@ -344,19 +403,25 @@ private async void PlayNextFile()
_player.PlaybackFinished += OnPlaybackStopped;
}


if (!File.Exists(audioPaths[_currentFileIndex]))
{
StopAudio();
v.MainWindowGetInput = true;
v.CurrentEdit.IsEnabled = true;
if (v.CurrentEdit is not null)
{
v.CurrentEdit.IsEnabled = true;
}
v.SingleTextBoxEditorEnabled = true;

}
else
{

await _player.Play(audioPaths[_currentFileIndex]);

v.LineBoxCollection[currentLine].viewModel.IsSelected = true;

}


Expand Down Expand Up @@ -386,9 +451,17 @@ private void OnPlaybackStopped(object? sender, EventArgs e)
{
Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
{

Log.Information("Playback stopped.");
v.isPlaying = false;

if (PlayingOneShot)
{
Log.Information("One-shot playback stopped.");
StopAudio();

return;
}


if (audioPaths.Count == 0) // when stopped
{

Expand All @@ -415,6 +488,7 @@ private void OnPlaybackStopped(object? sender, EventArgs e)
v.LineBoxCollection[currentLine].viewModel.IsSelected = false;
v.LinesViewerOffset = new Avalonia.Vector(0, v.LinesViewerOffset.Y + 104);


currentLine++;
_currentFileIndex++;

Expand All @@ -426,6 +500,7 @@ private void OnPlaybackStopped(object? sender, EventArgs e)
{
Log.Information("All cache files have been played.");

v.OnStopButtonClick();
v.isPlaying = false;
v.EnableGlobalPlay = true;
v.EnablePreviewPlay = true;
Expand All @@ -451,7 +526,7 @@ public void PauseAudio()
public void StopAudio()
{


PlayingOneShot = false;
if (_player is not null)
{
_player.Stop();
Expand Down
2 changes: 1 addition & 1 deletion Mirivoice/ViewModels/AppUpdaterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public AppUpdaterViewModel(Window w)
return null;
}
return releases
.Where(r => !r.draft/* && r.prerelease == MainManager.Instance.Setting.UseBeta */)
.Where(r => !r.draft && r.prerelease == false)
.OrderByDescending(r => r.id)
.FirstOrDefault();
}
Expand Down

0 comments on commit 2f2498b

Please sign in to comment.