From 462902f22a930c52d6d4ac4ac9097d078108b568 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 16 Dec 2015 20:35:18 +0000 Subject: Missing install target. --- src/wscript | 1 + 1 file changed, 1 insertion(+) (limited to 'src/wscript') diff --git a/src/wscript b/src/wscript index 6afe1d9..a054a91 100644 --- a/src/wscript +++ b/src/wscript @@ -50,6 +50,7 @@ def build(bld): raw_subtitle.h reader.h stl_binary_tables.h + stl_binary_reader.h stl_binary_writer.h stl_text_reader.h sub_time.h -- cgit v1.2.3 From 5a843c4c224051237105a6e8de472ae9a216c001 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 16 Dec 2015 20:40:21 +0000 Subject: Replace use of cassert with exceptions. --- src/exceptions.cc | 30 ++++++++++++++++++++++++++++++ src/exceptions.h | 6 ++++++ src/stl_binary_tables.cc | 4 ++-- src/stl_binary_writer.cc | 31 ++++++++++++++++--------------- src/sub_assert.h | 22 ++++++++++++++++++++++ src/wscript | 1 + 6 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 src/exceptions.cc create mode 100644 src/sub_assert.h (limited to 'src/wscript') diff --git a/src/exceptions.cc b/src/exceptions.cc new file mode 100644 index 0000000..f33a1e2 --- /dev/null +++ b/src/exceptions.cc @@ -0,0 +1,30 @@ +/* + Copyright (C) 2014-2015 Carl Hetherington + + 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 "compose.hpp" +#include "exceptions.h" + +using std::string; +using namespace sub; + +ProgrammingError::ProgrammingError (string file, int line) + : MessageError (String::compose ("Programming error at %1:%2", file, line)) +{ + +} diff --git a/src/exceptions.h b/src/exceptions.h index 62be0d5..5995942 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -99,6 +99,12 @@ public: {} }; +class ProgrammingError : public MessageError +{ +public: + ProgrammingError (std::string file, int line); +}; + } #endif diff --git a/src/stl_binary_tables.cc b/src/stl_binary_tables.cc index f843421..db623bf 100644 --- a/src/stl_binary_tables.cc +++ b/src/stl_binary_tables.cc @@ -19,8 +19,8 @@ #include "stl_binary_tables.h" #include "exceptions.h" +#include "sub_assert.h" #include "compose.hpp" -#include using std::map; using std::string; @@ -55,7 +55,7 @@ enum_to_file (E k, map > m) } } - assert (false); + SUB_ASSERT (false); return F (); } diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc index b9bd7e0..aa8943c 100644 --- a/src/stl_binary_writer.cc +++ b/src/stl_binary_writer.cc @@ -26,6 +26,7 @@ #include "iso6937.h" #include "stl_util.h" #include "compose.hpp" +#include "sub_assert.h" #include #include #include @@ -62,7 +63,7 @@ put_string (char* p, string s) static void put_string (char* p, unsigned int n, string s) { - assert (s.length() <= n); + SUB_ASSERT (s.length() <= n); memcpy (p, s.c_str (), s.length ()); memset (p + s.length(), ' ', n - s.length ()); @@ -76,7 +77,7 @@ put_int_as_string (char* p, int v, unsigned int n) s.imbue (std::locale::classic ()); s << setw (n) << setfill ('0'); s << v; - assert (s.str().length() == n); + SUB_ASSERT (s.str().length() == n); put_string (p, s.str ()); } @@ -110,19 +111,19 @@ sub::write_stl_binary ( boost::filesystem::path file_name ) { - assert (original_programme_title.size() <= 32); - assert (original_episode_title.size() <= 32); - assert (translated_programme_title.size() <= 32); - assert (translated_episode_title.size() <= 32); - assert (translator_name.size() <= 32); - assert (translator_contact_details.size() <= 32); - assert (creation_date.size() == 6); - assert (revision_date.size() == 6); - assert (revision_number <= 99); - assert (country_of_origin.size() == 3); - assert (publisher.size() <= 32); - assert (editor_name.size() <= 32); - assert (editor_contact_details.size() <= 32); + SUB_ASSERT (original_programme_title.size() <= 32); + SUB_ASSERT (original_episode_title.size() <= 32); + SUB_ASSERT (translated_programme_title.size() <= 32); + SUB_ASSERT (translated_episode_title.size() <= 32); + SUB_ASSERT (translator_name.size() <= 32); + SUB_ASSERT (translator_contact_details.size() <= 32); + SUB_ASSERT (creation_date.size() == 6); + SUB_ASSERT (revision_date.size() == 6); + SUB_ASSERT (revision_number <= 99); + SUB_ASSERT (country_of_origin.size() == 3); + SUB_ASSERT (publisher.size() <= 32); + SUB_ASSERT (editor_name.size() <= 32); + SUB_ASSERT (editor_contact_details.size() <= 32); char* buffer = new char[1024]; memset (buffer, 0, 1024); diff --git a/src/sub_assert.h b/src/sub_assert.h new file mode 100644 index 0000000..67c8abe --- /dev/null +++ b/src/sub_assert.h @@ -0,0 +1,22 @@ +/* + Copyright (C) 2014 Carl Hetherington + + 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 "exceptions.h" + +#define SUB_ASSERT(x) if (!(x)) throw ProgrammingError (__FILE__, __LINE__); diff --git a/src/wscript b/src/wscript index a054a91..eafd1c9 100644 --- a/src/wscript +++ b/src/wscript @@ -15,6 +15,7 @@ def build(bld): colour.cc dcp_reader.cc effect.cc + exceptions.cc font_size.cc interop_dcp_reader.cc iso6937.cc -- cgit v1.2.3 From 485794f8322b090a22da841961025b19642e42a2 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 16 Dec 2015 21:39:28 +0000 Subject: Some missing headers; Time tweaks. --- src/rational.cc | 33 +++++++++++++++++++++++++++++++++ src/rational.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/sub_time.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/sub_time.h | 21 +++++---------------- src/wscript | 4 ++++ 5 files changed, 134 insertions(+), 16 deletions(-) create mode 100644 src/rational.cc create mode 100644 src/rational.h (limited to 'src/wscript') diff --git a/src/rational.cc b/src/rational.cc new file mode 100644 index 0000000..09dadab --- /dev/null +++ b/src/rational.cc @@ -0,0 +1,33 @@ +/* + Copyright (C) 2014-2015 Carl Hetherington + + 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 "rational.h" + +using namespace sub; + +bool sub::operator== (Rational const & a, Rational const & b) +{ + return (a.numerator == b.numerator && a.denominator == b.denominator); +} + +bool +Rational::integer () const +{ + return (numerator % denominator) == 0; +} diff --git a/src/rational.h b/src/rational.h new file mode 100644 index 0000000..7ff71c0 --- /dev/null +++ b/src/rational.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2014-2015 Carl Hetherington + + 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. + +*/ + +namespace sub { + +class Rational +{ +public: + Rational (int numerator_, int denominator_) + : numerator (numerator_) + , denominator (denominator_) + {} + + int numerator; + int denominator; + + double fraction () const { + return double (numerator) / denominator; + } + + bool integer () const; + int integer_fraction () const { + return numerator / denominator; + } +}; + +bool operator== (Rational const & a, Rational const & b); + +} diff --git a/src/sub_time.cc b/src/sub_time.cc index 68dac19..c4e00ba 100644 --- a/src/sub_time.cc +++ b/src/sub_time.cc @@ -18,6 +18,7 @@ */ #include "sub_time.h" +#include "sub_assert.h" #include "exceptions.h" #include #include @@ -154,8 +155,54 @@ Time::from_hms (int h, int m, int s, int ms) return Time (h * 3600 + m * 60 + s, ms, Rational (1000, 1)); } +/** Create a Time from a number of frames. + * rate must be integer. + */ +Time +Time::from_frames (int f, Rational rate) +{ + SUB_ASSERT (rate.denominator != 0); + SUB_ASSERT (rate.integer ()); + return Time (f / rate.integer_fraction(), f % rate.integer_fraction(), rate); +} + double Time::all_as_seconds () const { return _seconds + double(milliseconds ()) / 1000; } + +/** Add a time to this one. This time must have an integer _rate + * and t must have the same rate. + */ +void +Time::add (Time t) +{ + SUB_ASSERT (_rate); + + _seconds += t._seconds; + _frames += t._frames; + + SUB_ASSERT (_rate.get().denominator != 0); + SUB_ASSERT (_rate.get().integer ()); + + if (_frames >= _rate.get().integer_fraction()) { + _frames -= _rate.get().integer_fraction(); + ++_seconds; + } +} + +void +Time::scale (float f) +{ + SUB_ASSERT (_rate); + SUB_ASSERT (_rate->denominator != 0); + SUB_ASSERT (_rate->integer ()); + + _seconds = rint (_seconds * f); + _frames = rint (_frames * f); + if (_frames >= _rate->integer_fraction()) { + _frames -= _rate->integer_fraction (); + ++_seconds; + } +} diff --git a/src/sub_time.h b/src/sub_time.h index 7abdedb..93088cb 100644 --- a/src/sub_time.h +++ b/src/sub_time.h @@ -20,26 +20,11 @@ #ifndef LIBSUB_SUB_TIME_H #define LIBSUB_SUB_TIME_H +#include "rational.h" #include namespace sub { -class Rational -{ -public: - Rational (int numerator_, int denominator_) - : numerator (numerator_) - , denominator (denominator_) - {} - - int numerator; - int denominator; - - double fraction () const { - return double (numerator) / denominator; - } -}; - class Time { public: @@ -57,8 +42,12 @@ public: double all_as_seconds () const; + void add (Time t); + void scale (float f); + static Time from_hmsf (int h, int m, int s, int f, boost::optional rate = boost::optional ()); static Time from_hms (int h, int m, int s, int ms); + static Time from_frames (int frames, Rational rate); private: friend bool operator< (Time const & a, Time const & b); diff --git a/src/wscript b/src/wscript index eafd1c9..ae53ae6 100644 --- a/src/wscript +++ b/src/wscript @@ -20,6 +20,7 @@ def build(bld): interop_dcp_reader.cc iso6937.cc iso6937_tables.cc + rational.cc raw_subtitle.cc reader.cc reader_factory.cc @@ -48,8 +49,11 @@ def build(bld): dcp_reader.h effect.h font_size.h + interop_dcp_reader.h + rational.h raw_subtitle.h reader.h + smpte_dcp_reader.h stl_binary_tables.h stl_binary_reader.h stl_binary_writer.h -- cgit v1.2.3