Update NTK.
[nondaw.git] / nonlib / JACK / Client.H
blob697156e7312c65212fed5b6076be6ab74e3cefd6
2 /*******************************************************************************/
3 /* Copyright (C) 2008 Jonathan Moore Liles                                     */
4 /*                                                                             */
5 /* This program is free software; you can redistribute it and/or modify it     */
6 /* under the terms of the GNU General Public License as published by the       */
7 /* Free Software Foundation; either version 2 of the License, or (at your      */
8 /* option) any later version.                                                  */
9 /*                                                                             */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       */
12 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   */
13 /* more details.                                                               */
14 /*                                                                             */
15 /* You should have received a copy of the GNU General Public License along     */
16 /* with This program; see the file COPYING.  If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18 /*******************************************************************************/
20 #pragma once
22 #include <jack/jack.h>
24 typedef jack_nframes_t nframes_t;
25 typedef float sample_t;
27 #include <list>
29 namespace JACK
31     class Port;
32     class Client
33     {
34         std::list <JACK::Port*> _active_ports;
36         jack_client_t *_client;
38         static nframes_t _sample_rate;
39         volatile int _xruns;
40         volatile bool _freewheeling;
41         volatile bool _zombified;
43         static void shutdown ( void *arg );
44         virtual void shutdown ( void ) = 0;
45         static int process ( nframes_t nframes, void *arg );
46         virtual int process ( nframes_t nframes ) = 0;
47         static int sync ( jack_transport_state_t state, jack_position_t *pos, void *arg );
48         virtual int sync ( jack_transport_state_t, jack_position_t * ) { return 1; }
49         static int xrun ( void *arg );
50         virtual int xrun ( void ) = 0;
51         static void timebase ( jack_transport_state_t state, jack_nframes_t nframes, jack_position_t *pos, int new_pos, void *arg );
52         virtual void timebase ( jack_transport_state_t, jack_nframes_t, jack_position_t *, int ) { }
53         static void freewheel ( int yes, void *arg );
54         virtual void freewheel ( bool yes ) = 0;
55         static int buffer_size ( nframes_t nframes, void *arg );
56         virtual int buffer_size ( nframes_t nframes ) = 0;
57         static void thread_init ( void *arg );
58         virtual void thread_init ( void ) = 0;
60         Client ( const Client &rhs );
61         Client & operator = ( const Client &rhs );
63         void freeze_ports ( void );
64         void thaw_ports ( void );
66     protected:
68         void deactivate ( void );
70     private:
72         friend class Port;
73         friend class Transport;
75     public:
77         enum options { DEFAULT = 0,
78                        SLOW_SYNC = 1 << 0,
79                        TIMEBASE_MASTER = 1 << 1 };
81         jack_client_t * jack_client ( void ) { return _client; }
83         void port_added ( JACK::Port * p );
84         void port_removed ( JACK::Port *p );
86         Client ( );
87         virtual ~Client ( );
89         const char * init ( const char *client_name, unsigned int opts = 0 );
90         const char * name ( const char * );
92         void close ( void );
93         nframes_t nframes ( void ) const { return jack_get_buffer_size( _client ); }
94         float frame_rate ( void ) const { return jack_get_sample_rate( _client ); }
95         static nframes_t sample_rate ( void ) { return _sample_rate; }
96         int xruns ( void ) const { return _xruns; };
97         bool freewheeling ( void ) const { return _freewheeling; }
98         void freewheeling ( bool yes );
99         bool zombified ( void ) const { return _zombified; }
100         float cpu_load ( void ) const { return jack_cpu_load( _client ); }
103         void transport_stop ( void );
104         void transport_start ( void );
105         void transport_locate ( nframes_t frame );
106         jack_transport_state_t transport_query ( jack_position_t *pos );
109         static int maximum_name_length ( void ) { return jack_client_name_size(); }
110     };