From 83001e7e5251c33308d42786e71bbce4f34efb8c Mon Sep 17 00:00:00 2001 From: Valeriy Kamyshniy Date: Mon, 2 Mar 2015 20:19:50 +0200 Subject: [Summary] Audio Backend code cleanup - PORTION B Conflicts: libs/backends/wavesaudio/waves_midi_device.cc --- libs/backends/wavesaudio/waves_audiobackend.cc | 5 +-- .../backends/wavesaudio/waves_audiobackend.midi.cc | 4 +- libs/backends/wavesaudio/waves_midi_device.cc | 45 +++++++++------------- libs/backends/wavesaudio/waves_midi_device.h | 1 - .../wavesaudio/waves_midi_device_manager.cc | 23 +++-------- .../wavesaudio/waves_midi_device_manager.h | 2 - 6 files changed, 29 insertions(+), 51 deletions(-) diff --git a/libs/backends/wavesaudio/waves_audiobackend.cc b/libs/backends/wavesaudio/waves_audiobackend.cc index da81b5054d..8a1661b580 100644 --- a/libs/backends/wavesaudio/waves_audiobackend.cc +++ b/libs/backends/wavesaudio/waves_audiobackend.cc @@ -785,8 +785,6 @@ WavesAudioBackend::stop () // COMMENTED DBG LOGS */ std::cout << "\t[" << _device->DeviceName () << "]" << std::endl; - _midi_device_manager.stop (); - if (_device) { wtErr = _device->SetStreaming (false); if (wtErr != eNoErr) { @@ -795,9 +793,10 @@ WavesAudioBackend::stop () } } + _midi_device_manager.stop (); _unregister_system_audio_ports (); _unregister_system_midi_ports (); - + return retVal; } diff --git a/libs/backends/wavesaudio/waves_audiobackend.midi.cc b/libs/backends/wavesaudio/waves_audiobackend.midi.cc index c41fbc90e3..296f3564f9 100644 --- a/libs/backends/wavesaudio/waves_audiobackend.midi.cc +++ b/libs/backends/wavesaudio/waves_audiobackend.midi.cc @@ -170,6 +170,7 @@ WavesAudioBackend::_changed_midi_devices () return; } + _unregister_system_midi_ports (); _midi_device_manager.stop (); if (_midi_device_manager.start () != 0) { @@ -317,8 +318,7 @@ WavesAudioBackend::_read_midi_data_from_devices () if (timestamp_st < 0) { timestamp_st = 0; - } - else if (timestamp_st >= (int32_t)_buffer_size) { + } else if (timestamp_st >= (int32_t)_buffer_size) { timestamp_st = _buffer_size - 1; } waves_midi_event->set_timestamp (timestamp_st); diff --git a/libs/backends/wavesaudio/waves_midi_device.cc b/libs/backends/wavesaudio/waves_midi_device.cc index 04570218b0..342e1293a1 100644 --- a/libs/backends/wavesaudio/waves_midi_device.cc +++ b/libs/backends/wavesaudio/waves_midi_device.cc @@ -38,7 +38,25 @@ WavesMidiDevice::WavesMidiDevice (const std::string& device_name) , _output_pm_stream (NULL) , _incomplete_waves_midi_event (NULL) { - validate (); + _pm_input_id = _pm_output_id = pmNoDevice; + int count = Pm_CountDevices (); + + for (int i = 0; i < count; i++) { + + const PmDeviceInfo* pm_device_info = Pm_GetDeviceInfo (i); + + if (pm_device_info == NULL) { + continue; + } + if (name () == pm_device_info->name) { + if (pm_device_info->input){ + _pm_input_id = i; + } + if (pm_device_info->output){ + _pm_output_id = i; + } + } + } } WavesMidiDevice::~WavesMidiDevice () @@ -47,31 +65,6 @@ WavesMidiDevice::~WavesMidiDevice () close (); } -void -WavesMidiDevice::validate () -{ - _pm_input_id = - _pm_output_id = pmNoDevice; - int count = Pm_CountDevices (); - - for (int i = 0; i < count; i++) { - - const PmDeviceInfo* pm_device_info = Pm_GetDeviceInfo (i); - - if (pm_device_info == NULL) { - continue; - } - if (name () == pm_device_info->name) { - if (pm_device_info->input){ - _pm_input_id = i; - } - if (pm_device_info->output){ - _pm_output_id = i; - } - } - } -} - int WavesMidiDevice::open (PmTimeProcPtr time_proc, void* time_info) { diff --git a/libs/backends/wavesaudio/waves_midi_device.h b/libs/backends/wavesaudio/waves_midi_device.h index 0f54d5128c..ed5dbef231 100644 --- a/libs/backends/wavesaudio/waves_midi_device.h +++ b/libs/backends/wavesaudio/waves_midi_device.h @@ -48,7 +48,6 @@ public: inline bool is_input () const { return _pm_input_id != pmNoDevice; }; inline bool is_output () const { return _pm_output_id != pmNoDevice; }; - void validate (); private: diff --git a/libs/backends/wavesaudio/waves_midi_device_manager.cc b/libs/backends/wavesaudio/waves_midi_device_manager.cc index 4066c533de..dcc5fa0f03 100644 --- a/libs/backends/wavesaudio/waves_midi_device_manager.cc +++ b/libs/backends/wavesaudio/waves_midi_device_manager.cc @@ -110,12 +110,13 @@ WavesMidiDeviceManager::stop () { // COMMENTED DBG LOGS */ std::cout << "WavesMidiDeviceManager::stop ():" << std::endl; - if ( _active == false ) + if ( _active == false ) { return 0; + } stream (false); - _close_devices (); + _delete_devices (); _active = false; if (Pm_Terminate () != pmNoError) { @@ -201,17 +202,13 @@ WavesMidiDeviceManager::_create_devices () } WavesMidiDevice *device = _get_device (pm_device_info->name); - if (device) { - device->validate (); - } - else - { + if (!device) { device = new WavesMidiDevice (pm_device_info->name); _devices.push_back (device); if (device->open (__get_time_ms, (void*)&_audiobackend)) { std::cerr << "WavesMidiDeviceManager::_create_devices (): [" << device->name () << "]->open () failed!" << std::endl; } - } + } } return 0; @@ -225,17 +222,9 @@ WavesMidiDeviceManager::_delete_devices () while (!_devices.empty ()) { WavesMidiDevice * device = _devices.back (); _devices.pop_back (); + device->close (); delete device; } return 0; } - -void -WavesMidiDeviceManager::_close_devices () -{ - // COMMENTED DBG LOGS */ std::cout << "WavesMidiDeviceManager::_close_devices ():" << std::endl; - for (size_t i = 0; i < _devices.size (); i++) { - _devices[i]->close (); - } -} diff --git a/libs/backends/wavesaudio/waves_midi_device_manager.h b/libs/backends/wavesaudio/waves_midi_device_manager.h index 2d1f934159..b218299a5e 100644 --- a/libs/backends/wavesaudio/waves_midi_device_manager.h +++ b/libs/backends/wavesaudio/waves_midi_device_manager.h @@ -46,8 +46,6 @@ public: private: int _create_devices (); - void _close_devices (); - int _delete_devices (); static void __portmidi_callback (PtTimestamp timestamp, void * userData); void _portmidi_callback (PtTimestamp timestamp); -- cgit v1.2.3