Esempio n. 1
0
        private int _handledOnWindowClosed = 0; //!!! temporal: OnWindowClosed fired twice
        void mainWindow_Closed(object sender, EventArgs e)
        {
            if (_handledOnWindowClosed++ > 0)
            {
                return;
            }

            Console.WriteLine(">>>> OnWindowClosed <<<<");

            // stop render thread
            lock (_renderLock) {
                _closingWindow = true;
            }
            _eventRenderDoWork.Set(); // unblock RenderThread()
            _threadRender.Join();
            _threadRender = null;


            SaveAppSettings();

            _mainBitmap.DisposeAll();

            // Sound
#if USE_MIDI
            if (_midiPlayer != null)
            {
                _midiPlayer.StopClock();
                _midiPlayer.Dispose();
                _midiPlayer = null;
            }
#endif
#if USE_WAVE
            if (_waveEngine != null)
            {
                _waveEngine.Stop();
                _waveEngine.Dispose();
                _waveEngine = null;
            }
#endif



#if USE_PERF
            Console.WriteLine("Performance counters");
            Console.WriteLine(_perfUpdateItems.GetReport());
            Console.WriteLine(_perfDrawItems.GetReport());
            Console.WriteLine(_perfRenderImage.GetReport());
            Console.WriteLine(_perfCopyPixels.GetReport());
#endif
        }
Esempio n. 2
0
        private void InitSoundEngines()
        {
            // Init sound
            var availableOutputs = new List <SoundSettings.EOutput>();

            availableOutputs.Add(SoundSettings.EOutput.None);
#if USE_MIDI
            try {
                _midiPlayer = new Midi.MidiPlayer(0); //!!! make device index configurable
                availableOutputs.Add(SoundSettings.EOutput.Midi);
            } catch (Exception ex) {
                Console.Error.WriteLine("Can't initialize Midi: {0}", ex.Message);
            }
#endif
#if USE_WAVE
            try {
                var format = new Wave.WaveFormat {
                    bytesPerSample = 2,
                    sampleRate     = 22050,
                    channels       = 1,
                };
                _waveEngine      = new Wave.WaveEngine(format, bufferLengthMs: 60);
                _partialProvider = new Wave.PartialProvider();
                _waveEngine.SetSampleProvider(_partialProvider);
                availableOutputs.Add(SoundSettings.EOutput.Wave);
                availableOutputs.Add(SoundSettings.EOutput.WavePartialsTempered);
            }
            catch (Exception ex) {
                Console.Error.WriteLine("Can't initialize WaveEngine: {0}", ex.Message);
            }
#endif
            _availableSoundOutputs = availableOutputs.ToArray();

            // Find controls
            _comboBoxSoundOutput       = ExpectControl <ComboBox>(this, "comboBoxSoundOutput");
            _comboBoxSoundOutput.Items = _availableSoundOutputs;
            //_textBoxWavePartials = ExpectControl<TextBox2>(this, "textBoxWavePartials");
        }