2 Copyright (C) 2008 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "export_timespan_selector.h"
23 #include "ardour/location.h"
24 #include "ardour/types.h"
25 #include "ardour/session.h"
26 #include "ardour/export_handler.h"
27 #include "ardour/export_timespan.h"
29 #include "pbd/enumwriter.h"
30 #include "pbd/convert.h"
38 using namespace ARDOUR;
42 ExportTimespanSelector::ExportTimespanSelector (ARDOUR::Session * session, ProfileManagerPtr manager) :
44 time_format_label (_("Show Times as:"), Gtk::ALIGN_LEFT)
46 set_session (session);
48 option_hbox.pack_start (time_format_label, false, false, 0);
49 option_hbox.pack_start (time_format_combo, false, false, 6);
51 Gtk::Button* b = Gtk::manage (new Gtk::Button (_("Select All")));
52 b->signal_clicked().connect (
54 sigc::mem_fun (*this, &ExportTimespanSelector::set_selection_state_of_all_timespans), true
57 option_hbox.pack_start (*b, false, false, 6);
59 b = Gtk::manage (new Gtk::Button (_("Deselect All")));
60 b->signal_clicked().connect (
62 sigc::mem_fun (*this, &ExportTimespanSelector::set_selection_state_of_all_timespans), false
65 option_hbox.pack_start (*b, false, false, 6);
67 range_scroller.add (range_view);
69 pack_start (option_hbox, false, false, 0);
70 pack_start (range_scroller, true, true, 6);
74 Gtk::TreeModel::iterator iter;
75 Gtk::TreeModel::Row row;
77 /* Time format combo */
79 time_format_list = Gtk::ListStore::create (time_format_cols);
80 time_format_combo.set_model (time_format_list);
82 iter = time_format_list->append();
84 row[time_format_cols.format] = ExportProfileManager::Timecode;
85 row[time_format_cols.label] = _("Timecode");
87 iter = time_format_list->append();
89 row[time_format_cols.format] = ExportProfileManager::MinSec;
90 row[time_format_cols.label] = _("Minutes:Seconds");
92 iter = time_format_list->append();
94 row[time_format_cols.format] = ExportProfileManager::BBT;
95 row[time_format_cols.label] = _("Bars:Beats");
97 time_format_combo.pack_start (time_format_cols.label);
98 time_format_combo.set_active (0);
100 time_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportTimespanSelector::change_time_format));
104 range_list = Gtk::ListStore::create (range_cols);
105 // order by location start times
106 range_list->set_sort_column(range_cols.location, Gtk::SORT_ASCENDING);
107 range_list->set_sort_func(range_cols.location, sigc::mem_fun(*this, &ExportTimespanSelector::location_sorter));
108 range_view.set_model (range_list);
109 range_view.set_headers_visible (true);
112 ExportTimespanSelector::~ExportTimespanSelector ()
118 ExportTimespanSelector::location_sorter(Gtk::TreeModel::iterator a, Gtk::TreeModel::iterator b)
120 Location *l1 = (*a)[range_cols.location];
121 Location *l2 = (*b)[range_cols.location];
122 const Location *ls = _session->locations()->session_range_location();
124 // always sort session range first
130 return l1->start() - l2->start();
134 ExportTimespanSelector::add_range_to_selection (ARDOUR::Location const * loc)
136 ExportTimespanPtr span = _session->get_export_handler()->add_timespan();
139 if (loc == state->selection_range.get()) {
142 id = loc->id().to_s();
145 span->set_range (loc->start(), loc->end());
146 span->set_name (loc->name());
147 span->set_range_id (id);
148 state->timespans->push_back (span);
152 ExportTimespanSelector::set_time_format_from_state ()
154 Gtk::TreeModel::Children::iterator tree_it;
155 for (tree_it = time_format_list->children().begin(); tree_it != time_format_list->children().end(); ++tree_it) {
156 if (tree_it->get_value (time_format_cols.format) == state->time_format) {
157 time_format_combo.set_active (tree_it);
163 ExportTimespanSelector::sync_with_manager ()
165 state = manager->get_timespans().front();
167 CriticalSelectionChanged();
171 ExportTimespanSelector::change_time_format ()
173 state->time_format = time_format_combo.get_active()->get_value (time_format_cols.format);
175 for (Gtk::ListStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
176 Location * location = it->get_value (range_cols.location);
177 it->set_value (range_cols.label, construct_label (location));
178 it->set_value (range_cols.length, construct_length (location));
183 ExportTimespanSelector::construct_label (ARDOUR::Location const * location) const
189 framepos_t start_frame = location->start();
190 framepos_t end_frame = location->end();
192 switch (state->time_format) {
193 case AudioClock::BBT:
194 start = bbt_str (start_frame);
195 end = bbt_str (end_frame);
198 case AudioClock::Timecode:
199 start = timecode_str (start_frame);
200 end = timecode_str (end_frame);
203 case AudioClock::MinSec:
204 start = ms_str (start_frame);
205 end = ms_str (end_frame);
208 case AudioClock::Frames:
209 start = to_string (start_frame, std::dec);
210 end = to_string (end_frame, std::dec);
214 // label += _("from ");
216 // label += "<span color=\"#7fff7f\">";
218 // label += "</span>";
222 // label += "<span color=\"#7fff7f\">";
224 // label += "</span>";
230 ExportTimespanSelector::construct_length (ARDOUR::Location const * location) const
232 if (location->length() == 0) {
238 switch (state->time_format) {
239 case AudioClock::BBT:
240 s << bbt_str (location->length ());
243 case AudioClock::Timecode:
246 _session->timecode_duration (location->length(), tc);
251 case AudioClock::MinSec:
252 s << ms_str (location->length ());
255 case AudioClock::Frames:
256 s << location->length ();
265 ExportTimespanSelector::bbt_str (framepos_t frames) const
271 std::ostringstream oss;
272 Timecode::BBT_Time time;
273 _session->bbt_time (frames, time);
275 print_padded (oss, time);
280 ExportTimespanSelector::timecode_str (framecnt_t frames) const
286 std::ostringstream oss;
289 _session->timecode_time (frames, time);
291 oss << std::setfill('0') << std::right <<
295 time.minutes << ":" <<
297 time.seconds << ":" <<
305 ExportTimespanSelector::ms_str (framecnt_t frames) const
311 std::ostringstream oss;
319 hrs = (int) floor (left / (_session->frame_rate() * 60.0f * 60.0f));
320 left -= (framecnt_t) floor (hrs * _session->frame_rate() * 60.0f * 60.0f);
321 mins = (int) floor (left / (_session->frame_rate() * 60.0f));
322 left -= (framecnt_t) floor (mins * _session->frame_rate() * 60.0f);
323 secs = (int) floor (left / (float) _session->frame_rate());
324 left -= (framecnt_t) floor ((double)(secs * _session->frame_rate()));
325 sec_promilles = (int) (left * 1000 / (float) _session->frame_rate() + 0.5);
327 oss << std::setfill('0') << std::right <<
341 ExportTimespanSelector::update_range_name (std::string const & path, std::string const & new_text)
343 Gtk::TreeStore::iterator it = range_list->get_iter (path);
344 it->get_value (range_cols.location)->set_name (new_text);
346 CriticalSelectionChanged();
350 ExportTimespanSelector::set_selection_state_of_all_timespans (bool s)
352 for (Gtk::ListStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
353 it->set_value (range_cols.selected, s);
357 /*** ExportTimespanSelectorSingle ***/
359 ExportTimespanSelectorSingle::ExportTimespanSelectorSingle (ARDOUR::Session * session, ProfileManagerPtr manager, std::string range_id) :
360 ExportTimespanSelector (session, manager),
363 range_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_NEVER);
364 range_view.append_column_editable (_("Range"), range_cols.name);
366 if (Gtk::CellRendererText * renderer = dynamic_cast<Gtk::CellRendererText *> (range_view.get_column_cell_renderer (0))) {
367 renderer->signal_edited().connect (sigc::mem_fun (*this, &ExportTimespanSelectorSingle::update_range_name));
370 Gtk::CellRendererText * label_render = Gtk::manage (new Gtk::CellRendererText());
371 Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column (_("Time Span"), *label_render));
372 label_col->add_attribute (label_render->property_markup(), range_cols.label);
373 range_view.append_column (*label_col);
375 range_view.append_column (_("Length"), range_cols.length);
379 ExportTimespanSelectorSingle::fill_range_list ()
381 if (!state) { return; }
384 if (!range_id.compare (X_("selection"))) {
385 id = state->selection_range->id().to_s();
391 state->timespans->clear();
393 Gtk::TreeModel::iterator iter;
394 Gtk::TreeModel::Row row;
395 for (LocationList::const_iterator it = state->ranges->begin(); it != state->ranges->end(); ++it) {
397 if (!(*it)->id().to_s().compare (id)) {
398 iter = range_list->append();
401 row[range_cols.location] = *it;
402 row[range_cols.selected] = true;
403 row[range_cols.name] = (*it)->name();
404 row[range_cols.label] = construct_label (*it);
405 row[range_cols.length] = construct_length (*it);
407 add_range_to_selection (*it);
413 set_time_format_from_state();
416 /*** ExportTimespanSelectorMultiple ***/
418 ExportTimespanSelectorMultiple::ExportTimespanSelectorMultiple (ARDOUR::Session * session, ProfileManagerPtr manager) :
419 ExportTimespanSelector (session, manager)
421 range_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
422 range_view.append_column_editable ("", range_cols.selected);
423 range_view.append_column_editable (_("Range"), range_cols.name);
425 if (Gtk::CellRendererToggle * renderer = dynamic_cast<Gtk::CellRendererToggle *> (range_view.get_column_cell_renderer (0))) {
426 renderer->signal_toggled().connect (sigc::hide (sigc::mem_fun (*this, &ExportTimespanSelectorMultiple::update_selection)));
428 if (Gtk::CellRendererText * renderer = dynamic_cast<Gtk::CellRendererText *> (range_view.get_column_cell_renderer (1))) {
429 renderer->signal_edited().connect (sigc::mem_fun (*this, &ExportTimespanSelectorMultiple::update_range_name));
432 Gtk::CellRendererText * label_render = Gtk::manage (new Gtk::CellRendererText());
433 Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column (_("Time Span"), *label_render));
434 label_col->add_attribute (label_render->property_markup(), range_cols.label);
435 range_view.append_column (*label_col);
437 range_view.append_column (_("Length"), range_cols.length);
441 ExportTimespanSelectorMultiple::fill_range_list ()
443 if (!state) { return; }
447 Gtk::TreeModel::iterator iter;
448 Gtk::TreeModel::Row row;
449 for (LocationList::const_iterator it = state->ranges->begin(); it != state->ranges->end(); ++it) {
451 iter = range_list->append();
454 row[range_cols.location] = *it;
455 row[range_cols.selected] = false;
456 row[range_cols.name] = (*it)->name();
457 row[range_cols.label] = construct_label (*it);
458 row[range_cols.length] = construct_length (*it);
461 set_selection_from_state ();
465 ExportTimespanSelectorMultiple::set_selection_from_state ()
467 Gtk::TreeModel::Children::iterator tree_it;
469 for (TimespanList::iterator it = state->timespans->begin(); it != state->timespans->end(); ++it) {
470 string id = (*it)->range_id();
471 for (tree_it = range_list->children().begin(); tree_it != range_list->children().end(); ++tree_it) {
472 Location * loc = tree_it->get_value (range_cols.location);
474 if ((id == "selection" && loc == state->selection_range.get()) ||
475 (id == loc->id().to_s())) {
476 tree_it->set_value (range_cols.selected, true);
481 set_time_format_from_state();
485 ExportTimespanSelectorMultiple::update_selection ()
488 CriticalSelectionChanged ();
492 ExportTimespanSelectorMultiple::update_timespans ()
494 state->timespans->clear();
496 for (Gtk::TreeStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
497 if (it->get_value (range_cols.selected)) {
498 add_range_to_selection (it->get_value (range_cols.location));