annotate evaluationtools/comparechords.m @ 1:8973548174c1 tip

adding tools to repo
author christopherh
date Mon, 06 May 2013 14:43:47 +0100
parents
children
rev   line source
christopherh@1 1
christopherh@1 2 %COMPARECHORDS
christopherh@1 3 %
christopherh@1 4 % [match,success,errormessage] = comparechords(chord1, chord2, comparison,
christopherh@1 5 % cardinality, inversion,verbose)
christopherh@1 6 %
christopherh@1 7 %
christopherh@1 8 % COMPARISON OPTIONS:
christopherh@1 9 %
christopherh@1 10 % CHORDS
christopherh@1 11 % s = string comparison
christopherh@1 12 % ov = ordered pnset comparison
christopherh@1 13 % op = ordered pcset comparison
christopherh@1 14 % uv = ordered pnset comparison
christopherh@1 15 % up = ordered pcset comparison
christopherh@1 16 %
christopherh@1 17 % mx08 = compare using MIREX08 chord mapping
christopherh@1 18 % mx09 = compare using MIREX09 chord mapping
christopherh@1 19 %
christopherh@1 20 % CHORDTYPES (root-blind)
christopherh@1 21 % q = quality
christopherh@1 22 % oi = ordered relative interval comparison
christopherh@1 23 % or = ordered relative pitchclass set comparison
christopherh@1 24 % ui = unordered relative interval comparison
christopherh@1 25 % ur = unordered relative pitchclass set comparison
christopherh@1 26
christopherh@1 27
christopherh@1 28 function [match,success,errormessage] = comparechords2(chord1, chord2, comparison, cardinality, inversion,verbose)
christopherh@1 29
christopherh@1 30 errormessage = '';
christopherh@1 31 success = 1;
christopherh@1 32 match = 0;
christopherh@1 33
christopherh@1 34 % remember these just in case there is an error to report
christopherh@1 35 c1 = chord1;
christopherh@1 36 c2 = chord2;
christopherh@1 37
christopherh@1 38 % initialise things if not specified...
christopherh@1 39 if nargin<3
christopherh@1 40 comparison = 's';
christopherh@1 41 end
christopherh@1 42
christopherh@1 43 if nargin<4
christopherh@1 44 cardinality = 6; % maximum cardinality in beatles collection
christopherh@1 45 end
christopherh@1 46
christopherh@1 47 if nargin<5
christopherh@1 48 inversion = 1; % assume people want to keep inversion information
christopherh@1 49 end
christopherh@1 50
christopherh@1 51 if nargin<6
christopherh@1 52 verbose = 0;
christopherh@1 53 end
christopherh@1 54
christopherh@1 55
christopherh@1 56
christopherh@1 57 % if inversion is 0, strip bass intervals off the chords if they have them
christopherh@1 58 if inversion==0
christopherh@1 59 chord1 = stripinversion(chord1);
christopherh@1 60 chord2 = stripinversion(chord2);
christopherh@1 61 end
christopherh@1 62
christopherh@1 63 mx=0;
christopherh@1 64 % strip roots from chords and replace with C if this is a chordtype comparison
christopherh@1 65 switch lower(comparison)
christopherh@1 66
christopherh@1 67 case {'mx08','mx09'}
christopherh@1 68 mx=1;
christopherh@1 69
christopherh@1 70 case {'q','oi','or','ui','ur'}
christopherh@1 71 chord1 = striproot(chord1,1);
christopherh@1 72 chord2 = striproot(chord2,1);
christopherh@1 73
christopherh@1 74 case {'s','ov','op','uv','up'}
christopherh@1 75 % do nothing in this case...
christopherh@1 76
christopherh@1 77 otherwise
christopherh@1 78 % not a recognised option so exit with errormessage
christopherh@1 79 errormessage = 'Error in comparechords: unrecognised comparison type';
christopherh@1 80 success = 0;
christopherh@1 81
christopherh@1 82 end
christopherh@1 83
christopherh@1 84
christopherh@1 85 if (success)
christopherh@1 86 if mx
christopherh@1 87
christopherh@1 88 % use a mirex 08/09 comparison
christopherh@1 89
christopherh@1 90 year = str2num(comparison(3:4));
christopherh@1 91
christopherh@1 92 if isempty(year)
christopherh@1 93 success = 0;
christopherh@1 94 else
christopherh@1 95
christopherh@1 96 [val1,success] = mxmap(chord1, year);
christopherh@1 97 if success
christopherh@1 98 [val2,success] = mxmap(chord2, year);
christopherh@1 99
christopherh@1 100 if success
christopherh@1 101 if abs(val1-val2)==0
christopherh@1 102 match = 1;
christopherh@1 103 end
christopherh@1 104 end
christopherh@1 105 end
christopherh@1 106 end
christopherh@1 107
christopherh@1 108 else
christopherh@1 109
christopherh@1 110
christopherh@1 111 if length(comparison)==2
christopherh@1 112 % if the comparison is 2 chars then it is a set-matching option
christopherh@1 113 switch comparison
christopherh@1 114 case {'oi','ov','uv','ui'}
christopherh@1 115 [set1x,bn,success,errormessage] = chord2notes(chord1,1);
christopherh@1 116 if success
christopherh@1 117 [set2x,bn,success,errormessage] = chord2notes(chord2,1);
christopherh@1 118 % cludge to get the sets the right way round, fix
christopherh@1 119 % later...
christopherh@1 120 if success
christopherh@1 121 set1 = set1x';
christopherh@1 122 set2 = set2x';
christopherh@1 123 end
christopherh@1 124 end
christopherh@1 125 case {'ur','or','op','up'}
christopherh@1 126 [set1, bc1, success,errormessage] = chord2pitchclasses(chord1);
christopherh@1 127 if success
christopherh@1 128 [set2, bc2,success,errormessage] = chord2pitchclasses(chord2);
christopherh@1 129 end
christopherh@1 130 otherwise
christopherh@1 131 %by this stage there shouldn't be an otherwise...
christopherh@1 132 success = 0;
christopherh@1 133 end
christopherh@1 134
christopherh@1 135
christopherh@1 136 if success
christopherh@1 137 switch comparison
christopherh@1 138 case {'ui','ur','uv','up'}
christopherh@1 139 % do an unordered match
christopherh@1 140 [match,success,errormessage] = compareunorderedsets(set1,set2,cardinality);
christopherh@1 141
christopherh@1 142 case {'ov','op','oi','or'}
christopherh@1 143 % do an ordered match
christopherh@1 144 [match,success,errormessage] = compareorderedsets(set1,set2,cardinality);
christopherh@1 145
christopherh@1 146 otherwise
christopherh@1 147 %by this stage there shouldn't be an otherwise...
christopherh@1 148 success = 0;
christopherh@1 149 end
christopherh@1 150 end
christopherh@1 151
christopherh@1 152 else
christopherh@1 153 % otherwise must be a string match
christopherh@1 154 [match,success,errormessage] = compareorderedsets(chord1,chord2);
christopherh@1 155 end
christopherh@1 156 end
christopherh@1 157 end
christopherh@1 158
christopherh@1 159
christopherh@1 160 if success==0
christopherh@1 161 errormessage = [errormessage sprintf(['Error in comparechords: Couldn''t compare chords "' c1 '" and "' c2 '"\n'])];
christopherh@1 162 if verbose ==1
christopherh@1 163 fprintf(1,errormessage);
christopherh@1 164 end
christopherh@1 165 end