diff options
author | David Robillard <d@drobilla.net> | 2010-02-23 20:25:53 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-02-23 20:25:53 +0000 |
commit | 650c6d5824222a8879df5c5ba9645c264ed3b84f (patch) | |
tree | 7cd5aace00cb23622f07727ae4f7963c03dd05c9 /libs/ardour/session.cc | |
parent | 0c20d48e7d436725396baf362368f7ce61717151 (diff) |
Fix various code quality issues found by cppcheck (e.g. uninitialized members, larger than necessary variable scope, memory leaks, etc).
git-svn-id: svn://localhost/ardour2/branches/3.0@6710 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/session.cc')
-rw-r--r-- | libs/ardour/session.cc | 93 |
1 files changed, 69 insertions, 24 deletions
diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index decb2603fe..c1fe4bb8c0 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -725,24 +725,27 @@ Session::when_engine_running () } else { - /* XXX this logic is wrong for mixed port types */ - - uint32_t shift = _master_out->n_outputs().n_audio(); - uint32_t mod = _engine.n_physical_outputs (DataType::AUDIO); - limit = _control_out->n_outputs().n_audio(); - - cerr << "Connecting " << limit << " control out ports, shift is " << shift << " mod is " << mod << endl; - - for (uint32_t n = 0; n < limit; ++n) { - - Port* p = _control_out->output()->nth (n); - string connect_to = _engine.get_nth_physical_output (DataType (p->type()), (n+shift) % mod); - - if (!connect_to.empty()) { - if (_control_out->output()->connect (p, connect_to, this)) { - error << string_compose (_("cannot connect control output %1 to %2"), n, connect_to) - << endmsg; - break; + for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { + uint32_t shift = _master_out->n_outputs().get(*t); + uint32_t mod = _engine.n_physical_outputs (*t); + limit = _control_out->n_outputs().get(*t); + + cerr << "Connecting " << limit << " control out ports, shift is " << shift + << " mod is " << mod << endl; + + for (uint32_t n = 0; n < limit; ++n) { + + Port* p = _control_out->output()->ports().port(*t, n); + string connect_to = _engine.get_nth_physical_output (*t, (n+shift) % mod); + + if (!connect_to.empty()) { + if (_control_out->output()->connect (p, connect_to, this)) { + error << string_compose ( + _("cannot connect control output %1 to %2"), + n, connect_to) + << endmsg; + break; + } } } } @@ -1527,12 +1530,11 @@ Session::new_midi_track (TrackMode mode, RouteGroup* route_group, uint32_t how_m char track_name[32]; uint32_t track_id = 0; uint32_t n = 0; + uint32_t channels_used = 0; string port; RouteList new_routes; list<boost::shared_ptr<MidiTrack> > ret; - //uint32_t control_id; - - // FIXME: need physical I/O and autoconnect stuff for MIDI + uint32_t control_id; /* count existing midi tracks */ @@ -1543,7 +1545,7 @@ Session::new_midi_track (TrackMode mode, RouteGroup* route_group, uint32_t how_m if (boost::dynamic_pointer_cast<MidiTrack>(*i) != 0) { if (!(*i)->is_hidden()) { n++; - //channels_used += (*i)->n_inputs().n_midi(); + channels_used += (*i)->n_inputs().n_midi(); } } } @@ -1555,7 +1557,7 @@ Session::new_midi_track (TrackMode mode, RouteGroup* route_group, uint32_t how_m _engine.get_physical_outputs (DataType::MIDI, physoutputs); _engine.get_physical_inputs (DataType::MIDI, physinputs); - // control_id = ntracks() + nbusses(); + control_id = ntracks() + nbusses(); while (how_many) { @@ -1580,7 +1582,9 @@ Session::new_midi_track (TrackMode mode, RouteGroup* route_group, uint32_t how_m shared_ptr<MidiTrack> track; try { - track = boost::shared_ptr<MidiTrack>((new MidiTrack (*this, track_name, Route::Flag (0), mode))); + MidiTrack* mt = new MidiTrack (*this, track_name, Route::Flag (0), mode); + boost_debug_shared_ptr_mark_interesting (mt, "Track"); + track = boost::shared_ptr<MidiTrack>(mt); if (track->input()->ensure_io (ChanCount(DataType::MIDI, 1), false, this)) { error << "cannot configure 1 in/1 out configuration for new midi track" << endmsg; @@ -1593,6 +1597,47 @@ Session::new_midi_track (TrackMode mode, RouteGroup* route_group, uint32_t how_m goto failed; } + if (!physinputs.empty()) { + uint32_t nphysical_in = physinputs.size(); + + for (uint32_t x = 0; x < track->n_inputs().n_midi() && x < nphysical_in; ++x) { + + port = ""; + + if (Config->get_input_auto_connect() & AutoConnectPhysical) { + port = physinputs[(channels_used+x)%nphysical_in]; + } + + if (port.length() && track->input()->connect (track->input()->nth(x), port, this)) { + break; + } + } + } + + if (!physoutputs.empty()) { + uint32_t nphysical_out = physoutputs.size(); + + for (uint32_t x = 0; x < track->n_outputs().n_midi(); ++x) { + port = ""; + + if (Config->get_output_auto_connect() & AutoConnectPhysical) { + port = physoutputs[(channels_used+x)%nphysical_out]; + } else if (Config->get_output_auto_connect() & AutoConnectMaster) { + if (_master_out && _master_out->n_inputs().n_midi() > 0) { + port = _master_out->input()->nth (x % _master_out->input()->n_ports().n_midi())->name(); + } + } + + if (port.length() && track->output()->connect (track->output()->nth(x), port, this)) { + break; + } + } + } + + channels_used += track->n_inputs ().n_audio(); + + + /* if (nphysical_in) { for (uint32_t x = 0; x < track->n_inputs().n_midi() && x < nphysical_in; ++x) { |