# HG changeset patch # User Chris Cannam # Date 1413196104 -3600 # Node ID 65a488d8c1bb7f40b452cb0798f5c102ddeeffa0 # Parent 2260947be4aa315853f32e83ddb40b04b4d55ac0 Might help to actually commit these files diff -r 2260947be4aa -r 65a488d8c1bb runner/MIDIFeatureWriter.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runner/MIDIFeatureWriter.cpp Mon Oct 13 11:28:24 2014 +0100 @@ -0,0 +1,93 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Annotator + A utility for batch feature extraction from audio files. + Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London. + Copyright 2007-2014 QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "MIDIFeatureWriter.h" + +using namespace std; +using Vamp::Plugin; +using Vamp::PluginBase; + +#include "base/Exceptions.h" +#include "data/fileio/MIDIFileWriter.h" + +MIDIFeatureWriter::MIDIFeatureWriter() : + FileFeatureWriter(SupportOneFilePerTrackTransform | + SupportOneFilePerTrack | + SupportOneFileTotal, + "mid") +{ +} + +MIDIFeatureWriter::~MIDIFeatureWriter() +{ +} + +MIDIFeatureWriter::ParameterList +MIDIFeatureWriter::getSupportedParameters() const +{ + ParameterList pl = FileFeatureWriter::getSupportedParameters(); + return pl; +} + +void +MIDIFeatureWriter::setParameters(map ¶ms) +{ + FileFeatureWriter::setParameters(params); +} + +void +MIDIFeatureWriter::setTrackMetadata(QString, TrackMetadata) +{ + cerr << "MIDIFeatureWriter::setTrackMetadata: not supported (yet?)" << endl; +} + +void +MIDIFeatureWriter::write(QString trackId, + const Transform &transform, + const Plugin::OutputDescriptor& output, + const Plugin::FeatureList& features, + std::string summaryType) +{ + QString filename = getOutputFilename(trackId, transform.getIdentifier()); + if (filename == "") { + throw FailedToOpenOutputStream(trackId, transform.getIdentifier()); + } + + //!!! implement! +} + +void +MIDIFeatureWriter::finish() +{ + for (NoteMap::const_iterator i = m_notes.begin(); i != m_notes.end(); ++i) { + + QString filename = i->first; + NoteList notes = i->second; + float rate = m_rates[filename]; + + TrivialNoteExportable exportable(notes); + + { + MIDIFileWriter writer(filename, &exportable, rate); + if (!writer.isOK()) { + cerr << "ERROR: Failed to create MIDI writer: " + << writer.getError() << endl; + throw FileOperationFailed(filename, "create MIDI writer"); + } + writer.write(); + } + } +} + diff -r 2260947be4aa -r 65a488d8c1bb runner/MIDIFeatureWriter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runner/MIDIFeatureWriter.h Mon Oct 13 11:28:24 2014 +0100 @@ -0,0 +1,75 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Annotator + A utility for batch feature extraction from audio files. + + Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London. + Copyright 2007-2014 QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef _MIDI_FEATURE_WRITER_H_ +#define _MIDI_FEATURE_WRITER_H_ + +#include "transform/FileFeatureWriter.h" +#include "data/model/NoteData.h" + +class MIDIFileWriter; + +class MIDIFeatureWriter : public FileFeatureWriter +{ +public: + MIDIFeatureWriter(); + virtual ~MIDIFeatureWriter(); + + virtual ParameterList getSupportedParameters() const; + virtual void setParameters(map ¶ms); + + virtual void setTrackMetadata(QString trackid, TrackMetadata metadata); + + virtual void write(QString trackid, + const Transform &transform, + const Vamp::Plugin::OutputDescriptor &output, + const Vamp::Plugin::FeatureList &features, + std::string summaryType = ""); + + virtual void finish(); + + virtual QString getWriterTag() const { return "midi"; } + +private: + class TrivialNoteExportable : public NoteExportable { + public: + TrivialNoteExportable(NoteList notes) : m_notes(notes) { } + virtual NoteList getNotes() const { + return m_notes; + } + virtual NoteList getNotesWithin(int startFrame, int endFrame) const { + // Not required by MIDIFileWriter, not supported + return NoteList(); + } + private: + NoteList m_notes; + }; + + typedef map NoteMap; // output filename -> notes + NoteMap m_notes; + + typedef map SampleRateMap; // NoteData uses sample timing + SampleRateMap m_rates; + + typedef map ChannelMap; + ChannelMap m_channels; + + typedef map LastChannelMap; + LastChannelMap m_lastChannels; +}; + +#endif +