summaryrefslogtreecommitdiff
path: root/libs/ardour/export_formats.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2008-09-17 12:58:33 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2008-09-17 12:58:33 +0000
commitf2b007195cd75b195e38a4cd7757debac73e7792 (patch)
tree90474413776806f02794602bbb495663e07a81ea /libs/ardour/export_formats.cc
parent6ba5125e991e08a9d117b39a4c337cf453fd015d (diff)
new files from sakari, missed last time
git-svn-id: svn://localhost/ardour2/branches/3.0@3740 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/export_formats.cc')
-rw-r--r--libs/ardour/export_formats.cc331
1 files changed, 331 insertions, 0 deletions
diff --git a/libs/ardour/export_formats.cc b/libs/ardour/export_formats.cc
new file mode 100644
index 0000000000..7df54bad1c
--- /dev/null
+++ b/libs/ardour/export_formats.cc
@@ -0,0 +1,331 @@
+/*
+ Copyright (C) 2008 Paul Davis
+ Author: Sakari Bergen
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <ardour/export_formats.h>
+
+#include "i18n.h"
+
+namespace ARDOUR
+{
+
+bool
+ExportFormat::has_sample_format ()
+{
+ return dynamic_cast<HasSampleFormat *> (this);
+}
+
+bool
+ExportFormat::sample_format_is_compatible (SampleFormat format) const
+{
+ return (sample_formats.find (format) != sample_formats.end());
+}
+
+/*** HasSampleFormat ***/
+
+HasSampleFormat::HasSampleFormat (ExportFormatBase::SampleFormatSet & sample_formats) :
+ _sample_formats (sample_formats)
+{
+ /* Dither Types */
+
+ add_dither_type (ExportFormatBase::D_Shaped, _("Shaped Noise"));
+ add_dither_type (ExportFormatBase::D_Tri, _("Triangular"));
+ add_dither_type (ExportFormatBase::D_Rect, _("Rectangular"));
+ add_dither_type (ExportFormatBase::D_None, _("None"));
+}
+
+void
+HasSampleFormat::add_sample_format (ExportFormatBase::SampleFormat format)
+{
+ _sample_formats.insert (format);
+
+ SampleFormatPtr ptr (new SampleFormatState (format, get_sample_format_name (format)));
+ sample_format_states.push_back (ptr);
+ ptr->SelectChanged.connect (sigc::bind (SampleFormatSelectChanged.make_slot(), WeakSampleFormatPtr (ptr)));
+ ptr->SelectChanged.connect (sigc::mem_fun (*this, &HasSampleFormat::update_sample_format_selection));
+ ptr->CompatibleChanged.connect (sigc::bind (SampleFormatCompatibleChanged.make_slot(), WeakSampleFormatPtr (ptr)));
+}
+
+void
+HasSampleFormat::add_dither_type (ExportFormatBase::DitherType type, Glib::ustring name)
+{
+ DitherTypePtr ptr (new DitherTypeState (type, name));
+ dither_type_states.push_back (ptr);
+ ptr->SelectChanged.connect (sigc::bind (DitherTypeSelectChanged.make_slot(), WeakDitherTypePtr (ptr)));
+ ptr->SelectChanged.connect (sigc::mem_fun (*this, &HasSampleFormat::update_dither_type_selection));
+ ptr->CompatibleChanged.connect (sigc::bind (DitherTypeCompatibleChanged.make_slot(), WeakDitherTypePtr (ptr)));
+}
+
+HasSampleFormat::SampleFormatPtr
+HasSampleFormat::get_selected_sample_format ()
+{
+ for (SampleFormatList::iterator it = sample_format_states.begin(); it != sample_format_states.end(); ++it) {
+ if ((*it)->selected()) {
+ return *it;
+ }
+ }
+
+ return SampleFormatPtr();
+}
+
+HasSampleFormat::DitherTypePtr
+HasSampleFormat::get_selected_dither_type ()
+{
+ for (DitherTypeList::iterator it = dither_type_states.begin(); it != dither_type_states.end(); ++it) {
+ if ((*it)->selected()) {
+ return *it;
+ }
+ }
+
+ return DitherTypePtr();
+}
+
+void
+HasSampleFormat::update_sample_format_selection (bool)
+{
+ SampleFormatPtr format = get_selected_sample_format();
+ if (!format) {
+ return;
+ }
+
+ if (format->format == ExportFormatBase::SF_24 ||
+ format->format == ExportFormatBase::SF_32 ||
+ format->format == ExportFormatBase::SF_Float ||
+ format->format == ExportFormatBase::SF_Double) {
+ for (DitherTypeList::iterator it = dither_type_states.begin(); it != dither_type_states.end(); ++it) {
+ if ((*it)->type == ExportFormatBase::D_None) {
+ (*it)->set_selected (true);
+ } else {
+ (*it)->set_compatible (false);
+ }
+ }
+
+ } else {
+ for (DitherTypeList::iterator it = dither_type_states.begin(); it != dither_type_states.end(); ++it) {
+ (*it)->set_compatible (true);
+ }
+ }
+}
+
+void
+HasSampleFormat::update_dither_type_selection (bool)
+{
+ DitherTypePtr type = get_selected_dither_type();
+ if (!type) {
+ return;
+ }
+
+ if (!type->compatible()) {
+ SampleFormatPtr format = get_selected_sample_format();
+ if (format) {
+ format->set_selected (false);
+ }
+
+ for (DitherTypeList::iterator it = dither_type_states.begin(); it != dither_type_states.end(); ++it) {
+ (*it)->set_compatible (true);
+ }
+ }
+}
+
+string
+HasSampleFormat::get_sample_format_name (ExportFormatBase::SampleFormat format)
+{
+ switch (format) {
+ case ExportFormatBase::SF_8:
+ return _("8bit");
+ case ExportFormatBase::SF_16:
+ return _("16bit");
+ case ExportFormatBase::SF_24:
+ return _("24bit");
+ case ExportFormatBase::SF_32:
+ return _("32bit");
+ case ExportFormatBase::SF_Float:
+ return _("float");
+ case ExportFormatBase::SF_Double:
+ return _("double");
+ case ExportFormatBase::SF_U8:
+ return _("8bit unsigned");
+ case ExportFormatBase::SF_Vorbis:
+ return _("Vorbis sample format");
+ case ExportFormatBase::SF_None:
+ return _("No sample format");
+ }
+ return "";
+}
+
+/*** Linear ***/
+
+ExportFormatLinear::ExportFormatLinear (Glib::ustring name, FormatId format_id) :
+ HasSampleFormat (sample_formats),
+ _default_sample_format (SF_None)
+{
+ set_name (name);
+ set_format_id (format_id);
+
+ add_sample_rate (SR_22_05);
+ add_sample_rate (SR_44_1);
+ add_sample_rate (SR_48);
+ add_sample_rate (SR_88_2);
+ add_sample_rate (SR_96);
+ add_sample_rate (SR_192);
+
+ add_endianness (E_FileDefault);
+
+ set_quality (Q_LosslessLinear);
+}
+
+bool
+ExportFormatLinear::set_compatibility_state (ExportFormatCompatibility const & compatibility)
+{
+ /* Global state */
+
+ bool compatible = true;
+
+ if (!compatibility.has_quality (Q_LosslessLinear)) {
+ compatible = false;
+ }
+
+ if (!compatibility.has_format (get_format_id())) {
+ compatible = false;
+ }
+
+ boost::shared_ptr<ExportFormatBase> intersection = get_intersection (compatibility);
+
+ if (intersection->endiannesses_empty()) {
+ compatible = false;
+ }
+
+ if (intersection->sample_rates_empty()) {
+ compatible = false;
+ }
+
+ if (intersection->sample_formats_empty()) {
+ compatible = false;
+ }
+
+ set_compatible (compatible);
+
+ /* Sample Formats */
+
+ for (SampleFormatList::iterator it = sample_format_states.begin(); it != sample_format_states.end(); ++it) {
+ (*it)->set_compatible (compatibility.has_sample_format ((*it)->format));
+ }
+
+ return compatible;
+}
+
+/*** Ogg Vorbis ***/
+
+ExportFormatOggVorbis::ExportFormatOggVorbis ()
+{
+ set_name ("Ogg Vorbis");
+ set_format_id (F_Ogg);
+ sample_formats.insert (SF_Vorbis);
+
+ add_sample_rate (SR_22_05);
+ add_sample_rate (SR_44_1);
+ add_sample_rate (SR_48);
+ add_sample_rate (SR_88_2);
+ add_sample_rate (SR_96);
+ add_sample_rate (SR_192);
+
+ add_endianness (E_FileDefault);
+
+ set_extension ("ogg");
+ set_quality (Q_LossyCompression);
+}
+
+bool
+ExportFormatOggVorbis::set_compatibility_state (ExportFormatCompatibility const & compatibility)
+{
+ bool compatible = compatibility.has_format (F_Ogg);
+ set_compatible (compatible);
+ return compatible;
+}
+
+/*** FLAC ***/
+
+ExportFormatFLAC::ExportFormatFLAC () :
+ HasSampleFormat (sample_formats)
+{
+ set_name ("FLAC");
+ set_format_id (F_FLAC);
+
+ add_sample_rate (SR_22_05);
+ add_sample_rate (SR_44_1);
+ add_sample_rate (SR_48);
+ add_sample_rate (SR_88_2);
+ add_sample_rate (SR_96);
+ add_sample_rate (SR_192);
+
+ add_sample_format (SF_8);
+ add_sample_format (SF_16);
+ add_sample_format (SF_24);
+
+ add_endianness (E_FileDefault);
+
+ set_extension ("flac");
+ set_quality (Q_LosslessCompression);
+}
+
+bool
+ExportFormatFLAC::set_compatibility_state (ExportFormatCompatibility const & compatibility)
+{
+ bool compatible = compatibility.has_format (F_FLAC);
+ set_compatible (compatible);
+ return compatible;
+}
+
+/*** BWF ***/
+
+ExportFormatBWF::ExportFormatBWF () :
+ HasSampleFormat (sample_formats)
+{
+ set_name ("BWF");
+ set_format_id (F_WAV);
+
+ add_sample_rate (SR_22_05);
+ add_sample_rate (SR_44_1);
+ add_sample_rate (SR_48);
+ add_sample_rate (SR_88_2);
+ add_sample_rate (SR_96);
+ add_sample_rate (SR_192);
+
+ add_sample_format (SF_U8);
+ add_sample_format (SF_16);
+ add_sample_format (SF_24);
+ add_sample_format (SF_32);
+ add_sample_format (SF_Float);
+ add_sample_format (SF_Double);
+
+ add_endianness (E_FileDefault);
+
+ set_extension ("wav");
+ set_quality (Q_LosslessLinear);
+}
+
+bool
+ExportFormatBWF::set_compatibility_state (ExportFormatCompatibility const & compatibility)
+{
+ bool compatible = compatibility.has_format (F_WAV);
+ set_compatible (compatible);
+ return compatible;
+}
+
+}; // namespace ARDOUR