annotate chordtools/notes2pitchclasses.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 %NOTES2PITCHCLASSES convert a note list to an array pitchclasses
christopherh@1 3 %
christopherh@1 4 % [pitchclasses, success, errormessage] = notes2pitchclasses(notes, {verbose})
christopherh@1 5 %
christopherh@1 6 % Converts a cell array of note strings to an array of pitch class integer
christopherh@1 7 % values. Pitch class values are referenced w.r.t. C = 0.
christopherh@1 8 %
christopherh@1 9 % Success = 1 if symbols converted correctly, 0 otherwise.
christopherh@1 10 %
christopherh@1 11 % If optional argument 'verbose' is 1, function prints any errormessage to
christopherh@1 12 % the screen.
christopherh@1 13 %
christopherh@1 14 % calls note2pitchclass
christopherh@1 15 %
christopherh@1 16 % returns: pitchclasses (array of integers)
christopherh@1 17 % success (boolean)
christopherh@1 18 % errormessage (string)
christopherh@1 19 %
christopherh@1 20 %
christopherh@1 21 % Author: Christopher Harte, March 2009
christopherh@1 22 %
christopherh@1 23 % Copyright: Centre for Digital Music, Queen Mary University of London 2005
christopherh@1 24 %
christopherh@1 25 % This file is part of the C4DM Chord Toolkit V2.0
christopherh@1 26 %
christopherh@1 27 % The C4DM Chord Toolkit is free software; you can redistribute it and/or
christopherh@1 28 % modify it under the terms of the GNU General Public License as published
christopherh@1 29 % by the Free Software Foundation; either version 2 of the License, or
christopherh@1 30 % (at your option) any later version.
christopherh@1 31 %
christopherh@1 32 % The C4DM Chord Toolkit is distributed in the hope that it will be useful,
christopherh@1 33 % but WITHOUT ANY WARRANTY; without even the implied warranty of
christopherh@1 34 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
christopherh@1 35 % GNU General Public License for more details.
christopherh@1 36 %
christopherh@1 37 % You should have received a copy of the GNU General Public License
christopherh@1 38 % along with the C4DM Toolkit; if not, write to the Free Software
christopherh@1 39 % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
christopherh@1 40 %
christopherh@1 41
christopherh@1 42 function [pitchclasses, success, errormessage] = notes2pitchclasses(notes, verbose)
christopherh@1 43
christopherh@1 44 % set verbose default to 0
christopherh@1 45 if nargin < 2
christopherh@1 46 verbose = 0;
christopherh@1 47 end
christopherh@1 48
christopherh@1 49 errormessage = '';
christopherh@1 50
christopherh@1 51 ilength = length(notes);
christopherh@1 52
christopherh@1 53 index = 1;
christopherh@1 54
christopherh@1 55 success = 1;
christopherh@1 56
christopherh@1 57 pitchclasses = [];
christopherh@1 58
christopherh@1 59 while index <= ilength
christopherh@1 60
christopherh@1 61 [pitchclasses(index), success, errormessage] = note2pitchclass(char(notes(index)));
christopherh@1 62
christopherh@1 63 if success
christopherh@1 64 index=index+1;
christopherh@1 65 else
christopherh@1 66 errormessage = [errormessage sprintf(['Error in notes2pitchclasses: couldn''t convert notes "' notes '"\n'])];
christopherh@1 67 index = ilength +1;
christopherh@1 68 end
christopherh@1 69
christopherh@1 70
christopherh@1 71 end
christopherh@1 72
christopherh@1 73 if (success == 0) && (verbose == 1)
christopherh@1 74
christopherh@1 75 fprintf(1,errormessage)
christopherh@1 76
christopherh@1 77 end
christopherh@1 78
christopherh@1 79
christopherh@1 80