christopherh@1: % christopherh@1: %INTERVALS2NOTES Convert an interval_list to an array of notes w.r.t. a root christopherh@1: % christopherh@1: % [notes, success, errormessage] = intervals2notes(interval_list, root, {verbose}) christopherh@1: % christopherh@1: % Converts the intervals in interval_list to correctly spelled notes with christopherh@1: % respect to the root note. christopherh@1: % christopherh@1: % Success = 1 if intervals converted 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: notes (cell array of strings) christopherh@1: % success (boolean) christopherh@1: % errormessage (string) christopherh@1: % christopherh@1: % See also interval2note christopherh@1: % 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 [notes, success, errormessage] = intervals2notes(interval_list, root, 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: ilength = length(interval_list); christopherh@1: christopherh@1: index = 1; christopherh@1: christopherh@1: tempindex = 1; christopherh@1: christopherh@1: tempstring = ''; christopherh@1: christopherh@1: success = 1; christopherh@1: christopherh@1: notes = {}; christopherh@1: christopherh@1: christopherh@1: while index <= ilength christopherh@1: christopherh@1: christopherh@1: while (interval_list(index) ~= ',') christopherh@1: christopherh@1: tempstring(tempindex) = interval_list(index); christopherh@1: tempindex = tempindex +1; christopherh@1: index = index + 1; christopherh@1: christopherh@1: if(index > ilength) christopherh@1: break; christopherh@1: end christopherh@1: christopherh@1: if (interval_list(index) == ',') && (index == ilength) christopherh@1: success = 0; christopherh@1: errormessage = sprintf(['Error in intervals2notes: interval list finishes with a comma "' interval_list '"\n']); christopherh@1: end christopherh@1: christopherh@1: christopherh@1: end christopherh@1: christopherh@1: [newnote,ok, error] = interval2note(tempstring,root); christopherh@1: % concatenate error messages if there are any... christopherh@1: errormessage = [errormessage error]; christopherh@1: christopherh@1: if(ok == 1) christopherh@1: tempstring = ''; christopherh@1: tempindex = 1; christopherh@1: notes = [notes; cellstr(newnote)]; christopherh@1: christopherh@1: index = index + 1; christopherh@1: else christopherh@1: christopherh@1: errormessage = [errormessage sprintf(['Error in intervals2notes: incorrect interval in list "' interval_list '"\n'])]; christopherh@1: success = 0; christopherh@1: index = ilength +1; christopherh@1: end christopherh@1: christopherh@1: christopherh@1: end christopherh@1: christopherh@1: if (success == 0) && (verbose == 1) christopherh@1: christopherh@1: fprintf(1,errormessage) christopherh@1: christopherh@1: end christopherh@1: christopherh@1: