diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2011-08-12 14:40:04 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2011-08-12 14:40:04 +0000 |
commit | 61eacc021a1783836f338638594e9bb5594c3d83 (patch) | |
tree | d2d66609cc16d5e176fac52524917797e01dbfb8 | |
parent | 11d041f6c021b70dd245fd41e9f167cb0f36c96e (diff) |
prevent illegal data being used to set note values, velocities and channels
git-svn-id: svn://localhost/ardour2/branches/3.0@9982 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | libs/evoral/evoral/Note.hpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/libs/evoral/evoral/Note.hpp b/libs/evoral/evoral/Note.hpp index d195e0d754..35b0b18f30 100644 --- a/libs/evoral/evoral/Note.hpp +++ b/libs/evoral/evoral/Note.hpp @@ -19,6 +19,7 @@ #ifndef EVORAL_NOTE_HPP #define EVORAL_NOTE_HPP +#include <algorithm> #include <glib.h> #include <stdint.h> #include "evoral/MIDIEvent.hpp" @@ -61,12 +62,16 @@ public: return _on_event.channel(); } + private: + inline int clamp (int val, int low, int high) { return std::min (std::max (val, low), high); } + + public: inline void set_time(Time t) { _off_event.time() = t + length(); _on_event.time() = t; } - inline void set_note(uint8_t n) { _on_event.buffer()[1] = n; _off_event.buffer()[1] = n; } - inline void set_velocity(uint8_t n) { _on_event.buffer()[2] = n; } - inline void set_off_velocity(uint8_t n) { _off_event.buffer()[2] = n; } + inline void set_note(uint8_t n) { uint8_t nn = clamp (n, 0, 127); _on_event.buffer()[1] = nn; _off_event.buffer()[1] = nn; } + inline void set_velocity(uint8_t n) { _on_event.buffer()[2] = clamp (n, 0, 127); } + inline void set_off_velocity(uint8_t n) { _off_event.buffer()[2] = clamp (n, 0, 127); } inline void set_length(Time l) { _off_event.time() = _on_event.time() + l; } - inline void set_channel(uint8_t c) { _on_event.set_channel(c); _off_event.set_channel(c); } + inline void set_channel(uint8_t c) { uint8_t cc = clamp (c, 0, 16); _on_event.set_channel(cc); _off_event.set_channel(cc); } inline Event<Time>& on_event() { return _on_event; } inline const Event<Time>& on_event() const { return _on_event; } |