Mercurial > hg > svgui
diff layer/NoteLayer.cpp @ 76:45ba0b381c5d
* Fix long-standing off-by-1 bug in WaveFileModel that was getting us the wrong
values for almost all audio data when merging channels (channel == -1)
* Implement cut, copy and paste
* Make draw mode work properly in time value layer
* Minor fixes to CSV import
author | Chris Cannam |
---|---|
date | Fri, 07 Apr 2006 17:50:33 +0000 |
parents | bf306158803d |
children | 19bf27e4fb29 |
line wrap: on
line diff
--- a/layer/NoteLayer.cpp Thu Apr 06 12:12:41 2006 +0000 +++ b/layer/NoteLayer.cpp Fri Apr 07 17:50:33 2006 +0000 @@ -727,6 +727,72 @@ command->finish(); } +void +NoteLayer::deleteSelection(Selection s) +{ + NoteModel::EditCommand *command = + new NoteModel::EditCommand(m_model, tr("Delete Selected Points")); + + NoteModel::PointList points = + m_model->getPoints(s.getStartFrame(), s.getEndFrame()); + + for (NoteModel::PointList::iterator i = points.begin(); + i != points.end(); ++i) { + + if (s.contains(i->frame)) { + command->deletePoint(*i); + } + } + + command->finish(); +} + +void +NoteLayer::copy(Selection s, Clipboard &to) +{ + NoteModel::PointList points = + m_model->getPoints(s.getStartFrame(), s.getEndFrame()); + + for (NoteModel::PointList::iterator i = points.begin(); + i != points.end(); ++i) { + if (s.contains(i->frame)) { + Clipboard::Point point(i->frame, i->label); + to.addPoint(point); + } + } +} + +void +NoteLayer::paste(const Clipboard &from, int frameOffset) +{ + const Clipboard::PointList &points = from.getPoints(); + + NoteModel::EditCommand *command = + new NoteModel::EditCommand(m_model, tr("Paste")); + + for (Clipboard::PointList::const_iterator i = points.begin(); + i != points.end(); ++i) { + + if (!i->haveFrame()) continue; + size_t frame = 0; + if (frameOffset > 0 || -frameOffset < i->getFrame()) { + frame = i->getFrame() + frameOffset; + } + NoteModel::Point newPoint(frame); + + if (i->haveLabel()) newPoint.label = i->getLabel(); + if (i->haveValue()) newPoint.value = i->getValue(); + else newPoint.value = (m_model->getValueMinimum() + + m_model->getValueMaximum()) / 2; + if (i->haveDuration()) newPoint.duration = i->getDuration(); + else newPoint.duration = m_model->getResolution(); //!!! + + command->addPoint(newPoint); + } + + command->finish(); +} + QString NoteLayer::toXmlString(QString indent, QString extraAttributes) const {