2 Copyright (C) 2006 Paul Davis
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.
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.
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.
22 #include <ardour/midi_port.h>
23 #include <ardour/jack_midi_port.h>
24 #include <ardour/data_type.h>
26 using namespace ARDOUR;
29 MidiPort::MidiPort (const std::string& name, Flags flags, bool external, nframes_t capacity)
31 , BaseMidiPort (name, flags)
32 , PortFacade (name, flags)
33 , _has_been_mixed_down (false)
35 // FIXME: size kludge (see BufferSet::ensure_buffers)
36 // Jack needs to tell us this
37 _buffer = new MidiBuffer (capacity * 8);
40 /* external ports use the same buffer for the jack port (_ext_port)
41 * and internal ports (this) */
42 _ext_port = new JackMidiPort (name, flags, _buffer);
43 Port::set_name (_ext_port->name());
45 /* internal ports just have a single buffer, no jack port */
64 BaseMidiPort::reset();
72 MidiPort::cycle_start (nframes_t nframes, nframes_t offset)
75 _ext_port->cycle_start (nframes, offset);
80 MidiPort::get_midi_buffer( nframes_t nframes, nframes_t offset ) {
82 if (_has_been_mixed_down)
85 if (_flags & IsInput) {
89 BaseMidiPort* mprt = dynamic_cast<BaseMidiPort*>(_ext_port);
91 assert(&mprt->get_midi_buffer(nframes,offset) == _buffer);
93 if (!_connections.empty()) {
94 (*_mixdown) (_connections, _buffer, nframes, offset, false);
99 if (_connections.empty()) {
100 _buffer->silence (nframes, offset);
102 (*_mixdown) (_connections, _buffer, nframes, offset, true);
107 _buffer->silence (nframes, offset);
110 _has_been_mixed_down = true;
117 MidiPort::cycle_end (nframes_t nframes, nframes_t offset)
120 _ext_port->cycle_end (nframes, offset);
122 _has_been_mixed_down = false;
126 MidiPort::flush_buffers (nframes_t nframes, nframes_t offset)
129 _ext_port->flush_buffers (nframes, offset);