matthiasm@8: % matthiasm@8: %ADDSHORT2LIST Combine degrees of a shorthand with another degree list matthiasm@8: % matthiasm@8: % [fulldegreelist, success, errormessage] = addshort2list(shorthand, degreelist, {verbose}) matthiasm@8: % matthiasm@8: % Combine shorthand and degreelist to form full degree list for a chord. matthiasm@8: % Takes into account the omit degree character '*' in producing final list. matthiasm@8: % matthiasm@8: % Success = 1 if shorthand and degreelist combined correctly, 0 otherwise. matthiasm@8: % matthiasm@8: % If optional argument 'verbose' is 1, function prints any errormessage to matthiasm@8: % the screen. matthiasm@8: % matthiasm@8: % returns: fulldegreelist (string) matthiasm@8: % success (boolean) matthiasm@8: % errormessage (string) matthiasm@8: % matthiasm@8: % Author: Christopher Harte, August 2005 matthiasm@8: % matthiasm@8: % Copyright: Centre for Digital Music, Queen Mary University of London 2005 matthiasm@8: % matthiasm@8: % This file is part of the C4DM Chord Toolkit. matthiasm@8: % matthiasm@8: % The C4DM Chord Toolkit is free software; you can redistribute it and/or matthiasm@8: % modify it under the terms of the GNU General Public License as published matthiasm@8: % by the Free Software Foundation; either version 2 of the License, or matthiasm@8: % (at your option) any later version. matthiasm@8: % matthiasm@8: % The C4DM Chord Toolkit is distributed in the hope that it will be useful, matthiasm@8: % but WITHOUT ANY WARRANTY; without even the implied warranty of matthiasm@8: % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the matthiasm@8: % GNU General Public License for more details. matthiasm@8: % matthiasm@8: % You should have received a copy of the GNU General Public License matthiasm@8: % along with the C4DM Toolkit; if not, write to the Free Software matthiasm@8: % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA matthiasm@8: matthiasm@8: % matthiasm@8: function [fulldegreelist, success, errormessage] = addshort2list(shorthand, degreelist, verbose) matthiasm@8: matthiasm@8: % set verbose default to 0 matthiasm@8: if nargin < 3 matthiasm@8: verbose = 0; matthiasm@8: end matthiasm@8: matthiasm@8: errormessage = ''; matthiasm@8: matthiasm@8: % initialise variables matthiasm@8: fulldegreelist = ''; matthiasm@8: shortintervals = []; matthiasm@8: degreeintervals = []; matthiasm@8: addlist = []; matthiasm@8: success = 1; matthiasm@8: matthiasm@8: % convert shorthand string to list of degrees matthiasm@8: [shortdegrees, ok, errors] = shorthand2degrees(shorthand); matthiasm@8: matthiasm@8: if ok matthiasm@8: % if that works convert the shorthand degrees and degreelist to matthiasm@8: % intervals and accidentals matthiasm@8: matthiasm@8: % add the implied 1 interval to the shorthand list matthiasm@8: if isempty(shortdegrees) matthiasm@8: rootinterval = '1'; % no comma if shorthand is empty matthiasm@8: else matthiasm@8: rootinterval = '1,'; % comma shows that there are further degrees after this one matthiasm@8: end matthiasm@8: matthiasm@8: matthiasm@8: [shortintervals, ok, errors] = parsedegreelist([rootinterval shortdegrees]); matthiasm@8: matthiasm@8: if (ok) matthiasm@8: matthiasm@8: matthiasm@8: % this part of the algorithm finds all the present intervals and sorts matthiasm@8: % them into ascending numeric order matthiasm@8: matthiasm@8: % First put the shorthand intervals into the full list matthiasm@8: matthiasm@8: [ilength,y] = size(shortintervals); matthiasm@8: matthiasm@8: for index = 1:ilength matthiasm@8: % convert interval to a semitone value matthiasm@8: semitone = interval2semitone(shortintervals(index,1),shortintervals(index,2)); matthiasm@8: matthiasm@8: % Using the semitone value as an index will find redundant matthiasm@8: % degrees and also sort them in number order. Multiplying the interval by its matthiasm@8: % presence value leaves either the interval value or 0. Any element matthiasm@8: % in the array with interval of 0 will be discarded later matthiasm@8: % We add 1 to the semitone value to handle the '1' or 'unity' matthiasm@8: % interval that would return a 0 semitone value matthiasm@8: matthiasm@8: % record the interval matthiasm@8: addlist(semitone+1,1) = shortintervals(index,1) .* shortintervals(index,3); matthiasm@8: % record the accidentals as well matthiasm@8: addlist(semitone+1,2) = shortintervals(index,2); matthiasm@8: matthiasm@8: end matthiasm@8: else matthiasm@8: success = 0; matthiasm@8: end matthiasm@8: matthiasm@8: [degreeintervals, ok2, errors] = parsedegreelist(degreelist); matthiasm@8: ok = ok && ok2; matthiasm@8: matthiasm@8: if ok matthiasm@8: % Now add the degrees from the degreelist taking redundant and matthiasm@8: % ommitted degrees into account matthiasm@8: matthiasm@8: [ilength,y] = size(degreeintervals); matthiasm@8: matthiasm@8: for index = 1:ilength matthiasm@8: % convert interval to a semitone value matthiasm@8: [semitone, ok, errors] = interval2semitone(degreeintervals(index,1),degreeintervals(index,2)); matthiasm@8: matthiasm@8: if ok && semitone >= 0 matthiasm@8: % record the interval matthiasm@8: addlist(semitone+1,1) = degreeintervals(index,1) .* degreeintervals(index,3); matthiasm@8: % record the accidentals as well matthiasm@8: addlist(semitone+1,2) = degreeintervals(index,2); matthiasm@8: matthiasm@8: else matthiasm@8: success = 0; matthiasm@8: end matthiasm@8: matthiasm@8: end matthiasm@8: else matthiasm@8: success=0; matthiasm@8: end matthiasm@8: matthiasm@8: matthiasm@8: % now create fulldegreelist matthiasm@8: if ok matthiasm@8: matthiasm@8: [ilength,y] = size(addlist); matthiasm@8: matthiasm@8: for index = 1:ilength matthiasm@8: matthiasm@8: % if there is a non zero interval in this element, convert matthiasm@8: % it to a degree symbol and add it to the output list matthiasm@8: if(addlist(index,1) ~=0) matthiasm@8: matthiasm@8: degreesymbol = interval2degree(addlist(index,1),addlist(index,2)); matthiasm@8: matthiasm@8: if isempty(fulldegreelist) matthiasm@8: % if this is the first degree then start list matthiasm@8: fulldegreelist = degreesymbol; matthiasm@8: else matthiasm@8: % add to list with a separating comma matthiasm@8: fulldegreelist = [fulldegreelist ',' degreesymbol]; matthiasm@8: end matthiasm@8: end matthiasm@8: end matthiasm@8: else matthiasm@8: matthiasm@8: success = 0; matthiasm@8: matthiasm@8: end matthiasm@8: matthiasm@8: else matthiasm@8: matthiasm@8: success = 0; matthiasm@8: matthiasm@8: end matthiasm@8: matthiasm@8: matthiasm@8: if success == 0 matthiasm@8: errormessage = [errors sprintf(['Error in addshort2list: unsuccessful '... matthiasm@8: 'combination "' shorthand '" and "' degreelist '"\n'])]; matthiasm@8: matthiasm@8: if verbose ==1 matthiasm@8: fprintf(1,errormessage); matthiasm@8: end matthiasm@8: matthiasm@8: matthiasm@8: end matthiasm@8: matthiasm@8: