canvas HSV color serialization needs LocaleGuard
[ardour.git] / gtk2_ardour / export_timespan_selector.cc
index 9f39fa556cc182f1585c993563e39253f1bd894f..9a294aff1baa35312b962778d39074a894a08b68 100644 (file)
@@ -20,8 +20,6 @@
 
 #include "export_timespan_selector.h"
 
-#include "ardour_ui.h"
-
 #include "ardour/location.h"
 #include "ardour/types.h"
 #include "ardour/session.h"
@@ -39,6 +37,7 @@
 using namespace Glib;
 using namespace ARDOUR;
 using namespace PBD;
+using std::string;
 
 ExportTimespanSelector::ExportTimespanSelector (ARDOUR::Session * session, ProfileManagerPtr manager) :
        manager (manager),
@@ -49,6 +48,22 @@ ExportTimespanSelector::ExportTimespanSelector (ARDOUR::Session * session, Profi
        option_hbox.pack_start (time_format_label, false, false, 0);
        option_hbox.pack_start (time_format_combo, false, false, 6);
 
+       Gtk::Button* b = Gtk::manage (new Gtk::Button (_("Select All")));
+       b->signal_clicked().connect (
+               sigc::bind (
+                       sigc::mem_fun (*this, &ExportTimespanSelector::set_selection_state_of_all_timespans), true
+                       )
+               );
+       option_hbox.pack_start (*b, false, false, 6);
+
+       b = Gtk::manage (new Gtk::Button (_("Deselect All")));
+       b->signal_clicked().connect (
+               sigc::bind (
+                       sigc::mem_fun (*this, &ExportTimespanSelector::set_selection_state_of_all_timespans), false
+                       )
+               );
+       option_hbox.pack_start (*b, false, false, 6);
+
        range_scroller.add (range_view);
 
        pack_start (option_hbox, false, false, 0);
@@ -63,12 +78,11 @@ ExportTimespanSelector::ExportTimespanSelector (ARDOUR::Session * session, Profi
 
        time_format_list = Gtk::ListStore::create (time_format_cols);
        time_format_combo.set_model (time_format_list);
-       time_format_combo.set_name ("PaddedButton");
 
        iter = time_format_list->append();
        row = *iter;
        row[time_format_cols.format] = ExportProfileManager::Timecode;
-       row[time_format_cols.label] = X_("Timecode");
+       row[time_format_cols.label] = _("Timecode");
 
        iter = time_format_list->append();
        row = *iter;
@@ -88,8 +102,11 @@ ExportTimespanSelector::ExportTimespanSelector (ARDOUR::Session * session, Profi
        /* Range view */
 
        range_list = Gtk::ListStore::create (range_cols);
+       // order by location start times
+       range_list->set_sort_column(range_cols.location, Gtk::SORT_ASCENDING);
+       range_list->set_sort_func(range_cols.location, sigc::mem_fun(*this, &ExportTimespanSelector::location_sorter));
        range_view.set_model (range_list);
-       range_view.set_headers_visible (false);
+       range_view.set_headers_visible (true);
 }
 
 ExportTimespanSelector::~ExportTimespanSelector ()
@@ -97,15 +114,29 @@ ExportTimespanSelector::~ExportTimespanSelector ()
 
 }
 
+int
+ExportTimespanSelector::location_sorter(Gtk::TreeModel::iterator a, Gtk::TreeModel::iterator b)
+{
+       Location *l1 = (*a)[range_cols.location];
+       Location *l2 = (*b)[range_cols.location];
+       const Location *ls = _session->locations()->session_range_location();
+
+       // always sort session range first
+       if (l1 == ls)
+               return -1;
+       if (l2 == ls)
+               return +1;
+
+       return l1->start() - l2->start();
+}
+
 void
 ExportTimespanSelector::add_range_to_selection (ARDOUR::Location const * loc)
 {
-       TimespanPtr span = _session->get_export_handler()->add_timespan();
+       ExportTimespanPtr span = _session->get_export_handler()->add_timespan();
 
-       Glib::ustring id;
-       if (loc == state->session_range.get()) {
-               id = "session";
-       } else if (loc == state->selection_range.get()) {
+       std::string id;
+       if (loc == state->selection_range.get()) {
                id = "selection";
        } else {
                id = loc->id().to_s();
@@ -144,18 +175,19 @@ ExportTimespanSelector::change_time_format ()
        for (Gtk::ListStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
                Location * location = it->get_value (range_cols.location);
                it->set_value (range_cols.label, construct_label (location));
+               it->set_value (range_cols.length, construct_length (location));
        }
 }
 
-Glib::ustring
+std::string
 ExportTimespanSelector::construct_label (ARDOUR::Location const * location) const
 {
-       Glib::ustring label;
-       Glib::ustring start;
-       Glib::ustring end;
+       std::string label;
+       std::string start;
+       std::string end;
 
-       nframes_t start_frame = location->start();
-       nframes_t end_frame = location->end();
+       framepos_t start_frame = location->start();
+       framepos_t end_frame = location->end();
 
        switch (state->time_format) {
          case AudioClock::BBT:
@@ -177,9 +209,6 @@ ExportTimespanSelector::construct_label (ARDOUR::Location const * location) cons
                start = to_string (start_frame, std::dec);
                end = to_string (end_frame, std::dec);
                break;
-
-         case AudioClock::Off:
-               break;
        }
 
        // label += _("from ");
@@ -197,32 +226,58 @@ ExportTimespanSelector::construct_label (ARDOUR::Location const * location) cons
        return label;
 }
 
+std::string
+ExportTimespanSelector::construct_length (ARDOUR::Location const * location) const
+{
+       if (location->length() == 0) {
+               return "";
+       }
+
+       std::stringstream s;
+
+       switch (state->time_format) {
+       case AudioClock::BBT:
+               s << bbt_str (location->length ());
+               break;
+
+       case AudioClock::Timecode:
+       {
+               Timecode::Time tc;
+               _session->timecode_duration (location->length(), tc);
+               tc.print (s);
+               break;
+       }
+
+       case AudioClock::MinSec:
+               s << ms_str (location->length ());
+               break;
 
-Glib::ustring
-ExportTimespanSelector::bbt_str (nframes_t frames) const
+       case AudioClock::Frames:
+               s << location->length ();
+               break;
+       }
+
+       return s.str ();
+}
+
+
+std::string
+ExportTimespanSelector::bbt_str (framepos_t frames) const
 {
        if (!_session) {
                return "Error!";
        }
 
        std::ostringstream oss;
-       BBT_Time time;
-
+       Timecode::BBT_Time time;
        _session->bbt_time (frames, time);
 
-       oss << std::setfill('0') << std::right <<
-         std::setw(3) <<
-         time.bars << "|" <<
-         std::setw(2) <<
-         time.beats << "|" <<
-         std::setw(4) <<
-         time.ticks;
-
-       return oss.str();
+       print_padded (oss, time);
+       return oss.str ();
 }
 
-Glib::ustring
-ExportTimespanSelector::timecode_str (nframes_t frames) const
+std::string
+ExportTimespanSelector::timecode_str (framecnt_t frames) const
 {
        if (!_session) {
                return "Error!";
@@ -246,15 +301,15 @@ ExportTimespanSelector::timecode_str (nframes_t frames) const
        return oss.str();
 }
 
-Glib::ustring
-ExportTimespanSelector::ms_str (nframes_t frames) const
+std::string
+ExportTimespanSelector::ms_str (framecnt_t frames) const
 {
        if (!_session) {
                return "Error!";
        }
 
        std::ostringstream oss;
-       nframes_t left;
+       framecnt_t left;
        int hrs;
        int mins;
        int secs;
@@ -262,11 +317,11 @@ ExportTimespanSelector::ms_str (nframes_t frames) const
 
        left = frames;
        hrs = (int) floor (left / (_session->frame_rate() * 60.0f * 60.0f));
-       left -= (nframes_t) floor (hrs * _session->frame_rate() * 60.0f * 60.0f);
+       left -= (framecnt_t) floor (hrs * _session->frame_rate() * 60.0f * 60.0f);
        mins = (int) floor (left / (_session->frame_rate() * 60.0f));
-       left -= (nframes_t) floor (mins * _session->frame_rate() * 60.0f);
+       left -= (framecnt_t) floor (mins * _session->frame_rate() * 60.0f);
        secs = (int) floor (left / (float) _session->frame_rate());
-       left -= (nframes_t) floor (secs * _session->frame_rate());
+       left -= (framecnt_t) floor ((double)(secs * _session->frame_rate()));
        sec_promilles = (int) (left * 1000 / (float) _session->frame_rate() + 0.5);
 
        oss << std::setfill('0') << std::right <<
@@ -283,7 +338,7 @@ ExportTimespanSelector::ms_str (nframes_t frames) const
 }
 
 void
-ExportTimespanSelector::update_range_name (Glib::ustring const & path, Glib::ustring const & new_text)
+ExportTimespanSelector::update_range_name (std::string const & path, std::string const & new_text)
 {
        Gtk::TreeStore::iterator it = range_list->get_iter (path);
        it->get_value (range_cols.location)->set_name (new_text);
@@ -291,30 +346,33 @@ ExportTimespanSelector::update_range_name (Glib::ustring const & path, Glib::ust
        CriticalSelectionChanged();
 }
 
+void
+ExportTimespanSelector::set_selection_state_of_all_timespans (bool s)
+{
+       for (Gtk::ListStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
+               it->set_value (range_cols.selected, s);
+       }
+}
+
 /*** ExportTimespanSelectorSingle ***/
 
-ExportTimespanSelectorSingle::ExportTimespanSelectorSingle (ARDOUR::Session * session, ProfileManagerPtr manager, Glib::ustring range_id) :
+ExportTimespanSelectorSingle::ExportTimespanSelectorSingle (ARDOUR::Session * session, ProfileManagerPtr manager, std::string range_id) :
        ExportTimespanSelector (session, manager),
        range_id (range_id)
 {
        range_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_NEVER);
-       range_view.append_column_editable ("", range_cols.name);
-
-       // Adjust selector height
-       int x_offset, y_offset, width, height;
-       Gtk::CellRenderer * renderer = *range_view.get_column(0)->get_cell_renderers().begin();
-       renderer->get_size (range_view, x_offset, y_offset, width, height);
-       range_scroller.set_size_request (-1, height);
+       range_view.append_column_editable (_("Range"), range_cols.name);
 
        if (Gtk::CellRendererText * renderer = dynamic_cast<Gtk::CellRendererText *> (range_view.get_column_cell_renderer (0))) {
                renderer->signal_edited().connect (sigc::mem_fun (*this, &ExportTimespanSelectorSingle::update_range_name));
        }
 
        Gtk::CellRendererText * label_render = Gtk::manage (new Gtk::CellRendererText());
-       Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column ("", *label_render));
+       Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column (_("Time Span"), *label_render));
        label_col->add_attribute (label_render->property_markup(), range_cols.label);
        range_view.append_column (*label_col);
 
+       range_view.append_column (_("Length"), range_cols.length);
 }
 
 void
@@ -322,10 +380,8 @@ ExportTimespanSelectorSingle::fill_range_list ()
 {
        if (!state) { return; }
 
-       Glib::ustring id;
-       if (!range_id.compare (X_("session"))) {
-               id = state->session_range->id().to_s();
-       } else if (!range_id.compare (X_("selection"))) {
+       std::string id;
+       if (!range_id.compare (X_("selection"))) {
                id = state->selection_range->id().to_s();
        } else {
                id = range_id;
@@ -346,6 +402,7 @@ ExportTimespanSelectorSingle::fill_range_list ()
                        row[range_cols.selected] = true;
                        row[range_cols.name] = (*it)->name();
                        row[range_cols.label] = construct_label (*it);
+                       row[range_cols.length] = construct_length (*it);
 
                        add_range_to_selection (*it);
 
@@ -363,7 +420,7 @@ ExportTimespanSelectorMultiple::ExportTimespanSelectorMultiple (ARDOUR::Session
 {
        range_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
        range_view.append_column_editable ("", range_cols.selected);
-       range_view.append_column_editable ("", range_cols.name);
+       range_view.append_column_editable (_("Range"), range_cols.name);
 
        if (Gtk::CellRendererToggle * renderer = dynamic_cast<Gtk::CellRendererToggle *> (range_view.get_column_cell_renderer (0))) {
                renderer->signal_toggled().connect (sigc::hide (sigc::mem_fun (*this, &ExportTimespanSelectorMultiple::update_selection)));
@@ -373,10 +430,11 @@ ExportTimespanSelectorMultiple::ExportTimespanSelectorMultiple (ARDOUR::Session
        }
 
        Gtk::CellRendererText * label_render = Gtk::manage (new Gtk::CellRendererText());
-       Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column ("", *label_render));
+       Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column (_("Time Span"), *label_render));
        label_col->add_attribute (label_render->property_markup(), range_cols.label);
        range_view.append_column (*label_col);
 
+       range_view.append_column (_("Length"), range_cols.length);
 }
 
 void
@@ -397,6 +455,7 @@ ExportTimespanSelectorMultiple::fill_range_list ()
                row[range_cols.selected] = false;
                row[range_cols.name] = (*it)->name();
                row[range_cols.label] = construct_label (*it);
+               row[range_cols.length] = construct_length (*it);
        }
 
        set_selection_from_state ();
@@ -408,13 +467,12 @@ ExportTimespanSelectorMultiple::set_selection_from_state ()
        Gtk::TreeModel::Children::iterator tree_it;
 
        for (TimespanList::iterator it = state->timespans->begin(); it != state->timespans->end(); ++it) {
-               ustring id = (*it)->range_id();
+               string id = (*it)->range_id();
                for (tree_it = range_list->children().begin(); tree_it != range_list->children().end(); ++tree_it) {
                        Location * loc = tree_it->get_value (range_cols.location);
 
-                       if ((!id.compare ("session") && loc == state->session_range.get()) ||
-                           (!id.compare ("selection") && loc == state->selection_range.get()) ||
-                           (!id.compare (loc->id().to_s()))) {
+                       if ((id == "selection" && loc == state->selection_range.get()) ||
+                           (id == loc->id().to_s())) {
                                tree_it->set_value (range_cols.selected, true);
                        }
                }