To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _chordtools / chord2quality.m
History | View | Annotate | Download (2.15 KB)
| 1 |
% |
|---|---|
| 2 |
% CHORD2QUALITY return the chord quality of a given chord symbol |
| 3 |
% |
| 4 |
% [quality,success, errormessage] = chord2quality(chordsymbol, {verbose})
|
| 5 |
% |
| 6 |
% Returns the chord quality of a given chord symbol. Quality values are from |
| 7 |
% the enumeration: |
| 8 |
% |
| 9 |
% 0 Major |
| 10 |
% 1 Minor |
| 11 |
% 2 Diminished |
| 12 |
% 3 Augmented |
| 13 |
% 4 Suspended |
| 14 |
% |
| 15 |
% Success = 1 if symbols parsed correctly, 0 otherwise. |
| 16 |
% |
| 17 |
% If optional argument 'verbose' is 1, function prints any errormessage to |
| 18 |
% the screen. |
| 19 |
% |
| 20 |
% calls: getchordinfo |
| 21 |
% short2quality |
| 22 |
% degrees2quality |
| 23 |
% |
| 24 |
% returns: quality (integer) |
| 25 |
% success (boolean) |
| 26 |
% errormessage (string) |
| 27 |
% |
| 28 |
% |
| 29 |
% Author: Christopher Harte, August 2005 |
| 30 |
% |
| 31 |
% Copyright: Centre for Digital Music, Queen Mary University of London 2005 |
| 32 |
% |
| 33 |
% This file is part of the C4DM Chord Toolkit. |
| 34 |
% |
| 35 |
% The C4DM Chord Toolkit is free software; you can redistribute it and/or |
| 36 |
% modify it under the terms of the GNU General Public License as published |
| 37 |
% by the Free Software Foundation; either version 2 of the License, or |
| 38 |
% (at your option) any later version. |
| 39 |
% |
| 40 |
% The C4DM Chord Toolkit is distributed in the hope that it will be useful, |
| 41 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 42 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 43 |
% GNU General Public License for more details. |
| 44 |
% |
| 45 |
% You should have received a copy of the GNU General Public License |
| 46 |
% along with the C4DM Toolkit; if not, write to the Free Software |
| 47 |
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 48 |
|
| 49 |
% |
| 50 |
|
| 51 |
function [quality, success, errormessage] = chord2quality(chordsymbol,verbose) |
| 52 |
|
| 53 |
quality = ''; |
| 54 |
errormessage = ''; |
| 55 |
|
| 56 |
if nargin < 2 |
| 57 |
verbose = 0; |
| 58 |
end |
| 59 |
|
| 60 |
[rootnote,shorthand,degreelist,bassdegree,success,error] = getchordinfo(chordsymbol); |
| 61 |
|
| 62 |
if success |
| 63 |
|
| 64 |
if ~isempty(shorthand) |
| 65 |
|
| 66 |
[quality, success, error] = short2quality(shorthand); |
| 67 |
|
| 68 |
else |
| 69 |
|
| 70 |
[quality, success, error] = degrees2quality(degreelist); |
| 71 |
|
| 72 |
end |
| 73 |
|
| 74 |
end |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
if(success==0) |
| 79 |
|
| 80 |
errormessage = sprintf([error 'Error in Chord2quality: Chord "' chordsymbol '"\n']); |
| 81 |
|
| 82 |
if verbose == 1 |
| 83 |
fprintf(1, errormessage); |
| 84 |
end |
| 85 |
end |