Chris@147: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@147: Chris@147: /* Chris@147: Sonic Visualiser Chris@147: An audio file viewer and annotation editor. Chris@147: Centre for Digital Music, Queen Mary, University of London. Chris@147: This file copyright 2006 Chris Cannam. Chris@147: Chris@147: This program is free software; you can redistribute it and/or Chris@147: modify it under the terms of the GNU General Public License as Chris@147: published by the Free Software Foundation; either version 2 of the Chris@147: License, or (at your option) any later version. See the file Chris@147: COPYING included with this distribution for more information. Chris@147: */ Chris@147: Chris@147: #include "NoteModel.h" Chris@147: Chris@147: NoteModel::PointList Chris@147: NoteModel::getPoints(long start, long end) const Chris@147: { Chris@147: if (start > end) return PointList(); Chris@147: QMutexLocker locker(&m_mutex); Chris@147: Chris@147: Note endPoint(end); Chris@147: Chris@147: PointListIterator endItr = m_points.upper_bound(endPoint); Chris@147: Chris@147: if (endItr != m_points.end()) ++endItr; Chris@147: if (endItr != m_points.end()) ++endItr; Chris@147: Chris@147: PointList rv; Chris@147: Chris@147: for (PointListIterator i = endItr; i != m_points.begin(); ) { Chris@147: --i; Chris@147: if (i->frame < start) { Chris@259: if (i->frame + long(i->duration) >= start) { Chris@147: rv.insert(*i); Chris@147: } Chris@147: } else if (i->frame <= end) { Chris@147: rv.insert(*i); Chris@147: } Chris@147: } Chris@147: Chris@147: return rv; Chris@147: } Chris@147: Chris@147: NoteModel::PointList Chris@147: NoteModel::getPoints(long frame) const Chris@147: { Chris@147: QMutexLocker locker(&m_mutex); Chris@147: Chris@147: if (m_resolution == 0) return PointList(); Chris@147: Chris@147: long start = (frame / m_resolution) * m_resolution; Chris@147: long end = start + m_resolution; Chris@147: Chris@147: Note endPoint(end); Chris@147: Chris@147: PointListIterator endItr = m_points.upper_bound(endPoint); Chris@147: Chris@147: PointList rv; Chris@147: Chris@147: for (PointListIterator i = endItr; i != m_points.begin(); ) { Chris@147: --i; Chris@147: if (i->frame < start) { Chris@259: if (i->frame + long(i->duration) >= start) { Chris@147: rv.insert(*i); Chris@147: } Chris@147: } else if (i->frame <= end) { Chris@147: rv.insert(*i); Chris@147: } Chris@147: } Chris@147: Chris@147: return rv; Chris@147: }