annotate src/Instruments.cpp @ 167:416b555df3b2 finetune

More on returning fine tuning (but we're treating different shifts of the same pitch as different notes at the moment which is not right)
author Chris Cannam
date Tue, 20 May 2014 17:49:07 +0100
parents 6003a9af43af
children 8af9b6cd7451
rev   line source
Chris@161 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@161 2
Chris@161 3 /*
Chris@161 4 Silvet
Chris@161 5
Chris@161 6 A Vamp plugin for note transcription.
Chris@161 7 Centre for Digital Music, Queen Mary University of London.
Chris@161 8
Chris@161 9 This program is free software; you can redistribute it and/or
Chris@161 10 modify it under the terms of the GNU General Public License as
Chris@161 11 published by the Free Software Foundation; either version 2 of the
Chris@161 12 License, or (at your option) any later version. See the file
Chris@161 13 COPYING included with this distribution for more information.
Chris@161 14 */
Chris@161 15
Chris@161 16 #include "Instruments.h"
Chris@161 17
Chris@161 18 #include "data/include/templates.h"
Chris@161 19
Chris@161 20 #include <iostream>
Chris@161 21
Chris@161 22 const int InstrumentPack::templateNoteCount = SILVET_TEMPLATE_NOTE_COUNT;
Chris@161 23 const int InstrumentPack::templateHeight = SILVET_TEMPLATE_HEIGHT;
Chris@161 24 const int InstrumentPack::templateMaxShift = SILVET_TEMPLATE_MAX_SHIFT;
Chris@161 25 const int InstrumentPack::templateSize = SILVET_TEMPLATE_SIZE;
Chris@161 26
Chris@161 27 using std::string;
Chris@161 28 using std::vector;
Chris@161 29 using std::cerr;
Chris@161 30 using std::endl;
Chris@161 31
Chris@161 32 const char *simpleInstruments[] = {
Chris@161 33 "Guitar", "guitar",
Chris@161 34 "Violin", "violin",
Chris@161 35 "Cello", "cello",
Chris@161 36 "Horn", "horn",
Chris@161 37 "Flute", "flute",
Chris@161 38 "Oboe", "oboe",
Chris@161 39 "Clarinet", "clarinet",
Chris@161 40 "Tenor Sax", "tenorsax",
Chris@161 41 "Bassoon", "bassoon",
Chris@161 42 };
Chris@161 43
Chris@161 44 static InstrumentPack::Templates
Chris@161 45 templatesFor(string name)
Chris@161 46 {
Chris@161 47 for (int i = 0; i < SILVET_TEMPLATE_COUNT; ++i) {
Chris@161 48
Chris@161 49 if (string(silvet_templates[i].name) == name) {
Chris@161 50
Chris@161 51 silvet_template_t *t = &silvet_templates[i];
Chris@161 52
Chris@161 53 InstrumentPack::Templates rt;
Chris@161 54 rt.lowestNote = t->lowest;
Chris@161 55 rt.highestNote = t->highest;
Chris@161 56 rt.data = vector<vector<float> >
Chris@161 57 (SILVET_TEMPLATE_NOTE_COUNT,
Chris@161 58 vector<float>(SILVET_TEMPLATE_SIZE, 0.f));
Chris@161 59
Chris@161 60 for (int j = 0; j < SILVET_TEMPLATE_NOTE_COUNT; ++j) {
Chris@161 61 for (int k = 0; k < SILVET_TEMPLATE_SIZE; ++k) {
Chris@161 62 rt.data[j][k] = t->data[j][k];
Chris@161 63 }
Chris@161 64 }
Chris@161 65
Chris@161 66 return rt;
Chris@161 67 }
Chris@161 68 }
Chris@161 69
Chris@161 70 return InstrumentPack::Templates();
Chris@161 71 }
Chris@161 72
Chris@161 73 static bool
Chris@161 74 isOK(InstrumentPack &d)
Chris@161 75 {
Chris@161 76 if (d.name == "") {
Chris@161 77 cerr << "ERROR: Silvet::InstrumentPack: Empty name in instrument definition" << endl;
Chris@161 78 return false;
Chris@161 79 }
Chris@161 80 if (d.templates.empty()) {
Chris@161 81 cerr << "ERROR: Silvet::InstrumentPack: Instrument definition \"" << d.name << "\" contains no templates!" << endl;
Chris@161 82 return false;
Chris@161 83 }
Chris@161 84 for (int i = 0; i < int(d.templates.size()); ++i) {
Chris@161 85 if (d.templates[i].data.empty()) {
Chris@161 86 cerr << "ERROR: Silvet::InstrumentPack: Instrument definition \"" << d.name << "\" contains one or more empty templates!" << endl;
Chris@161 87 return false;
Chris@161 88 }
Chris@161 89 }
Chris@161 90 return true;
Chris@161 91 }
Chris@161 92
Chris@161 93 vector<InstrumentPack>
Chris@161 94 InstrumentPack::listInstrumentPacks()
Chris@161 95 {
Chris@161 96 vector<InstrumentPack> ii;
Chris@161 97
Chris@161 98 vector<Templates> allTemplates;
Chris@161 99 //!!! is piano-maps-SptkBGCl the same as one of piano1, piano2, piano3?
Chris@161 100 allTemplates.push_back(templatesFor("piano1"));
Chris@161 101
Chris@161 102 vector<Templates> pianoTemplates;
Chris@161 103 pianoTemplates.push_back(templatesFor("piano1"));
Chris@161 104 pianoTemplates.push_back(templatesFor("piano2"));
Chris@161 105 pianoTemplates.push_back(templatesFor("piano3"));
Chris@161 106 InstrumentPack piano(silvet_templates_lowest_note,
Chris@161 107 silvet_templates_highest_note,
Chris@161 108 "Piano",
Chris@161 109 pianoTemplates);
Chris@161 110 if (isOK(piano)) {
Chris@161 111 ii.push_back(piano);
Chris@161 112 }
Chris@161 113
Chris@161 114 for (int i = 0;
Chris@161 115 i < int(sizeof(simpleInstruments)/sizeof(simpleInstruments[0]));
Chris@161 116 i += 2) {
Chris@161 117 vector<Templates> tt;
Chris@161 118 Templates t = templatesFor(simpleInstruments[i+1]);
Chris@161 119 tt.push_back(t);
Chris@161 120 allTemplates.push_back(t);
Chris@161 121 InstrumentPack instr(t.lowestNote,
Chris@161 122 t.highestNote,
Chris@161 123 simpleInstruments[i],
Chris@161 124 tt);
Chris@161 125 if (isOK(instr)) {
Chris@161 126 ii.push_back(instr);
Chris@161 127 }
Chris@161 128 }
Chris@161 129
Chris@161 130 InstrumentPack all(silvet_templates_lowest_note,
Chris@161 131 silvet_templates_highest_note,
Chris@161 132 "Multiple or unknown instruments",
Chris@161 133 allTemplates);
Chris@161 134 if (isOK(all)) {
Chris@161 135 ii.insert(ii.begin(), all);
Chris@161 136 }
Chris@161 137
Chris@161 138 return ii;
Chris@161 139 }
Chris@161 140