Mercurial > hg > sonic-annotator
changeset 139:a4bee1a374b4 midi
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 13 Oct 2014 11:43:24 +0100 |
parents | 65a488d8c1bb (diff) ee56e3e9eeb5 (current diff) |
children | 9b94545a7fdc |
files | tests/include.sh |
diffstat | 5 files changed, 177 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgsubstate Mon Oct 13 11:42:54 2014 +0100 +++ b/.hgsubstate Mon Oct 13 11:43:24 2014 +0100 @@ -1,3 +1,3 @@ d16f0fd6db6104d87882bc43788a3bb1b0f8c528 dataquay 879bdc878826bebec67130326f99397c430419b1 sv-dependency-builds -952005e252668fecdee23fed6227c52ba28cf0a3 svcore +2104ea2204d2b8e5f19401526d8009ac8eba63ea svcore
--- a/runner.pro Mon Oct 13 11:42:54 2014 +0100 +++ b/runner.pro Mon Oct 13 11:43:24 2014 +0100 @@ -53,8 +53,8 @@ TARGET = sonic-annotator -DEPENDPATH += . svcore -INCLUDEPATH += . dataquay svcore +DEPENDPATH += . svcore runner +INCLUDEPATH += . dataquay svcore runner QMAKE_LIBDIR = svcore $$QMAKE_LIBDIR @@ -84,6 +84,7 @@ runner/FeatureWriterFactory.h \ runner/DefaultFeatureWriter.h \ runner/FeatureExtractionManager.h \ + runner/MIDIFeatureWriter.h \ runner/MultiplexedReader.h SOURCES += \ @@ -92,6 +93,7 @@ runner/FeatureExtractionManager.cpp \ runner/AudioDBFeatureWriter.cpp \ runner/FeatureWriterFactory.cpp \ + runner/MIDIFeatureWriter.cpp \ runner/MultiplexedReader.cpp !win32 {
--- a/runner/FeatureWriterFactory.cpp Mon Oct 13 11:42:54 2014 +0100 +++ b/runner/FeatureWriterFactory.cpp Mon Oct 13 11:43:24 2014 +0100 @@ -19,6 +19,7 @@ #include "DefaultFeatureWriter.h" #include "rdf/RDFFeatureWriter.h" #include "AudioDBFeatureWriter.h" +#include "MIDIFeatureWriter.h" #include "transform/CSVFeatureWriter.h" set<string> @@ -29,6 +30,7 @@ tags.insert("rdf"); tags.insert("audiodb"); tags.insert("csv"); + tags.insert("midi"); return tags; } @@ -43,6 +45,8 @@ return new AudioDBFeatureWriter(); } else if (tag == "csv") { return new CSVFeatureWriter(); + } else if (tag == "midi") { + return new MIDIFeatureWriter(); } return 0;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runner/MIDIFeatureWriter.cpp Mon Oct 13 11:43: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<string, string> ¶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(); + } + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runner/MIDIFeatureWriter.h Mon Oct 13 11:43: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<string, string> ¶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<QString, NoteList> NoteMap; // output filename -> notes + NoteMap m_notes; + + typedef map<QString, float> SampleRateMap; // NoteData uses sample timing + SampleRateMap m_rates; + + typedef map<TransformId, int> ChannelMap; + ChannelMap m_channels; + + typedef map<QString, int> LastChannelMap; + LastChannelMap m_lastChannels; +}; + +#endif +