annotate _chordtools/addshort2list.m @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1 %
matthiasm@8 2 %ADDSHORT2LIST Combine degrees of a shorthand with another degree list
matthiasm@8 3 %
matthiasm@8 4 % [fulldegreelist, success, errormessage] = addshort2list(shorthand, degreelist, {verbose})
matthiasm@8 5 %
matthiasm@8 6 % Combine shorthand and degreelist to form full degree list for a chord.
matthiasm@8 7 % Takes into account the omit degree character '*' in producing final list.
matthiasm@8 8 %
matthiasm@8 9 % Success = 1 if shorthand and degreelist combined correctly, 0 otherwise.
matthiasm@8 10 %
matthiasm@8 11 % If optional argument 'verbose' is 1, function prints any errormessage to
matthiasm@8 12 % the screen.
matthiasm@8 13 %
matthiasm@8 14 % returns: fulldegreelist (string)
matthiasm@8 15 % success (boolean)
matthiasm@8 16 % errormessage (string)
matthiasm@8 17 %
matthiasm@8 18 % Author: Christopher Harte, August 2005
matthiasm@8 19 %
matthiasm@8 20 % Copyright: Centre for Digital Music, Queen Mary University of London 2005
matthiasm@8 21 %
matthiasm@8 22 % This file is part of the C4DM Chord Toolkit.
matthiasm@8 23 %
matthiasm@8 24 % The C4DM Chord Toolkit is free software; you can redistribute it and/or
matthiasm@8 25 % modify it under the terms of the GNU General Public License as published
matthiasm@8 26 % by the Free Software Foundation; either version 2 of the License, or
matthiasm@8 27 % (at your option) any later version.
matthiasm@8 28 %
matthiasm@8 29 % The C4DM Chord Toolkit is distributed in the hope that it will be useful,
matthiasm@8 30 % but WITHOUT ANY WARRANTY; without even the implied warranty of
matthiasm@8 31 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
matthiasm@8 32 % GNU General Public License for more details.
matthiasm@8 33 %
matthiasm@8 34 % You should have received a copy of the GNU General Public License
matthiasm@8 35 % along with the C4DM Toolkit; if not, write to the Free Software
matthiasm@8 36 % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
matthiasm@8 37
matthiasm@8 38 %
matthiasm@8 39 function [fulldegreelist, success, errormessage] = addshort2list(shorthand, degreelist, verbose)
matthiasm@8 40
matthiasm@8 41 % set verbose default to 0
matthiasm@8 42 if nargin < 3
matthiasm@8 43 verbose = 0;
matthiasm@8 44 end
matthiasm@8 45
matthiasm@8 46 errormessage = '';
matthiasm@8 47
matthiasm@8 48 % initialise variables
matthiasm@8 49 fulldegreelist = '';
matthiasm@8 50 shortintervals = [];
matthiasm@8 51 degreeintervals = [];
matthiasm@8 52 addlist = [];
matthiasm@8 53 success = 1;
matthiasm@8 54
matthiasm@8 55 % convert shorthand string to list of degrees
matthiasm@8 56 [shortdegrees, ok, errors] = shorthand2degrees(shorthand);
matthiasm@8 57
matthiasm@8 58 if ok
matthiasm@8 59 % if that works convert the shorthand degrees and degreelist to
matthiasm@8 60 % intervals and accidentals
matthiasm@8 61
matthiasm@8 62 % add the implied 1 interval to the shorthand list
matthiasm@8 63 if isempty(shortdegrees)
matthiasm@8 64 rootinterval = '1'; % no comma if shorthand is empty
matthiasm@8 65 else
matthiasm@8 66 rootinterval = '1,'; % comma shows that there are further degrees after this one
matthiasm@8 67 end
matthiasm@8 68
matthiasm@8 69
matthiasm@8 70 [shortintervals, ok, errors] = parsedegreelist([rootinterval shortdegrees]);
matthiasm@8 71
matthiasm@8 72 if (ok)
matthiasm@8 73
matthiasm@8 74
matthiasm@8 75 % this part of the algorithm finds all the present intervals and sorts
matthiasm@8 76 % them into ascending numeric order
matthiasm@8 77
matthiasm@8 78 % First put the shorthand intervals into the full list
matthiasm@8 79
matthiasm@8 80 [ilength,y] = size(shortintervals);
matthiasm@8 81
matthiasm@8 82 for index = 1:ilength
matthiasm@8 83 % convert interval to a semitone value
matthiasm@8 84 semitone = interval2semitone(shortintervals(index,1),shortintervals(index,2));
matthiasm@8 85
matthiasm@8 86 % Using the semitone value as an index will find redundant
matthiasm@8 87 % degrees and also sort them in number order. Multiplying the interval by its
matthiasm@8 88 % presence value leaves either the interval value or 0. Any element
matthiasm@8 89 % in the array with interval of 0 will be discarded later
matthiasm@8 90 % We add 1 to the semitone value to handle the '1' or 'unity'
matthiasm@8 91 % interval that would return a 0 semitone value
matthiasm@8 92
matthiasm@8 93 % record the interval
matthiasm@8 94 addlist(semitone+1,1) = shortintervals(index,1) .* shortintervals(index,3);
matthiasm@8 95 % record the accidentals as well
matthiasm@8 96 addlist(semitone+1,2) = shortintervals(index,2);
matthiasm@8 97
matthiasm@8 98 end
matthiasm@8 99 else
matthiasm@8 100 success = 0;
matthiasm@8 101 end
matthiasm@8 102
matthiasm@8 103 [degreeintervals, ok2, errors] = parsedegreelist(degreelist);
matthiasm@8 104 ok = ok && ok2;
matthiasm@8 105
matthiasm@8 106 if ok
matthiasm@8 107 % Now add the degrees from the degreelist taking redundant and
matthiasm@8 108 % ommitted degrees into account
matthiasm@8 109
matthiasm@8 110 [ilength,y] = size(degreeintervals);
matthiasm@8 111
matthiasm@8 112 for index = 1:ilength
matthiasm@8 113 % convert interval to a semitone value
matthiasm@8 114 [semitone, ok, errors] = interval2semitone(degreeintervals(index,1),degreeintervals(index,2));
matthiasm@8 115
matthiasm@8 116 if ok && semitone >= 0
matthiasm@8 117 % record the interval
matthiasm@8 118 addlist(semitone+1,1) = degreeintervals(index,1) .* degreeintervals(index,3);
matthiasm@8 119 % record the accidentals as well
matthiasm@8 120 addlist(semitone+1,2) = degreeintervals(index,2);
matthiasm@8 121
matthiasm@8 122 else
matthiasm@8 123 success = 0;
matthiasm@8 124 end
matthiasm@8 125
matthiasm@8 126 end
matthiasm@8 127 else
matthiasm@8 128 success=0;
matthiasm@8 129 end
matthiasm@8 130
matthiasm@8 131
matthiasm@8 132 % now create fulldegreelist
matthiasm@8 133 if ok
matthiasm@8 134
matthiasm@8 135 [ilength,y] = size(addlist);
matthiasm@8 136
matthiasm@8 137 for index = 1:ilength
matthiasm@8 138
matthiasm@8 139 % if there is a non zero interval in this element, convert
matthiasm@8 140 % it to a degree symbol and add it to the output list
matthiasm@8 141 if(addlist(index,1) ~=0)
matthiasm@8 142
matthiasm@8 143 degreesymbol = interval2degree(addlist(index,1),addlist(index,2));
matthiasm@8 144
matthiasm@8 145 if isempty(fulldegreelist)
matthiasm@8 146 % if this is the first degree then start list
matthiasm@8 147 fulldegreelist = degreesymbol;
matthiasm@8 148 else
matthiasm@8 149 % add to list with a separating comma
matthiasm@8 150 fulldegreelist = [fulldegreelist ',' degreesymbol];
matthiasm@8 151 end
matthiasm@8 152 end
matthiasm@8 153 end
matthiasm@8 154 else
matthiasm@8 155
matthiasm@8 156 success = 0;
matthiasm@8 157
matthiasm@8 158 end
matthiasm@8 159
matthiasm@8 160 else
matthiasm@8 161
matthiasm@8 162 success = 0;
matthiasm@8 163
matthiasm@8 164 end
matthiasm@8 165
matthiasm@8 166
matthiasm@8 167 if success == 0
matthiasm@8 168 errormessage = [errors sprintf(['Error in addshort2list: unsuccessful '...
matthiasm@8 169 'combination "' shorthand '" and "' degreelist '"\n'])];
matthiasm@8 170
matthiasm@8 171 if verbose ==1
matthiasm@8 172 fprintf(1,errormessage);
matthiasm@8 173 end
matthiasm@8 174
matthiasm@8 175
matthiasm@8 176 end
matthiasm@8 177
matthiasm@8 178