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