Chris@8: /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ Chris@8: Chris@8: /* Chris@8: A waveform viewer and audio annotation editor. Chris@8: Chris Cannam, Queen Mary University of London, 2005-2006 Chris@8: Chris@8: This is experimental software. Not for distribution. Chris@8: */ Chris@8: Chris@8: #include "Selection.h" Chris@8: Chris@8: Selection::Selection() : Chris@8: m_startFrame(0), Chris@8: m_endFrame(0) Chris@8: { Chris@8: } Chris@8: Chris@8: Selection::Selection(size_t startFrame, size_t endFrame) : Chris@8: m_startFrame(startFrame), Chris@8: m_endFrame(endFrame) Chris@8: { Chris@8: if (m_startFrame > m_endFrame) { Chris@8: size_t tmp = m_endFrame; Chris@8: m_endFrame = m_startFrame; Chris@8: m_startFrame = tmp; Chris@8: } Chris@8: } Chris@8: Chris@8: Selection::Selection(const Selection &s) : Chris@8: m_startFrame(s.m_startFrame), Chris@8: m_endFrame(s.m_endFrame) Chris@8: { Chris@8: } Chris@8: Chris@8: Selection & Chris@8: Selection::operator=(const Selection &s) Chris@8: { Chris@8: if (this != &s) { Chris@8: m_startFrame = s.m_startFrame; Chris@8: m_endFrame = s.m_endFrame; Chris@8: } Chris@8: return *this; Chris@8: } Chris@8: Chris@8: Selection::~Selection() Chris@8: { Chris@8: } Chris@8: Chris@8: bool Chris@8: Selection::isEmpty() const Chris@8: { Chris@8: return m_startFrame == m_endFrame; Chris@8: } Chris@8: Chris@8: size_t Chris@8: Selection::getStartFrame() const Chris@8: { Chris@8: return m_startFrame; Chris@8: } Chris@8: Chris@8: size_t Chris@8: Selection::getEndFrame() const Chris@8: { Chris@8: return m_endFrame; Chris@8: } Chris@8: Chris@8: bool Chris@9: Selection::contains(size_t frame) const Chris@9: { Chris@9: return (frame >= m_startFrame) && (frame < m_endFrame); Chris@9: } Chris@9: Chris@9: bool Chris@8: Selection::operator<(const Selection &s) const Chris@8: { Chris@9: if (isEmpty()) { Chris@9: if (s.isEmpty()) return false; Chris@9: else return true; Chris@9: } else { Chris@9: if (s.isEmpty()) return false; Chris@9: else return (m_startFrame < s.m_startFrame); Chris@9: } Chris@8: } Chris@8: Chris@8: bool Chris@8: Selection::operator==(const Selection &s) const Chris@8: { Chris@9: if (isEmpty()) return s.isEmpty(); Chris@9: Chris@8: return (m_startFrame == s.m_startFrame && Chris@8: m_endFrame == s.m_endFrame); Chris@8: } Chris@8: