Skip to content

Commit

Permalink
Bug fixes to settings persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
CaffeineAU committed Aug 19, 2016
1 parent 208e977 commit f354831
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 51 deletions.
66 changes: 32 additions & 34 deletions Translator/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private void PlayButton_Click(object sender, RoutedEventArgs e)

if (((dep as DataGridRow).DataContext as PhraseItem).DownloadComplete)
{
PlayAudio(((Button)sender).CommandParameter);
PlayAudioFullPath(String.Format("{0}\\wav\\{1}.wav", OutputDirectoryName, ((Button)sender).CommandParameter), false);
}
else
{
Expand All @@ -355,59 +355,50 @@ private void PlayButton_Click(object sender, RoutedEventArgs e)
}
}

private void PlayAudio(object file)
{
PlayAudioFullPath(String.Format("{0}\\wav\\{1}.wav", OutputDirectoryName, file), false);
}

public static void PlayAudioFullPath(string file, Boolean? deleteAfterPlay = false)
{
if (LoadedWindow)
{
if (Application.Current.Dispatcher.CheckAccess())
{
media.Open(new Uri(file, UriKind.RelativeOrAbsolute));
media.Volume = 1;
media.Play();
media.MediaEnded += delegate
{
media.Close();
if (deleteAfterPlay.Value == true)
{
File.Delete(file);
}

};
PlayAudio(file, deleteAfterPlay);
}
else
{
Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Background,
new Action(() =>
{
media.Open(new Uri(file, UriKind.RelativeOrAbsolute));
media.Volume = 1;
media.Play();
media.MediaEnded += delegate
{
media.Close();
if (deleteAfterPlay.Value == true)
{
File.Delete(file);
}

};
PlayAudio(file, deleteAfterPlay);
}));
}
}
}

private void VoiceComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
private static void PlayAudio(string file, bool? deleteAfterPlay)
{
foreach (var item in PhraseItems)
media.Open(new Uri(file, UriKind.RelativeOrAbsolute));
media.Volume = 1;
media.Play();
media.MediaEnded += delegate
{
item.DownloadComplete = false;
}
media.Close();
if (deleteAfterPlay.Value == true)
{
File.Delete(file);
}

};
}

private void VoiceComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PhraseItems.ToList().ForEach(n => n.DownloadComplete = false);

//foreach (var item in PhraseItems)
//{
// item.DownloadComplete = false;
//}
}

private void WordsListView_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
Expand Down Expand Up @@ -823,6 +814,13 @@ private void WordsListView_PreviewKeyDown(object sender, KeyEventArgs e)

private void EngineComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (LoadedWindow)
{
Properties.Settings.Default.LastTTSDiscreteVolume = SelectedEngine.SelectedDiscreteVolume;
Properties.Settings.Default.LastTTSDiscreteSpeed = SelectedEngine.SelectedDiscreteSpeed;
Properties.Settings.Default.LastTTSVoice= SelectedEngine.SelectedVoice.Name;

}
foreach (var item in PhraseItems)
{
item.DownloadComplete = false;
Expand Down
4 changes: 2 additions & 2 deletions Translator/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1.1.1")]
[assembly: AssemblyFileVersion("2.1.1.1")]
[assembly: AssemblyVersion("2.1.1.2")]
[assembly: AssemblyFileVersion("2.1.1.2")]
4 changes: 2 additions & 2 deletions Translator/TTSAutomate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@
<Content Include="libmp3lame.64.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Resource Include="settings-1.png">
<None Include="settings.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
</None>
<Resource Include="ToDo.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
13 changes: 0 additions & 13 deletions Translator/TTSProvider/MicrosoftTTSProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,15 @@ public MicrosoftTTSProvider()
}
}).Start();

//BackgroundWorker loadVoicesWorker = new BackgroundWorker();
//loadVoicesWorker.DoWork += delegate
//{
// foreach (var v in speechSynth.GetInstalledVoices().Select(v => v.VoiceInfo))
// {
// AvailableVoices.Add(new Voice { Name = v.Name, Gender = v.Gender.ToString(), Language = v.Culture.DisplayName });
// }
// SelectedVoice = AvailableVoices[0];
//};
//loadVoicesWorker.RunWorkerAsync();

for (int i = -10; i <= 10; i++)
{
AvailableSpeeds.Add(i.ToString());

}
SelectedDiscreteSpeed = "0";

for (int i = 0; i <= 100; i++)
{
AvailableVolumes.Add(i.ToString());

}
SelectedDiscreteVolume = "100";
}
Expand Down
Binary file removed Translator/settings-1.png
Binary file not shown.
Binary file added Translator/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f354831

Please sign in to comment.