annotate chordtools/short2quality.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 %SHORT2QUALITY return the quality of a given shorthand string
christopherh@1 3 %
christopherh@1 4 % [quality,success, errormessage] = short2quality(shorthand, {verbose})
christopherh@1 5 %
christopherh@1 6 % Returns the quality of a given shorthand string. Quality values are from
christopherh@1 7 % the enumeration:
christopherh@1 8 %
christopherh@1 9 % 0 Major
christopherh@1 10 % 1 Minor
christopherh@1 11 % 2 Diminished
christopherh@1 12 % 3 Augmented
christopherh@1 13 % 4 Suspended
christopherh@1 14 %
christopherh@1 15 %
christopherh@1 16 % Success = 1 if symbols parsed correctly, 0 otherwise.
christopherh@1 17 %
christopherh@1 18 % If optional argument 'verbose' is 1, function prints any errormessage to
christopherh@1 19 % the screen.
christopherh@1 20 %
christopherh@1 21 % calls:
christopherh@1 22 %
christopherh@1 23 % returns: quality (integer)
christopherh@1 24 % success (boolean)
christopherh@1 25 % errormessage (string)
christopherh@1 26 %
christopherh@1 27 %
christopherh@1 28 % Author: Christopher Harte, March 2009
christopherh@1 29 %
christopherh@1 30 % Copyright: Centre for Digital Music, Queen Mary University of London 2005
christopherh@1 31 %
christopherh@1 32 % This file is part of the C4DM Chord Toolkit V2.0
christopherh@1 33 %
christopherh@1 34 % The C4DM Chord Toolkit is free software; you can redistribute it and/or
christopherh@1 35 % modify it under the terms of the GNU General Public License as published
christopherh@1 36 % by the Free Software Foundation; either version 2 of the License, or
christopherh@1 37 % (at your option) any later version.
christopherh@1 38 %
christopherh@1 39 % The C4DM Chord Toolkit is distributed in the hope that it will be useful,
christopherh@1 40 % but WITHOUT ANY WARRANTY; without even the implied warranty of
christopherh@1 41 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
christopherh@1 42 % GNU General Public License for more details.
christopherh@1 43 %
christopherh@1 44 % You should have received a copy of the GNU General Public License
christopherh@1 45 % along with the C4DM Toolkit; if not, write to the Free Software
christopherh@1 46 % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
christopherh@1 47
christopherh@1 48 %
christopherh@1 49 function [quality,success,errormessage] = short2quality(shorthand,verbose)
christopherh@1 50
christopherh@1 51 if nargin < 2
christopherh@1 52 verbose = 0;
christopherh@1 53 end
christopherh@1 54
christopherh@1 55 success = 1;
christopherh@1 56 errormessage = '';
christopherh@1 57 quality = '';
christopherh@1 58
christopherh@1 59 switch shorthand
christopherh@1 60
christopherh@1 61
christopherh@1 62 % triads
christopherh@1 63 case 'maj'
christopherh@1 64 quality = 0;
christopherh@1 65 case 'min'
christopherh@1 66 quality = 1;
christopherh@1 67 case 'dim'
christopherh@1 68 quality = 2;
christopherh@1 69 case 'aug'
christopherh@1 70 quality = 3;
christopherh@1 71
christopherh@1 72 % sevenths
christopherh@1 73 case 'maj7'
christopherh@1 74 quality = 0;
christopherh@1 75 case 'min7'
christopherh@1 76 quality = 1;
christopherh@1 77 case '7'
christopherh@1 78 quality = 0;
christopherh@1 79 case 'minmaj7'
christopherh@1 80 quality = 1;
christopherh@1 81 case 'dim7'
christopherh@1 82 quality = 2;
christopherh@1 83 case 'hdim7'
christopherh@1 84 quality = 2;
christopherh@1 85
christopherh@1 86 % sixths
christopherh@1 87 case 'maj6'
christopherh@1 88 quality = 0;
christopherh@1 89 case 'min6'
christopherh@1 90 quality = 1;
christopherh@1 91
christopherh@1 92 % ninths
christopherh@1 93
christopherh@1 94 case '9'
christopherh@1 95 quality = 0;
christopherh@1 96 case 'maj9'
christopherh@1 97 quality = 0;
christopherh@1 98 case 'min9'
christopherh@1 99 quality = 1;
christopherh@1 100
christopherh@1 101 % suspended
christopherh@1 102 case 'sus4'
christopherh@1 103 quality = 4;
christopherh@1 104 case 'sus2'
christopherh@1 105 quality = 4;
christopherh@1 106
christopherh@1 107 otherwise
christopherh@1 108 success = 0;
christopherh@1 109 errormessage = ['Error in short2quality: unrecognised shorthand: ' shorthand];
christopherh@1 110 end
christopherh@1 111
christopherh@1 112
christopherh@1 113 if (success ==0) && (verbose == 1)
christopherh@1 114 fprintf(1,errormessage);
christopherh@1 115 end