Add toc and cue information to export format descriptions
[ardour.git] / libs / ardour / export_format_specification.cc
index 60a7732b582497779b655f5648467eeffa055d20..763f507de4a7bb045390178c9b5df8fec6b98db3 100644 (file)
@@ -42,25 +42,14 @@ using std::string;
 ExportFormatSpecification::Time &
 ExportFormatSpecification::Time::operator= (AnyTime const & other)
 {
-       type = other.type;
-       smpte = other.smpte;
-       bbt = other.bbt;
-
-       if (type == Frames) {
-               frames = other.frames;
-       } else {
-               seconds = other.seconds;
-       }
-
+       static_cast<AnyTime &>(*this) = other;
        return *this;
 }
 
-nframes_t
-ExportFormatSpecification::Time::get_frames (nframes_t target_rate) const
+framecnt_t
+ExportFormatSpecification::Time::get_frames_at (framepos_t position, framecnt_t target_rate) const
 {
-       //TODO position
-       nframes_t duration = session.convert_to_frames_at (0, *this);
-
+       framecnt_t duration = session.any_duration_to_frames (position, *this);
        return ((double) target_rate / session.frame_rate()) * duration + 0.5;
 }
 
@@ -73,11 +62,11 @@ ExportFormatSpecification::Time::get_state ()
        node->add_property ("format", enum_2_string (type));
 
        switch (type) {
-         case SMPTE:
-               node->add_property ("hours", to_string (smpte.hours, std::dec));
-               node->add_property ("minutes", to_string (smpte.minutes, std::dec));
-               node->add_property ("seconds", to_string (smpte.seconds, std::dec));
-               node->add_property ("frames", to_string (smpte.frames, std::dec));
+         case Timecode:
+               node->add_property ("hours", to_string (timecode.hours, std::dec));
+               node->add_property ("minutes", to_string (timecode.minutes, std::dec));
+               node->add_property ("seconds", to_string (timecode.seconds, std::dec));
+               node->add_property ("frames", to_string (timecode.frames, std::dec));
                break;
          case BBT:
                node->add_property ("bars", to_string (bbt.bars, std::dec));
@@ -107,21 +96,21 @@ ExportFormatSpecification::Time::set_state (const XMLNode & node)
        type = (Type) string_2_enum (prop->value(), Type);
 
        switch (type) {
-         case SMPTE:
+         case Timecode:
                if ((prop = node.property ("hours"))) {
-                       smpte.hours = atoi (prop->value());
+                       timecode.hours = atoi (prop->value());
                }
 
                if ((prop = node.property ("minutes"))) {
-                       smpte.minutes = atoi (prop->value());
+                       timecode.minutes = atoi (prop->value());
                }
 
                if ((prop = node.property ("seconds"))) {
-                       smpte.seconds = atoi (prop->value());
+                       timecode.seconds = atoi (prop->value());
                }
 
                if ((prop = node.property ("frames"))) {
-                       smpte.frames = atoi (prop->value());
+                       timecode.frames = atoi (prop->value());
                }
 
                break;
@@ -178,6 +167,8 @@ ExportFormatSpecification::ExportFormatSpecification (Session & s)
 
        , _normalize (false)
        , _normalize_target (1.0)
+       , _with_toc (false)
+       , _with_cue (false)
 {
        format_ids.insert (F_None);
        endiannesses.insert (E_FileDefault);
@@ -191,8 +182,8 @@ ExportFormatSpecification::ExportFormatSpecification (Session & s, XMLNode const
        , _silence_beginning (s)
        , _silence_end (s)
 {
-       _silence_beginning.type = Time::SMPTE;
-       _silence_end.type = Time::SMPTE;
+       _silence_beginning.type = Time::Timecode;
+       _silence_end.type = Time::Timecode;
 
        set_state (state);
 }
@@ -230,6 +221,8 @@ ExportFormatSpecification::ExportFormatSpecification (ExportFormatSpecification
 
        set_silence_beginning (other.silence_beginning_time());
        set_silence_end (other.silence_end_time());
+
+       set_extension(other.extension());
 }
 
 ExportFormatSpecification::~ExportFormatSpecification ()
@@ -244,6 +237,8 @@ ExportFormatSpecification::get_state ()
 
        root->add_property ("name", _name);
        root->add_property ("id", _id.to_s());
+       root->add_property ("with-cue", _with_cue ? "true" : "false");
+       root->add_property ("with-toc", _with_toc ? "true" : "false");
 
        node = root->add_child ("Encoding");
        node->add_property ("id", enum_2_string (format_id()));
@@ -281,14 +276,14 @@ ExportFormatSpecification::get_state ()
        node->add_property ("enabled", trim_beginning() ? "true" : "false");
 
        node = start->add_child ("Add");
-       node->add_property ("enabled", silence_beginning() > 0 ? "true" : "false");
+       node->add_property ("enabled", _silence_beginning.not_zero() ? "true" : "false");
        node->add_child_nocopy (_silence_beginning.get_state());
 
        node = end->add_child ("Trim");
        node->add_property ("enabled", trim_end() ? "true" : "false");
 
        node = end->add_child ("Add");
-       node->add_property ("enabled", silence_end() > 0 ? "true" : "false");
+       node->add_property ("enabled", _silence_end.not_zero() ? "true" : "false");
        node->add_child_nocopy (_silence_end.get_state());
 
        return *root;
@@ -309,6 +304,18 @@ ExportFormatSpecification::set_state (const XMLNode & root)
                _id = prop->value();
        }
 
+       if ((prop = root.property ("with-cue"))) {
+               _with_cue = string_is_affirmative (prop->value());
+       } else {
+               _with_cue = false;
+       }
+       
+       if ((prop = root.property ("with-toc"))) {
+               _with_toc = string_is_affirmative (prop->value());
+       } else {
+               _with_toc = false;
+       }
+       
        /* Encoding and SRC */
 
        if ((child = root.child ("Encoding"))) {
@@ -329,7 +336,11 @@ ExportFormatSpecification::set_state (const XMLNode & root)
                }
 
                if ((prop = child->property ("has-sample-format"))) {
-                       has_sample_format = !prop->value().compare ("true");
+                       has_sample_format = string_is_affirmative (prop->value());
+               }
+
+               if ((prop = child->property ("has-sample-format"))) {
+                       has_sample_format = string_is_affirmative (prop->value());
                }
 
                if ((prop = child->property ("channel-limit"))) {
@@ -396,7 +407,7 @@ ExportFormatSpecification::set_state (const XMLNode & root)
                                        _silence_beginning.set_state (*child);
                                }
                        } else {
-                               _silence_beginning.type = Time::SMPTE;
+                               _silence_beginning.type = Time::Timecode;
                        }
                }
        }
@@ -416,7 +427,7 @@ ExportFormatSpecification::set_state (const XMLNode & root)
                                        _silence_end.set_state (*child);
                                }
                        } else {
-                               _silence_end.type = Time::SMPTE;
+                               _silence_end.type = Time::Timecode;
                        }
                }
        }
@@ -512,10 +523,10 @@ ExportFormatSpecification::set_format (boost::shared_ptr<ExportFormat> format)
        }
 }
 
-Glib::ustring
+string
 ExportFormatSpecification::description ()
 {
-       Glib::ustring desc;
+       string desc;
 
        desc = _name + ": ";
 
@@ -528,7 +539,7 @@ ExportFormatSpecification::description ()
        } else if (_trim_beginning) {
                desc += _("trim start, ");
        } else if (_trim_end) {
-               desc += "trim end, ";
+               desc += _("trim end, ");
        }
 
        desc += _format_name + ", ";
@@ -556,10 +567,21 @@ ExportFormatSpecification::description ()
          case SR_192:
                desc += "192 kHz";
                break;
+         case SR_Session:
+               desc += _("Session rate");
+               break;
          case SR_None:
                break;
        }
 
+       if (_with_toc) {
+               desc += ", TOC";
+       }
+
+       if (_with_cue) {
+               desc += ", CUE";
+       }
+
        return desc;
 }