christopherh@1: % christopherh@1: %SHORT2QUALITY return the quality of a given shorthand string christopherh@1: % christopherh@1: % [quality,success, errormessage] = short2quality(shorthand, {verbose}) christopherh@1: % christopherh@1: % Returns the quality of a given shorthand string. Quality values are from christopherh@1: % the enumeration: christopherh@1: % christopherh@1: % 0 Major christopherh@1: % 1 Minor christopherh@1: % 2 Diminished christopherh@1: % 3 Augmented christopherh@1: % 4 Suspended christopherh@1: % christopherh@1: % christopherh@1: % Success = 1 if symbols parsed 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: % calls: christopherh@1: % christopherh@1: % returns: quality (integer) christopherh@1: % success (boolean) christopherh@1: % errormessage (string) 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 [quality,success,errormessage] = short2quality(shorthand,verbose) christopherh@1: christopherh@1: if nargin < 2 christopherh@1: verbose = 0; christopherh@1: end christopherh@1: christopherh@1: success = 1; christopherh@1: errormessage = ''; christopherh@1: quality = ''; christopherh@1: christopherh@1: switch shorthand christopherh@1: christopherh@1: christopherh@1: % triads christopherh@1: case 'maj' christopherh@1: quality = 0; christopherh@1: case 'min' christopherh@1: quality = 1; christopherh@1: case 'dim' christopherh@1: quality = 2; christopherh@1: case 'aug' christopherh@1: quality = 3; christopherh@1: christopherh@1: % sevenths christopherh@1: case 'maj7' christopherh@1: quality = 0; christopherh@1: case 'min7' christopherh@1: quality = 1; christopherh@1: case '7' christopherh@1: quality = 0; christopherh@1: case 'minmaj7' christopherh@1: quality = 1; christopherh@1: case 'dim7' christopherh@1: quality = 2; christopherh@1: case 'hdim7' christopherh@1: quality = 2; christopherh@1: christopherh@1: % sixths christopherh@1: case 'maj6' christopherh@1: quality = 0; christopherh@1: case 'min6' christopherh@1: quality = 1; christopherh@1: christopherh@1: % ninths christopherh@1: christopherh@1: case '9' christopherh@1: quality = 0; christopherh@1: case 'maj9' christopherh@1: quality = 0; christopherh@1: case 'min9' christopherh@1: quality = 1; christopherh@1: christopherh@1: % suspended christopherh@1: case 'sus4' christopherh@1: quality = 4; christopherh@1: case 'sus2' christopherh@1: quality = 4; christopherh@1: christopherh@1: otherwise christopherh@1: success = 0; christopherh@1: errormessage = ['Error in short2quality: unrecognised shorthand: ' shorthand]; christopherh@1: end christopherh@1: christopherh@1: christopherh@1: if (success ==0) && (verbose == 1) christopherh@1: fprintf(1,errormessage); christopherh@1: end