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 / notes2pitchclasses.m @ 8:b5b38998ef3b

History | View | Annotate | Download (2.14 KB)

1
%
2
%NOTES2PITCHCLASSES convert a note list to an array pitchclasses
3
% 
4
% [pitchclasses, success, errormessage] = notes2pitchclasses(notes, {verbose})
5
% 
6
% Converts a cell array of note strings to an array of pitch class integer 
7
% values. Pitch class values are referenced w.r.t. C = 0. 
8
% 
9
% Success = 1 if symbols converted correctly, 0 otherwise.
10
% 
11
% If optional argument 'verbose' is 1, function prints any errormessage to 
12
% the screen.
13
% 
14
% calls note2pitchclass
15
% 
16
% returns:  pitchclasses (array of integers)
17
%           success (boolean)
18
%           errormessage (string)
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 [pitchclasses, success, errormessage] = notes2pitchclasses(notes, verbose)
43

    
44
% set verbose default to 0
45
if nargin < 2
46
    verbose = 0;
47
end
48

    
49
errormessage = '';
50

    
51
ilength = length(notes);
52

    
53
index = 1;
54

    
55
success = 1;
56

    
57
pitchclasses = [];
58

    
59
while index <= ilength
60
    
61
        [pitchclasses(index), success, errormessage] = note2pitchclass(char(notes(index)));
62
    
63
        if success
64
            index=index+1;
65
        else
66
            errormessage = [errormessage sprintf(['Error in notes2pitchclasses: couldn''t convert notes "' notes '"\n'])];
67
            index = ilength +1;            
68
        end
69
    
70
    
71
end
72

    
73
if (success == 0) && (verbose == 1)
74

    
75
    fprintf(1,errormessage)
76
    
77
end    
78

    
79

    
80