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 / parsedegreelist.m @ 8:b5b38998ef3b

History | View | Annotate | Download (3.01 KB)

1
%
2
% PARSEDEGREELIST
3
% 
4
% [pardegrees, success, errormessage] = parsedegreelist(degreelist, {verbose})
5
% 
6
% Parses a comma delimited list of degrees to an array of intervals, their 
7
% associated accidentals and whether or not they are present (presence 
8
% denoted by a '*' in front of a degree in the input degreelist). 
9
%
10
% Success = 1 if symbols parsed correctly, 0 otherwise.
11
%
12
% If optional argument 'verbose' is 1, function prints any errormessage to 
13
% the screen.
14
% 
15
% calls parsedegree
16
% 
17
% returns:  degrees       (array of int: [interval,accidental,present])
18
%           success       (boolean)
19
%           errormessage  (string) 
20
% 
21
%
22
% Author: Christopher Harte,  August 2005
23
% 
24
% Copyright: Centre for Digital Music, Queen Mary University of London 2005 
25
%
26
% This file is part of the C4DM Chord Toolkit.  
27
%
28
% The C4DM Chord Toolkit is free software; you can redistribute it and/or 
29
% modify it under the terms of the GNU General Public License as published 
30
% by the Free Software Foundation; either version 2 of the License, or
31
% (at your option) any later version.
32
%
33
% The C4DM Chord Toolkit is distributed in the hope that it will be useful,
34
% but WITHOUT ANY WARRANTY; without even the implied warranty of
35
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36
% GNU General Public License for more details.
37
%
38
% You should have received a copy of the GNU General Public License
39
% along with the C4DM Toolkit; if not, write to the Free Software
40
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
41

    
42
%
43
function [pardegrees, success, errormessage] = parsedegreelist(degreelist, verbose)
44

    
45
% set verbose default to 0
46
if nargin < 2
47
    verbose = 0;
48
end
49

    
50
errormessage = '';
51

    
52
ilength = length(degreelist);
53

    
54
index = 1;
55

    
56
tempindex = 1;
57

    
58
tempstring = '';
59

    
60
success = 1;
61

    
62
parindex  = 1;
63

    
64
pardegrees = [];
65

    
66

    
67
while index <= ilength
68
    
69
   
70
    while (degreelist(index) ~= ',')  
71
        
72
        tempstring(tempindex) = degreelist(index);
73
        tempindex = tempindex +1;
74
        index = index + 1;
75
        
76
        if(index > ilength)
77
            break;
78
        end
79
        
80
        if (degreelist(index) == ',') && (index == ilength)
81
            success = 0;
82
            errormessage = sprintf(['Error in parsedegreelist: degree list finishes with a comma "' degreelist '"\n']);
83
        end
84
            
85
            
86
    end
87
    
88
        [pardegrees(parindex,1),pardegrees(parindex,2),pardegrees(parindex,3),ok, error] = parsedegree(tempstring);
89
        % concatenate error messages if there are any...
90
        errormessage = [errormessage error];
91
        
92
        if(ok == 1)
93
            tempstring = '';
94
            tempindex = 1;
95
            parindex = parindex + 1;
96
            index = index + 1;
97
        else
98

    
99
            errormessage = [errormessage sprintf(['Error in parsedegreelist: incorrect degree in list "' degreelist '"\n'])];
100
            success = 0;
101
            index = ilength +1;            
102
        end
103
    
104
    
105
end
106

    
107
if (success == 0) && (verbose == 1)
108

    
109
    fprintf(1,errormessage)
110
    
111
end    
112

    
113

    
114
    
115
              
116

    
117

    
118

    
119

    
120

    
121