Wouldn't it be nice if plugin presets had a description/comment?
[ardour.git] / libs / ardour / export_format_specification.cc
index ea7b4ac4484cb68da127aba866d7a0bc56b43d84..d976cd6e97830750a92061dc1dccde7ac3d7254f 100644 (file)
@@ -57,11 +57,11 @@ ExportFormatSpecification::Time::operator= (AnyTime const & other)
        return *this;
 }
 
-framecnt_t
-ExportFormatSpecification::Time::get_frames_at (framepos_t position, framecnt_t target_rate) const
+samplecnt_t
+ExportFormatSpecification::Time::get_samples_at (samplepos_t position, samplecnt_t target_rate) const
 {
-       framecnt_t duration = session.any_duration_to_frames (position, *this);
-       return ((double) target_rate / session.frame_rate()) * duration + 0.5;
+       samplecnt_t duration = session.any_duration_to_samples (position, *this);
+       return ((double) target_rate / session.sample_rate()) * duration + 0.5;
 }
 
 XMLNode &
@@ -84,8 +84,8 @@ ExportFormatSpecification::Time::get_state ()
                node->set_property ("beats", bbt.beats);
                node->set_property ("ticks", bbt.ticks);
                break;
-         case Frames:
-               node->set_property ("frames", frames);
+         case Samples:
+               node->set_property ("samples", samples);
                break;
          case Seconds:
                node->set_property ("seconds", seconds);
@@ -116,8 +116,8 @@ ExportFormatSpecification::Time::set_state (const XMLNode & node)
                node.get_property ("ticks", bbt.ticks);
                break;
 
-       case Frames:
-               node.get_property ("frames", frames);
+       case Samples:
+               node.get_property ("samples", samples);
                break;
 
        case Seconds:
@@ -131,9 +131,9 @@ ExportFormatSpecification::Time::set_state (const XMLNode & node)
 
 ExportFormatSpecification::ExportFormatSpecification (Session & s)
        : session (s)
-
        , has_sample_format (false)
        , supports_tagging (false)
+       , _has_codec_quality (false)
        , _has_broadcast_info (false)
        , _channel_limit (0)
        , _dither_type (D_None)
@@ -156,6 +156,7 @@ ExportFormatSpecification::ExportFormatSpecification (Session & s)
        , _soundcloud_upload (false)
        , _command ("")
        , _analyse (true)
+       , _codec_quality (0)
 {
        format_ids.insert (F_None);
        endiannesses.insert (E_FileDefault);
@@ -166,9 +167,9 @@ ExportFormatSpecification::ExportFormatSpecification (Session & s)
 
 ExportFormatSpecification::ExportFormatSpecification (Session & s, XMLNode const & state)
        : session (s)
-
        , has_sample_format (false)
        , supports_tagging (false)
+       , _has_codec_quality (false)
        , _has_broadcast_info (false)
        , _channel_limit (0)
        , _dither_type (D_None)
@@ -191,6 +192,7 @@ ExportFormatSpecification::ExportFormatSpecification (Session & s, XMLNode const
        , _soundcloud_upload (false)
        , _command ("")
        , _analyse (true)
+       , _codec_quality (0)
 {
        _silence_beginning.type = Time::Timecode;
        _silence_end.type = Time::Timecode;
@@ -203,8 +205,13 @@ ExportFormatSpecification::ExportFormatSpecification (ExportFormatSpecification
        , session (other.session)
        , _silence_beginning (other.session)
        , _silence_end (other.session)
+       , _with_toc (other._with_toc)
+       , _with_cue (other._with_cue)
+       , _with_mp4chaps (other._with_mp4chaps)
        , _soundcloud_upload (false)
+       , _command (other._command)
        , _analyse (other._analyse)
+       , _codec_quality (other._codec_quality)
 {
        if (modify_name) {
                set_name (other.name() + " (copy)");
@@ -214,8 +221,8 @@ ExportFormatSpecification::ExportFormatSpecification (ExportFormatSpecification
 
        _format_name = other._format_name;
        has_sample_format = other.has_sample_format;
-
        supports_tagging = other.supports_tagging;
+       _has_codec_quality = other._has_codec_quality;
        _has_broadcast_info = other._has_broadcast_info;
        _channel_limit = other._channel_limit;
 
@@ -251,7 +258,6 @@ ExportFormatSpecification::~ExportFormatSpecification ()
 XMLNode &
 ExportFormatSpecification::get_state ()
 {
-       LocaleGuard lg;
        XMLNode * node;
        XMLNode * root = new XMLNode ("ExportFormatSpecification");
 
@@ -278,6 +284,11 @@ ExportFormatSpecification::get_state ()
        node = root->add_child ("SRCQuality");
        node->set_property ("quality", src_quality());
 
+       if (_has_codec_quality) {
+               node = root->add_child ("CodecQuality");
+               node->set_property ("quality", codec_quality());
+       }
+
        XMLNode * enc_opts = root->add_child ("EncodingOptions");
 
        add_option (enc_opts, "sample-format", to_string(sample_format()));
@@ -321,7 +332,6 @@ ExportFormatSpecification::set_state (const XMLNode & root)
 {
        XMLNode const * child;
        string str;
-       LocaleGuard lg;
 
        root.get_property ("name", _name);
 
@@ -386,6 +396,28 @@ ExportFormatSpecification::set_state (const XMLNode & root)
                child->get_property ("quality", _src_quality);
        }
 
+       if ((child = root.child ("CodecQuality"))) {
+               child->get_property ("quality", _codec_quality);
+               _has_codec_quality = true;
+       } else {
+               _has_codec_quality = false;
+       }
+
+       /* fixup codec quality for old states */
+       if (!_has_codec_quality) {
+               /* We'd need an instance of ExportFormatManager to look up
+                * defaults for a given type -- in the future there may even be
+                * difference qualities depending on sub-type, so we just
+                * hardcode them here for the time being.
+                */
+               if (format_id() == F_FFMPEG) {
+                       _codec_quality = -2; // ExportFormatOggVorbis::default_codec_quality();
+               }
+               else if (format_id() == F_Ogg) {
+                       _codec_quality = 40; // ExportFormatFFMPEG::default_codec_quality();
+               }
+       }
+
        /* Encoding options */
 
        if ((child = root.child ("EncodingOptions"))) {
@@ -510,7 +542,10 @@ void
 ExportFormatSpecification::set_format (boost::shared_ptr<ExportFormat> format)
 {
        if (format) {
-               set_format_id (format->get_format_id ());
+               FormatId new_fmt = format->get_format_id ();
+               bool fmt_changed = format_id() != new_fmt;
+               set_format_id (new_fmt);
+
                set_type (format->get_type());
                set_extension (format->extension());
 
@@ -526,6 +561,13 @@ ExportFormatSpecification::set_format (boost::shared_ptr<ExportFormat> format)
                        _has_broadcast_info = true;
                }
 
+               _has_codec_quality = format->has_codec_quality();
+               if (!_has_codec_quality) {
+                       _codec_quality = 0;
+               } else if (fmt_changed) {
+                       _codec_quality = boost::dynamic_pointer_cast<HasCodecQuality> (format)->default_codec_quality();
+               }
+
                supports_tagging = format->supports_tagging ();
                _channel_limit = format->get_channel_limit();
 
@@ -538,6 +580,7 @@ ExportFormatSpecification::set_format (boost::shared_ptr<ExportFormat> format)
                has_sample_format = false;
                supports_tagging = false;
                _channel_limit = 0;
+               _codec_quality = 0;
                _format_name = "";
        }
 }