/*
- Copyright (C) 2006 Paul Davis
+ Copyright (C) 2006 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
*/
#include <cassert>
-#include <ardour/audio_port.h>
-#include <ardour/data_type.h>
+
+#include "pbd/stacktrace.h"
+
+#include "ardour/audio_buffer.h"
+#include "ardour/audio_port.h"
+#include "ardour/data_type.h"
using namespace ARDOUR;
using namespace std;
-nframes_t AudioPort::_short_over_length = 2;
-nframes_t AudioPort::_long_over_length = 10;
+AudioPort::AudioPort (const std::string& name, Flags flags)
+ : Port (name, DataType::AUDIO, flags)
+ , _buffer (new AudioBuffer (0))
+{
+ assert (name.find_first_of (':') == string::npos);
+}
-AudioPort::AudioPort()
- : _buffer (0)
+AudioPort::~AudioPort ()
{
- _type = DataType::AUDIO;
- reset();
+ delete _buffer;
}
-AudioPort::AudioPort(nframes_t nframes)
- : _buffer (nframes)
+void
+AudioPort::cycle_start (pframes_t nframes)
{
- _type = DataType::AUDIO;
- reset();
+ /* caller must hold process lock */
+
+ Port::cycle_start (nframes);
+
+ if (sends_output()) {
+ _buffer->prepare ();
+ }
}
void
-AudioPort::reset()
+AudioPort::cycle_end (pframes_t)
{
- Port::reset();
- if (_flags & IsOutput) {
- if (_buffer.capacity() > 0) {
- _buffer.clear();
+ if (sends_output() && !_buffer->written()) {
+ /* we can't use nframes here because the current buffer capacity may
+ be shorter than the full buffer size if we split the cycle.
+ */
+ if (_buffer->capacity () > 0) {
+ _buffer->silence (_buffer->capacity());
}
- assert(_buffer.silent());
}
-
- _metering = 0;
- reset_meters ();
}
+void
+AudioPort::cycle_split ()
+{
+}
+
+AudioBuffer&
+AudioPort::get_audio_buffer (pframes_t nframes)
+{
+ /* caller must hold process lock */
+ _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, _cycle_nframes) +
+ _global_port_buffer_offset + _port_buffer_offset, nframes);
+ return *_buffer;
+}
+
+