comparison chordtools/parseintervals.m @ 1:8973548174c1 tip

adding tools to repo
author christopherh
date Mon, 06 May 2013 14:43:47 +0100
parents
children
comparison
equal deleted inserted replaced
0:0a4ad3e72e75 1:8973548174c1
1 %
2 % PARSEINTERVALS
3 %
4 % [parintervals, success, errormessage] = parseintervals(interval_list, {verbose})
5 %
6 % Parses a comma delimited list of intervals to an array of degrees, their
7 % associated accidentals and whether or not they are present (presence
8 % denoted by a '*' in front of an interval in the input interval_list).
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 parseinterval
16 %
17 % returns: intervals (array of int: [degree,accidental,present])
18 % success (boolean)
19 % errormessage (string)
20 %
21 %
22 % Author: Christopher Harte, March 2009
23 %
24 % Copyright: Centre for Digital Music, Queen Mary University of London 2005
25 %
26 % This file is part of the C4DM Chord Toolkit V2.0
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 [parintervals, success, errormessage] = parseintervals(interval_list, verbose)
44
45 % set verbose default to 0
46 if nargin < 2
47 verbose = 0;
48 end
49
50 errormessage = '';
51
52 ilength = length(interval_list);
53
54 index = 1;
55
56 tempindex = 1;
57
58 tempstring = '';
59
60 success = 1;
61
62 parindex = 1;
63
64 parintervals = [];
65
66
67 while index <= ilength
68
69
70 while (interval_list(index) ~= ',')
71
72 tempstring(tempindex) = interval_list(index);
73 tempindex = tempindex +1;
74 index = index + 1;
75
76 if(index > ilength)
77 break;
78 end
79
80 if (interval_list(index) == ',') && (index == ilength)
81 success = 0;
82 errormessage = sprintf(['Error in parseintervals: interval list finishes with a comma "' interval_list '"\n']);
83 end
84
85
86 end
87
88 [parintervals(parindex,1),parintervals(parindex,2),parintervals(parindex,3),ok, error] = parseinterval(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 parseintervals: incorrect interval in list "' interval_list '"\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