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_ui.h"
25 #include "ardour/location.h"
26 #include "ardour/types.h"
27 #include "ardour/session.h"
28 #include "ardour/export_handler.h"
29 #include "ardour/export_timespan.h"
31 #include "pbd/enumwriter.h"
32 #include "pbd/convert.h"
40 using namespace ARDOUR;
44 ExportTimespanSelector::ExportTimespanSelector (ARDOUR::Session * session, ProfileManagerPtr manager) :
46 time_format_label (_("Show Times as:"), Gtk::ALIGN_LEFT)
48 set_session (session);
50 option_hbox.pack_start (time_format_label, false, false, 0);
51 option_hbox.pack_start (time_format_combo, false, false, 6);
53 Gtk::Button* b = Gtk::manage (new Gtk::Button (_("Select All")));
54 b->signal_clicked().connect (
56 sigc::mem_fun (*this, &ExportTimespanSelector::set_selection_state_of_all_timespans), true
59 option_hbox.pack_start (*b, false, false, 6);
61 b = Gtk::manage (new Gtk::Button (_("Deselect All")));
62 b->signal_clicked().connect (
64 sigc::mem_fun (*this, &ExportTimespanSelector::set_selection_state_of_all_timespans), false
67 option_hbox.pack_start (*b, false, false, 6);
69 range_scroller.add (range_view);
71 pack_start (option_hbox, false, false, 0);
72 pack_start (range_scroller, true, true, 6);
76 Gtk::TreeModel::iterator iter;
77 Gtk::TreeModel::Row row;
79 /* Time format combo */
81 time_format_list = Gtk::ListStore::create (time_format_cols);
82 time_format_combo.set_model (time_format_list);
83 time_format_combo.set_name ("PaddedButton");
85 iter = time_format_list->append();
87 row[time_format_cols.format] = ExportProfileManager::Timecode;
88 row[time_format_cols.label] = _("Timecode");
90 iter = time_format_list->append();
92 row[time_format_cols.format] = ExportProfileManager::MinSec;
93 row[time_format_cols.label] = _("Minutes:Seconds");
95 iter = time_format_list->append();
97 row[time_format_cols.format] = ExportProfileManager::BBT;
98 row[time_format_cols.label] = _("Bars:Beats");
100 time_format_combo.pack_start (time_format_cols.label);
101 time_format_combo.set_active (0);
103 time_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportTimespanSelector::change_time_format));
107 range_list = Gtk::ListStore::create (range_cols);
108 // order by location start times
109 range_list->set_sort_column(range_cols.location, Gtk::SORT_ASCENDING);
110 range_list->set_sort_func(range_cols.location, sigc::mem_fun(*this, &ExportTimespanSelector::location_sorter));
111 range_view.set_model (range_list);
112 range_view.set_headers_visible (true);
115 ExportTimespanSelector::~ExportTimespanSelector ()
121 ExportTimespanSelector::location_sorter(Gtk::TreeModel::iterator a, Gtk::TreeModel::iterator b)
123 Location *l1 = (*a)[range_cols.location];
124 Location *l2 = (*b)[range_cols.location];
125 const Location *ls = _session->locations()->session_range_location();
127 // always sort session range first
133 return l1->start() - l2->start();
137 ExportTimespanSelector::add_range_to_selection (ARDOUR::Location const * loc)
139 ExportTimespanPtr span = _session->get_export_handler()->add_timespan();
142 if (loc == state->selection_range.get()) {
145 id = loc->id().to_s();
148 span->set_range (loc->start(), loc->end());
149 span->set_name (loc->name());
150 span->set_range_id (id);
151 state->timespans->push_back (span);
155 ExportTimespanSelector::set_time_format_from_state ()
157 Gtk::TreeModel::Children::iterator tree_it;
158 for (tree_it = time_format_list->children().begin(); tree_it != time_format_list->children().end(); ++tree_it) {
159 if (tree_it->get_value (time_format_cols.format) == state->time_format) {
160 time_format_combo.set_active (tree_it);
166 ExportTimespanSelector::sync_with_manager ()
168 state = manager->get_timespans().front();
170 CriticalSelectionChanged();
174 ExportTimespanSelector::change_time_format ()
176 state->time_format = time_format_combo.get_active()->get_value (time_format_cols.format);
178 for (Gtk::ListStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
179 Location * location = it->get_value (range_cols.location);
180 it->set_value (range_cols.label, construct_label (location));
181 it->set_value (range_cols.length, construct_length (location));
186 ExportTimespanSelector::construct_label (ARDOUR::Location const * location) const
192 framepos_t start_frame = location->start();
193 framepos_t end_frame = location->end();
195 switch (state->time_format) {
196 case AudioClock::BBT:
197 start = bbt_str (start_frame);
198 end = bbt_str (end_frame);
201 case AudioClock::Timecode:
202 start = timecode_str (start_frame);
203 end = timecode_str (end_frame);
206 case AudioClock::MinSec:
207 start = ms_str (start_frame);
208 end = ms_str (end_frame);
211 case AudioClock::Frames:
212 start = to_string (start_frame, std::dec);
213 end = to_string (end_frame, std::dec);
217 // label += _("from ");
219 // label += "<span color=\"#7fff7f\">";
221 // label += "</span>";
225 // label += "<span color=\"#7fff7f\">";
227 // label += "</span>";
233 ExportTimespanSelector::construct_length (ARDOUR::Location const * location) const
235 if (location->length() == 0) {
241 switch (state->time_format) {
242 case AudioClock::BBT:
243 s << bbt_str (location->length ());
246 case AudioClock::Timecode:
249 _session->timecode_duration (location->length(), tc);
254 case AudioClock::MinSec:
255 s << ms_str (location->length ());
258 case AudioClock::Frames:
259 s << location->length ();
268 ExportTimespanSelector::bbt_str (framepos_t frames) const
274 std::ostringstream oss;
275 Timecode::BBT_Time time;
276 _session->bbt_time (frames, time);
278 print_padded (oss, time);
283 ExportTimespanSelector::timecode_str (framecnt_t frames) const
289 std::ostringstream oss;
292 _session->timecode_time (frames, time);
294 oss << std::setfill('0') << std::right <<
298 time.minutes << ":" <<
300 time.seconds << ":" <<
308 ExportTimespanSelector::ms_str (framecnt_t frames) const
314 std::ostringstream oss;
322 hrs = (int) floor (left / (_session->frame_rate() * 60.0f * 60.0f));
323 left -= (framecnt_t) floor (hrs * _session->frame_rate() * 60.0f * 60.0f);
324 mins = (int) floor (left / (_session->frame_rate() * 60.0f));
325 left -= (framecnt_t) floor (mins * _session->frame_rate() * 60.0f);
326 secs = (int) floor (left / (float) _session->frame_rate());
327 left -= (framecnt_t) floor ((double)(secs * _session->frame_rate()));
328 sec_promilles = (int) (left * 1000 / (float) _session->frame_rate() + 0.5);
330 oss << std::setfill('0') << std::right <<
344 ExportTimespanSelector::update_range_name (std::string const & path, std::string const & new_text)
346 Gtk::TreeStore::iterator it = range_list->get_iter (path);
347 it->get_value (range_cols.location)->set_name (new_text);
349 CriticalSelectionChanged();
353 ExportTimespanSelector::set_selection_state_of_all_timespans (bool s)
355 for (Gtk::ListStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
356 it->set_value (range_cols.selected, s);
360 /*** ExportTimespanSelectorSingle ***/
362 ExportTimespanSelectorSingle::ExportTimespanSelectorSingle (ARDOUR::Session * session, ProfileManagerPtr manager, std::string range_id) :
363 ExportTimespanSelector (session, manager),
366 range_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_NEVER);
367 range_view.append_column_editable (_("Range"), range_cols.name);
369 if (Gtk::CellRendererText * renderer = dynamic_cast<Gtk::CellRendererText *> (range_view.get_column_cell_renderer (0))) {
370 renderer->signal_edited().connect (sigc::mem_fun (*this, &ExportTimespanSelectorSingle::update_range_name));
373 Gtk::CellRendererText * label_render = Gtk::manage (new Gtk::CellRendererText());
374 Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column (_("Time Span"), *label_render));
375 label_col->add_attribute (label_render->property_markup(), range_cols.label);
376 range_view.append_column (*label_col);
378 range_view.append_column (_("Length"), range_cols.length);
382 ExportTimespanSelectorSingle::fill_range_list ()
384 if (!state) { return; }
387 if (!range_id.compare (X_("selection"))) {
388 id = state->selection_range->id().to_s();
394 state->timespans->clear();
396 Gtk::TreeModel::iterator iter;
397 Gtk::TreeModel::Row row;
398 for (LocationList::const_iterator it = state->ranges->begin(); it != state->ranges->end(); ++it) {
400 if (!(*it)->id().to_s().compare (id)) {
401 iter = range_list->append();
404 row[range_cols.location] = *it;
405 row[range_cols.selected] = true;
406 row[range_cols.name] = (*it)->name();
407 row[range_cols.label] = construct_label (*it);
408 row[range_cols.length] = construct_length (*it);
410 add_range_to_selection (*it);
416 set_time_format_from_state();
419 /*** ExportTimespanSelectorMultiple ***/
421 ExportTimespanSelectorMultiple::ExportTimespanSelectorMultiple (ARDOUR::Session * session, ProfileManagerPtr manager) :
422 ExportTimespanSelector (session, manager)
424 range_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
425 range_view.append_column_editable ("", range_cols.selected);
426 range_view.append_column_editable (_("Range"), range_cols.name);
428 if (Gtk::CellRendererToggle * renderer = dynamic_cast<Gtk::CellRendererToggle *> (range_view.get_column_cell_renderer (0))) {
429 renderer->signal_toggled().connect (sigc::hide (sigc::mem_fun (*this, &ExportTimespanSelectorMultiple::update_selection)));
431 if (Gtk::CellRendererText * renderer = dynamic_cast<Gtk::CellRendererText *> (range_view.get_column_cell_renderer (1))) {
432 renderer->signal_edited().connect (sigc::mem_fun (*this, &ExportTimespanSelectorMultiple::update_range_name));
435 Gtk::CellRendererText * label_render = Gtk::manage (new Gtk::CellRendererText());
436 Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column (_("Time Span"), *label_render));
437 label_col->add_attribute (label_render->property_markup(), range_cols.label);
438 range_view.append_column (*label_col);
440 range_view.append_column (_("Length"), range_cols.length);
444 ExportTimespanSelectorMultiple::fill_range_list ()
446 if (!state) { return; }
450 Gtk::TreeModel::iterator iter;
451 Gtk::TreeModel::Row row;
452 for (LocationList::const_iterator it = state->ranges->begin(); it != state->ranges->end(); ++it) {
454 iter = range_list->append();
457 row[range_cols.location] = *it;
458 row[range_cols.selected] = false;
459 row[range_cols.name] = (*it)->name();
460 row[range_cols.label] = construct_label (*it);
461 row[range_cols.length] = construct_length (*it);
464 set_selection_from_state ();
468 ExportTimespanSelectorMultiple::set_selection_from_state ()
470 Gtk::TreeModel::Children::iterator tree_it;
472 for (TimespanList::iterator it = state->timespans->begin(); it != state->timespans->end(); ++it) {
473 string id = (*it)->range_id();
474 for (tree_it = range_list->children().begin(); tree_it != range_list->children().end(); ++tree_it) {
475 Location * loc = tree_it->get_value (range_cols.location);
477 if ((id == "selection" && loc == state->selection_range.get()) ||
478 (id == loc->id().to_s())) {
479 tree_it->set_value (range_cols.selected, true);
484 set_time_format_from_state();
488 ExportTimespanSelectorMultiple::update_selection ()
491 CriticalSelectionChanged ();
495 ExportTimespanSelectorMultiple::update_timespans ()
497 state->timespans->clear();
499 for (Gtk::TreeStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
500 if (it->get_value (range_cols.selected)) {
501 add_range_to_selection (it->get_value (range_cols.location));