To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / _chordtools / getchordinfo.m @ 8:b5b38998ef3b

History | View | Annotate | Download (2.85 KB)

1
%
2
% GETCHORDINFO Check chord symbol validity and return constituent parts
3
% 
4
% [rootnote, shorthand,degreelist,bassdegree, success, errormessage] = getchordinfo(chordsymbol, {verbose})
5
% 
6
% Checks symbol for correct syntax and returns chord information  Differs 
7
% from parsechord in that notes, shorthands, degrees and bass values are all 
8
% checked for validity in the process.
9
% 
10
% Success = 1 if all symbols have correct syntax, 0 otherwise.
11
% 
12
% If optional argument 'verbose' is 1, function prints any errormessage to 
13
% the screen.
14
% 
15
% Returns:	rootnote   (string)
16
%           shorthand  (string)
17
%           degreelist (string)
18
%           bassdegree (string)
19
%           success (boolean) true or false for correct syntax 
20
%           errormessage (string)  
21
%
22
% See also: syntaxcheck
23
%
24
% Author: Christopher Harte,  August 2005
25
% 
26
% Copyright: Centre for Digital Music, Queen Mary University of London 2005 
27
%
28
% This file is part of the C4DM Chord Toolkit.  
29
%
30
% The C4DM Chord Toolkit is free software; you can redistribute it and/or 
31
% modify it under the terms of the GNU General Public License as published 
32
% by the Free Software Foundation; either version 2 of the License, or
33
% (at your option) any later version.
34
%
35
% The C4DM Chord Toolkit is distributed in the hope that it will be useful,
36
% but WITHOUT ANY WARRANTY; without even the implied warranty of
37
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38
% GNU General Public License for more details.
39
%
40
% You should have received a copy of the GNU General Public License
41
% along with the C4DM Toolkit; if not, write to the Free Software
42
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
43

    
44
%		
45
function [rootnote, shorthand,degreelist,bassdegree, success, errormessage] = getchordinfo(chordsymbol, verbose)
46

    
47
if nargin < 2
48
    verbose = 0;
49
end
50
    
51
errormessage = '';
52
rootnote = '';
53
shorthand =  '';
54
degrees = '';
55
bassdegreel = '';
56

    
57

    
58
success = 0;
59

    
60
% parse the chord symbol into its constituent parts
61
[rootnote,shorthand, degreelist,bassdegree, success, errormessage] = parsechord(chordsymbol);
62

    
63
if success == 1
64
    
65
    if rootnote ~= 'N'
66
        
67
        % check validity of rootnote
68
        [temp, temp2, success, errormessage] = parsenote(rootnote);
69

    
70
        %check validity of shorthand list
71
        if ((success == 1) && ~(isempty(shorthand)))
72
           [temp, success, errormessage] = shorthand2degrees(shorthand);
73
        end        
74
        
75
        % check validity of degreelist
76
        if (success == 1) && ~(isempty(degreelist))
77
            [temp, success, errormessage] = parsedegreelist(degreelist);
78
        end
79
    
80
        % check validity of bass degree
81
        if (success == 1) && ~(isempty(bassdegree))
82
           [temp,temp2,temp3, success, errormessage] = parsedegree(bassdegree); 
83
        end
84
          
85
    end
86

    
87
end
88

    
89
if (success ==0) && (verbose == 1)
90
    fprintf(1,errormessage);
91
end