Separate MidiBuffer and AudioBuffer into separate headers (trims the dependency tree...
[ardour.git] / libs / ardour / ardour / audio_port.h
1 /*
2     Copyright (C) 2002 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id: port.h 712 2006-07-28 01:08:57Z drobilla $
19 */
20
21 #ifndef __ardour_audio_port_h__
22 #define __ardour_audio_port_h__
23
24 #include <sigc++/signal.h>
25 #include <pbd/failed_constructor.h>
26 #include <ardour/ardour.h>
27 #include <jack/jack.h>
28 #include <ardour/port.h>
29 #include <ardour/audio_buffer.h>
30
31 namespace ARDOUR {
32
33 class AudioEngine;
34
35 class AudioPort : public Port {
36    public:
37         virtual ~AudioPort() { 
38                 free (_port);
39         }
40
41         void cycle_start(nframes_t nframes) {
42                 _buffer.set_data ((Sample*) jack_port_get_buffer (_port, nframes), nframes);
43         }
44
45         void cycle_end() {}
46
47         DataType type() const { return DataType(DataType::AUDIO); }
48
49         Buffer& get_buffer () {
50                 return _buffer;
51         }
52         
53         AudioBuffer& get_audio_buffer() {
54                 return _buffer;
55         }
56
57         void reset_overs () {
58                 _short_overs = 0;
59                 _long_overs = 0;
60                 _overlen = 0;
61         }
62
63         void reset_peak_meter () {
64                 _peak = 0;
65         }
66         
67         void reset_meters () {
68                 reset_peak_meter ();
69                 reset_overs ();
70         }
71
72         float                       peak_db() const { return _peak_db; }
73         jack_default_audio_sample_t peak()    const { return _peak; }
74
75         uint32_t short_overs () const { return _short_overs; }
76         uint32_t long_overs ()  const { return _long_overs; }
77         
78         static void set_short_over_length (nframes_t);
79         static void set_long_over_length (nframes_t);
80
81   protected:
82         friend class AudioEngine;
83
84         AudioPort (jack_port_t *port);
85         void reset ();
86         
87         /* engine isn't supposed to access below here */
88
89         AudioBuffer _buffer;
90
91         nframes_t               _overlen;
92         jack_default_audio_sample_t  _peak;
93         float                        _peak_db;
94         uint32_t                     _short_overs;
95         uint32_t                     _long_overs;
96         
97         static nframes_t        _long_over_length;
98         static nframes_t        _short_over_length;
99 };
100  
101 } // namespace ARDOUR
102
103 #endif /* __ardour_audio_port_h__ */