To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _dbn / add_chords.m @ 8:b5b38998ef3b
History | View | Annotate | Download (3.53 KB)
| 1 |
function param = add_chords(param) |
|---|---|
| 2 |
|
| 3 |
|
| 4 |
patterns = []; |
| 5 |
lilytypenames = {};
|
| 6 |
bassn = []; |
| 7 |
hasN = false; |
| 8 |
for iChord = 1:length(param.dbn.chordclassset) |
| 9 |
switch param.dbn.chordclassset{iChord}
|
| 10 |
case '' |
| 11 |
patterns = [patterns; ... |
| 12 |
1 0 0 0 1 0 0 1 0 0 0 0]; % major |
| 13 |
lilytypenames = [lilytypenames, ' ']; |
| 14 |
bassn = [bassn, 1]; |
| 15 |
case '/3' |
| 16 |
patterns = [patterns; ... |
| 17 |
1 0 0 0 1 0 0 1 0 0 0 0]; % major/3 |
| 18 |
lilytypenames = [lilytypenames, ' ']; |
| 19 |
bassn = [bassn, 5]; |
| 20 |
case '/5' |
| 21 |
patterns = [patterns; ... |
| 22 |
1 0 0 0 1 0 0 1 0 0 0 0]; % major/5 |
| 23 |
lilytypenames = [lilytypenames, ' ']; |
| 24 |
bassn = [bassn, 8]; |
| 25 |
case ':maj6' |
| 26 |
patterns = [patterns; ... |
| 27 |
1 0 0 0 1 0 0 1 0 1 0 0]; % major 6 |
| 28 |
lilytypenames = [lilytypenames, ':6']; |
| 29 |
bassn = [bassn, 1]; |
| 30 |
case ':maj7' |
| 31 |
patterns = [patterns; ... |
| 32 |
1 0 0 0 1 0 0 1 0 0 0 1]; % major 7 |
| 33 |
lilytypenames = [lilytypenames, ':maj7']; |
| 34 |
bassn = [bassn, 1]; |
| 35 |
case ':min' |
| 36 |
patterns = [patterns; ... |
| 37 |
1 0 0 1 0 0 0 1 0 0 0 0]; % minor |
| 38 |
lilytypenames = [lilytypenames, ':m']; |
| 39 |
bassn = [bassn, 1]; |
| 40 |
case ':min7' |
| 41 |
patterns = [patterns; ... |
| 42 |
1 0 0 1 0 0 0 1 0 0 1 0]; % minor |
| 43 |
lilytypenames = [lilytypenames, ':m7']; |
| 44 |
bassn = [bassn, 1]; |
| 45 |
case ':7' |
| 46 |
patterns = [patterns; ... |
| 47 |
1 0 0 0 1 0 0 1 0 0 1 0]; % dominant |
| 48 |
lilytypenames = [lilytypenames, ':7']; |
| 49 |
bassn = [bassn, 1]; |
| 50 |
case ':dim' |
| 51 |
patterns = [patterns; ... |
| 52 |
1 0 0 1 0 0 1 0 0 0 0 0]; % diminished |
| 53 |
lilytypenames = [lilytypenames, ':dim']; |
| 54 |
bassn = [bassn, 1]; |
| 55 |
case ':aug' |
| 56 |
patterns = [patterns; ... |
| 57 |
1 0 0 0 1 0 0 0 1 0 0 0]; % augmented |
| 58 |
lilytypenames = [lilytypenames, ':aug']; |
| 59 |
bassn = [bassn, 1]; |
| 60 |
case 'N' |
| 61 |
hasN = true; |
| 62 |
hasN0 = false; |
| 63 |
case 'N0'; |
| 64 |
hasN0 = true; |
| 65 |
hasN = false; |
| 66 |
end |
| 67 |
end |
| 68 |
nRow = size(patterns,1); |
| 69 |
|
| 70 |
sz = 12; |
| 71 |
|
| 72 |
bass_notes = zeros(1,sz*nRow+1); |
| 73 |
root_notes = bass_notes; |
| 74 |
chordnames = cell(1,sz*nRow+1); |
| 75 |
lilychordnames = chordnames; |
| 76 |
mu = zeros(sz,sz*nRow+1); |
| 77 |
cova = zeros(sz,sz,sz*nRow+1); |
| 78 |
count = 1; |
| 79 |
|
| 80 |
for iRow = 1:nRow |
| 81 |
for iSemitone = 1:sz |
| 82 |
mu(:,count) = circshift(patterns(iRow,:)',iSemitone-1); |
| 83 |
cova(:,:,count) = eye(sz) * param.dbn.chromavar; |
| 84 |
root_notes(count) = iSemitone; |
| 85 |
chordnames{count} = param.dbn.chordclassset{iRow};
|
| 86 |
lilychordnames{count} = lilytypenames{iRow};
|
| 87 |
if bassn(iRow) ~= 13 |
| 88 |
bass_notes(count) = mod(bassn(iRow)+iSemitone-2,12)+1; |
| 89 |
else |
| 90 |
bass_notes(count) = 13; |
| 91 |
end |
| 92 |
count = count + 1; |
| 93 |
end |
| 94 |
end |
| 95 |
indexN = count; |
| 96 |
if hasN |
| 97 |
mu(:,indexN) = ones(12,1); % "no chord" |
| 98 |
lilychordnames{count} = ' ';
|
| 99 |
cova(:,:,indexN) = mean(cova,3); |
| 100 |
bass_notes(indexN) = 13; |
| 101 |
root_notes(indexN) = 13; |
| 102 |
end |
| 103 |
if hasN0 |
| 104 |
mu(:,indexN) = zeros(12,1); % "no chord" |
| 105 |
cova(:,:,indexN) = mean(cova,3); |
| 106 |
bass_notes(indexN) = 13; |
| 107 |
root_notes(indexN) = 13; |
| 108 |
end |
| 109 |
|
| 110 |
%% |
| 111 |
param.dbn.nChord = size(mu,2); |
| 112 |
param.dbn.chordpcs = mu; |
| 113 |
param.dbn.cova = cova; |
| 114 |
param.dbn.lilytypechordnames = lilychordnames; |
| 115 |
param.dbn.chordnames = chordnames; |
| 116 |
param.dbn.chordrootnotes = root_notes; |
| 117 |
param.dbn.chordbassnotes = bass_notes; |
| 118 |
|