Mercurial > hg > nnls-chroma
comparison chromamethods.cpp @ 140:8ff2aa01df4d darwintunes
Johan's changes:
* removing slash notation substitution in the case of Harte's syntax
* remove obsolete chorddict.cpp
author | Matthias Mauch <matthias.mauch@eecs.qmul.ac.uk> |
---|---|
date | Tue, 19 Jun 2012 15:40:09 +0100 |
parents | 75a46075bf4e |
children | c5eb728a8725 0d70058c2bce |
comparison
equal
deleted
inserted
replaced
135:75a46075bf4e | 140:8ff2aa01df4d |
---|---|
28 #include <cstdio> | 28 #include <cstdio> |
29 #include <boost/tokenizer.hpp> | 29 #include <boost/tokenizer.hpp> |
30 #include <boost/iostreams/device/file.hpp> | 30 #include <boost/iostreams/device/file.hpp> |
31 #include <boost/iostreams/stream.hpp> | 31 #include <boost/iostreams/stream.hpp> |
32 #include <boost/lexical_cast.hpp> | 32 #include <boost/lexical_cast.hpp> |
33 | |
34 #include "chorddict.cpp" | |
35 | 33 |
36 using namespace std; | 34 using namespace std; |
37 using namespace boost; | 35 using namespace boost; |
38 | 36 |
39 | 37 |
353 | 351 |
354 const char* notenames[24] = { | 352 const char* notenames[24] = { |
355 "A (bass)","Bb (bass)","B (bass)","C (bass)","C# (bass)","D (bass)","Eb (bass)","E (bass)","F (bass)","F# (bass)","G (bass)","Ab (bass)", | 353 "A (bass)","Bb (bass)","B (bass)","C (bass)","C# (bass)","D (bass)","Eb (bass)","E (bass)","F (bass)","F# (bass)","G (bass)","Ab (bass)", |
356 "A","Bb","B","C","C#","D","Eb","E","F","F#","G","Ab"}; | 354 "A","Bb","B","C","C#","D","Eb","E","F","F#","G","Ab"}; |
357 | 355 |
358 const char* bassnames[13][12] ={ | 356 const char* bassnames[12][12] ={ |
359 {"A","","B","C","C#","D","","E","","F#","G","G#"}, | 357 {"A","","B","C","C#","D","","E","","F#","G","G#"}, |
360 {"Bb","","C","Db","D","Eb","","F","","G","Ab","A"}, | 358 {"Bb","","C","Db","D","Eb","","F","","G","Ab","A"}, |
361 {"B","","C#","D","D#","E","","F#","","G#","A","A#"}, | 359 {"B","","C#","D","D#","E","","F#","","G#","A","A#"}, |
362 {"C","","D","Eb","E","F","","G","","A","Bb","B"}, | 360 {"C","","D","Eb","E","F","","G","","A","Bb","B"}, |
363 {"C#","","D#","E","E#","F#","","G#","","A#","B","B#"}, | 361 {"C#","","D#","E","E#","F#","","G#","","A#","B","B#"}, |
365 {"Eb","","F","Gb","G","Ab","","Bb","","C","Db","D"}, | 363 {"Eb","","F","Gb","G","Ab","","Bb","","C","Db","D"}, |
366 {"E","","F#","G","G#","A","","B","","C#","D","D#"}, | 364 {"E","","F#","G","G#","A","","B","","C#","D","D#"}, |
367 {"F","","G","Ab","A","Bb","","C","","D","Eb","E"}, | 365 {"F","","G","Ab","A","Bb","","C","","D","Eb","E"}, |
368 {"F#","","G#","A","A#","B","","C#","","D#","E","E#"}, | 366 {"F#","","G#","A","A#","B","","C#","","D#","E","E#"}, |
369 {"G","","A","Bb","B","C","","D","","E","F","F#"}, | 367 {"G","","A","Bb","B","C","","D","","E","F","F#"}, |
370 {"Ab","","Bb","Cb","C","Db","","Eb","","F","Gb","G"}, | 368 {"Ab","","Bb","Cb","C","Db","","Eb","","F","Gb","G"} |
371 {"1","","2","b3","3","4","","5","","6","b7","7"} | |
372 }; | 369 }; |
373 | 370 |
374 bool hasExternalDictinoary = true; | 371 bool hasExternalDictinoary = true; |
375 int ppathsize = static_cast<int>(ppath.size()); | 372 int ppathsize = static_cast<int>(ppath.size()); |
376 for (int i = 0; i < ppathsize; ++i) { | 373 for (int i = 0; i < ppathsize; ++i) { |
406 } | 403 } |
407 | 404 |
408 vector<string> loadedChordNames; | 405 vector<string> loadedChordNames; |
409 vector<float> loadedChordDict; | 406 vector<float> loadedChordDict; |
410 if (hasExternalDictinoary && chordDictFile.is_open()) { | 407 if (hasExternalDictinoary && chordDictFile.is_open()) { |
411 cerr << "-----------------> " << tempChordNames.size() << endl; | |
412 tempChordDict.clear(); | 408 tempChordDict.clear(); |
413 tempChordNames.clear(); | 409 tempChordNames.clear(); |
414 while (std::getline(chordDictFile, line)) { // loop over lines in chord.dict file | 410 while (std::getline(chordDictFile, line)) { // loop over lines in chord.dict file |
415 // first, get the chord definition | 411 // first, get the chord definition |
416 string chordType; | 412 string chordType; |
433 } | 429 } |
434 } | 430 } |
435 tempChordNames.push_back(chordType); | 431 tempChordNames.push_back(chordType); |
436 } | 432 } |
437 } | 433 } |
434 cerr << "-----------------> " << tempChordNames.size() << endl; | |
438 } | 435 } |
439 | 436 |
440 | 437 |
441 for (int iType = 0; iType < (int)tempChordNames.size(); ++iType) { | 438 for (int iType = 0; iType < (int)tempChordNames.size(); ++iType) { |
442 // now make all 12 chords of every type | 439 // now make all 12 chords of every type |
446 string slashNotation = ""; | 443 string slashNotation = ""; |
447 for (int kSemitone = 1; kSemitone < 12; kSemitone++) { | 444 for (int kSemitone = 1; kSemitone < 12; kSemitone++) { |
448 if (tempChordDict[24*iType+(kSemitone) % 12] > 0.99) { | 445 if (tempChordDict[24*iType+(kSemitone) % 12] > 0.99) { |
449 if (harte_syntax == 0.0) { | 446 if (harte_syntax == 0.0) { |
450 slashNotation = bassnames[iSemitone][kSemitone]; | 447 slashNotation = bassnames[iSemitone][kSemitone]; |
451 } else { | |
452 slashNotation = bassnames[12][kSemitone]; | |
453 } | 448 } |
454 } | 449 } |
455 } | 450 } |
456 if (slashNotation=="") tempchordnotes.push_back(MIDI_basenote + (iSemitone+12) % 12); | 451 if (slashNotation=="") tempchordnotes.push_back(MIDI_basenote + (iSemitone+12) % 12); |
457 for (int kSemitone = 0; kSemitone < 12; kSemitone++) { // bass pitch classes | 452 for (int kSemitone = 0; kSemitone < 12; kSemitone++) { // bass pitch classes |