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);
81 time_format_combo.set_name ("PaddedButton");
83 iter = time_format_list->append();
85 row[time_format_cols.format] = ExportProfileManager::Timecode;
86 row[time_format_cols.label] = _("Timecode");
88 iter = time_format_list->append();
90 row[time_format_cols.format] = ExportProfileManager::MinSec;
91 row[time_format_cols.label] = _("Minutes:Seconds");
93 iter = time_format_list->append();
95 row[time_format_cols.format] = ExportProfileManager::BBT;
96 row[time_format_cols.label] = _("Bars:Beats");
98 time_format_combo.pack_start (time_format_cols.label);
99 time_format_combo.set_active (0);
101 time_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportTimespanSelector::change_time_format));
105 range_list = Gtk::ListStore::create (range_cols);
106 // order by location start times
107 range_list->set_sort_column(range_cols.location, Gtk::SORT_ASCENDING);
108 range_list->set_sort_func(range_cols.location, sigc::mem_fun(*this, &ExportTimespanSelector::location_sorter));
109 range_view.set_model (range_list);
110 range_view.set_headers_visible (true);
113 ExportTimespanSelector::~ExportTimespanSelector ()
119 ExportTimespanSelector::location_sorter(Gtk::TreeModel::iterator a, Gtk::TreeModel::iterator b)
121 Location *l1 = (*a)[range_cols.location];
122 Location *l2 = (*b)[range_cols.location];
123 const Location *ls = _session->locations()->session_range_location();
125 // always sort session range first
131 return l1->start() - l2->start();
135 ExportTimespanSelector::add_range_to_selection (ARDOUR::Location const * loc)
137 ExportTimespanPtr span = _session->get_export_handler()->add_timespan();
140 if (loc == state->selection_range.get()) {
143 id = loc->id().to_s();
146 span->set_range (loc->start(), loc->end());
147 span->set_name (loc->name());
148 span->set_range_id (id);
149 state->timespans->push_back (span);
153 ExportTimespanSelector::set_time_format_from_state ()
155 Gtk::TreeModel::Children::iterator tree_it;
156 for (tree_it = time_format_list->children().begin(); tree_it != time_format_list->children().end(); ++tree_it) {
157 if (tree_it->get_value (time_format_cols.format) == state->time_format) {
158 time_format_combo.set_active (tree_it);
164 ExportTimespanSelector::sync_with_manager ()
166 state = manager->get_timespans().front();
168 CriticalSelectionChanged();
172 ExportTimespanSelector::change_time_format ()
174 state->time_format = time_format_combo.get_active()->get_value (time_format_cols.format);
176 for (Gtk::ListStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
177 Location * location = it->get_value (range_cols.location);
178 it->set_value (range_cols.label, construct_label (location));
179 it->set_value (range_cols.length, construct_length (location));
184 ExportTimespanSelector::construct_label (ARDOUR::Location const * location) const
190 framepos_t start_frame = location->start();
191 framepos_t end_frame = location->end();
193 switch (state->time_format) {
194 case AudioClock::BBT:
195 start = bbt_str (start_frame);
196 end = bbt_str (end_frame);
199 case AudioClock::Timecode:
200 start = timecode_str (start_frame);
201 end = timecode_str (end_frame);
204 case AudioClock::MinSec:
205 start = ms_str (start_frame);
206 end = ms_str (end_frame);
209 case AudioClock::Frames:
210 start = to_string (start_frame, std::dec);
211 end = to_string (end_frame, std::dec);
215 // label += _("from ");
217 // label += "<span color=\"#7fff7f\">";
219 // label += "</span>";
223 // label += "<span color=\"#7fff7f\">";
225 // label += "</span>";
231 ExportTimespanSelector::construct_length (ARDOUR::Location const * location) const
233 if (location->length() == 0) {
239 switch (state->time_format) {
240 case AudioClock::BBT:
241 s << bbt_str (location->length ());
244 case AudioClock::Timecode:
247 _session->timecode_duration (location->length(), tc);
252 case AudioClock::MinSec:
253 s << ms_str (location->length ());
256 case AudioClock::Frames:
257 s << location->length ();
266 ExportTimespanSelector::bbt_str (framepos_t frames) const
272 std::ostringstream oss;
273 Timecode::BBT_Time time;
274 _session->bbt_time (frames, time);
276 print_padded (oss, time);
281 ExportTimespanSelector::timecode_str (framecnt_t frames) const
287 std::ostringstream oss;
290 _session->timecode_time (frames, time);
292 oss << std::setfill('0') << std::right <<
296 time.minutes << ":" <<
298 time.seconds << ":" <<
306 ExportTimespanSelector::ms_str (framecnt_t frames) const
312 std::ostringstream oss;
320 hrs = (int) floor (left / (_session->frame_rate() * 60.0f * 60.0f));
321 left -= (framecnt_t) floor (hrs * _session->frame_rate() * 60.0f * 60.0f);
322 mins = (int) floor (left / (_session->frame_rate() * 60.0f));
323 left -= (framecnt_t) floor (mins * _session->frame_rate() * 60.0f);
324 secs = (int) floor (left / (float) _session->frame_rate());
325 left -= (framecnt_t) floor ((double)(secs * _session->frame_rate()));
326 sec_promilles = (int) (left * 1000 / (float) _session->frame_rate() + 0.5);
328 oss << std::setfill('0') << std::right <<
342 ExportTimespanSelector::update_range_name (std::string const & path, std::string const & new_text)
344 Gtk::TreeStore::iterator it = range_list->get_iter (path);
345 it->get_value (range_cols.location)->set_name (new_text);
347 CriticalSelectionChanged();
351 ExportTimespanSelector::set_selection_state_of_all_timespans (bool s)
353 for (Gtk::ListStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
354 it->set_value (range_cols.selected, s);
358 /*** ExportTimespanSelectorSingle ***/
360 ExportTimespanSelectorSingle::ExportTimespanSelectorSingle (ARDOUR::Session * session, ProfileManagerPtr manager, std::string range_id) :
361 ExportTimespanSelector (session, manager),
364 range_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_NEVER);
365 range_view.append_column_editable (_("Range"), range_cols.name);
367 if (Gtk::CellRendererText * renderer = dynamic_cast<Gtk::CellRendererText *> (range_view.get_column_cell_renderer (0))) {
368 renderer->signal_edited().connect (sigc::mem_fun (*this, &ExportTimespanSelectorSingle::update_range_name));
371 Gtk::CellRendererText * label_render = Gtk::manage (new Gtk::CellRendererText());
372 Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column (_("Time Span"), *label_render));
373 label_col->add_attribute (label_render->property_markup(), range_cols.label);
374 range_view.append_column (*label_col);
376 range_view.append_column (_("Length"), range_cols.length);
380 ExportTimespanSelectorSingle::fill_range_list ()
382 if (!state) { return; }
385 if (!range_id.compare (X_("selection"))) {
386 id = state->selection_range->id().to_s();
392 state->timespans->clear();
394 Gtk::TreeModel::iterator iter;
395 Gtk::TreeModel::Row row;
396 for (LocationList::const_iterator it = state->ranges->begin(); it != state->ranges->end(); ++it) {
398 if (!(*it)->id().to_s().compare (id)) {
399 iter = range_list->append();
402 row[range_cols.location] = *it;
403 row[range_cols.selected] = true;
404 row[range_cols.name] = (*it)->name();
405 row[range_cols.label] = construct_label (*it);
406 row[range_cols.length] = construct_length (*it);
408 add_range_to_selection (*it);
414 set_time_format_from_state();
417 /*** ExportTimespanSelectorMultiple ***/
419 ExportTimespanSelectorMultiple::ExportTimespanSelectorMultiple (ARDOUR::Session * session, ProfileManagerPtr manager) :
420 ExportTimespanSelector (session, manager)
422 range_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
423 range_view.append_column_editable ("", range_cols.selected);
424 range_view.append_column_editable (_("Range"), range_cols.name);
426 if (Gtk::CellRendererToggle * renderer = dynamic_cast<Gtk::CellRendererToggle *> (range_view.get_column_cell_renderer (0))) {
427 renderer->signal_toggled().connect (sigc::hide (sigc::mem_fun (*this, &ExportTimespanSelectorMultiple::update_selection)));
429 if (Gtk::CellRendererText * renderer = dynamic_cast<Gtk::CellRendererText *> (range_view.get_column_cell_renderer (1))) {
430 renderer->signal_edited().connect (sigc::mem_fun (*this, &ExportTimespanSelectorMultiple::update_range_name));
433 Gtk::CellRendererText * label_render = Gtk::manage (new Gtk::CellRendererText());
434 Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column (_("Time Span"), *label_render));
435 label_col->add_attribute (label_render->property_markup(), range_cols.label);
436 range_view.append_column (*label_col);
438 range_view.append_column (_("Length"), range_cols.length);
442 ExportTimespanSelectorMultiple::fill_range_list ()
444 if (!state) { return; }
448 Gtk::TreeModel::iterator iter;
449 Gtk::TreeModel::Row row;
450 for (LocationList::const_iterator it = state->ranges->begin(); it != state->ranges->end(); ++it) {
452 iter = range_list->append();
455 row[range_cols.location] = *it;
456 row[range_cols.selected] = false;
457 row[range_cols.name] = (*it)->name();
458 row[range_cols.label] = construct_label (*it);
459 row[range_cols.length] = construct_length (*it);
462 set_selection_from_state ();
466 ExportTimespanSelectorMultiple::set_selection_from_state ()
468 Gtk::TreeModel::Children::iterator tree_it;
470 for (TimespanList::iterator it = state->timespans->begin(); it != state->timespans->end(); ++it) {
471 string id = (*it)->range_id();
472 for (tree_it = range_list->children().begin(); tree_it != range_list->children().end(); ++tree_it) {
473 Location * loc = tree_it->get_value (range_cols.location);
475 if ((id == "selection" && loc == state->selection_range.get()) ||
476 (id == loc->id().to_s())) {
477 tree_it->set_value (range_cols.selected, true);
482 set_time_format_from_state();
486 ExportTimespanSelectorMultiple::update_selection ()
489 CriticalSelectionChanged ();
493 ExportTimespanSelectorMultiple::update_timespans ()
495 state->timespans->clear();
497 for (Gtk::TreeStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
498 if (it->get_value (range_cols.selected)) {
499 add_range_to_selection (it->get_value (range_cols.location));