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 / degrees2notes.m

History | View | Annotate | Download (2.83 KB)

1
%
2
%DEGREES2NOTES Convert a degreelist to an array of notes w.r.t. a root
3
% 
4
% [notes, success, errormessage] = degrees2notes(degreelist, root, {verbose})
5
% 
6
% Converts the degrees in degreelist to correctly spelled notes with 
7
% respect to the root note.
8
% 
9
% Success = 1 if degrees 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 degree2note
19
%
20
%
21
%% Author: Christopher Harte,  August 2005
22
% 
23
% Copyright: Centre for Digital Music, Queen Mary University of London 2005 
24
%
25
% This file is part of the C4DM Chord Toolkit.  
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] = degrees2notes(degreelist, 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(degreelist);
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 (degreelist(index) ~= ',')  
68
        
69
        tempstring(tempindex) = degreelist(index);
70
        tempindex = tempindex +1;
71
        index = index + 1;
72
        
73
        if(index > ilength)
74
            break;
75
        end
76
        
77
        if (degreelist(index) == ',') && (index == ilength)
78
            success = 0;
79
            errormessage = sprintf(['Error in degrees2notes: degree list finishes with a comma "' degreelist '"\n']);
80
        end
81
            
82
            
83
    end
84
    
85
        [newnote,ok, error] = degree2note(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 degrees2notes: incorrect degree in list "' degreelist '"\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