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

History | View | Annotate | Download (2.12 KB)

1
%
2
% INTERVAL2DEGREE
3
% 
4
% [degree,success,errormessage] = interval2degree(interval,accidentals,{verbose})
5
% 
6
% Converts an interval and accidental pair to a degree string.
7
% 
8
% Success = 1 if interval converted correctly, 0 otherwise.
9
% 
10
% If optional argument 'verbose' is 1, function prints any errormessage to 
11
% the screen.
12
% 
13
% returns:  degree (string)
14
%           success (boolean)
15
%           errormessage (string)
16
%
17
% Author: Christopher Harte,  August 2005
18
% 
19
% Copyright: Centre for Digital Music, Queen Mary University of London 2005 
20
%
21
% This file is part of the C4DM Chord Toolkit.  
22
%
23
% The C4DM Chord Toolkit is free software; you can redistribute it and/or 
24
% modify it under the terms of the GNU General Public License as published 
25
% by the Free Software Foundation; either version 2 of the License, or
26
% (at your option) any later version.
27
%
28
% The C4DM Chord Toolkit is distributed in the hope that it will be useful,
29
% but WITHOUT ANY WARRANTY; without even the implied warranty of
30
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31
% GNU General Public License for more details.
32
%
33
% You should have received a copy of the GNU General Public License
34
% along with the C4DM Toolkit; if not, write to the Free Software
35
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
36

    
37
%		
38
function [degree,success,errormessage] = interval2degree(interval,accidentals, verbose)
39

    
40
% set verbose default to 0
41
if nargin < 3
42
    verbose = 0;
43
end
44

    
45
errormessage = '';
46

    
47

    
48
success = 1;
49
degree = '';
50

    
51

    
52
if accidentals >=1
53
   % then the interval is either a natural or has a number of sharps 
54
    if accidentals ~= 0
55
        for index = 1:accidentals 
56
            degree = [degree '#'];
57
        end
58
    end
59
    
60
else
61
    % then the interval has a number of flats
62
    
63
    for index = 1:abs(accidentals) 
64
   
65
        degree = [degree 'b'];
66
    end
67
    
68
end
69

    
70
if isnumeric(interval)
71
    
72
    intervalstring = num2str(interval);
73
    degree = [degree intervalstring];
74
    
75
else
76
   success = 0;
77
   errormessage = 'Error in interval2degree: incorrect interval';
78
end
79
    
80
if (success == 0) && (verbose == 1)   
81
    fprintf(1,errormessage);
82
end  
83

    
84