NoteModel.cpp

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #include "NoteModel.h"
00017 
00018 NoteModel::PointList
00019 NoteModel::getPoints(long start, long end) const
00020 {
00021     if (start > end) return PointList();
00022     QMutexLocker locker(&m_mutex);
00023 
00024     Note endPoint(end);
00025     
00026     PointListIterator endItr = m_points.upper_bound(endPoint);
00027 
00028     if (endItr != m_points.end()) ++endItr;
00029     if (endItr != m_points.end()) ++endItr;
00030 
00031     PointList rv;
00032 
00033     for (PointListIterator i = endItr; i != m_points.begin(); ) {
00034         --i;
00035         if (i->frame < start) {
00036             if (i->frame + long(i->duration) >= start) {
00037                 rv.insert(*i);
00038             }
00039         } else if (i->frame <= end) {
00040             rv.insert(*i);
00041         }
00042     }
00043 
00044     return rv;
00045 }
00046 
00047 NoteModel::PointList
00048 NoteModel::getPoints(long frame) const
00049 {
00050     QMutexLocker locker(&m_mutex);
00051 
00052     if (m_resolution == 0) return PointList();
00053 
00054     long start = (frame / m_resolution) * m_resolution;
00055     long end = start + m_resolution;
00056 
00057     Note endPoint(end);
00058     
00059     PointListIterator endItr = m_points.upper_bound(endPoint);
00060 
00061     PointList rv;
00062 
00063     for (PointListIterator i = endItr; i != m_points.begin(); ) {
00064         --i;
00065         if (i->frame < start) {
00066             if (i->frame + long(i->duration) >= start) {
00067                 rv.insert(*i);
00068             }
00069         } else if (i->frame <= end) {
00070             rv.insert(*i);
00071         }
00072     }
00073 
00074     return rv;
00075 }

Generated on Wed Feb 20 15:45:27 2008 for SonicVisualiser by  doxygen 1.5.1