diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs index ccc45e954..35a65fef1 100644 --- a/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs +++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs @@ -45,7 +45,7 @@ namespace mbts.spark { IOrderBookCellStore _time_in_force_store; IOrderBookCellStore _time_created_store; // State - IOrderBookCellStore _last_change_store { get; set; } + IOrderBookCellStore _last_change_store; IOrderBookCellStore _status_store; IOrderBookCellStore _price_store; IOrderBookCellStore _quantity_store; @@ -367,10 +367,6 @@ namespace mbts.spark { bool _update_partial(IEnumerable 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; } } -} +} \ No newline at end of file diff --git a/src/client/spark/Notifications/INotifier.cs b/src/client/spark/Notifications/INotifier.cs index ad804556f..0c0ebc67f 100644 --- a/src/client/spark/Notifications/INotifier.cs +++ b/src/client/spark/Notifications/INotifier.cs @@ -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. diff --git a/src/client/spark/Notifications/NAudioPlayer.cs b/src/client/spark/Notifications/NAudioPlayer.cs new file mode 100644 index 000000000..12bbb2dc1 --- /dev/null +++ b/src/client/spark/Notifications/NAudioPlayer.cs @@ -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}."); + } + } + } +} \ No newline at end of file diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/Animation/SoundAnimationView.xaml b/src/client/spark/view/Controls/DIYGrid/Settings/Animation/SoundAnimationView.xaml index faeb4e6c2..bdd576dfb 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/Animation/SoundAnimationView.xaml +++ b/src/client/spark/view/Controls/DIYGrid/Settings/Animation/SoundAnimationView.xaml @@ -33,6 +33,8 @@