2014-02-24 14:39:10 -05:00
|
|
|
/*
|
2014-10-07 16:09:29 -04:00
|
|
|
Copyright (C) 2013 Waves Audio Ltd.
|
2014-02-24 14:39:10 -05:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __libardour_waves_audiobackend_h__
|
|
|
|
#define __libardour_waves_audiobackend_h__
|
|
|
|
|
|
|
|
#include <string>
|
2015-10-04 14:51:05 -04:00
|
|
|
#include <vector>
|
2014-02-24 14:39:10 -05:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <boost/function.hpp>
|
|
|
|
|
|
|
|
#include "ardour/types.h"
|
|
|
|
#include "ardour/audio_backend.h"
|
|
|
|
|
|
|
|
#include "waves_midi_device_manager.h"
|
|
|
|
|
2014-05-01 09:32:18 -04:00
|
|
|
#ifdef __APPLE__
|
2014-02-24 14:39:10 -05:00
|
|
|
|
|
|
|
#include <WCMRCoreAudioDeviceManager.h>
|
|
|
|
|
|
|
|
class ArdourAudioDeviceManager : public WCMRCoreAudioDeviceManager
|
|
|
|
{
|
|
|
|
public:
|
2014-04-30 13:46:41 -04:00
|
|
|
ArdourAudioDeviceManager (WCMRAudioDeviceManagerClient *client) : WCMRCoreAudioDeviceManager (client, eAllDevices) {};
|
2014-02-24 14:39:10 -05:00
|
|
|
};
|
|
|
|
|
2014-05-01 09:32:18 -04:00
|
|
|
#elif defined (PLATFORM_WINDOWS)
|
2014-02-24 14:39:10 -05:00
|
|
|
|
|
|
|
#include <WCMRPortAudioDeviceManager.h>
|
|
|
|
|
|
|
|
class ArdourAudioDeviceManager : public WCMRPortAudioDeviceManager
|
|
|
|
{
|
|
|
|
public:
|
2014-04-30 13:46:41 -04:00
|
|
|
ArdourAudioDeviceManager (WCMRAudioDeviceManagerClient *client) : WCMRPortAudioDeviceManager (client, eAllDevices) {};
|
2014-02-24 14:39:10 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace ARDOUR {
|
|
|
|
|
|
|
|
class AudioEngine;
|
|
|
|
class PortEngine;
|
|
|
|
class PortManager;
|
|
|
|
class WavesAudioBackend;
|
|
|
|
class WavesDataPort;
|
|
|
|
class WavesAudioPort;
|
|
|
|
class WavesMidiPort;
|
|
|
|
|
|
|
|
|
|
|
|
class WavesAudioBackend : public AudioBackend, WCMRAudioDeviceManagerClient
|
|
|
|
{
|
|
|
|
public:
|
2015-05-14 10:47:38 -04:00
|
|
|
WavesAudioBackend (AudioEngine& e);
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual ~WavesAudioBackend ();
|
|
|
|
|
|
|
|
/* AUDIOBACKEND API */
|
|
|
|
|
|
|
|
virtual std::string name () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual bool is_realtime () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual bool requires_driver_selection () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual std::vector<std::string> enumerate_drivers () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual int set_driver (const std::string& /*drivername*/);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual std::vector<DeviceStatus> enumerate_devices () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual std::vector<float> available_sample_rates (const std::string& device) const;
|
|
|
|
|
|
|
|
virtual float default_sample_rate () const;
|
|
|
|
|
|
|
|
virtual std::vector<uint32_t> available_buffer_sizes (const std::string& device) const;
|
|
|
|
|
|
|
|
virtual uint32_t available_input_channel_count (const std::string& device) const;
|
|
|
|
|
|
|
|
virtual uint32_t available_output_channel_count (const std::string& device) const;
|
|
|
|
|
|
|
|
virtual bool can_change_sample_rate_when_running () const;
|
|
|
|
|
|
|
|
virtual bool can_change_buffer_size_when_running () const;
|
|
|
|
|
|
|
|
virtual int set_device_name (const std::string& name);
|
|
|
|
|
2014-04-30 13:46:41 -04:00
|
|
|
virtual int drop_device();
|
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual int set_sample_rate (float);
|
|
|
|
|
|
|
|
virtual int set_buffer_size (uint32_t);
|
|
|
|
|
2014-04-30 13:46:41 -04:00
|
|
|
virtual int set_sample_format (SampleFormat);
|
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual int set_interleaved (bool yn);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual int set_input_channels (uint32_t);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual int set_output_channels (uint32_t);
|
|
|
|
|
|
|
|
virtual int set_systemic_input_latency (uint32_t);
|
|
|
|
|
|
|
|
virtual int set_systemic_output_latency (uint32_t);
|
|
|
|
|
2014-06-12 15:35:25 -04:00
|
|
|
int set_systemic_midi_input_latency (std::string const, uint32_t) { return 0; }
|
|
|
|
int set_systemic_midi_output_latency (std::string const, uint32_t) { return 0; }
|
|
|
|
|
2014-09-30 20:35:31 -04:00
|
|
|
virtual int reset_device ();
|
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual std::string device_name () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual float sample_rate () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual uint32_t buffer_size () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-04-30 13:46:41 -04:00
|
|
|
virtual SampleFormat sample_format () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual bool interleaved () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual uint32_t input_channels () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual uint32_t output_channels () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual uint32_t systemic_input_latency () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual uint32_t systemic_output_latency () const;
|
|
|
|
|
2014-06-12 15:35:25 -04:00
|
|
|
uint32_t systemic_midi_input_latency (std::string const) const { return 0; }
|
|
|
|
|
|
|
|
uint32_t systemic_midi_output_latency (std::string const) const { return 0; }
|
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual std::string control_app_name () const;
|
|
|
|
|
|
|
|
virtual void launch_control_app ();
|
|
|
|
|
|
|
|
virtual std::vector<std::string> enumerate_midi_options () const;
|
|
|
|
|
|
|
|
virtual int set_midi_option (const std::string& option);
|
|
|
|
|
|
|
|
virtual std::string midi_option () const;
|
|
|
|
|
2014-06-12 15:35:25 -04:00
|
|
|
std::vector<DeviceStatus> enumerate_midi_devices () const {
|
|
|
|
return std::vector<AudioBackend::DeviceStatus> ();
|
|
|
|
}
|
|
|
|
int set_midi_device_enabled (std::string const, bool) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
bool midi_device_enabled (std::string const) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool can_set_systemic_midi_latencies () const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual int _start (bool for_latency_measurement);
|
|
|
|
|
|
|
|
virtual int stop ();
|
|
|
|
|
|
|
|
virtual int freewheel (bool start_stop);
|
|
|
|
|
|
|
|
virtual float dsp_load () const ;
|
|
|
|
|
|
|
|
virtual void transport_start ();
|
|
|
|
|
|
|
|
virtual void transport_stop ();
|
|
|
|
|
|
|
|
virtual TransportState transport_state () const;
|
|
|
|
|
|
|
|
virtual void transport_locate (framepos_t pos);
|
|
|
|
|
|
|
|
virtual framepos_t transport_frame () const;
|
|
|
|
|
|
|
|
virtual int set_time_master (bool yn);
|
|
|
|
|
|
|
|
virtual int usecs_per_cycle () const;
|
|
|
|
|
|
|
|
virtual size_t raw_buffer_size (DataType data_type);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2015-02-19 17:43:16 -05:00
|
|
|
virtual framepos_t sample_time ();
|
2014-02-24 14:39:10 -05:00
|
|
|
|
2015-02-19 17:43:16 -05:00
|
|
|
virtual framepos_t sample_time_at_cycle_start ();
|
2014-02-24 14:39:10 -05:00
|
|
|
|
|
|
|
virtual pframes_t samples_since_cycle_start ();
|
|
|
|
|
|
|
|
virtual bool get_sync_offset (pframes_t& offset) const;
|
|
|
|
|
|
|
|
virtual int create_process_thread (boost::function<void ()> func);
|
|
|
|
|
|
|
|
virtual int join_process_threads ();
|
|
|
|
|
|
|
|
virtual bool in_process_thread ();
|
|
|
|
|
|
|
|
virtual uint32_t process_thread_count ();
|
|
|
|
|
|
|
|
virtual void update_latencies ();
|
|
|
|
|
|
|
|
virtual bool speed_and_position (double& speed, framepos_t& position) {
|
|
|
|
speed = 0.0;
|
|
|
|
position = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PORTENGINE API */
|
|
|
|
|
|
|
|
virtual void* private_handle () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual const std::string& my_name () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual bool available () const;
|
|
|
|
|
|
|
|
virtual uint32_t port_name_size () const;
|
|
|
|
|
|
|
|
virtual int set_port_name (PortHandle port_handle, const std::string& port_name);
|
|
|
|
|
|
|
|
virtual std::string get_port_name (PortHandle port_handle ) const;
|
|
|
|
|
|
|
|
virtual PortHandle get_port_by_name (const std::string& port_name) const;
|
|
|
|
|
|
|
|
virtual int get_ports (const std::string& port_name_pattern, DataType type, PortFlags flags, std::vector<std::string>& port_handles) const;
|
|
|
|
|
|
|
|
virtual DataType port_data_type (PortHandle port_handle) const;
|
|
|
|
|
|
|
|
virtual PortHandle register_port (const std::string& shortname, ARDOUR::DataType type, ARDOUR::PortFlags flags);
|
|
|
|
|
|
|
|
virtual void unregister_port (PortHandle port_handle);
|
|
|
|
|
|
|
|
virtual int connect (const std::string& src, const std::string& dst);
|
|
|
|
|
|
|
|
virtual int disconnect (const std::string& src, const std::string& dst);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual int connect (PortHandle port_handle, const std::string& port_name);
|
|
|
|
|
|
|
|
virtual int disconnect (PortHandle port_handle, const std::string& port_name);
|
|
|
|
|
|
|
|
virtual int disconnect_all (PortHandle port_handle);
|
|
|
|
|
|
|
|
virtual bool connected (PortHandle port_handle, bool process_callback_safe);
|
|
|
|
|
|
|
|
virtual bool connected_to (PortHandle port_handle, const std::string& port_name, bool process_callback_safe);
|
|
|
|
|
|
|
|
virtual bool physically_connected (PortHandle port_handle, bool process_callback_safe);
|
|
|
|
|
|
|
|
virtual int get_connections (PortHandle port_handle, std::vector<std::string>&, bool process_callback_safe);
|
|
|
|
|
|
|
|
virtual int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t** buf, void* port_buffer, uint32_t event_index);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual int midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual uint32_t get_midi_event_count (void* port_buffer);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual void midi_clear (void* port_buffer);
|
|
|
|
|
|
|
|
virtual bool can_monitor_input () const;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual int request_input_monitoring (PortHandle port_handle, bool);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual int ensure_input_monitoring (PortHandle port_handle, bool);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual bool monitoring_input (PortHandle port_handle);
|
|
|
|
|
|
|
|
virtual void set_latency_range (PortHandle port_handle, bool for_playback, LatencyRange);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
virtual LatencyRange get_latency_range (PortHandle port_handle, bool for_playback);
|
|
|
|
|
|
|
|
virtual bool port_is_physical (PortHandle port_handle) const;
|
|
|
|
|
|
|
|
virtual void get_physical_outputs (DataType type, std::vector<std::string>& port_names);
|
|
|
|
|
|
|
|
virtual void get_physical_inputs (DataType type, std::vector<std::string>& port_names);
|
|
|
|
|
|
|
|
virtual ChanCount n_physical_outputs () const;
|
|
|
|
|
|
|
|
virtual ChanCount n_physical_inputs () const;
|
|
|
|
|
|
|
|
virtual void* get_buffer (PortHandle port_handle, pframes_t frames);
|
|
|
|
|
|
|
|
static AudioBackendInfo& backend_info () { return __backend_info; }
|
|
|
|
|
|
|
|
virtual void AudioDeviceManagerNotification (NotificationReason reason, void* pParam);
|
|
|
|
|
|
|
|
private:
|
|
|
|
//ArdourAudioDeviceManagerClient _audio_device_manager_client;
|
|
|
|
ArdourAudioDeviceManager _audio_device_manager;
|
|
|
|
WavesMidiDeviceManager _midi_device_manager;
|
|
|
|
|
|
|
|
WCMRAudioDevice *_device;
|
2014-04-30 13:46:41 -04:00
|
|
|
SampleFormat _sample_format;
|
2014-02-24 14:39:10 -05:00
|
|
|
bool _interleaved;
|
|
|
|
static std::string __instantiated_name;
|
|
|
|
uint32_t _input_channels;
|
|
|
|
uint32_t _max_input_channels;
|
|
|
|
uint32_t _output_channels;
|
|
|
|
uint32_t _max_output_channels;
|
|
|
|
float _sample_rate;
|
|
|
|
uint32_t _buffer_size;
|
|
|
|
uint32_t _systemic_input_latency;
|
|
|
|
uint32_t _systemic_output_latency;
|
|
|
|
bool _call_thread_init_callback;
|
|
|
|
std::vector<pthread_t> _backend_threads;
|
2014-10-22 17:02:15 -04:00
|
|
|
pthread_t _main_thread;
|
2014-02-24 14:39:10 -05:00
|
|
|
static const size_t __max_raw_midi_buffer_size;
|
|
|
|
|
|
|
|
static const std::vector<std::string> __available_midi_options;
|
|
|
|
bool _use_midi;
|
|
|
|
|
|
|
|
struct ThreadData {
|
|
|
|
WavesAudioBackend* engine;
|
|
|
|
boost::function<void ()> f;
|
|
|
|
size_t stacksize;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
ThreadData (WavesAudioBackend* e, boost::function<void ()> fp, size_t stacksz)
|
|
|
|
: engine (e) , f (fp) , stacksize (stacksz) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
static boost::shared_ptr<AudioBackend> __waves_backend_factory (AudioEngine& e);
|
|
|
|
static int __instantiate (const std::string& arg1, const std::string& arg2);
|
|
|
|
static int __deinstantiate ();
|
|
|
|
static bool __already_configured ();
|
2014-10-23 07:02:02 -04:00
|
|
|
static bool __available ();
|
2014-02-24 14:39:10 -05:00
|
|
|
|
|
|
|
static void* __start_process_thread (void*);
|
|
|
|
static uint64_t __get_time_nanos ();
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
static size_t __thread_stack_size ();
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
void _audio_device_callback (const float* input_audio_buffer,
|
|
|
|
float* output_buffer,
|
2014-02-24 14:39:10 -05:00
|
|
|
unsigned long nframes,
|
2015-02-19 17:43:16 -05:00
|
|
|
framepos_t sample_time,
|
2014-02-24 14:39:10 -05:00
|
|
|
uint64_t cycle_start_time_nanos);
|
|
|
|
|
|
|
|
void _changed_midi_devices ();
|
|
|
|
|
2014-04-30 13:46:41 -04:00
|
|
|
// DO change sample rate and buffer size
|
|
|
|
int _buffer_size_change(uint32_t new_buffer_size);
|
|
|
|
int _sample_rate_change(float new_sample_rate);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
int _register_system_audio_ports ();
|
|
|
|
int _register_system_midi_ports ();
|
|
|
|
|
|
|
|
int _read_midi_data_from_devices ();
|
|
|
|
int _write_midi_data_to_devices (pframes_t);
|
|
|
|
|
|
|
|
pframes_t _ms_to_sample_time (int32_t time_ms) const;
|
|
|
|
int32_t _sample_time_to_ms (pframes_t sample_time) const ;
|
|
|
|
|
|
|
|
void _read_audio_data_from_device (const float* input_buffer, pframes_t nframes);
|
|
|
|
void _write_audio_data_to_device (float* output_buffer, pframes_t nframes);
|
|
|
|
|
|
|
|
void _unregister_system_audio_ports ();
|
|
|
|
void _unregister_system_midi_ports ();
|
|
|
|
|
|
|
|
WavesDataPort* _register_port (const std::string& port_name, ARDOUR::DataType type, ARDOUR::PortFlags flags);
|
|
|
|
inline bool _registered (PortHandle port_handle) const
|
|
|
|
{
|
|
|
|
return std::find (_ports.begin (), _ports.end (), (WavesDataPort*)port_handle) != _ports.end ();
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
WavesDataPort* _find_port (const std::string& port_name) const;
|
|
|
|
void _freewheel_thread ();
|
|
|
|
|
|
|
|
std::vector<WavesAudioPort*> _physical_audio_inputs;
|
|
|
|
std::vector<WavesAudioPort*> _physical_audio_outputs;
|
|
|
|
std::vector<WavesMidiPort*> _physical_midi_inputs;
|
|
|
|
std::vector<WavesMidiPort*> _physical_midi_outputs;
|
|
|
|
std::vector<WavesDataPort*> _ports;
|
|
|
|
static AudioBackendInfo __backend_info;
|
|
|
|
|
2014-05-01 09:32:18 -04:00
|
|
|
#if defined (PLATFORM_WINDOWS)
|
2014-02-24 14:39:10 -05:00
|
|
|
static uint64_t __performance_counter_frequency;
|
|
|
|
#endif
|
|
|
|
uint64_t _cycle_start_time_nanos;
|
2015-02-19 18:21:03 -05:00
|
|
|
framepos_t _sample_time_at_cycle_start;
|
2014-02-24 14:39:10 -05:00
|
|
|
|
|
|
|
bool _freewheeling;
|
|
|
|
bool _freewheel_thread_active;
|
|
|
|
|
|
|
|
friend class WavesMidiDeviceManager;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-02-24 14:39:10 -05:00
|
|
|
std::list<uint64_t> _dsp_load_history;
|
|
|
|
size_t _dsp_load_history_length;
|
|
|
|
uint64_t _dsp_load_accumulator;
|
|
|
|
float _audio_cycle_period_nanos;
|
|
|
|
void _init_dsp_load_history();
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif /* __libardour_waves_audiobackend_h__ */
|
2015-10-04 14:51:05 -04:00
|
|
|
|