2009-12-25 01:57:34 +01:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Copyright (C) 2008 Jonathan Moore Liles */
|
|
|
|
/* */
|
|
|
|
/* 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; see the file COPYING. If not,write to the Free Software */
|
|
|
|
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <jack/jack.h>
|
2013-06-06 01:26:36 +02:00
|
|
|
#include <jack/midiport.h>
|
2014-05-17 12:11:40 +02:00
|
|
|
#ifdef HAVE_JACK_METADATA
|
|
|
|
# include <jack/metadata.h>
|
|
|
|
#endif
|
2013-07-18 04:27:21 +02:00
|
|
|
#include <Mutex.H>
|
2009-12-25 01:57:34 +01:00
|
|
|
|
|
|
|
typedef jack_nframes_t nframes_t;
|
2013-06-06 01:26:36 +02:00
|
|
|
typedef jack_default_audio_sample_t sample_t;
|
2009-12-25 01:57:34 +01:00
|
|
|
|
2010-01-17 01:38:27 +01:00
|
|
|
#include <list>
|
|
|
|
|
2009-12-25 01:57:34 +01:00
|
|
|
namespace JACK
|
|
|
|
{
|
2010-01-17 01:38:27 +01:00
|
|
|
class Port;
|
2009-12-25 01:57:34 +01:00
|
|
|
class Client
|
|
|
|
{
|
2010-01-17 01:38:27 +01:00
|
|
|
std::list <JACK::Port*> _active_ports;
|
|
|
|
|
2013-07-18 04:27:21 +02:00
|
|
|
Mutex _frozen;
|
|
|
|
|
2009-12-25 01:57:34 +01:00
|
|
|
jack_client_t *_client;
|
|
|
|
|
2013-06-16 02:51:50 +02:00
|
|
|
// nframes_t _sample_rate;
|
2009-12-25 01:57:34 +01:00
|
|
|
volatile int _xruns;
|
|
|
|
volatile bool _freewheeling;
|
|
|
|
volatile bool _zombified;
|
2013-08-06 09:03:19 +02:00
|
|
|
volatile bool _active;
|
2009-12-25 01:57:34 +01:00
|
|
|
|
2013-06-16 02:51:50 +02:00
|
|
|
static int sample_rate_changed ( nframes_t srate, void *arg );
|
|
|
|
virtual int sample_rate_changed ( nframes_t srate ) { return 0; }
|
2013-04-22 08:14:52 +02:00
|
|
|
static void port_connect ( jack_port_id_t a, jack_port_id_t b, int connect, void *arg );
|
|
|
|
virtual void port_connect ( jack_port_id_t a, jack_port_id_t b, int connect ) { }
|
2009-12-25 01:57:34 +01:00
|
|
|
static void shutdown ( void *arg );
|
|
|
|
virtual void shutdown ( void ) = 0;
|
|
|
|
static int process ( nframes_t nframes, void *arg );
|
|
|
|
virtual int process ( nframes_t nframes ) = 0;
|
|
|
|
static int sync ( jack_transport_state_t state, jack_position_t *pos, void *arg );
|
2010-01-19 08:45:44 +01:00
|
|
|
virtual int sync ( jack_transport_state_t, jack_position_t * ) { return 1; }
|
2009-12-25 01:57:34 +01:00
|
|
|
static int xrun ( void *arg );
|
|
|
|
virtual int xrun ( void ) = 0;
|
|
|
|
static void timebase ( jack_transport_state_t state, jack_nframes_t nframes, jack_position_t *pos, int new_pos, void *arg );
|
2010-01-19 08:45:44 +01:00
|
|
|
virtual void timebase ( jack_transport_state_t, jack_nframes_t, jack_position_t *, int ) { }
|
2009-12-25 01:57:34 +01:00
|
|
|
static void freewheel ( int yes, void *arg );
|
|
|
|
virtual void freewheel ( bool yes ) = 0;
|
|
|
|
static int buffer_size ( nframes_t nframes, void *arg );
|
|
|
|
virtual int buffer_size ( nframes_t nframes ) = 0;
|
|
|
|
static void thread_init ( void *arg );
|
|
|
|
virtual void thread_init ( void ) = 0;
|
|
|
|
|
2013-08-24 23:21:44 +02:00
|
|
|
static void latency ( jack_latency_callback_mode_t mode, void *arg );
|
|
|
|
virtual void latency ( jack_latency_callback_mode_t mode ) { }
|
|
|
|
|
2009-12-25 01:57:34 +01:00
|
|
|
Client ( const Client &rhs );
|
|
|
|
Client & operator = ( const Client &rhs );
|
|
|
|
|
2010-01-17 01:38:27 +01:00
|
|
|
void freeze_ports ( void );
|
|
|
|
void thaw_ports ( void );
|
|
|
|
|
2010-01-23 17:16:12 +01:00
|
|
|
protected:
|
2013-08-06 09:03:19 +02:00
|
|
|
|
|
|
|
bool active ( void ) const { return _active; }
|
2010-01-23 17:16:12 +01:00
|
|
|
void deactivate ( void );
|
2013-08-06 09:03:19 +02:00
|
|
|
void activate ( void );
|
2010-01-23 17:16:12 +01:00
|
|
|
|
2009-12-25 01:57:34 +01:00
|
|
|
private:
|
|
|
|
|
|
|
|
friend class Port;
|
|
|
|
friend class Transport;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2010-01-19 08:45:44 +01:00
|
|
|
enum options { DEFAULT = 0,
|
|
|
|
SLOW_SYNC = 1 << 0,
|
|
|
|
TIMEBASE_MASTER = 1 << 1 };
|
|
|
|
|
2013-08-24 23:21:44 +02:00
|
|
|
jack_client_t * jack_client ( void ) const { return _client; }
|
2010-01-17 01:38:27 +01:00
|
|
|
|
|
|
|
void port_added ( JACK::Port * p );
|
|
|
|
void port_removed ( JACK::Port *p );
|
2009-12-25 01:57:34 +01:00
|
|
|
|
|
|
|
Client ( );
|
|
|
|
virtual ~Client ( );
|
|
|
|
|
2010-01-19 08:45:44 +01:00
|
|
|
const char * init ( const char *client_name, unsigned int opts = 0 );
|
2010-01-17 01:38:27 +01:00
|
|
|
const char * name ( const char * );
|
2009-12-25 01:57:34 +01:00
|
|
|
|
2013-08-06 09:03:19 +02:00
|
|
|
const char *jack_name ( void ) const;
|
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
void close ( void );
|
2009-12-25 01:57:34 +01:00
|
|
|
nframes_t nframes ( void ) const { return jack_get_buffer_size( _client ); }
|
2013-06-16 02:51:50 +02:00
|
|
|
// float frame_rate ( void ) const { return jack_get_sample_rate( _client ); }
|
|
|
|
nframes_t sample_rate ( void ) const { return jack_get_sample_rate( _client ); }
|
2009-12-25 01:57:34 +01:00
|
|
|
int xruns ( void ) const { return _xruns; };
|
|
|
|
bool freewheeling ( void ) const { return _freewheeling; }
|
|
|
|
void freewheeling ( bool yes );
|
|
|
|
bool zombified ( void ) const { return _zombified; }
|
|
|
|
float cpu_load ( void ) const { return jack_cpu_load( _client ); }
|
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
void transport_stop ( void );
|
|
|
|
void transport_start ( void );
|
|
|
|
void transport_locate ( nframes_t frame );
|
|
|
|
jack_transport_state_t transport_query ( jack_position_t *pos );
|
2013-08-24 23:21:44 +02:00
|
|
|
|
|
|
|
void recompute_latencies ( void );
|
2010-01-21 01:33:02 +01:00
|
|
|
|
2010-01-31 20:34:18 +01:00
|
|
|
static int maximum_name_length ( void ) { return jack_client_name_size(); }
|
2009-12-25 01:57:34 +01:00
|
|
|
};
|
|
|
|
}
|