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