Remove unnecessary 0 checks before delete; see http://www.parashift.com/c++-faq-lite...
[ardour.git] / libs / ardour / base_audio_port.cc
1 /*
2     Copyright (C) 2006 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
19 #include <cassert>
20 #include <glib.h>
21 #include <ardour/base_audio_port.h>
22 #include <ardour/audioengine.h>
23 #include <ardour/data_type.h>
24
25 using namespace ARDOUR;
26 using namespace std;
27
28 nframes_t BaseAudioPort::_short_over_length = 2;
29 nframes_t BaseAudioPort::_long_over_length = 10;
30
31 BaseAudioPort::BaseAudioPort (const std::string& name, Flags flgs)
32         : Port (name, flgs)
33         , _buffer (0)
34         , _own_buffer (false)
35 {
36         _type = DataType::AUDIO;
37         _mixdown = default_mixdown;
38 }
39
40 BaseAudioPort::~BaseAudioPort ()
41 {
42         if (_own_buffer) {
43                 delete _buffer;
44         }
45 }
46
47 void
48 BaseAudioPort::reset()
49 {
50         Port::reset();
51
52         if (_own_buffer && _buffer) {
53                 _buffer->resize (engine->frames_per_cycle());
54                 _buffer->clear ();
55         }
56         
57         _metering = 0;
58         reset_meters ();
59 }
60
61 void
62 BaseAudioPort::default_mixdown (const set<Port*>& ports, AudioBuffer* dest, nframes_t cnt, nframes_t offset, bool first_overwrite)
63 {
64         set<Port*>::const_iterator p = ports.begin();
65
66         if (first_overwrite) {
67                 dest->read_from ((dynamic_cast<BaseAudioPort*>(*p))->get_audio_buffer( cnt, offset ), cnt, offset);
68                 p++;
69         }
70
71         for (; p != ports.end(); ++p) {
72                 dest->accumulate_from ((dynamic_cast<BaseAudioPort*>(*p))->get_audio_buffer( cnt, offset ), cnt, offset);
73         }
74 }
75
76 void 
77 BaseAudioPort::set_mixdown_function (void (*func)(const set<Port*>&, AudioBuffer*, nframes_t, nframes_t, bool))
78 {
79         g_atomic_pointer_set(&_mixdown, func);
80 }
81
82