Update NTK.
[nondaw.git] / nonlib / JACK / Port.H
blob24f3c4be3243c519a7b76b6f24f84a437db1e73d
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>
23 #include "Client.H"
24 #include <stdlib.h>
26 namespace JACK
28     class Port
29     {
30         jack_port_t *_port;
31         char *_name;
32         JACK::Client *_client;
34         /* FIXME: reference count? */
36 /*     /\* not permitted  *\/ */
37 /*     Port ( const Port &rhs ); */
38 /*     Port & operator= ( const Port &rhs ); */
40     public:
42         bool operator < ( const Port & rhs ) const;
44         enum type_e { Output, Input };
46         static int max_name ( void );
48         Port ( JACK::Client *client, jack_port_t *port );
49         Port ( JACK::Client *client, const char *name, type_e dir );
50         Port ( JACK::Client *client, type_e dir, const char *base, int n, const char *type=0 );
51         Port ( JACK::Client *client, type_e dir, int n, const char *type=0 );
53 //    Port ( );
54         ~Port ( );
56         Port ( const Port & rhs );
59         bool valid ( void ) const { return _port; }
60         bool connected ( void ) const { return jack_port_connected( _port ); }
61         type_e type ( void ) const;
62         const char * name ( void ) const { return _name; }
63         bool name ( const char *name );
64         bool name ( const char *base, int n, const char *type=0 );
66         nframes_t total_latency ( void ) const;
67         nframes_t latency ( void ) const;
68         void latency ( nframes_t frames );
70         bool activate ( void );
71         void shutdown ( void );
72         void write ( sample_t *buf, nframes_t nframes );
73         void read ( sample_t *buf, nframes_t nframes );
74         void *buffer ( nframes_t nframes );
75         void silence ( nframes_t nframes );
77         /*  */
78         const char ** connections ( void );
79         bool connections ( const char **port_names );
80         void freeze ( void );
81         void thaw ( void );
83     private:
85         type_e _direction;
87         bool activate ( const char *name, type_e dir );
89         /* holds all we need to know about a jack port to recreate it on a
90          new client */
91         struct freeze_state
92         {
93             const char **connections;
94             char *name;
96             freeze_state ( )
97                 {
98                     connections = NULL;
99                     name = NULL;
100                 }
102             ~freeze_state ( )
103                 {
104                     if ( connections )
105                     {
106                         free( connections );
107                         connections = NULL;
108                     }
109                     if ( name )
110                     {
111                         free( name );
112                     }
113                 }
114         };
116         freeze_state *_freezer;
118     };