diff chordtools/short2quality.m @ 1:8973548174c1 tip

adding tools to repo
author christopherh
date Mon, 06 May 2013 14:43:47 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/chordtools/short2quality.m	Mon May 06 14:43:47 2013 +0100
@@ -0,0 +1,115 @@
+%
+%SHORT2QUALITY return the quality of a given shorthand string
+% 
+% [quality,success, errormessage] = short2quality(shorthand, {verbose})
+% 
+% Returns the quality of a given shorthand string. Quality values are from 
+% the enumeration:
+%
+% 0   Major
+% 1   Minor
+% 2   Diminished
+% 3   Augmented
+% 4   Suspended
+% 
+%
+% Success = 1 if symbols parsed correctly, 0 otherwise. 
+%
+% If optional argument 'verbose' is 1, function prints any errormessage to 
+% the screen.
+% 
+% calls:   
+% 
+% returns:  quality (integer)
+%           success  (boolean)  
+%           errormessage (string)
+%
+%
+% Author: Christopher Harte, March 2009
+% 
+% Copyright: Centre for Digital Music, Queen Mary University of London 2005 
+%
+% This file is part of the C4DM Chord Toolkit V2.0  
+%
+% The C4DM Chord Toolkit is free software; you can redistribute it and/or 
+% modify it under the terms of the GNU General Public License as published 
+% by the Free Software Foundation; either version 2 of the License, or
+% (at your option) any later version.
+%
+% The C4DM Chord Toolkit is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with the C4DM Toolkit; if not, write to the Free Software
+% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+%
+function [quality,success,errormessage] = short2quality(shorthand,verbose)
+
+if nargin < 2
+    verbose = 0;
+end
+
+success = 1;
+errormessage = '';
+quality = '';
+
+switch shorthand
+    
+        
+    % triads
+    case 'maj'
+        quality = 0;        
+    case 'min' 
+        quality = 1;        
+    case 'dim' 
+        quality = 2;    
+    case 'aug' 
+        quality = 3;
+        
+    % sevenths    
+    case 'maj7' 
+        quality = 0;
+    case 'min7' 
+        quality = 1;
+    case '7' 
+        quality = 0;        
+    case 'minmaj7' 
+        quality = 1;        
+    case 'dim7' 
+        quality = 2;
+    case 'hdim7'
+        quality = 2;
+ 
+    % sixths
+    case 'maj6'
+        quality = 0;        
+    case 'min6' 
+        quality = 1;
+
+    % ninths 
+ 
+    case '9'
+        quality = 0;          
+    case 'maj9'
+        quality = 0;    
+    case 'min9'
+        quality = 1;    
+
+    % suspended
+    case 'sus4'
+        quality = 4;
+    case 'sus2'
+        quality = 4;
+        
+    otherwise
+        success = 0;
+        errormessage = ['Error in short2quality: unrecognised shorthand: ' shorthand];
+end
+
+        
+if (success ==0) && (verbose == 1)
+    fprintf(1,errormessage);
+end
\ No newline at end of file