comparison chordtools/degree2interval.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 % DEGREE2INTERVAL
3 %
4 % [interval,success,errormessage] = degree2interval(degree,accidentals,{verbose})
5 %
6 % Converts a degree and accidental pair to an interval string.
7 %
8 % Success = 1 if degree converted correctly, 0 otherwise.
9 %
10 % If optional argument 'verbose' is 1, function prints any errormessage to
11 % the screen.
12 %
13 % returns: interval (string)
14 % success (boolean)
15 % errormessage (string)
16 %
17 % Author: Christopher Harte, March 2009
18 %
19 % Copyright: Centre for Digital Music, Queen Mary University of London 2005
20 %
21 % This file is part of the C4DM Chord Toolkit V2.0
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 [interval,success,errormessage] = degree2interval(degree,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 interval = '';
50
51
52 if accidentals >=1
53 % then the degree is either a natural or has a number of sharps
54 if accidentals ~= 0
55 for index = 1:accidentals
56 interval = [interval '#'];
57 end
58 end
59
60 else
61 % then the degree has a number of flats
62
63 for index = 1:abs(accidentals)
64
65 interval = [interval 'b'];
66 end
67
68 end
69
70 if isnumeric(degree)
71
72 degreestring = num2str(degree);
73 interval = [interval degreestring];
74
75 else
76 success = 0;
77 errormessage = 'Error in degree2interval: incorrect degree';
78 end
79
80 if (success == 0) && (verbose == 1)
81 fprintf(1,errormessage);
82 end
83
84