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 range_view.set_model (range_list);
109 range_view.set_headers_visible (true);
112 ExportTimespanSelector::~ExportTimespanSelector ()
118 ExportTimespanSelector::add_range_to_selection (ARDOUR::Location const * loc)
120 ExportTimespanPtr span = _session->get_export_handler()->add_timespan();
123 if (loc == state->selection_range.get()) {
126 id = loc->id().to_s();
129 span->set_range (loc->start(), loc->end());
130 span->set_name (loc->name());
131 span->set_range_id (id);
132 state->timespans->push_back (span);
136 ExportTimespanSelector::set_time_format_from_state ()
138 Gtk::TreeModel::Children::iterator tree_it;
139 for (tree_it = time_format_list->children().begin(); tree_it != time_format_list->children().end(); ++tree_it) {
140 if (tree_it->get_value (time_format_cols.format) == state->time_format) {
141 time_format_combo.set_active (tree_it);
147 ExportTimespanSelector::sync_with_manager ()
149 state = manager->get_timespans().front();
151 CriticalSelectionChanged();
155 ExportTimespanSelector::change_time_format ()
157 state->time_format = time_format_combo.get_active()->get_value (time_format_cols.format);
159 for (Gtk::ListStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
160 Location * location = it->get_value (range_cols.location);
161 it->set_value (range_cols.label, construct_label (location));
162 it->set_value (range_cols.length, construct_length (location));
167 ExportTimespanSelector::construct_label (ARDOUR::Location const * location) const
173 framepos_t start_frame = location->start();
174 framepos_t end_frame = location->end();
176 switch (state->time_format) {
177 case AudioClock::BBT:
178 start = bbt_str (start_frame);
179 end = bbt_str (end_frame);
182 case AudioClock::Timecode:
183 start = timecode_str (start_frame);
184 end = timecode_str (end_frame);
187 case AudioClock::MinSec:
188 start = ms_str (start_frame);
189 end = ms_str (end_frame);
192 case AudioClock::Frames:
193 start = to_string (start_frame, std::dec);
194 end = to_string (end_frame, std::dec);
198 // label += _("from ");
200 // label += "<span color=\"#7fff7f\">";
202 // label += "</span>";
206 // label += "<span color=\"#7fff7f\">";
208 // label += "</span>";
214 ExportTimespanSelector::construct_length (ARDOUR::Location const * location) const
216 if (location->length() == 0) {
222 switch (state->time_format) {
223 case AudioClock::BBT:
224 s << bbt_str (location->length ());
227 case AudioClock::Timecode:
230 _session->timecode_duration (location->length(), tc);
235 case AudioClock::MinSec:
236 s << ms_str (location->length ());
239 case AudioClock::Frames:
240 s << location->length ();
249 ExportTimespanSelector::bbt_str (framepos_t frames) const
255 std::ostringstream oss;
256 Timecode::BBT_Time time;
257 _session->bbt_time (frames, time);
259 print_padded (oss, time);
264 ExportTimespanSelector::timecode_str (framecnt_t frames) const
270 std::ostringstream oss;
273 _session->timecode_time (frames, time);
275 oss << std::setfill('0') << std::right <<
279 time.minutes << ":" <<
281 time.seconds << ":" <<
289 ExportTimespanSelector::ms_str (framecnt_t frames) const
295 std::ostringstream oss;
303 hrs = (int) floor (left / (_session->frame_rate() * 60.0f * 60.0f));
304 left -= (framecnt_t) floor (hrs * _session->frame_rate() * 60.0f * 60.0f);
305 mins = (int) floor (left / (_session->frame_rate() * 60.0f));
306 left -= (framecnt_t) floor (mins * _session->frame_rate() * 60.0f);
307 secs = (int) floor (left / (float) _session->frame_rate());
308 left -= (framecnt_t) floor ((double)(secs * _session->frame_rate()));
309 sec_promilles = (int) (left * 1000 / (float) _session->frame_rate() + 0.5);
311 oss << std::setfill('0') << std::right <<
325 ExportTimespanSelector::update_range_name (std::string const & path, std::string const & new_text)
327 Gtk::TreeStore::iterator it = range_list->get_iter (path);
328 it->get_value (range_cols.location)->set_name (new_text);
330 CriticalSelectionChanged();
334 ExportTimespanSelector::set_selection_state_of_all_timespans (bool s)
336 for (Gtk::ListStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
337 it->set_value (range_cols.selected, s);
341 /*** ExportTimespanSelectorSingle ***/
343 ExportTimespanSelectorSingle::ExportTimespanSelectorSingle (ARDOUR::Session * session, ProfileManagerPtr manager, std::string range_id) :
344 ExportTimespanSelector (session, manager),
347 range_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_NEVER);
348 range_view.append_column_editable (_("Range"), range_cols.name);
350 if (Gtk::CellRendererText * renderer = dynamic_cast<Gtk::CellRendererText *> (range_view.get_column_cell_renderer (0))) {
351 renderer->signal_edited().connect (sigc::mem_fun (*this, &ExportTimespanSelectorSingle::update_range_name));
354 Gtk::CellRendererText * label_render = Gtk::manage (new Gtk::CellRendererText());
355 Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column (_("Time Span"), *label_render));
356 label_col->add_attribute (label_render->property_markup(), range_cols.label);
357 range_view.append_column (*label_col);
359 range_view.append_column (_("Length"), range_cols.length);
363 ExportTimespanSelectorSingle::fill_range_list ()
365 if (!state) { return; }
368 if (!range_id.compare (X_("selection"))) {
369 id = state->selection_range->id().to_s();
375 state->timespans->clear();
377 Gtk::TreeModel::iterator iter;
378 Gtk::TreeModel::Row row;
379 for (LocationList::const_iterator it = state->ranges->begin(); it != state->ranges->end(); ++it) {
381 if (!(*it)->id().to_s().compare (id)) {
382 iter = range_list->append();
385 row[range_cols.location] = *it;
386 row[range_cols.selected] = true;
387 row[range_cols.name] = (*it)->name();
388 row[range_cols.label] = construct_label (*it);
389 row[range_cols.length] = construct_length (*it);
391 add_range_to_selection (*it);
397 set_time_format_from_state();
400 /*** ExportTimespanSelectorMultiple ***/
402 ExportTimespanSelectorMultiple::ExportTimespanSelectorMultiple (ARDOUR::Session * session, ProfileManagerPtr manager) :
403 ExportTimespanSelector (session, manager)
405 range_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
406 range_view.append_column_editable ("", range_cols.selected);
407 range_view.append_column_editable (_("Range"), range_cols.name);
409 if (Gtk::CellRendererToggle * renderer = dynamic_cast<Gtk::CellRendererToggle *> (range_view.get_column_cell_renderer (0))) {
410 renderer->signal_toggled().connect (sigc::hide (sigc::mem_fun (*this, &ExportTimespanSelectorMultiple::update_selection)));
412 if (Gtk::CellRendererText * renderer = dynamic_cast<Gtk::CellRendererText *> (range_view.get_column_cell_renderer (1))) {
413 renderer->signal_edited().connect (sigc::mem_fun (*this, &ExportTimespanSelectorMultiple::update_range_name));
416 Gtk::CellRendererText * label_render = Gtk::manage (new Gtk::CellRendererText());
417 Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column (_("Time Span"), *label_render));
418 label_col->add_attribute (label_render->property_markup(), range_cols.label);
419 range_view.append_column (*label_col);
421 range_view.append_column (_("Length"), range_cols.length);
425 ExportTimespanSelectorMultiple::fill_range_list ()
427 if (!state) { return; }
431 Gtk::TreeModel::iterator iter;
432 Gtk::TreeModel::Row row;
433 for (LocationList::const_iterator it = state->ranges->begin(); it != state->ranges->end(); ++it) {
435 iter = range_list->append();
438 row[range_cols.location] = *it;
439 row[range_cols.selected] = false;
440 row[range_cols.name] = (*it)->name();
441 row[range_cols.label] = construct_label (*it);
442 row[range_cols.length] = construct_length (*it);
445 set_selection_from_state ();
449 ExportTimespanSelectorMultiple::set_selection_from_state ()
451 Gtk::TreeModel::Children::iterator tree_it;
453 for (TimespanList::iterator it = state->timespans->begin(); it != state->timespans->end(); ++it) {
454 string id = (*it)->range_id();
455 for (tree_it = range_list->children().begin(); tree_it != range_list->children().end(); ++tree_it) {
456 Location * loc = tree_it->get_value (range_cols.location);
458 if ((id == "selection" && loc == state->selection_range.get()) ||
459 (id == loc->id().to_s())) {
460 tree_it->set_value (range_cols.selected, true);
465 set_time_format_from_state();
469 ExportTimespanSelectorMultiple::update_selection ()
472 CriticalSelectionChanged ();
476 ExportTimespanSelectorMultiple::update_timespans ()
478 state->timespans->clear();
480 for (Gtk::TreeStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
481 if (it->get_value (range_cols.selected)) {
482 add_range_to_selection (it->get_value (range_cols.location));