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;
43 ExportTimespanSelector::ExportTimespanSelector (ARDOUR::Session * session, ProfileManagerPtr manager) :
46 time_format_label (_("Show Times as:"), Gtk::ALIGN_LEFT)
49 option_hbox.pack_start (time_format_label, false, false, 0);
50 option_hbox.pack_start (time_format_combo, false, false, 6);
52 range_scroller.add (range_view);
54 pack_start (option_hbox, false, false, 0);
55 pack_start (range_scroller, true, true, 6);
59 Gtk::TreeModel::iterator iter;
60 Gtk::TreeModel::Row row;
62 /* Time format combo */
64 time_format_list = Gtk::ListStore::create (time_format_cols);
65 time_format_combo.set_model (time_format_list);
66 time_format_combo.set_name ("PaddedButton");
68 iter = time_format_list->append();
70 row[time_format_cols.format] = ExportProfileManager::SMPTE;
71 row[time_format_cols.label] = X_("Timecode");
73 iter = time_format_list->append();
75 row[time_format_cols.format] = ExportProfileManager::MinSec;
76 row[time_format_cols.label] = _("Minutes:Seconds");
78 iter = time_format_list->append();
80 row[time_format_cols.format] = ExportProfileManager::BBT;
81 row[time_format_cols.label] = _("Bars:Beats");
83 time_format_combo.pack_start (time_format_cols.label);
84 time_format_combo.set_active (0);
86 time_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportTimespanSelector::change_time_format));
90 range_list = Gtk::ListStore::create (range_cols);
91 range_view.set_model (range_list);
92 range_view.set_headers_visible (false);
95 ExportTimespanSelector::~ExportTimespanSelector ()
101 ExportTimespanSelector::add_range_to_selection (ARDOUR::Location const * loc)
103 TimespanPtr span = session->get_export_handler()->add_timespan();
106 if (loc == state->session_range.get()) {
108 } else if (loc == state->selection_range.get()) {
111 id = loc->id().to_s();
114 span->set_range (loc->start(), loc->end());
115 span->set_name (loc->name());
116 span->set_range_id (id);
117 state->timespans->push_back (span);
121 ExportTimespanSelector::set_time_format_from_state ()
123 Gtk::TreeModel::Children::iterator tree_it;
124 for (tree_it = time_format_list->children().begin(); tree_it != time_format_list->children().end(); ++tree_it) {
125 if (tree_it->get_value (time_format_cols.format) == state->time_format) {
126 time_format_combo.set_active (tree_it);
132 ExportTimespanSelector::sync_with_manager ()
134 state = manager->get_timespans().front();
136 CriticalSelectionChanged();
140 ExportTimespanSelector::change_time_format ()
142 state->time_format = time_format_combo.get_active()->get_value (time_format_cols.format);
144 for (Gtk::ListStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
145 Location * location = it->get_value (range_cols.location);
146 it->set_value (range_cols.label, construct_label (location));
151 ExportTimespanSelector::construct_label (ARDOUR::Location const * location) const
157 nframes_t start_frame = location->start();
158 nframes_t end_frame = location->end();
160 switch (state->time_format) {
161 case AudioClock::BBT:
162 start = bbt_str (start_frame);
163 end = bbt_str (end_frame);
166 case AudioClock::SMPTE:
167 start = smpte_str (start_frame);
168 end = smpte_str (end_frame);
171 case AudioClock::MinSec:
172 start = ms_str (start_frame);
173 end = ms_str (end_frame);
176 case AudioClock::Frames:
177 start = to_string (start_frame, std::dec);
178 end = to_string (end_frame, std::dec);
181 case AudioClock::Off:
185 // label += _("from ");
187 // label += "<span color=\"#7fff7f\">";
189 // label += "</span>";
193 // label += "<span color=\"#7fff7f\">";
195 // label += "</span>";
202 ExportTimespanSelector::bbt_str (nframes_t frames) const
208 std::ostringstream oss;
211 session->bbt_time (frames, time);
213 oss << std::setfill('0') << std::right <<
225 ExportTimespanSelector::smpte_str (nframes_t frames) const
231 std::ostringstream oss;
234 session->smpte_time (frames, time);
236 oss << std::setfill('0') << std::right <<
240 time.minutes << ":" <<
242 time.seconds << ":" <<
250 ExportTimespanSelector::ms_str (nframes_t frames) const
256 std::ostringstream oss;
264 hrs = (int) floor (left / (session->frame_rate() * 60.0f * 60.0f));
265 left -= (nframes_t) floor (hrs * session->frame_rate() * 60.0f * 60.0f);
266 mins = (int) floor (left / (session->frame_rate() * 60.0f));
267 left -= (nframes_t) floor (mins * session->frame_rate() * 60.0f);
268 secs = (int) floor (left / (float) session->frame_rate());
269 left -= (nframes_t) floor (secs * session->frame_rate());
270 sec_promilles = (int) (left * 1000 / (float) session->frame_rate() + 0.5);
272 oss << std::setfill('0') << std::right <<
286 ExportTimespanSelector::update_range_name (Glib::ustring const & path, Glib::ustring const & new_text)
288 Gtk::TreeStore::iterator it = range_list->get_iter (path);
289 it->get_value (range_cols.location)->set_name (new_text);
291 CriticalSelectionChanged();
294 /*** ExportTimespanSelectorSingle ***/
296 ExportTimespanSelectorSingle::ExportTimespanSelectorSingle (ARDOUR::Session * session, ProfileManagerPtr manager, Glib::ustring range_id) :
297 ExportTimespanSelector (session, manager),
300 range_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_NEVER);
301 range_view.append_column_editable ("", range_cols.name);
303 // Adjust selector height
304 int x_offset, y_offset, width, height;
305 Gtk::CellRenderer * renderer = *range_view.get_column(0)->get_cell_renderers().begin();
306 renderer->get_size (range_view, x_offset, y_offset, width, height);
307 range_scroller.set_size_request (-1, height);
309 if (Gtk::CellRendererText * renderer = dynamic_cast<Gtk::CellRendererText *> (range_view.get_column_cell_renderer (0))) {
310 renderer->signal_edited().connect (sigc::mem_fun (*this, &ExportTimespanSelectorSingle::update_range_name));
313 Gtk::CellRendererText * label_render = Gtk::manage (new Gtk::CellRendererText());
314 Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column ("", *label_render));
315 label_col->add_attribute (label_render->property_markup(), range_cols.label);
316 range_view.append_column (*label_col);
321 ExportTimespanSelectorSingle::fill_range_list ()
323 if (!state) { return; }
326 if (!range_id.compare (X_("session"))) {
327 id = state->session_range->id().to_s();
328 } else if (!range_id.compare (X_("selection"))) {
329 id = state->selection_range->id().to_s();
335 state->timespans->clear();
337 Gtk::TreeModel::iterator iter;
338 Gtk::TreeModel::Row row;
339 for (LocationList::const_iterator it = state->ranges->begin(); it != state->ranges->end(); ++it) {
341 if (!(*it)->id().to_s().compare (id)) {
342 iter = range_list->append();
345 row[range_cols.location] = *it;
346 row[range_cols.selected] = true;
347 row[range_cols.name] = (*it)->name();
348 row[range_cols.label] = construct_label (*it);
350 add_range_to_selection (*it);
356 set_time_format_from_state();
359 /*** ExportTimespanSelectorMultiple ***/
361 ExportTimespanSelectorMultiple::ExportTimespanSelectorMultiple (ARDOUR::Session * session, ProfileManagerPtr manager) :
362 ExportTimespanSelector (session, manager)
364 range_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
365 range_view.append_column_editable ("", range_cols.selected);
366 range_view.append_column_editable ("", range_cols.name);
368 if (Gtk::CellRendererToggle * renderer = dynamic_cast<Gtk::CellRendererToggle *> (range_view.get_column_cell_renderer (0))) {
369 renderer->signal_toggled().connect (sigc::hide (sigc::mem_fun (*this, &ExportTimespanSelectorMultiple::update_selection)));
371 if (Gtk::CellRendererText * renderer = dynamic_cast<Gtk::CellRendererText *> (range_view.get_column_cell_renderer (1))) {
372 renderer->signal_edited().connect (sigc::mem_fun (*this, &ExportTimespanSelectorMultiple::update_range_name));
375 Gtk::CellRendererText * label_render = Gtk::manage (new Gtk::CellRendererText());
376 Gtk::TreeView::Column * label_col = Gtk::manage (new Gtk::TreeView::Column ("", *label_render));
377 label_col->add_attribute (label_render->property_markup(), range_cols.label);
378 range_view.append_column (*label_col);
383 ExportTimespanSelectorMultiple::fill_range_list ()
385 if (!state) { return; }
389 Gtk::TreeModel::iterator iter;
390 Gtk::TreeModel::Row row;
391 for (LocationList::const_iterator it = state->ranges->begin(); it != state->ranges->end(); ++it) {
393 iter = range_list->append();
396 row[range_cols.location] = *it;
397 row[range_cols.selected] = false;
398 row[range_cols.name] = (*it)->name();
399 row[range_cols.label] = construct_label (*it);
402 set_selection_from_state ();
406 ExportTimespanSelectorMultiple::set_selection_from_state ()
408 Gtk::TreeModel::Children::iterator tree_it;
410 for (TimespanList::iterator it = state->timespans->begin(); it != state->timespans->end(); ++it) {
411 ustring id = (*it)->range_id();
412 for (tree_it = range_list->children().begin(); tree_it != range_list->children().end(); ++tree_it) {
413 Location * loc = tree_it->get_value (range_cols.location);
415 if ((!id.compare ("session") && loc == state->session_range.get()) ||
416 (!id.compare ("selection") && loc == state->selection_range.get()) ||
417 (!id.compare (loc->id().to_s()))) {
418 tree_it->set_value (range_cols.selected, true);
423 set_time_format_from_state();
427 ExportTimespanSelectorMultiple::update_selection ()
430 CriticalSelectionChanged ();
434 ExportTimespanSelectorMultiple::update_timespans ()
436 state->timespans->clear();
438 for (Gtk::TreeStore::Children::iterator it = range_list->children().begin(); it != range_list->children().end(); ++it) {
439 if (it->get_value (range_cols.selected)) {
440 add_range_to_selection (it->get_value (range_cols.location));