christopherh@1
|
1 %
|
christopherh@1
|
2 %INTERVALS2SEMITONES convert an interval list to an array of semitone values
|
christopherh@1
|
3 %
|
christopherh@1
|
4 % [semitones, success, errormessage] = intervals2semitones(interval_list, {verbose})
|
christopherh@1
|
5 %
|
christopherh@1
|
6 % Converts a list of intervals to corresponding semitone degrees
|
christopherh@1
|
7 %
|
christopherh@1
|
8 % Success = 1 if symbols parsed correctly, 0 otherwise.
|
christopherh@1
|
9 %
|
christopherh@1
|
10 % If optional argument 'verbose' is 1, function prints any errormessage to
|
christopherh@1
|
11 % the screen.
|
christopherh@1
|
12 %
|
christopherh@1
|
13 % calls interval2semitone
|
christopherh@1
|
14 %
|
christopherh@1
|
15 % returns: semitones (array of integers)
|
christopherh@1
|
16 % success (boolean)
|
christopherh@1
|
17 % errormessage (string)
|
christopherh@1
|
18 %
|
christopherh@1
|
19 %
|
christopherh@1
|
20 % Author: Christopher Harte, March 2009
|
christopherh@1
|
21 %
|
christopherh@1
|
22 % Copyright: Centre for Digital Music, Queen Mary University of London 2005
|
christopherh@1
|
23 %
|
christopherh@1
|
24 % This file is part of the C4DM Chord Toolkit V2.0
|
christopherh@1
|
25 %
|
christopherh@1
|
26 % The C4DM Chord Toolkit is free software; you can redistribute it and/or
|
christopherh@1
|
27 % modify it under the terms of the GNU General Public License as published
|
christopherh@1
|
28 % by the Free Software Foundation; either version 2 of the License, or
|
christopherh@1
|
29 % (at your option) any later version.
|
christopherh@1
|
30 %
|
christopherh@1
|
31 % The C4DM Chord Toolkit is distributed in the hope that it will be useful,
|
christopherh@1
|
32 % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
christopherh@1
|
33 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
christopherh@1
|
34 % GNU General Public License for more details.
|
christopherh@1
|
35 %
|
christopherh@1
|
36 % You should have received a copy of the GNU General Public License
|
christopherh@1
|
37 % along with the C4DM Toolkit; if not, write to the Free Software
|
christopherh@1
|
38 % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
christopherh@1
|
39 %
|
christopherh@1
|
40
|
christopherh@1
|
41 function [semitones, success, errormessage] = intervals2semitones(interval_list, verbose)
|
christopherh@1
|
42
|
christopherh@1
|
43 % set verbose default to 0
|
christopherh@1
|
44 if nargin < 2
|
christopherh@1
|
45 verbose = 0;
|
christopherh@1
|
46 end
|
christopherh@1
|
47
|
christopherh@1
|
48 errormessage = '';
|
christopherh@1
|
49
|
christopherh@1
|
50 ilength = length(interval_list);
|
christopherh@1
|
51
|
christopherh@1
|
52 index = 1;
|
christopherh@1
|
53
|
christopherh@1
|
54 tempindex = 1;
|
christopherh@1
|
55
|
christopherh@1
|
56 tempstring = '';
|
christopherh@1
|
57
|
christopherh@1
|
58 success = 1;
|
christopherh@1
|
59
|
christopherh@1
|
60 parindex = 1;
|
christopherh@1
|
61
|
christopherh@1
|
62 semitones = [];
|
christopherh@1
|
63
|
christopherh@1
|
64
|
christopherh@1
|
65 while index <= ilength
|
christopherh@1
|
66
|
christopherh@1
|
67
|
christopherh@1
|
68 while (interval_list(index) ~= ',')
|
christopherh@1
|
69
|
christopherh@1
|
70 tempstring(tempindex) = interval_list(index);
|
christopherh@1
|
71 tempindex = tempindex +1;
|
christopherh@1
|
72 index = index + 1;
|
christopherh@1
|
73
|
christopherh@1
|
74 if(index > ilength)
|
christopherh@1
|
75 break;
|
christopherh@1
|
76 end
|
christopherh@1
|
77
|
christopherh@1
|
78 if (interval_list(index) == ',') && (index == ilength)
|
christopherh@1
|
79 success = 0;
|
christopherh@1
|
80 errormessage = sprintf(['Error in intervals2semitones: interval list finishes with a comma "' interval_list '"\n']);
|
christopherh@1
|
81 end
|
christopherh@1
|
82
|
christopherh@1
|
83
|
christopherh@1
|
84 end
|
christopherh@1
|
85
|
christopherh@1
|
86 [semitones(parindex),ok, error] = interval2semitone(tempstring);
|
christopherh@1
|
87 % concatenate error messages if there are any...
|
christopherh@1
|
88 errormessage = [errormessage error];
|
christopherh@1
|
89
|
christopherh@1
|
90 if(ok == 1)
|
christopherh@1
|
91 tempstring = '';
|
christopherh@1
|
92 tempindex = 1;
|
christopherh@1
|
93 parindex = parindex + 1;
|
christopherh@1
|
94 index = index + 1;
|
christopherh@1
|
95 else
|
christopherh@1
|
96
|
christopherh@1
|
97 errormessage = [errormessage sprintf(['Error in intervals2semitones: incorrect interval in list "' interval_list '"\n'])];
|
christopherh@1
|
98 success = 0;
|
christopherh@1
|
99 index = ilength +1;
|
christopherh@1
|
100 end
|
christopherh@1
|
101
|
christopherh@1
|
102
|
christopherh@1
|
103 end
|
christopherh@1
|
104
|
christopherh@1
|
105 if (success == 0) && (verbose == 1)
|
christopherh@1
|
106
|
christopherh@1
|
107 fprintf(1,errormessage)
|
christopherh@1
|
108
|
christopherh@1
|
109 end
|
christopherh@1
|
110
|
christopherh@1
|
111
|
christopherh@1
|
112
|
christopherh@1
|
113
|
christopherh@1
|
114
|
christopherh@1
|
115
|
christopherh@1
|
116
|
christopherh@1
|
117
|