comparison chromamethods.cpp @ 86:e5c16976513d consonance

implemented note output for estimated chords
author matthiasm
date Sun, 28 Nov 2010 23:10:57 +0900
parents 026a5c0ee2c2
children f568555390f1
comparison
equal deleted inserted replaced
85:ccc0d4b3f867 86:e5c16976513d
275 path.push_back(envPath.substr(index)); 275 path.push_back(envPath.substr(index));
276 276
277 return path; 277 return path;
278 } 278 }
279 279
280 vector<string> chordDictionary(vector<float> *mchorddict) { 280 vector<string> chordDictionary(vector<float> *mchorddict, vector<vector<int> > *m_chordnotes) {
281 281
282 typedef tokenizer<char_separator<char> > Tok; 282 typedef tokenizer<char_separator<char> > Tok;
283 char_separator<char> sep(",; ","="); 283 char_separator<char> sep(",; ","=");
284 284
285 string chordDictBase("chord.dict"); 285 string chordDictBase("chord.dict");
286 string chordDictFilename; 286 string chordDictFilename;
308 int nChord = 0; 308 int nChord = 0;
309 309
310 vector<string> loadedChordNames; 310 vector<string> loadedChordNames;
311 vector<float> loadedChordDict; 311 vector<float> loadedChordDict;
312 if (chordDictFile.is_open()) { 312 if (chordDictFile.is_open()) {
313 while (std::getline(chordDictFile, line)) { // loop over lines in chord.dict file 313 while (std::getline(chordDictFile, line)) { // loop over lines in chord.dict file
314 // first, get the chord definition 314 // first, get the chord definition
315 string chordType; 315 string chordType;
316 vector<float> tempPCVector; 316 vector<float> tempPCVector;
317 // cerr << line << endl; 317 // cerr << line << endl;
318 if (!line.empty() && line.substr(0,1) != "#") { 318 if (!line.empty() && line.substr(0,1) != "#") {
331 tempPCVector.push_back(lexical_cast<float>(*tok_iter)); 331 tempPCVector.push_back(lexical_cast<float>(*tok_iter));
332 } 332 }
333 } 333 }
334 334
335 // now make all 12 chords of every type 335 // now make all 12 chords of every type
336 for (unsigned iSemitone = 0; iSemitone < 12; iSemitone++) { 336 for (unsigned iSemitone = 0; iSemitone < 12; iSemitone++) {
337 vector<int> tempchordnotes;
337 // add bass slash notation 338 // add bass slash notation
338 string slashNotation = ""; 339 string slashNotation = "";
339 for (unsigned kSemitone = 1; kSemitone < 12; kSemitone++) { 340 for (unsigned kSemitone = 1; kSemitone < 12; kSemitone++) {
340 if (tempPCVector[(kSemitone) % 12] > 0.99) { 341 if (tempPCVector[(kSemitone) % 12] > 0.99) {
341 slashNotation = bassnames[iSemitone][kSemitone]; 342 slashNotation = bassnames[iSemitone][kSemitone];
344 for (unsigned kSemitone = 0; kSemitone < 12; kSemitone++) { // bass pitch classes 345 for (unsigned kSemitone = 0; kSemitone < 12; kSemitone++) { // bass pitch classes
345 // cerr << ((kSemitone - iSemitone + 12) % 12) << endl; 346 // cerr << ((kSemitone - iSemitone + 12) % 12) << endl;
346 float bassValue = 0; 347 float bassValue = 0;
347 if (tempPCVector[(kSemitone - iSemitone + 12) % 12]==1) { 348 if (tempPCVector[(kSemitone - iSemitone + 12) % 12]==1) {
348 bassValue = 1; 349 bassValue = 1;
350 tempchordnotes.push_back(MIDI_basenote + (kSemitone+12) % 12);
349 } else { 351 } else {
350 if (tempPCVector[((kSemitone - iSemitone + 12) % 12) + 12] == 1) bassValue = 0.5; 352 if (tempPCVector[((kSemitone - iSemitone + 12) % 12) + 12] == 1) bassValue = 0.5;
351 } 353 }
352 loadedChordDict.push_back(bassValue); 354 loadedChordDict.push_back(bassValue);
353 } 355 }
354 for (unsigned kSemitone = 0; kSemitone < 12; kSemitone++) { // chord pitch classes 356 for (unsigned kSemitone = 0; kSemitone < 12; kSemitone++) { // chord pitch classes
355 loadedChordDict.push_back(tempPCVector[((kSemitone - iSemitone + 12) % 12) + 12]); 357 loadedChordDict.push_back(tempPCVector[((kSemitone - iSemitone + 12) % 12) + 12]);
358 if (tempPCVector[((kSemitone - iSemitone + 12) % 12) + 12] > 0) tempchordnotes.push_back(MIDI_basenote + (kSemitone+12+6) % 12 - 6 + 24);
356 } 359 }
357 ostringstream os; 360 ostringstream os;
358 if (slashNotation.empty()) { 361 if (slashNotation.empty()) {
359 os << notenames[12+iSemitone] << chordType; 362 os << notenames[12+iSemitone] << chordType;
360 } else { 363 } else {
361 os << notenames[12+iSemitone] << chordType << "/" << slashNotation; 364 os << notenames[12+iSemitone] << chordType << "/" << slashNotation;
362 } 365 }
363 // cerr << os.str() << endl; 366 // cerr << os.str() << endl;
364 loadedChordNames.push_back(os.str()); 367 loadedChordNames.push_back(os.str());
368 m_chordnotes->push_back(tempchordnotes);
369 for (int iNote = 0; iNote < tempchordnotes.size(); ++iNote) {
370 cerr << tempchordnotes[iNote] << " ";
371 }
372 cerr << endl;
365 } 373 }
366 } 374 }
367 } 375 }
368 // N type 376 // N type
369 loadedChordNames.push_back("N"); 377 loadedChordNames.push_back("N");
370 for (unsigned kSemitone = 0; kSemitone < 12; kSemitone++) loadedChordDict.push_back(0.5); 378 for (unsigned kSemitone = 0; kSemitone < 12; kSemitone++) loadedChordDict.push_back(0.5);
371 for (unsigned kSemitone = 0; kSemitone < 12; kSemitone++) loadedChordDict.push_back(1.0); 379 for (unsigned kSemitone = 0; kSemitone < 12; kSemitone++) loadedChordDict.push_back(1.0);
372 380 vector<int> tempchordvector;
381 m_chordnotes->push_back(tempchordvector);
373 float exponent = 2.0; 382 float exponent = 2.0;
374 float boostN = 1.1; 383 float boostN = 1.1;
375 384
376 for (int iChord = 0; iChord < loadedChordDict.size()/24; iChord++) { 385 for (int iChord = 0; iChord < loadedChordDict.size()/24; iChord++) {
377 float sum = 0; 386 float sum = 0;