Chris@498: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@498: 
Chris@498: /*
Chris@498:     Sonic Visualiser
Chris@498:     An audio file viewer and annotation editor.
Chris@498: 
Chris@498:     Sonic Annotator
Chris@498:     A utility for batch feature extraction from audio files.
Chris@498: 
Chris@498:     Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London.
Chris@498:     Copyright 2007-2008 QMUL.
Chris@498: 
Chris@498:     This program is free software; you can redistribute it and/or
Chris@498:     modify it under the terms of the GNU General Public License as
Chris@498:     published by the Free Software Foundation; either version 2 of the
Chris@498:     License, or (at your option) any later version.  See the file
Chris@498:     COPYING included with this distribution for more information.
Chris@498: */
Chris@498: 
Chris@498: #ifndef _RDF_FEATURE_WRITER_H_
Chris@498: #define _RDF_FEATURE_WRITER_H_
Chris@498: 
Chris@498: #include <string>
Chris@498: #include <map>
Chris@498: #include <set>
Chris@498: 
Chris@498: #include <QString>
Chris@498: 
Chris@498: #include "transform/FileFeatureWriter.h"
Chris@498: 
Chris@498: #include "PluginRDFDescription.h"
Chris@498: 
Chris@498: using std::string;
Chris@498: using std::map;
Chris@498: using std::set;
Chris@498: using std::pair;
Chris@498: 
Chris@498: class QTextStream;
Chris@498: class QFile;
Chris@498: 
Chris@498: class RDFFeatureWriter : public FileFeatureWriter
Chris@498: {
Chris@498: public:
Chris@498:     RDFFeatureWriter();
Chris@498:     virtual ~RDFFeatureWriter();
Chris@498: 
Chris@998:     virtual string getDescription() const;
Chris@998: 
Chris@498:     virtual ParameterList getSupportedParameters() const;
Chris@498:     virtual void setParameters(map<string, string> &params);
Chris@498: 
Chris@504:     virtual void setTrackMetadata(QString trackid, TrackMetadata metadata);
Chris@504: 
Chris@498:     virtual void write(QString trackid,
Chris@498:                        const Transform &transform,
Chris@498:                        const Vamp::Plugin::OutputDescriptor &output,
Chris@498:                        const Vamp::Plugin::FeatureList &features,
Chris@498:                        std::string summaryType = "");
Chris@498: 
Chris@510:     virtual void setFixedEventTypeURI(QString uri); // something of a hack
Chris@510: 
Chris@498:     virtual void finish();
Chris@498: 
Chris@605:     virtual QString getWriterTag() const { return "rdf"; }
Chris@605: 
Chris@498: private:
Chris@498:     typedef map<QString, PluginRDFDescription> RDFDescriptionMap; // by plugin id
Chris@498:     RDFDescriptionMap m_rdfDescriptions;
Chris@498: 
Chris@504:     typedef map<QString, TrackMetadata> TrackMetadataMap;
Chris@504:     TrackMetadataMap m_metadata;
Chris@504: 
Chris@1144:     bool haveTitleArtistMetadata(QString trackId) const {
Chris@1144:         // Formerly in various places we used to test whether a track
Chris@1144:         // appeared in the metadata map at all, in order to determine
Chris@1144:         // whether it had any associated metadata. That won't work any
Chris@1144:         // more because metadata now includes duration, which can
Chris@1144:         // appear even if no title/artist are given and which is not
Chris@1144:         // something whose presence indicates the involvement of a
Chris@1144:         // "publication Track". So check for artist/title explicitly.
Chris@1144:         auto mitr = m_metadata.find(trackId);
Chris@1144:         if (mitr == m_metadata.end()) return false;
Chris@1144:         return (mitr->second.title != "" || mitr->second.maker != "");
Chris@1144:     }
Chris@1144: 
Chris@510:     QString m_fixedEventTypeURI;
Chris@510: 
Chris@590:     virtual void reviewFileForAppending(QString filename);
Chris@590: 
Chris@498:     void writePrefixes(QTextStream *);
Chris@498:     void writeSignalDescription(QTextStream *, QString);
Chris@498:     void writeLocalFeatureTypes(QTextStream *,
Chris@498:                                 const Transform &,
Chris@498:                                 const Vamp::Plugin::OutputDescriptor &,
Chris@730:                                 PluginRDFDescription &,
Chris@730:                                 std::string summaryType);
Chris@498: 
Chris@498:     void writeSparseRDF(QTextStream *stream,
Chris@498:                         const Transform &transform,
Chris@498:                         const Vamp::Plugin::OutputDescriptor &output,
Chris@498:                         const Vamp::Plugin::FeatureList &features,
Chris@498:                         PluginRDFDescription &desc,
Chris@498:                         QString timelineURI);
Chris@498: 
Chris@507:     void writeTrackLevelRDF(QTextStream *stream,
Chris@507:                             const Transform &transform,
Chris@507:                             const Vamp::Plugin::OutputDescriptor &output,
Chris@507:                             const Vamp::Plugin::FeatureList &features,
Chris@507:                             PluginRDFDescription &desc,
Chris@507:                             QString signalURI);
Chris@507: 
Chris@498:     void writeDenseRDF(QTextStream *stream,
Chris@498:                        const Transform &transform,
Chris@498:                        const Vamp::Plugin::OutputDescriptor &output,
Chris@498:                        const Vamp::Plugin::FeatureList &features,
Chris@498:                        PluginRDFDescription &desc,
Chris@498:                        QString signalURI,
Chris@498:                        QString timelineURI);
Chris@498: 
Chris@498:     set<QString> m_startedTrackIds;
Chris@498: 
Chris@498:     map<QTextStream *, set<Transform> > m_startedStreamTransforms;
Chris@498: 
Chris@585:     map<QString, QString> m_trackTrackURIs;
Chris@498:     map<QString, QString> m_trackTimelineURIs;
Chris@498:     map<QString, QString> m_trackSignalURIs;
Chris@498: 
Chris@498:     map<Transform, QString> m_transformURIs;
Chris@498:     map<Transform, QString> m_syntheticEventTypeURIs;
Chris@498:     map<Transform, QString> m_syntheticSignalTypeURIs;
Chris@498: 
Chris@498:     typedef pair<QString, Transform> StringTransformPair;
Chris@498:     typedef pair<QTextStream *, QString> StreamBuffer;
Chris@498:     map<StringTransformPair, StreamBuffer> m_openDenseFeatures; // signal URI + transform -> stream + text
Chris@594:     QString m_userAudioFileUri;
Chris@594:     QString m_userTrackUri;
Chris@594:     QString m_userMakerUri;
Chris@498: 
Chris@498:     bool m_plain;
Chris@498: 
Chris@597:     bool m_network;
Chris@597:     bool m_networkRetrieved;
Chris@597: 
Chris@930:     long m_count;
Chris@498: };
Chris@498: 
Chris@498: #endif