X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fexport_channel_selector.cc;h=acbed62030a7396ddb91d403f5d2f334ff8ee3d1;hb=aed07c49987b497c225944059f4da72ab64a4cff;hp=74a18b9770b6ed49b08ec9f16da8b92215f225fc;hpb=f6fdd8dcbf41f864e9f0cc32dabe81fe3533ddfe;p=ardour.git diff --git a/gtk2_ardour/export_channel_selector.cc b/gtk2_ardour/export_channel_selector.cc index 74a18b9770..acbed62030 100644 --- a/gtk2_ardour/export_channel_selector.cc +++ b/gtk2_ardour/export_channel_selector.cc @@ -18,24 +18,23 @@ */ -#include "export_channel_selector.h" - #include #include "pbd/convert.h" -#include "ardour/audio_port.h" #include "ardour/audio_track.h" -#include "ardour/audioengine.h" +#include "ardour/audioregion.h" #include "ardour/export_channel_configuration.h" -#include "ardour/export_handler.h" #include "ardour/io.h" #include "ardour/route.h" #include "ardour/session.h" #include -#include "i18n.h" +#include "export_channel_selector.h" +#include "route_sorter.h" + +#include "pbd/i18n.h" using namespace std; using namespace Glib; @@ -100,6 +99,11 @@ PortExportChannelSelector::sync_with_manager () split_checkbox.set_active (state->config->get_split()); channels_spinbutton.set_value (state->config->get_n_chans()); + /* when loading presets, config is ready set here (shared ptr) + * fill_route_list () -> update_channel_count () -> set_channel_count () -> update_config() + * will call config->clear_channels(); and clear the config + */ + channel_view.set_config (ChannelConfigPtr ()); fill_route_list (); channel_view.set_config (state->config); } @@ -112,11 +116,15 @@ PortExportChannelSelector::fill_route_list () /* Add master bus and then everything else */ - ARDOUR::IO* master = _session->master_out()->output().get(); - channel_view.add_route (master); + if (_session->master_out()) { + ARDOUR::IO* master = _session->master_out()->output().get(); + channel_view.add_route (master); + } + + routes.sort (Stripable::PresentationOrderSorter ()); for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) { - if ((*it)->output().get() == master) { + if ((*it)->is_master () || (*it)->is_monitor ()) { continue; } channel_view.add_route ((*it)->output().get()); @@ -154,7 +162,7 @@ PortExportChannelSelector::RouteCols::Channel & PortExportChannelSelector::RouteCols::get_channel (uint32_t channel) { if (channel > n_channels) { - std::cout << "Invalid channel cout for get_channel!" << std::endl; + std::cout << "Invalid channel count for get_channel!" << std::endl; } std::list::iterator it = channels.begin(); @@ -179,16 +187,21 @@ PortExportChannelSelector::ChannelTreeView::ChannelTreeView (uint32_t max_channe /* Add column with toggle and text */ - append_column_editable (_("Bus or Track"), route_cols.selected); + append_column_editable (_("Export"), route_cols.selected); Gtk::CellRendererText* text_renderer = Gtk::manage (new Gtk::CellRendererText); text_renderer->property_editable() = false; + text_renderer->set_alignment (0.0, 0.5); - Gtk::TreeView::Column* column = get_column (0); + Gtk::TreeView::Column* column = Gtk::manage (new Gtk::TreeView::Column); + column->set_title (_("Bus or Track")); column->pack_start (*text_renderer); + column->set_expand (true); column->add_attribute (text_renderer->property_text(), route_cols.name); + append_column (*column); Gtk::CellRendererToggle *toggle = dynamic_cast(get_column_cell_renderer (0)); + toggle->set_alignment (0.0, 0.5); toggle->signal_toggled().connect (sigc::mem_fun (*this, &PortExportChannelSelector::ChannelTreeView::update_toggle_selection)); static_columns = get_columns().size(); @@ -204,6 +217,7 @@ PortExportChannelSelector::ChannelTreeView::set_config (ChannelConfigPtr c) if (config == c) { return; } config = c; + if (!config) { return; } uint32_t i = 1; ExportChannelConfiguration::ChannelList chan_list = config->get_channels(); @@ -217,21 +231,21 @@ PortExportChannelSelector::ChannelTreeView::set_config (ChannelConfigPtr c) } Glib::RefPtr port_list = r_it->get_value (route_cols.port_list_col); - std::set route_ports; - std::set intersection; - std::map port_labels; + std::set > route_ports; + std::set > intersection; + std::map, string> port_labels; for (Gtk::ListStore::Children::const_iterator p_it = port_list->children().begin(); p_it != port_list->children().end(); ++p_it) { route_ports.insert ((*p_it)->get_value (route_cols.port_cols.port)); - port_labels.insert (std::pair ((*p_it)->get_value (route_cols.port_cols.port), - (*p_it)->get_value (route_cols.port_cols.label))); + port_labels.insert (make_pair ((*p_it)->get_value (route_cols.port_cols.port), + (*p_it)->get_value (route_cols.port_cols.label))); } std::set_intersection (pec->get_ports().begin(), pec->get_ports().end(), route_ports.begin(), route_ports.end(), - std::insert_iterator > (intersection, intersection.begin())); + std::insert_iterator > > (intersection, intersection.begin())); - intersection.erase (0); // Remove "none" selection + intersection.erase (boost::weak_ptr ()); // Remove "none" selection if (intersection.empty()) { continue; @@ -243,14 +257,14 @@ PortExportChannelSelector::ChannelTreeView::set_config (ChannelConfigPtr c) /* Set previous channels (if any) to none */ for (uint32_t chn = 1; chn < i; ++chn) { - r_it->set_value (route_cols.get_channel (chn).port, (AudioPort *) 0); - r_it->set_value (route_cols.get_channel (chn).label, ustring ("(none)")); + r_it->set_value (route_cols.get_channel (chn).port, boost::weak_ptr ()); + r_it->set_value (route_cols.get_channel (chn).label, string ("(none)")); } } - AudioPort * port = *intersection.begin(); - std::map::iterator label_it = port_labels.find (port); - ustring label = label_it != port_labels.end() ? label_it->second : "error"; + boost::weak_ptr port = *intersection.begin(); + std::map, string>::iterator label_it = port_labels.find (port); + string label = label_it != port_labels.end() ? label_it->second : "error"; r_it->set_value (route_cols.get_channel (i).port, port); r_it->set_value (route_cols.get_channel (i).label, label); @@ -293,7 +307,7 @@ PortExportChannelSelector::ChannelTreeView::add_route (ARDOUR::IO * io) row = *iter; row[route_cols.port_cols.selected] = false; - row[route_cols.port_cols.port] = 0; + row[route_cols.port_cols.port] = boost::weak_ptr (); row[route_cols.port_cols.label] = "(none)"; } @@ -315,6 +329,7 @@ PortExportChannelSelector::ChannelTreeView::set_channel_count (uint32_t channels Gtk::CellRendererCombo* combo_renderer = Gtk::manage (new Gtk::CellRendererCombo); combo_renderer->property_text_column() = 2; + combo_renderer->property_has_entry() = false; column->pack_start (*combo_renderer); append_column (*column); @@ -328,9 +343,9 @@ PortExportChannelSelector::ChannelTreeView::set_channel_count (uint32_t channels /* put data into view */ for (Gtk::ListStore::Children::iterator it = route_list->children().begin(); it != route_list->children().end(); ++it) { - Glib::ustring label = it->get_value(route_cols.selected) ? "(none)" : ""; + std::string label = it->get_value(route_cols.selected) ? "(none)" : ""; it->set_value (route_cols.get_channel (n_channels).label, label); - it->set_value (route_cols.get_channel (n_channels).port, (AudioPort *) 0); + it->set_value (route_cols.get_channel (n_channels).port, boost::weak_ptr ()); } /* set column width */ @@ -354,7 +369,6 @@ PortExportChannelSelector::ChannelTreeView::set_channel_count (uint32_t channels void PortExportChannelSelector::ChannelTreeView::update_config () { - if (!config) { return; } config->clear_channels(); @@ -371,7 +385,8 @@ PortExportChannelSelector::ChannelTreeView::update_config () continue; } - AudioPort * port = row[route_cols.get_channel (i).port]; + boost::weak_ptr weak_port = row[route_cols.get_channel (i).port]; + boost::shared_ptr port = weak_port.lock (); if (port) { pec->add_port (port); } @@ -384,7 +399,7 @@ PortExportChannelSelector::ChannelTreeView::update_config () } void -PortExportChannelSelector::ChannelTreeView::update_toggle_selection (Glib::ustring const & path) +PortExportChannelSelector::ChannelTreeView::update_toggle_selection (std::string const & path) { Gtk::TreeModel::iterator iter = get_model ()->get_iter (path); bool selected = iter->get_value (route_cols.selected); @@ -392,12 +407,12 @@ PortExportChannelSelector::ChannelTreeView::update_toggle_selection (Glib::ustri for (uint32_t i = 1; i <= n_channels; ++i) { if (!selected) { - iter->set_value (route_cols.get_channel (i).label, Glib::ustring ("")); + iter->set_value (route_cols.get_channel (i).label, std::string ("")); continue; } - iter->set_value (route_cols.get_channel (i).label, Glib::ustring("(none)")); - iter->set_value (route_cols.get_channel (i).port, (AudioPort *) 0); + iter->set_value (route_cols.get_channel (i).label, std::string("(none)")); + iter->set_value (route_cols.get_channel (i).port, boost::weak_ptr ()); Glib::RefPtr port_list = iter->get_value (route_cols.port_list_col); Gtk::ListStore::Children::iterator port_it; @@ -405,8 +420,8 @@ PortExportChannelSelector::ChannelTreeView::update_toggle_selection (Glib::ustri for (port_it = port_list->children().begin(); port_it != port_list->children().end(); ++port_it) { if (port_number == i) { - iter->set_value (route_cols.get_channel (i).label, (Glib::ustring) (*port_it)->get_value (route_cols.port_cols.label)); - iter->set_value (route_cols.get_channel (i).port, (AudioPort *) (*port_it)->get_value (route_cols.port_cols.port)); + iter->set_value (route_cols.get_channel (i).label, (std::string) (*port_it)->get_value (route_cols.port_cols.label)); + iter->set_value (route_cols.get_channel (i).port, (*port_it)->get_value (route_cols.port_cols.port)); } ++port_number; @@ -417,7 +432,7 @@ PortExportChannelSelector::ChannelTreeView::update_toggle_selection (Glib::ustri } void -PortExportChannelSelector::ChannelTreeView::update_selection_text (Glib::ustring const & path, Glib::ustring const & new_text, uint32_t channel) +PortExportChannelSelector::ChannelTreeView::update_selection_text (std::string const & path, std::string const & new_text, uint32_t channel) { Gtk::TreeModel::iterator iter = get_model ()->get_iter (path); iter->set_value (route_cols.get_channel (channel).label, new_text); @@ -426,9 +441,10 @@ PortExportChannelSelector::ChannelTreeView::update_selection_text (Glib::ustring Gtk::ListStore::Children::iterator port_it; for (port_it = port_list->children().begin(); port_it != port_list->children().end(); ++port_it) { - Glib::ustring label = port_it->get_value (route_cols.port_cols.label); + std::string label = port_it->get_value (route_cols.port_cols.label); if (label == new_text) { - iter->set_value (route_cols.get_channel (channel).port, (AudioPort *) (*port_it)[route_cols.port_cols.port]); + boost::weak_ptr w = (*port_it)[route_cols.port_cols.port]; + iter->set_value (route_cols.get_channel (channel).port, w); } } @@ -451,17 +467,21 @@ RegionExportChannelSelector::RegionExportChannelSelector (ARDOUR::Session * _ses { pack_start (vbox); - raw_button.set_label (string_compose (_("Region contents without fades (channels: %1)"), region_chans)); + /* make fades+region gain be the default */ + + fades_button.set_active (); + + raw_button.set_label (string_compose (_("Region contents without fades nor region gain (channels: %1)"), region_chans)); raw_button.signal_toggled ().connect (sigc::mem_fun (*this, &RegionExportChannelSelector::handle_selection)); - vbox.pack_start (raw_button); + vbox.pack_start (raw_button, false, false); - fades_button.set_label (string_compose (_("Region contents with fades (channels: %1)"), region_chans)); + fades_button.set_label (string_compose (_("Region contents with fades and region gain (channels: %1)"), region_chans)); fades_button.signal_toggled ().connect (sigc::mem_fun (*this, &RegionExportChannelSelector::handle_selection)); - vbox.pack_start (fades_button); + vbox.pack_start (fades_button, false, false); processed_button.set_label (string_compose (_("Track output (channels: %1)"), track_chans)); processed_button.signal_toggled ().connect (sigc::mem_fun (*this, &RegionExportChannelSelector::handle_selection)); - vbox.pack_start (processed_button); + vbox.pack_start (processed_button, false, false); sync_with_manager(); vbox.show_all_children (); @@ -472,6 +492,24 @@ void RegionExportChannelSelector::sync_with_manager () { state = manager->get_channel_configs().front(); + + if (!state) { return; } + + switch (state->config->region_processing_type()) { + case RegionExportChannelFactory::None: + // Do nothing + break; + case RegionExportChannelFactory::Raw: + raw_button.set_active (true); + break; + case RegionExportChannelFactory::Fades: + fades_button.set_active (true); + break; + case RegionExportChannelFactory::Processed: + processed_button.set_active (true); + break; + } + handle_selection (); } @@ -484,20 +522,227 @@ RegionExportChannelSelector::handle_selection () state->config->clear_channels (); + RegionExportChannelFactory::Type type = RegionExportChannelFactory::None; if (raw_button.get_active ()) { - factory.reset (new RegionExportChannelFactory (_session, region, track, RegionExportChannelFactory::Raw)); + type = RegionExportChannelFactory::Raw; } else if (fades_button.get_active ()) { - factory.reset (new RegionExportChannelFactory (_session, region, track, RegionExportChannelFactory::Fades)); + type = RegionExportChannelFactory::Fades; } else if (processed_button.get_active ()) { - factory.reset (new RegionExportChannelFactory(_session, region, track, RegionExportChannelFactory::Processed)); + type = RegionExportChannelFactory::Processed; } else { CriticalSelectionChanged (); return; } - for (size_t chan = 0; chan < region_chans; ++chan) { + factory.reset (new RegionExportChannelFactory (_session, region, track, type)); + state->config->set_region_processing_type (type); + + const size_t cc = type == RegionExportChannelFactory::Processed ? track_chans : region_chans; + for (size_t chan = 0; chan < cc; ++chan) { state->config->register_channel (factory->create (chan)); } CriticalSelectionChanged (); } + +/* Track export channel selector */ + +TrackExportChannelSelector::TrackExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager) + : ExportChannelSelector(session, manager) + , track_output_button(_("Apply track/bus processing")) + , select_tracks_button (_("Select all tracks")) + , select_busses_button (_("Select all busses")) + , select_none_button (_("Deselect all")) +{ + pack_start(main_layout); + + // Options + options_box.pack_start(track_output_button); + options_box.pack_start (select_tracks_button); + options_box.pack_start (select_busses_button); + options_box.pack_start (select_none_button); + main_layout.pack_start(options_box, false, false); + + // Track scroller + track_scroller.add (track_view); + track_scroller.set_size_request (-1, 130); + track_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); + main_layout.pack_start(track_scroller); + + // Track list + track_list = Gtk::ListStore::create (track_cols); + track_list->set_sort_column (track_cols.order_key, Gtk::SORT_ASCENDING); + track_view.set_model (track_list); + track_view.set_headers_visible (true); + + track_view.append_column_editable (_("Export"), track_cols.selected); + Gtk::CellRendererToggle *toggle = dynamic_cast(track_view.get_column_cell_renderer (0)); + toggle->set_alignment (0.0, 0.5); + + toggle->signal_toggled().connect (sigc::hide (sigc::mem_fun (*this, &TrackExportChannelSelector::update_config))); + + Gtk::CellRendererText* text_renderer = Gtk::manage (new Gtk::CellRendererText); + text_renderer->property_editable() = false; + text_renderer->set_alignment (0.0, 0.5); + + Gtk::TreeView::Column* column = Gtk::manage (new Gtk::TreeView::Column); + column->set_title (_("Track name")); + + track_view.append_column (*column); + column->pack_start (*text_renderer, false); + column->add_attribute (text_renderer->property_text(), track_cols.label); + + select_tracks_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::select_tracks)); + select_busses_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::select_busses)); + select_none_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::select_none)); + + track_output_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::track_outputs_selected)); + + fill_list(); + + show_all_children (); +} + +void +TrackExportChannelSelector::sync_with_manager () +{ + // TODO implement properly + update_config(); +} + +void +TrackExportChannelSelector::select_tracks () +{ + for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) { + Gtk::TreeModel::Row row = *it; + boost::shared_ptr route = row[track_cols.route]; + if (boost::dynamic_pointer_cast (route)) { + // it's a track + row[track_cols.selected] = true; + } + } + update_config(); +} + +void +TrackExportChannelSelector::select_busses () +{ + for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) { + Gtk::TreeModel::Row row = *it; + boost::shared_ptr route = row[track_cols.route]; + if (!boost::dynamic_pointer_cast (route)) { + // it's not a track, must be a bus + row[track_cols.selected] = true; + } + } + update_config(); +} + +void +TrackExportChannelSelector::select_none () +{ + for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) { + Gtk::TreeModel::Row row = *it; + row[track_cols.selected] = false; + } + update_config(); +} + +void +TrackExportChannelSelector::track_outputs_selected () +{ + update_config(); +} + +void +TrackExportChannelSelector::fill_list() +{ + track_list->clear(); + RouteList routes = *_session->get_routes(); + + for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) { + if (!boost::dynamic_pointer_cast(*it)) { + // not a track, must be a bus + if ((*it)->is_master () || (*it)->is_monitor ()) { + continue; + } + if (!(*it)->active ()) { + // don't include inactive busses + continue; + } + + // not monitor or master bus + add_track (*it); + } + } + for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) { + if (boost::dynamic_pointer_cast(*it)) { + if (!(*it)->active ()) { + // don't include inactive tracks + continue; + } + add_track (*it); + } + } +} + +void +TrackExportChannelSelector::add_track (boost::shared_ptr route) +{ + Gtk::TreeModel::iterator iter = track_list->append(); + Gtk::TreeModel::Row row = *iter; + + row[track_cols.selected] = false; + row[track_cols.label] = route->name(); + row[track_cols.route] = route; + row[track_cols.order_key] = route->presentation_info().order(); +} + +void +TrackExportChannelSelector::update_config() +{ + manager->clear_channel_configs(); + + for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) { + Gtk::TreeModel::Row row = *it; + + if (!row[track_cols.selected]) { + continue; + } + + ExportProfileManager::ChannelConfigStatePtr state; + + boost::shared_ptr route = row[track_cols.route]; + + if (track_output_button.get_active()) { + uint32_t outs = route->n_outputs().n_audio(); + for (uint32_t i = 0; i < outs; ++i) { + boost::shared_ptr port = route->output()->audio (i); + if (port) { + ExportChannelPtr channel (new PortExportChannel ()); + PortExportChannel * pec = static_cast (channel.get()); + pec->add_port(port); + if (!state) { + state = manager->add_channel_config(); + } + state->config->register_channel(channel); + } + } + } else { + std::list list; + RouteExportChannel::create_from_route (list, route); + if (list.size () == 0) { + continue; + } + state = manager->add_channel_config(); + state->config->register_channels (list); + } + + if (state) { + state->config->set_name (route->name()); + } + + } + + CriticalSelectionChanged (); +}