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