Chris@148: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@148: 
Chris@148: /*
Chris@148:     Sonic Visualiser
Chris@148:     An audio file viewer and annotation editor.
Chris@148:     Centre for Digital Music, Queen Mary, University of London.
Chris@148:     This file copyright 2006 Chris Cannam.
Chris@148:     
Chris@148:     This program is free software; you can redistribute it and/or
Chris@148:     modify it under the terms of the GNU General Public License as
Chris@148:     published by the Free Software Foundation; either version 2 of the
Chris@148:     License, or (at your option) any later version.  See the file
Chris@148:     COPYING included with this distribution for more information.
Chris@148: */
Chris@148: 
Chris@148: #ifndef _DATA_FILE_READER_FACTORY_H_
Chris@148: #define _DATA_FILE_READER_FACTORY_H_
Chris@148: 
Chris@148: #include <QString>
Chris@148: 
Chris@392: #include "CSVFormat.h"
Chris@392: #include "MIDIFileReader.h"
Chris@392: 
Chris@148: class DataFileReader;
Chris@148: class Model;
Chris@148: 
Chris@148: class DataFileReaderFactory
Chris@148: {
Chris@148: public:
Chris@308:     enum Exception { ImportCancelled };
Chris@308: 
Chris@148:     /**
Chris@148:      * Return the file extensions that we have data file readers for,
Chris@148:      * in a format suitable for use with QFileDialog.  For example,
Chris@148:      * "*.csv *.xml".
Chris@148:      */
Chris@148:     static QString getKnownExtensions();
Chris@148: 
Chris@148:     /**
Chris@148:      * Return a data file reader initialised to the file at the
Chris@148:      * given path, or NULL if no suitable reader for this path is
Chris@148:      * available or the file cannot be opened.
Chris@392:      *
Chris@148:      * Caller owns the returned object and must delete it after use.
Chris@392:      * 
Chris@392:      * Note that this function is non-interactive -- the user is not
Chris@392:      * asked for file format preferences.
Chris@148:      */
Chris@148:     static DataFileReader *createReader(QString path,
Chris@392:                                         MIDIFileImportPreferenceAcquirer *,
Chris@148: 					size_t mainModelSampleRate);
Chris@148: 
Chris@148:     /**
Chris@148:      * Read the given path, if a suitable reader is available.
Chris@148:      * Return NULL if no reader succeeded in reading this file.
Chris@392:      * 
Chris@392:      * Note that this function is non-interactive -- the user is not
Chris@392:      * asked for file format preferences.  If the CSV file reader is
Chris@392:      * used, it is with default format.
Chris@148:      */
Chris@392:     static Model *load(QString path,
Chris@392:                        MIDIFileImportPreferenceAcquirer *acquirer,
Chris@392:                        size_t mainModelSampleRate);
Chris@392: 
Chris@392:     /**
Chris@392:      * Read the given path, if a suitable reader is available.
Chris@392:      * Return NULL if no reader succeeded in reading this file.
Chris@392:      * Do not attempt the general CSV reader.
Chris@392:      */
Chris@392:     static Model *loadNonCSV(QString path,
Chris@392:                              MIDIFileImportPreferenceAcquirer *acquirer,
Chris@392:                              size_t mainModelSampleRate);
Chris@392: 
Chris@392:     /**
Chris@392:      * Read the given path using the CSV reader with the given format.
Chris@392:      * Return NULL if it failed in reading this file.
Chris@392:      */
Chris@392:     static Model *loadCSV(QString path,
Chris@392:                           CSVFormat format,
Chris@392:                           size_t mainModelSampleRate);
Chris@392: 
Chris@392: protected:
Chris@392:     static DataFileReader *createReader(QString path, bool csv,
Chris@392:                                         MIDIFileImportPreferenceAcquirer *,
Chris@392:                                         CSVFormat format,
Chris@392: 					size_t mainModelSampleRate);
Chris@148: };
Chris@148: 
Chris@148: #endif
Chris@148: