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

History | View | Annotate | Download (2.05 KB)

1
%
2
% DEGREE2SEMITONE convert a degree to equivalent number of semitones
3
% 
4
% [semitone,success, errormessage] = degree2semitone(degree, {verbose})
5
% 
6
% Converts a degree string to equivalent number of semitones.
7
%
8
% Success = 1 if symbols parsed correctly, 0 otherwise. 
9
%
10
% If optional argument 'verbose' is 1, function prints any errormessage to 
11
% the screen.
12
% 
13
% calls:    parsedegree
14
%           interval2semitone
15
% 
16
% returns:  semitone (integer)
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  [semitone, success, errormessage] = degree2semitone(degree, verbose)
43
    
44
if nargin <2 
45
    % verbose defaults 0
46
    verbose = 0;
47
end
48

    
49
errormessage = '';
50

    
51
ilength = length(degree);
52

    
53
success=0;
54
semitone = 0;
55

    
56
% parse the degree string
57

    
58
[interval, accidentals, present, ok] = parsedegree(degree);
59

    
60
if (ok == 1)
61
    
62
    % convert interval and accidentals to equivalent number of semitones 
63
    [semitone, ok, errors] = interval2semitone(interval,accidentals);
64
    
65
    success = 1;
66
    
67
else
68
    
69
    errormessage = sprintf(['Error in degree2semitone: incorrect degree "' degree '"\n']);
70

    
71
end
72

    
73
if (verbose ==1) && (success ==0)
74
    fprintf(1,errormessage); 
75
end
76