annotate data/fileio/DataFileReaderFactory.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 14e0f60435b8
children 183ee2a55fc7
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 "DataFileReaderFactory.h"
Chris@148 17 #include "MIDIFileReader.h"
Chris@148 18 #include "CSVFileReader.h"
Chris@148 19
Chris@150 20 #include "model/Model.h"
Chris@148 21
Chris@148 22 #include <QString>
Chris@148 23
Chris@148 24 QString
Chris@148 25 DataFileReaderFactory::getKnownExtensions()
Chris@148 26 {
Chris@148 27 return "*.svl *.csv *.lab *.mid *.txt";
Chris@148 28 }
Chris@148 29
Chris@148 30 DataFileReader *
Chris@148 31 DataFileReaderFactory::createReader(QString path, size_t mainModelSampleRate)
Chris@148 32 {
Chris@148 33 QString err;
Chris@148 34
Chris@148 35 DataFileReader *reader = 0;
Chris@148 36
Chris@148 37 reader = new MIDIFileReader(path, mainModelSampleRate);
Chris@148 38 if (reader->isOK()) return reader;
Chris@148 39 if (reader->getError() != "") err = reader->getError();
Chris@148 40 delete reader;
Chris@148 41
Chris@148 42 reader = new CSVFileReader(path, mainModelSampleRate);
Chris@148 43 if (reader->isOK()) return reader;
Chris@148 44 if (reader->getError() != "") err = reader->getError();
Chris@148 45 delete reader;
Chris@148 46
Chris@148 47 return 0;
Chris@148 48 }
Chris@148 49
Chris@148 50 Model *
Chris@148 51 DataFileReaderFactory::load(QString path, size_t mainModelSampleRate)
Chris@148 52 {
Chris@148 53 DataFileReader *reader = createReader(path, mainModelSampleRate);
Chris@148 54 if (!reader) return NULL;
Chris@148 55
Chris@308 56 try {
Chris@308 57 Model *model = reader->load();
Chris@308 58 delete reader;
Chris@308 59 return model;
Chris@308 60 } catch (Exception) {
Chris@308 61 delete reader;
Chris@308 62 throw;
Chris@308 63 }
Chris@148 64 }
Chris@148 65