Merge branch 'master' of bitbucket.org:bluetradesys/spark

This commit is contained in:
Taha Afzal committed 2018-08-16 14:30:18 -04:00
commit 3aa8b8cd26
5 files changed
+88 -42

No files matched your search

@@ -45,7 +45,7 @@ namespace mbts.spark {
IOrderBookCellStore<TimeInForce> _time_in_force_store;
IOrderBookCellStore<DateTime> _time_created_store;
// State
IOrderBookCellStore<DateTime> _last_change_store { get; set; }
IOrderBookCellStore<DateTime> _last_change_store;
IOrderBookCellStore<OrderStatus> _status_store;
IOrderBookCellStore<double> _price_store;
IOrderBookCellStore<uint> _quantity_store;
@@ -367,10 +367,6 @@ namespace mbts.spark {
bool _update_partial(IEnumerable<IOrderBookCellStore> target_cell_stores) {
bool updated = false;
foreach (var cell_store in target_cell_stores) {
// although the price-related stores will be inlcuded in the IEnumerable,
// we need to force .refresh b/c the price* backing store's value does not
// change when the security becomes known
bool force_refresh = cell_store.prop_name.Equals(nameof(price)) || cell_store.prop_name.Equals(nameof(avg_price)) || cell_store.prop_name.Equals(nameof(last_price));
if (cell_store.refresh()) {
updated = true;
if (_book_vm.live_sorting_columns.Contains(cell_store.column.key)) {
@@ -383,4 +379,4 @@ namespace mbts.spark {
return updated;
}
}
}
}
@@ -180,40 +180,6 @@ namespace mbts.ui {
{ SoundNotification.SystemSound.CashRegister, new NAudioPlayer(bts.Properties.Resources.cash_register_purchase) },
{ SoundNotification.SystemSound.Reload, new NAudioPlayer(bts.Properties.Resources.reload_1911) }
};
class NAudioPlayer {
WaveOutEvent _wave_out = new WaveOutEvent();
WaveFileReader _wave_reader;
bool _restarting;
public NAudioPlayer(UnmanagedMemoryStream uwave_stream) {
var ms = new MemoryStream();
uwave_stream.CopyTo(ms);
ms.Position = 0;
_wave_reader = new WaveFileReader(ms);
_wave_out.Init(_wave_reader);
_wave_out.PlaybackStopped += _on_playback_stopped;
}
public void play() {
if (_restarting) {
return;
} else if (_wave_out.PlaybackState == PlaybackState.Playing) {
_restarting = true;
_wave_out.Stop();
} else {
_wave_out.Play();
}
}
void _on_playback_stopped(object sender, StoppedEventArgs e) {
_wave_reader.Position = 0;
if (_restarting) {
_wave_out.Play();
_restarting = false;
}
}
}
}
// This class adopts to role of view-controller in the mvc paradigm, rather than view-model in mvvm.
@@ -0,0 +1,67 @@
using bts.shell;
using NAudio.Wave;
using System;
using System.IO;
using System.Threading.Tasks;
namespace mbts.ui {
class NAudioPlayer {
// number of milliseconds to delay playing sound,
// during which time all subsequent requests to play the same sound will be ignored.
const int _delay_ms = 75;
WaveOutEvent _wave_out = new WaveOutEvent();
WaveFileReader _wave_reader;
bool _is_playing, _is_play_requested;
public NAudioPlayer(Stream uwave_stream) {
var ms = new MemoryStream();
uwave_stream.CopyTo(ms);
ms.Position = 0;
_wave_reader = new WaveFileReader(ms);
_wave_out.Init(_wave_reader);
_wave_out.PlaybackStopped += _on_playback_stopped;
}
public static NAudioPlayer create(SoundNotification.SystemSound system_sound) =>
new NAudioPlayer(_get_stream(system_sound));
public void play() {
if (_is_playing) {
return;
} else if (_wave_out.PlaybackState == PlaybackState.Playing) {
_is_play_requested = true;
_wave_out.Stop();
} else
_play_core();
}
void _on_playback_stopped(object sender, StoppedEventArgs e) {
_wave_reader.Position = 0;
if (_is_play_requested) {
_is_play_requested = false;
_play_core();
}
}
async void _play_core() {
_is_playing = true;
_wave_out.Play();
await Task.Delay(_delay_ms);
_is_playing = false;
}
static Stream _get_stream(SoundNotification.SystemSound system_sound) {
switch (system_sound) {
case SoundNotification.SystemSound.GameCorrect: return bts.Properties.Resources.game_sound_correct;
case SoundNotification.SystemSound.GameIncorrect: return bts.Properties.Resources.game_sound_wrong;
case SoundNotification.SystemSound.GameOverArcade: return bts.Properties.Resources.game_over_arcade;
case SoundNotification.SystemSound.Whistle: return bts.Properties.Resources.whistle;
case SoundNotification.SystemSound.BellCounter: return bts.Properties.Resources.bell_counter;
case SoundNotification.SystemSound.Powerup: return bts.Properties.Resources.powerup;
case SoundNotification.SystemSound.CashRegister: return bts.Properties.Resources.cash_register_purchase;
case SoundNotification.SystemSound.Reload: return bts.Properties.Resources.reload_1911;
default: throw new NotImplementedException($"Unknown {nameof(SoundNotification.SystemSound)}: {system_sound}.");
}
}
}
}
@@ -33,6 +33,8 @@
<Button
Grid.Column="1"
Margin="2,0,0,0"
Command="{x:Static c:SoundAnimationView.PreviewSoundCommand}"
CommandParameter="{Binding value}"
Style="{StaticResource HelpButtonBaseStyle}"
>
<Button.CommandBindings>
@@ -85,7 +87,8 @@
</DataTemplate>
</u:TemplateSelectorKeyValue>
</u:KeyedTemplateSelector>
<ControlTemplate x:Key="SoundAnimationViewTemplate" TargetType="c:SoundAnimationView">
<!--TODO: use commented-out template below when custom-sounds are ready (while System-sounds are the only option, we don't need the extra dropdown)-->
<!--<ControlTemplate x:Key="SoundAnimationViewTemplate" TargetType="c:SoundAnimationView">
<Grid x:Name="Root" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
@@ -108,6 +111,16 @@
ContentTemplateSelector="{StaticResource SoundItemTemplateSelector}"
/>
</Grid>
</ControlTemplate>-->
<ControlTemplate x:Key="SoundAnimationViewTemplate" TargetType="c:SoundAnimationView">
<ContentControl
HorizontalAlignment="Stretch"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Content="{Binding SelectedSound, RelativeSource={RelativeSource TemplatedParent}}"
ContentTemplateSelector="{StaticResource SoundItemTemplateSelector}"
/>
</ControlTemplate>
<Style TargetType="c:SoundAnimationView">
<Setter Property="BorderThickness" Value="1"/>
@@ -8,6 +8,7 @@ using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
namespace mbts.ui.controls {
/// <summary>
@@ -36,6 +37,9 @@ namespace mbts.ui.controls {
set => SetValue(BusProperty, value);
}
public static ICommand PreviewSoundCommand =>
new DelegateCommand<SoundNotification.SystemSound>(s => NAudioPlayer.create(s).play());
#region SoundTypes
public static readonly DependencyProperty SoundTypesProperty =
WPFHelper.create_dp<IEnumerable<SoundNotification.SoundTypeOneofCase>, SoundAnimationView>(
@@ -83,7 +87,7 @@ namespace mbts.ui.controls {
} else sb.Append(la.link);
}
if (append_click_hint) {
string click_hint = "Ctrl + Click to copy to clipboard";
string click_hint = "Click to play, Ctrl+Click to copy to clipboard";
// TODO: fix the OpenUriCommand, for now, the user may copy the link to clipboard and open it that way.
//if (!string.IsNullOrEmpty(la.link)) {
// click_hint += ", Alt + Click to go to link";