diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2009-09-14 16:01:32 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2009-09-14 16:01:32 +0000 |
commit | bf0a99f0c0a8f76725fba89d076010009c4cdcb0 (patch) | |
tree | 128afdd123424872c922260a8f180912ff996431 /libs/evoral | |
parent | 3023d53d7d3f6dd726bcd07b0ebec8d7cfc2948d (diff) |
fix up marshall/unmarshall of note data for MidiModel::DiffCommand
git-svn-id: svn://localhost/ardour2/branches/3.0@5662 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/evoral')
-rw-r--r-- | libs/evoral/evoral/Note.hpp | 10 | ||||
-rw-r--r-- | libs/evoral/evoral/SMF.hpp | 2 | ||||
-rw-r--r-- | libs/evoral/evoral/types.hpp | 6 | ||||
-rw-r--r-- | libs/evoral/src/Note.cpp | 2 | ||||
-rw-r--r-- | libs/evoral/src/SMF.cpp | 9 |
5 files changed, 23 insertions, 6 deletions
diff --git a/libs/evoral/evoral/Note.hpp b/libs/evoral/evoral/Note.hpp index e92094ae78..b636df46e2 100644 --- a/libs/evoral/evoral/Note.hpp +++ b/libs/evoral/evoral/Note.hpp @@ -38,11 +38,11 @@ public: const Note<Time>& operator=(const Note<Time>& copy); inline bool operator==(const Note<Time>& other) { - return time() == other.time() && - note() == other.note() && - length() == other.length() && - velocity() == other.velocity() && - channel() == other.channel(); + return musical_time_equal (time(), other.time()) && + note() == other.note() && + musical_time_equal (length(), other.length()) && + velocity() == other.velocity() && + channel() == other.channel(); } inline Time time() const { return _on_event.time(); } diff --git a/libs/evoral/evoral/SMF.hpp b/libs/evoral/evoral/SMF.hpp index 4a6b21870b..b921a80e6d 100644 --- a/libs/evoral/evoral/SMF.hpp +++ b/libs/evoral/evoral/SMF.hpp @@ -64,6 +64,8 @@ public: void flush() {}; + double round_to_file_precision (double val) const; + private: std::string _file_path; smf_t* _smf; diff --git a/libs/evoral/evoral/types.hpp b/libs/evoral/evoral/types.hpp index e9ce503068..9e48a68e3c 100644 --- a/libs/evoral/evoral/types.hpp +++ b/libs/evoral/evoral/types.hpp @@ -21,6 +21,7 @@ #include <stdint.h> #include <list> +#include <cmath> namespace Evoral { @@ -30,6 +31,11 @@ typedef uint32_t FrameTime; /** Musical time: beats relative to some defined origin */ typedef double MusicalTime; +static inline bool musical_time_equal (MusicalTime a, MusicalTime b) { + /* acceptable tolerance is 1 tick. Nice if there was no magic number here */ + return fabs (a - b) <= (1.0/1920.0); +} + /** Type of an event (opaque, mapped by application) */ typedef uint32_t EventType; diff --git a/libs/evoral/src/Note.cpp b/libs/evoral/src/Note.cpp index 9440cde273..d97cfef429 100644 --- a/libs/evoral/src/Note.cpp +++ b/libs/evoral/src/Note.cpp @@ -39,7 +39,7 @@ Note<Time>::Note(uint8_t chan, Time t, Time l, uint8_t n, uint8_t v) _off_event.buffer()[2] = 0x40; assert(time() == t); - assert(length() - l <= 1.0/1920.0); /* acceptable tolerance is 1/ppqn. Nice if there was no magic number here */ + assert(musical_time_equal (length(), l)); assert(note() == n); assert(velocity() == v); assert(_on_event.channel() == _off_event.channel()); diff --git a/libs/evoral/src/SMF.cpp b/libs/evoral/src/SMF.cpp index 372c37c0bb..2103ad8eae 100644 --- a/libs/evoral/src/SMF.cpp +++ b/libs/evoral/src/SMF.cpp @@ -19,6 +19,7 @@ #define __STDC_LIMIT_MACROS 1 #include <cassert> +#include <cmath> #include <iostream> #include <stdint.h> #include "libsmf/smf.h" @@ -262,5 +263,13 @@ SMF::end_write() THROW_FILE_ERROR throw FileError(); } +double +SMF::round_to_file_precision (double val) const +{ + double div = ppqn(); + + return round (val * div) / div; +} + } // namespace Evoral |