Mercurial > hg > svcore
annotate data/fileio/CSVFileWriter.cpp @ 363:0e30c8ec15a0
* Add wave file model method for reading more than one channel at once,
avoiding ludicrously expensive backward seeks and double-reads when
playing multi-channel files or using them as inputs to feature extraction
plugins
author | Chris Cannam |
---|---|
date | Thu, 24 Jan 2008 14:35:43 +0000 |
parents | 4b2ea82fd0ed |
children | 341e4e1a6ed3 |
rev | line source |
---|---|
Chris@148 | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
Chris@148 | 2 |
Chris@148 | 3 /* |
Chris@148 | 4 Sonic Visualiser |
Chris@148 | 5 An audio file viewer and annotation editor. |
Chris@148 | 6 Centre for Digital Music, Queen Mary, University of London. |
Chris@148 | 7 This file copyright 2006 Chris Cannam. |
Chris@148 | 8 |
Chris@148 | 9 This program is free software; you can redistribute it and/or |
Chris@148 | 10 modify it under the terms of the GNU General Public License as |
Chris@148 | 11 published by the Free Software Foundation; either version 2 of the |
Chris@148 | 12 License, or (at your option) any later version. See the file |
Chris@148 | 13 COPYING included with this distribution for more information. |
Chris@148 | 14 */ |
Chris@148 | 15 |
Chris@148 | 16 #include "CSVFileWriter.h" |
Chris@148 | 17 |
Chris@150 | 18 #include "model/Model.h" |
Chris@148 | 19 #include "model/SparseOneDimensionalModel.h" |
Chris@148 | 20 #include "model/SparseTimeValueModel.h" |
Chris@148 | 21 #include "model/NoteModel.h" |
Chris@148 | 22 #include "model/TextModel.h" |
Chris@148 | 23 |
Chris@148 | 24 #include <QFile> |
Chris@148 | 25 #include <QTextStream> |
Chris@148 | 26 |
Chris@148 | 27 CSVFileWriter::CSVFileWriter(QString path, Model *model, QString delimiter) : |
Chris@148 | 28 m_path(path), |
Chris@148 | 29 m_model(model), |
Chris@148 | 30 m_error(""), |
Chris@148 | 31 m_delimiter(delimiter) |
Chris@148 | 32 { |
Chris@148 | 33 } |
Chris@148 | 34 |
Chris@148 | 35 CSVFileWriter::~CSVFileWriter() |
Chris@148 | 36 { |
Chris@148 | 37 } |
Chris@148 | 38 |
Chris@148 | 39 bool |
Chris@148 | 40 CSVFileWriter::isOK() const |
Chris@148 | 41 { |
Chris@148 | 42 return m_error == ""; |
Chris@148 | 43 } |
Chris@148 | 44 |
Chris@148 | 45 QString |
Chris@148 | 46 CSVFileWriter::getError() const |
Chris@148 | 47 { |
Chris@148 | 48 return m_error; |
Chris@148 | 49 } |
Chris@148 | 50 |
Chris@148 | 51 void |
Chris@148 | 52 CSVFileWriter::write() |
Chris@148 | 53 { |
Chris@148 | 54 QFile file(m_path); |
Chris@148 | 55 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { |
Chris@148 | 56 m_error = tr("Failed to open file %1 for writing").arg(m_path); |
Chris@148 | 57 return; |
Chris@148 | 58 } |
Chris@148 | 59 |
Chris@148 | 60 QTextStream out(&file); |
Chris@148 | 61 out << m_model->toDelimitedDataString(m_delimiter); |
Chris@148 | 62 |
Chris@148 | 63 file.close(); |
Chris@148 | 64 } |
Chris@148 | 65 |
Chris@148 | 66 |