#include <ardour/playlist_factory.h>
#include <ardour/panner.h>
#include <ardour/utils.h>
+#include <ardour/mix.h>
#include "i18n.h"
AudioTrack::AudioTrack (Session& sess, string name, Route::Flag flag, TrackMode mode)
: Track (sess, name, flag, mode)
+{
+ use_new_diskstream ();
+}
+
+AudioTrack::AudioTrack (Session& sess, const XMLNode& node)
+ : Track (sess, node)
+{
+ _set_state (node, false);
+}
+
+AudioTrack::~AudioTrack ()
+{
+}
+
+void
+AudioTrack::use_new_diskstream ()
{
AudioDiskstream::Flag dflags = AudioDiskstream::Flag (0);
dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Recordable);
}
- if (mode == Destructive) {
+ if (_mode == Destructive) {
dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Destructive);
}
- boost::shared_ptr<AudioDiskstream> ds (new AudioDiskstream (_session, name, dflags));
+ boost::shared_ptr<AudioDiskstream> ds (new AudioDiskstream (_session, name(), dflags));
_session.add_diskstream (ds);
set_diskstream (boost::dynamic_pointer_cast<AudioDiskstream> (ds), this);
}
-AudioTrack::AudioTrack (Session& sess, const XMLNode& node)
- : Track (sess, node)
-{
- _set_state (node, false);
-}
-
-AudioTrack::~AudioTrack ()
-{
-}
-
int
AudioTrack::set_mode (TrackMode m)
{
} else {
PBD::ID id (prop->value());
-
- if (use_diskstream (id)) {
+ PBD::ID zero ("0");
+
+ /* this wierd hack is used when creating tracks from a template. there isn't
+ a particularly good time to interpose between setting the first part of
+ the track state (notably Route::set_state() and the track mode), and the
+ second part (diskstream stuff). So, we have a special ID for the diskstream
+ that means "you should create a new diskstream here, not look for
+ an old one.
+ */
+
+ if (id == zero) {
+ use_new_diskstream ();
+ } else if (use_diskstream (id)) {
return -1;
}
}
pending_state = const_cast<XMLNode*> (&node);
- _session.StateReady.connect (mem_fun (*this, &AudioTrack::set_state_part_two));
+ if (_session.state_of_the_state() & Session::Loading) {
+ _session.StateReady.connect (mem_fun (*this, &AudioTrack::set_state_part_two));
+ } else {
+ set_state_part_two ();
+ }
return 0;
}
XMLProperty* prop;
LocaleGuard lg (X_("POSIX"));
- /* This is called after all session state has been restored but before
- have been made ports and connections are established.
+ /* During session loading: this is called after all session state has been restored but before
+ ports have been created and connections are established.
+
+ During creation from templates: this is called after ports have been created, and connections
+ are established.
*/
if (pending_state == 0) {
}
void
-AudioTrack::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
+AudioTrack::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, int declick, bool meter)
{
uint32_t nbufs = n_process_buffers ();
- process_output_buffers (_session.get_silent_buffers (nbufs), nbufs, start_frame, end_frame, nframes, offset, true, declick, meter);
+
+ process_output_buffers (_session.get_silent_buffers (nbufs), nbufs, start_frame, end_frame, nframes, true, declick, meter);
}
int
-AudioTrack::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
+AudioTrack::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame,
bool session_state_changing, bool can_record, bool rec_monitors_input)
{
if (n_outputs() == 0) {
}
if (!_active) {
- silence (nframes, offset);
+ silence (nframes);
return 0;
}
/* XXX is this safe to do against transport state changes? */
- passthru_silence (start_frame, end_frame, nframes, offset, 0, false);
+ passthru_silence (start_frame, end_frame, nframes, 0, false);
return 0;
}
send_silence = true;
} else {
- if (Config->get_adat_monitor_mode()) {
+ if (!Config->get_tape_machine_mode()) {
/*
ADATs work in a strange way..
they monitor input always when stopped.and auto-input is engaged.
*/
- if (Config->get_monitoring_model() == SoftwareMonitoring && Config->get_auto_input()) {
+ if ((Config->get_monitoring_model() == SoftwareMonitoring) && (Config->get_auto_input () || _diskstream->record_enabled())) {
send_silence = false;
} else {
send_silence = true;
*/
if (_have_internal_generator) {
- passthru_silence (start_frame, end_frame, nframes, offset, 0, true);
+ passthru_silence (start_frame, end_frame, nframes, 0, true);
} else {
if (_meter_point == MeterInput) {
- just_meter_input (start_frame, end_frame, nframes, offset);
+ just_meter_input (start_frame, end_frame, nframes);
}
- passthru_silence (start_frame, end_frame, nframes, offset, 0, false);
+ passthru_silence (start_frame, end_frame, nframes, 0, false);
}
} else {
/* we're sending signal, but we may still want to meter the input.
*/
- passthru (start_frame, end_frame, nframes, offset, 0, (_meter_point == MeterInput));
+ passthru (start_frame, end_frame, nframes, 0, (_meter_point == MeterInput));
}
return 0;
}
int
-AudioTrack::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
+AudioTrack::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, int declick,
bool can_record, bool rec_monitors_input)
{
int dret;
Sample* tmpb;
nframes_t transport_frame;
boost::shared_ptr<AudioDiskstream> diskstream = audio_diskstream();
-
+
{
Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
if (lm.locked()) {
}
if (!_active) {
- silence (nframes, offset);
+ silence (nframes);
return 0;
}
transport_frame = _session.transport_frame();
- if ((nframes = check_initial_delay (nframes, offset, transport_frame)) == 0) {
- /* need to do this so that the diskstream sets its
- playback distance to zero, thus causing diskstream::commit
- to do nothing.
- */
- return diskstream->process (transport_frame, 0, 0, can_record, rec_monitors_input);
- }
+ if (!can_record || !diskstream->record_enabled()) {
+ if ((nframes = check_initial_delay (nframes, transport_frame)) == 0) {
+ /* need to do this so that the diskstream sets its
+ playback distance to zero, thus causing diskstream::commit
+ to do nothing.
+ */
+ return diskstream->process (transport_frame, 0, can_record, rec_monitors_input);
+ }
+ }
_silent = false;
apply_gain_automation = false;
- if ((dret = diskstream->process (transport_frame, nframes, offset, can_record, rec_monitors_input)) != 0) {
+ if ((dret = diskstream->process (transport_frame, nframes, can_record, rec_monitors_input)) != 0) {
- silence (nframes, offset);
+ silence (nframes);
return dret;
}
/* special condition applies */
if (_meter_point == MeterInput) {
- just_meter_input (start_frame, end_frame, nframes, offset);
+ just_meter_input (start_frame, end_frame, nframes);
}
if (diskstream->record_enabled() && !can_record && !Config->get_auto_input()) {
at least potentially (depending on monitoring options)
*/
- passthru (start_frame, end_frame, nframes, offset, 0, true);
+ passthru (start_frame, end_frame, nframes, 0, true);
} else if ((b = diskstream->playback_buffer(0)) != 0) {
/* copy the diskstream data to all output buffers */
vector<Sample*>& bufs = _session.get_passthru_buffers ();
+ vector<Sample*>::size_type blimit = bufs.size();
uint32_t limit = n_process_buffers ();
uint32_t n;
uint32_t i;
+ if (limit > blimit) {
+
+ /* example case: auditioner configured for stereo output,
+ but loaded with an 8 channel file. there are only
+ 2 passthrough buffers, but n_process_buffers() will
+ return 8.
+
+ arbitrary decision: map all channels in the diskstream
+ to the outputs available.
+ */
+
+ float scaling = limit/blimit;
+
+ for (i = 0, n = 1; i < blimit; ++i, ++n) {
+
+ /* first time through just copy a channel into
+ the output buffer.
+ */
+
+ for (nframes_t xx = 0; xx < nframes; ++xx) {
+ bufs[i][xx] = b[xx] * scaling;
+ }
+
+ if (n < diskstream->n_channels()) {
+ tmpb = diskstream->playback_buffer(n);
+ if (tmpb!=0) {
+ b = tmpb;
+ }
+ }
+ }
+
+ for (;i < limit; ++i, ++n) {
+
+ /* for all remaining channels, sum with existing
+ data in the output buffers
+ */
+
+ Session::mix_buffers_with_gain (bufs[i%blimit], b, nframes, scaling);
+
+ if (n < diskstream->n_channels()) {
+ tmpb = diskstream->playback_buffer(n);
+ if (tmpb!=0) {
+ b = tmpb;
+ }
+ }
+
+ }
+
+ limit = blimit;
- for (i = 0, n = 1; i < limit; ++i, ++n) {
- memcpy (bufs[i], b, sizeof (Sample) * nframes);
- if (n < diskstream->n_channels()) {
- tmpb = diskstream->playback_buffer(n);
- if (tmpb!=0) {
- b = tmpb;
+ } else {
+ for (i = 0, n = 1; i < limit; ++i, ++n) {
+ memcpy (bufs[i], b, sizeof (Sample) * nframes);
+ if (n < diskstream->n_channels()) {
+ tmpb = diskstream->playback_buffer(n);
+ if (tmpb!=0) {
+ b = tmpb;
+ }
}
}
}
}
}
- process_output_buffers (bufs, limit, start_frame, end_frame, nframes, offset, (!_session.get_record_enabled() || !Config->get_do_not_record_plugins()), declick, (_meter_point != MeterInput));
+ process_output_buffers (bufs, limit, start_frame, end_frame, nframes, (!_session.get_record_enabled() || !Config->get_do_not_record_plugins()), declick, (_meter_point != MeterInput));
} else {
/* problem with the diskstream; just be quiet for a bit */
- silence (nframes, offset);
+ silence (nframes);
}
return 0;
}
int
-AudioTrack::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
+AudioTrack::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame,
bool can_record, bool rec_monitors_input)
{
if (n_outputs() == 0 && _redirects.empty()) {
}
if (!_active) {
- silence (nframes, offset);
+ silence (nframes);
return 0;
}
_silent = true;
apply_gain_automation = false;
- silence (nframes, offset);
+ silence (nframes);
- return audio_diskstream()->process (_session.transport_frame() + offset, nframes, offset, can_record, rec_monitors_input);
+ return audio_diskstream()->process (_session.transport_frame(), nframes, can_record, rec_monitors_input);
}
int
-AudioTrack::export_stuff (vector<Sample*>& buffers, uint32_t nbufs, nframes_t start, nframes_t nframes)
+AudioTrack::export_stuff (vector<Sample*>& buffers, uint32_t nbufs, nframes_t start, nframes_t nframes, bool enable_processing)
{
gain_t gain_automation[nframes];
gain_t gain_buffer[nframes];
}
}
+ // If no processing is required, there's no need to go any further.
+ if (!enable_processing)
+ return 0;
/* note: only run inserts during export. other layers in the machinery
will already have checked that there are no external port inserts.
if ((insert = boost::dynamic_pointer_cast<Insert>(*i)) != 0) {
switch (insert->placement()) {
case PreFader:
- insert->run (buffers, nbufs, nframes, 0);
+ insert->run (buffers, nbufs, nframes);
break;
case PostFader:
post_fader_work = true;
} else {
for (bi = buffers.begin(); bi != buffers.end(); ++bi) {
- Sample *b = *bi;
- for (nframes_t n = 0; n < nframes; ++n) {
- b[n] *= this_gain;
- }
+ apply_gain_to_buffer(*bi, nframes, this_gain);
}
}
case PreFader:
break;
case PostFader:
- insert->run (buffers, nbufs, nframes, 0);
+ insert->run (buffers, nbufs, nframes);
break;
}
}
return 0;
}
-void
+boost::shared_ptr<Region>
AudioTrack::bounce (InterThreadInfo& itt)
{
vector<boost::shared_ptr<AudioSource> > srcs;
- _session.write_one_audio_track (*this, 0, _session.current_end_frame(), false, srcs, itt);
+ return _session.write_one_audio_track (*this, _session.current_start_frame(), _session.current_end_frame(),
+ false, srcs, itt);
}
-void
-AudioTrack::bounce_range (nframes_t start, nframes_t end, InterThreadInfo& itt)
+boost::shared_ptr<Region>
+AudioTrack::bounce_range (nframes_t start, nframes_t end, InterThreadInfo& itt, bool enable_processing)
{
vector<boost::shared_ptr<AudioSource> > srcs;
- _session.write_one_audio_track (*this, start, end, false, srcs, itt);
+ return _session.write_one_audio_track (*this, start, end, false, srcs, itt, enable_processing);
}
void
return;
}
- if (_session.write_one_audio_track (*this, _session.current_start_frame(), _session.current_end_frame(), true, srcs, itt)) {
+ boost::shared_ptr<Region> res;
+
+ if ((res = _session.write_one_audio_track (*this, _session.current_start_frame(), _session.current_end_frame(), true, srcs, itt)) == 0) {
return;
}
}
}
+ _freeze_record.gain = _gain;
+ _freeze_record.gain_automation_state = _gain_automation_curve.automation_state();
+ _freeze_record.pan_automation_state = _panner->automation_state();
+
new_playlist = PlaylistFactory::create (_session, new_playlist_name, false);
region_name = new_playlist_name;
diskstream->use_playlist (boost::dynamic_pointer_cast<AudioPlaylist>(new_playlist));
diskstream->set_record_enabled (false);
+ /* reset stuff that has already been accounted for in the freeze process */
+
+ set_gain (1.0, this);
+ _gain_automation_curve.set_automation_state (Off);
+ _panner->set_automation_state (Off);
+
_freeze_record.state = Frozen;
FreezeChange(); /* EMIT SIGNAL */
}
}
_freeze_record.playlist.reset ();
+ set_gain (_freeze_record.gain, this);
+ _gain_automation_curve.set_automation_state (_freeze_record.gain_automation_state);
+ _panner->set_automation_state (_freeze_record.pan_automation_state);
}
_freeze_record.state = UnFrozen;