using namespace PBD;
MidiTrack::MidiTrack (Session& sess, string name, Route::Flag flag, TrackMode mode)
- : Route (sess, name, 1, -1, -1, -1, flag, Buffer::MIDI),
- _diskstream (0),
- _rec_enable_control (*this)
+ : Track (sess, name, flag, mode, DataType::MIDI)
{
MidiDiskstream::Flag dflags = MidiDiskstream::Flag (0);
_saved_meter_point = _meter_point;
_mode = mode;
- set_diskstream (*ds, this);
+ set_diskstream (*ds);
}
MidiTrack::MidiTrack (Session& sess, const XMLNode& node)
- : Route (sess, "to be renamed", 0, 0, -1, -1),
- _diskstream (0),
- _rec_enable_control (*this)
+ : Track (sess, node)
{
_freeze_record.state = NoFreeze;
set_state (node);
}
}
-#if 0
-void
-MidiTrack::handle_smpte_offset_change ()
-{
- diskstream
-}
-#endif
-
-int
-MidiTrack::deprecated_use_diskstream_connections ()
-{
- if (_diskstream->deprecated_io_node == 0) {
- return 0;
- }
-
- const XMLProperty* prop;
- XMLNode& node (*_diskstream->deprecated_io_node);
-
- /* don't do this more than once. */
-
- _diskstream->deprecated_io_node = 0;
-
- set_input_minimum (-1);
- set_input_maximum (-1);
- set_output_minimum (-1);
- set_output_maximum (-1);
-
- if ((prop = node.property ("gain")) != 0) {
- set_gain (atof (prop->value().c_str()), this);
- _gain = _desired_gain;
- }
-
- if ((prop = node.property ("input-connection")) != 0) {
- Connection* c = _session.connection_by_name (prop->value());
-
- if (c == 0) {
- PBD::error << string_compose(_("Unknown connection \"%1\" listed for input of %2"), prop->value(), _name) << endmsg;
-
- if ((c = _session.connection_by_name (_("in 1"))) == 0) {
- PBD::error << _("No input connections available as a replacement")
- << endmsg;
- return -1;
- } else {
- PBD::info << string_compose (_("Connection %1 was not available - \"in 1\" used instead"), prop->value())
- << endmsg;
- }
- }
-
- use_input_connection (*c, this);
-
- } else if ((prop = node.property ("inputs")) != 0) {
- if (set_inputs (prop->value())) {
- PBD::error << string_compose(_("improper input channel list in XML node (%1)"), prop->value()) << endmsg;
- return -1;
- }
- }
-
- return 0;
-}
int
-MidiTrack::set_diskstream (MidiDiskstream& ds, void *src)
+MidiTrack::set_diskstream (MidiDiskstream& ds)
{
if (_diskstream) {
_diskstream->unref();
_diskstream->set_io (*this);
_diskstream->set_destructive (_mode == Destructive);
- if (_diskstream->deprecated_io_node) {
-
- if (!connecting_legal) {
- ConnectingLegal.connect (mem_fun (*this, &MidiTrack::deprecated_use_diskstream_connections));
- } else {
- deprecated_use_diskstream_connections ();
- }
- }
-
- _diskstream->set_record_enabled (false, this);
+ _diskstream->set_record_enabled (false);
//_diskstream->monitor_input (false);
ic_connection.disconnect();
ic_connection = input_changed.connect (mem_fun (*_diskstream, &MidiDiskstream::handle_input_change));
- diskstream_changed (src); /* EMIT SIGNAL */
+ DiskstreamChanged (); /* EMIT SIGNAL */
return 0;
}
return -1;
}
- return set_diskstream (*dstream, this);
+ return set_diskstream (*dstream);
}
int
return -1;
}
- return set_diskstream (*dstream, this);
+ return set_diskstream (*dstream);
}
bool
#endif
}
-void
-MidiTrack::set_meter_point (MeterPoint p, void *src)
+MidiDiskstream&
+MidiTrack::midi_diskstream() const
{
- Route::set_meter_point (p, src);
+ return *dynamic_cast<MidiDiskstream*>(_diskstream);
}
int
return 0;
}
-XMLNode&
-MidiTrack::get_template ()
-{
- return state (false);
-}
-
-XMLNode&
-MidiTrack::get_state ()
-{
- return state (true);
-}
-
XMLNode&
MidiTrack::state(bool full_state)
{
continue;
}
- FreezeRecordInsertInfo* frii = new FreezeRecordInsertInfo (*((*citer)->children().front()));
- frii->insert = 0;
+ FreezeRecordInsertInfo* frii = new FreezeRecordInsertInfo (*((*citer)->children().front()),
+ boost::shared_ptr<Insert>());
frii->id = prop->value ();
_freeze_record.insert_info.push_back (frii);
}
return;
}
-uint32_t
+ChanCount
MidiTrack::n_process_buffers ()
{
- return max ((uint32_t) _diskstream->n_channels(), redirect_max_outs);
+ return max (_diskstream->n_channels(), redirect_max_outs);
}
void
MidiTrack::passthru_silence (jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t nframes, jack_nframes_t offset, 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 (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
}
int
MidiTrack::no_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t offset,
bool session_state_changing, bool can_record, bool rec_monitors_input)
{
- if (n_outputs() == 0) {
+ if (n_outputs().get(DataType::MIDI) == 0) {
return 0;
}
return 0;
}
- _diskstream->check_record_status (start_frame, nframes, can_record);
+ midi_diskstream().check_record_status (start_frame, nframes, can_record);
bool send_silence;
MidiTrack::roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t offset, int declick,
bool can_record, bool rec_monitors_input)
{
-#if 0
- int dret;
- Sample* b;
- Sample* tmpb;
- jack_nframes_t transport_frame;
-
- {
- Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
- if (lm.locked()) {
- // automation snapshot can also be called from the non-rt context
- // and it uses the redirect list, so we take the lock out here
- automation_snapshot (start_frame);
- }
- }
-
- if (n_outputs() == 0 && _redirects.empty()) {
- return 0;
- }
-
- if (!_active) {
- silence (nframes, offset);
- 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);
- }
-
- _silent = false;
- apply_gain_automation = false;
-
- if ((dret = diskstream->process (transport_frame, nframes, offset, can_record, rec_monitors_input)) != 0) {
-
- silence (nframes, offset);
-
- return dret;
- }
-
- /* special condition applies */
-
- if (_meter_point == MeterInput) {
- just_meter_input (start_frame, end_frame, nframes, offset);
- }
-
- if (diskstream->record_enabled() && !can_record && !_session.get_auto_input()) {
-
- /* not actually recording, but we want to hear the input material anyway,
- at least potentially (depending on monitoring options)
- */
-
- passthru (start_frame, end_frame, nframes, offset, 0, true);
-
- } else if ((b = diskstream->playback_buffer(0)) != 0) {
-
- /*
- XXX is it true that the earlier test on n_outputs()
- means that we can avoid checking it again here? i think
- so, because changing the i/o configuration of an IO
- requires holding the AudioEngine lock, which we hold
- while in the process() tree.
- */
-
-
- /* copy the diskstream data to all output buffers */
-
- vector<Sample*>& bufs = _session.get_passthru_buffers ();
- uint32_t limit = n_process_buffers ();
-
- uint32_t n;
- uint32_t i;
-
-
- 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;
- }
- }
- }
-
- /* don't waste time with automation if we're recording or we've just stopped (yes it can happen) */
-
- if (!diskstream->record_enabled() && _session.transport_rolling()) {
- Glib::Mutex::Lock am (automation_lock, Glib::TRY_LOCK);
-
- if (am.locked() && gain_automation_playback()) {
- apply_gain_automation = _gain_automation_curve.rt_safe_get_vector (start_frame, end_frame, _session.gain_automation_buffer(), nframes);
- }
- }
-
- process_output_buffers (bufs, limit, start_frame, end_frame, nframes, offset, (!_session.get_record_enabled() || !_session.get_do_not_record_plugins()), declick, (_meter_point != MeterInput));
-
- } else {
- /* problem with the diskstream; just be quiet for a bit */
- silence (nframes, offset);
- }
-#endif
return 0;
}
MidiTrack::silent_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t offset,
bool can_record, bool rec_monitors_input)
{
- if (n_outputs() == 0 && _redirects.empty()) {
+ if (n_outputs().get(DataType::MIDI) == 0 && _redirects.empty()) {
return 0;
}
silence (nframes, offset);
- return _diskstream->process (_session.transport_frame() + offset, nframes, offset, can_record, rec_monitors_input);
+ return midi_diskstream().process (_session.transport_frame() + offset, nframes, offset, can_record, rec_monitors_input);
}
void
-MidiTrack::toggle_monitor_input ()
+MidiTrack::process_output_buffers (BufferSet& bufs,
+ jack_nframes_t start_frame, jack_nframes_t end_frame,
+ jack_nframes_t nframes, jack_nframes_t offset, bool with_redirects, int declick,
+ bool meter)
{
- for (vector<Port*>::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
- (*i)->request_monitor_input(!(*i)->monitoring_input());
- }
+ // Do nothing (just bypass the Route version to avoid flaming death)
}
int
return -1;
}
- if (_diskstream->set_name (str, src)) {
+ if (_diskstream->set_name (str)) {
return -1;
}
}
int
-MidiTrack::export_stuff (vector<unsigned char*>& buffers, char * workbuf, uint32_t nbufs, jack_nframes_t start, jack_nframes_t nframes)
+MidiTrack::export_stuff (BufferSet& bufs, jack_nframes_t nframes, jack_nframes_t end_frame)
{
-#if 0
- gain_t gain_automation[nframes];
- gain_t gain_buffer[nframes];
- float mix_buffer[nframes];
- RedirectList::iterator i;
- bool post_fader_work = false;
- gain_t this_gain = _gain;
- vector<Sample*>::iterator bi;
- Sample * b;
-
- Glib::RWLock::ReaderLock rlock (redirect_lock);
-
- if (diskstream->playlist()->read (buffers[0], mix_buffer, gain_buffer, workbuf, start, nframes) != nframes) {
- return -1;
- }
-
- uint32_t n=1;
- bi = buffers.begin();
- b = buffers[0];
- ++bi;
- for (; bi != buffers.end(); ++bi, ++n) {
- if (n < diskstream->n_channels()) {
- if (diskstream->playlist()->read ((*bi), mix_buffer, gain_buffer, workbuf, start, nframes, n) != nframes) {
- return -1;
- }
- b = (*bi);
- }
- else {
- /* duplicate last across remaining buffers */
- memcpy ((*bi), b, sizeof (Sample) * nframes);
- }
- }
-
-
- /* note: only run inserts during export. other layers in the machinery
- will already have checked that there are no external port inserts.
- */
-
- for (i = _redirects.begin(); i != _redirects.end(); ++i) {
- Insert *insert;
-
- if ((insert = dynamic_cast<Insert*>(*i)) != 0) {
- switch (insert->placement()) {
- case PreFader:
- insert->run (buffers, nbufs, nframes, 0);
- break;
- case PostFader:
- post_fader_work = true;
- break;
- }
- }
- }
-
- if (_gain_automation_curve.automation_state() == Play) {
-
- _gain_automation_curve.get_vector (start, start + nframes, gain_automation, nframes);
-
- for (bi = buffers.begin(); bi != buffers.end(); ++bi) {
- Sample *b = *bi;
- for (jack_nframes_t n = 0; n < nframes; ++n) {
- b[n] *= gain_automation[n];
- }
- }
-
- } else {
-
- for (bi = buffers.begin(); bi != buffers.end(); ++bi) {
- Sample *b = *bi;
- for (jack_nframes_t n = 0; n < nframes; ++n) {
- b[n] *= this_gain;
- }
- }
- }
-
- if (post_fader_work) {
-
- for (i = _redirects.begin(); i != _redirects.end(); ++i) {
- PluginInsert *insert;
-
- if ((insert = dynamic_cast<PluginInsert*>(*i)) != 0) {
- switch ((*i)->placement()) {
- case PreFader:
- break;
- case PostFader:
- insert->run (buffers, nbufs, nframes, 0);
- break;
- }
- }
- }
- }
-#endif
- return 0;
+ return -1;
}
void
_diskstream->set_roll_delay (_roll_delay);
}
-jack_nframes_t
-MidiTrack::update_total_latency ()
-{
- _own_latency = 0;
-
- for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
- if ((*i)->active ()) {
- _own_latency += (*i)->latency ();
- }
- }
-
- set_port_latency (_own_latency);
-
- return _own_latency;
-}
-
void
MidiTrack::bounce (InterThreadInfo& itt)
{
void
MidiTrack::freeze (InterThreadInfo& itt)
{
-#if 0
- Insert* insert;
- vector<MidiSource*> srcs;
- string new_playlist_name;
- Playlist* new_playlist;
- string dir;
- AudioRegion* region;
- string region_name;
-
- if ((_freeze_record.playlist = diskstream->playlist()) == 0) {
- return;
- }
-
- uint32_t n = 1;
-
- while (n < (UINT_MAX-1)) {
-
- string candidate;
-
- candidate = string_compose ("<F%2>%1", _freeze_record.playlist->name(), n);
-
- if (_session.playlist_by_name (candidate) == 0) {
- new_playlist_name = candidate;
- break;
- }
-
- ++n;
-
- }
-
- if (n == (UINT_MAX-1)) {
- PBD::error << string_compose (X_("There Are too many frozen versions of playlist \"%1\""
- " to create another one"), _freeze_record.playlist->name())
- << endmsg;
- return;
- }
-
- if (_session.write_one_midi_track (*this, 0, _session.current_end_frame(), true, srcs, itt)) {
- return;
- }
-
- _freeze_record.insert_info.clear ();
- _freeze_record.have_mementos = true;
-
- {
- Glib::RWLock::ReaderLock lm (redirect_lock);
-
- for (RedirectList::iterator r = _redirects.begin(); r != _redirects.end(); ++r) {
-
- if ((insert = dynamic_cast<Insert*>(*r)) != 0) {
-
- FreezeRecordInsertInfo* frii = new FreezeRecordInsertInfo ((*r)->get_state());
-
- frii->insert = insert;
- frii->id = insert->id();
- frii->memento = (*r)->get_memento();
-
- _freeze_record.insert_info.push_back (frii);
-
- /* now deactivate the insert */
-
- insert->set_active (false, this);
- }
- }
- }
-
- new_playlist = new MidiPlaylist (_session, new_playlist_name, false);
- region_name = new_playlist_name;
-
- /* create a new region from all filesources, keep it private */
-
- region = new AudioRegion (srcs, 0, srcs[0]->length(),
- region_name, 0,
- (AudioRegion::Flag) (AudioRegion::WholeFile|AudioRegion::DefaultFlags),
- false);
-
- new_playlist->set_orig_diskstream_id (diskstream->id());
- new_playlist->add_region (*region, 0);
- new_playlist->set_frozen (true);
- region->set_locked (true);
-
- diskstream->use_playlist (dynamic_cast<MidiPlaylist*>(new_playlist));
- diskstream->set_record_enabled (false, this);
-
- _freeze_record.state = Frozen;
- FreezeChange(); /* EMIT SIGNAL */
}
void
MidiTrack::unfreeze ()
{
- if (_freeze_record.playlist) {
- diskstream->use_playlist (_freeze_record.playlist);
-
- if (_freeze_record.have_mementos) {
-
- for (vector<FreezeRecordInsertInfo*>::iterator i = _freeze_record.insert_info.begin(); i != _freeze_record.insert_info.end(); ++i) {
- (*i)->memento ();
- }
-
- } else {
-
- Glib::RWLock::ReaderLock lm (redirect_lock); // should this be a write lock? jlc
- for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
- for (vector<FreezeRecordInsertInfo*>::iterator ii = _freeze_record.insert_info.begin(); ii != _freeze_record.insert_info.end(); ++ii) {
- if ((*ii)->id == (*i)->id()) {
- (*i)->set_state (((*ii)->state));
- break;
- }
- }
- }
- }
-
- _freeze_record.playlist = 0;
- }
-#endif
_freeze_record.state = UnFrozen;
FreezeChange (); /* EMIT SIGNAL */
}
-MidiTrack::FreezeRecord::~FreezeRecord ()
-{
- for (vector<FreezeRecordInsertInfo*>::iterator i = insert_info.begin(); i != insert_info.end(); ++i) {
- delete *i;
- }
-}
-
-MidiTrack::FreezeState
-MidiTrack::freeze_state() const
-{
- return _freeze_record.state;
-}
-
-
-MidiTrack::MIDIRecEnableControllable::MIDIRecEnableControllable (MidiTrack& s)
- : track(s)
-{
-}
-
-void
-MidiTrack::MIDIRecEnableControllable::set_value (float val)
-{
- bool bval = ((val >= 0.5f) ? true: false);
- track.set_record_enable (bval, this);
-}
-
-float
-MidiTrack::MIDIRecEnableControllable::get_value (void) const
-{
- if (track.record_enabled()) { return 1.0f; }
- return 0.0f;
-}
-
void
MidiTrack::set_mode (TrackMode m)
{