Chris@137
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@137
|
2
|
Chris@137
|
3 /*
|
Chris@137
|
4 Sonic Annotator
|
Chris@137
|
5 A utility for batch feature extraction from audio files.
|
Chris@137
|
6 Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London.
|
Chris@137
|
7 Copyright 2007-2014 QMUL.
|
Chris@137
|
8
|
Chris@137
|
9 This program is free software; you can redistribute it and/or
|
Chris@137
|
10 modify it under the terms of the GNU General Public License as
|
Chris@137
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@137
|
12 License, or (at your option) any later version. See the file
|
Chris@137
|
13 COPYING included with this distribution for more information.
|
Chris@137
|
14 */
|
Chris@137
|
15
|
Chris@137
|
16 #include "MIDIFeatureWriter.h"
|
Chris@137
|
17
|
Chris@137
|
18 using namespace std;
|
Chris@137
|
19 using Vamp::Plugin;
|
Chris@137
|
20 using Vamp::PluginBase;
|
Chris@137
|
21
|
Chris@137
|
22 #include "base/Exceptions.h"
|
Chris@137
|
23 #include "data/fileio/MIDIFileWriter.h"
|
Chris@137
|
24
|
Chris@137
|
25 MIDIFeatureWriter::MIDIFeatureWriter() :
|
Chris@137
|
26 FileFeatureWriter(SupportOneFilePerTrackTransform |
|
Chris@137
|
27 SupportOneFilePerTrack |
|
Chris@137
|
28 SupportOneFileTotal,
|
Chris@137
|
29 "mid")
|
Chris@137
|
30 {
|
Chris@137
|
31 }
|
Chris@137
|
32
|
Chris@137
|
33 MIDIFeatureWriter::~MIDIFeatureWriter()
|
Chris@137
|
34 {
|
Chris@137
|
35 }
|
Chris@137
|
36
|
Chris@137
|
37 MIDIFeatureWriter::ParameterList
|
Chris@137
|
38 MIDIFeatureWriter::getSupportedParameters() const
|
Chris@137
|
39 {
|
Chris@137
|
40 ParameterList pl = FileFeatureWriter::getSupportedParameters();
|
Chris@137
|
41 return pl;
|
Chris@137
|
42 }
|
Chris@137
|
43
|
Chris@137
|
44 void
|
Chris@137
|
45 MIDIFeatureWriter::setParameters(map<string, string> ¶ms)
|
Chris@137
|
46 {
|
Chris@137
|
47 FileFeatureWriter::setParameters(params);
|
Chris@137
|
48 }
|
Chris@137
|
49
|
Chris@137
|
50 void
|
Chris@137
|
51 MIDIFeatureWriter::setTrackMetadata(QString, TrackMetadata)
|
Chris@137
|
52 {
|
Chris@137
|
53 cerr << "MIDIFeatureWriter::setTrackMetadata: not supported (yet?)" << endl;
|
Chris@137
|
54 }
|
Chris@137
|
55
|
Chris@137
|
56 void
|
Chris@137
|
57 MIDIFeatureWriter::write(QString trackId,
|
Chris@137
|
58 const Transform &transform,
|
Chris@137
|
59 const Plugin::OutputDescriptor& output,
|
Chris@137
|
60 const Plugin::FeatureList& features,
|
Chris@137
|
61 std::string summaryType)
|
Chris@137
|
62 {
|
Chris@137
|
63 QString filename = getOutputFilename(trackId, transform.getIdentifier());
|
Chris@137
|
64 if (filename == "") {
|
Chris@137
|
65 throw FailedToOpenOutputStream(trackId, transform.getIdentifier());
|
Chris@137
|
66 }
|
Chris@137
|
67
|
Chris@137
|
68 //!!! implement!
|
Chris@137
|
69 }
|
Chris@137
|
70
|
Chris@137
|
71 void
|
Chris@137
|
72 MIDIFeatureWriter::finish()
|
Chris@137
|
73 {
|
Chris@137
|
74 for (NoteMap::const_iterator i = m_notes.begin(); i != m_notes.end(); ++i) {
|
Chris@137
|
75
|
Chris@137
|
76 QString filename = i->first;
|
Chris@137
|
77 NoteList notes = i->second;
|
Chris@137
|
78 float rate = m_rates[filename];
|
Chris@137
|
79
|
Chris@137
|
80 TrivialNoteExportable exportable(notes);
|
Chris@137
|
81
|
Chris@137
|
82 {
|
Chris@137
|
83 MIDIFileWriter writer(filename, &exportable, rate);
|
Chris@137
|
84 if (!writer.isOK()) {
|
Chris@137
|
85 cerr << "ERROR: Failed to create MIDI writer: "
|
Chris@137
|
86 << writer.getError() << endl;
|
Chris@137
|
87 throw FileOperationFailed(filename, "create MIDI writer");
|
Chris@137
|
88 }
|
Chris@137
|
89 writer.write();
|
Chris@137
|
90 }
|
Chris@137
|
91 }
|
Chris@137
|
92 }
|
Chris@137
|
93
|