annotate data/model/NoteModel.cpp @ 301:73537d900d4b

* Add MIDI file export (closes FR#1643721)
author Chris Cannam
date Thu, 04 Oct 2007 11:52:38 +0000
parents dc46851837d6
children
rev   line source
Chris@147 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@147 2
Chris@147 3 /*
Chris@147 4 Sonic Visualiser
Chris@147 5 An audio file viewer and annotation editor.
Chris@147 6 Centre for Digital Music, Queen Mary, University of London.
Chris@147 7 This file copyright 2006 Chris Cannam.
Chris@147 8
Chris@147 9 This program is free software; you can redistribute it and/or
Chris@147 10 modify it under the terms of the GNU General Public License as
Chris@147 11 published by the Free Software Foundation; either version 2 of the
Chris@147 12 License, or (at your option) any later version. See the file
Chris@147 13 COPYING included with this distribution for more information.
Chris@147 14 */
Chris@147 15
Chris@147 16 #include "NoteModel.h"
Chris@147 17
Chris@147 18 NoteModel::PointList
Chris@147 19 NoteModel::getPoints(long start, long end) const
Chris@147 20 {
Chris@147 21 if (start > end) return PointList();
Chris@147 22 QMutexLocker locker(&m_mutex);
Chris@147 23
Chris@147 24 Note endPoint(end);
Chris@147 25
Chris@147 26 PointListIterator endItr = m_points.upper_bound(endPoint);
Chris@147 27
Chris@147 28 if (endItr != m_points.end()) ++endItr;
Chris@147 29 if (endItr != m_points.end()) ++endItr;
Chris@147 30
Chris@147 31 PointList rv;
Chris@147 32
Chris@147 33 for (PointListIterator i = endItr; i != m_points.begin(); ) {
Chris@147 34 --i;
Chris@147 35 if (i->frame < start) {
Chris@259 36 if (i->frame + long(i->duration) >= start) {
Chris@147 37 rv.insert(*i);
Chris@147 38 }
Chris@147 39 } else if (i->frame <= end) {
Chris@147 40 rv.insert(*i);
Chris@147 41 }
Chris@147 42 }
Chris@147 43
Chris@147 44 return rv;
Chris@147 45 }
Chris@147 46
Chris@147 47 NoteModel::PointList
Chris@147 48 NoteModel::getPoints(long frame) const
Chris@147 49 {
Chris@147 50 QMutexLocker locker(&m_mutex);
Chris@147 51
Chris@147 52 if (m_resolution == 0) return PointList();
Chris@147 53
Chris@147 54 long start = (frame / m_resolution) * m_resolution;
Chris@147 55 long end = start + m_resolution;
Chris@147 56
Chris@147 57 Note endPoint(end);
Chris@147 58
Chris@147 59 PointListIterator endItr = m_points.upper_bound(endPoint);
Chris@147 60
Chris@147 61 PointList rv;
Chris@147 62
Chris@147 63 for (PointListIterator i = endItr; i != m_points.begin(); ) {
Chris@147 64 --i;
Chris@147 65 if (i->frame < start) {
Chris@259 66 if (i->frame + long(i->duration) >= start) {
Chris@147 67 rv.insert(*i);
Chris@147 68 }
Chris@147 69 } else if (i->frame <= end) {
Chris@147 70 rv.insert(*i);
Chris@147 71 }
Chris@147 72 }
Chris@147 73
Chris@147 74 return rv;
Chris@147 75 }