Mercurial > hg > c4dm-chord-transcriptions
comparison chordtools/interval2rcclass.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 % INTERVAL2RCCLASS convert an interval to relative pitchclass displacement | |
3 % | |
4 % [rcclass,success, errormessage] = interval2rcclass(interval, {verbose}) | |
5 % | |
6 % Converts an interval string to relative pitchclass displacement. | |
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: parseinterval | |
14 % degree2semitone | |
15 % | |
16 % returns: rcclass (integer) | |
17 % success (boolean) | |
18 % errormessage (string) | |
19 % | |
20 % | |
21 % Author: Christopher Harte, January 2010 | |
22 % | |
23 % Copyright: Centre for Digital Music, Queen Mary University of London 2005 | |
24 % | |
25 % This file is part of the C4DM Chord Toolkit V2.0 | |
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 [rcclass, success, errormessage] = interval2rcclass(interval, verbose) | |
43 | |
44 if nargin <2 | |
45 % verbose defaults 0 | |
46 verbose = 0; | |
47 end | |
48 | |
49 errormessage = ''; | |
50 | |
51 ilength = length(interval); | |
52 | |
53 success=0; | |
54 semitone = 0; | |
55 | |
56 % parse the interval string | |
57 | |
58 [degree, accidentals, present, ok,errormessage] = parseinterval(interval); | |
59 | |
60 if (ok == 1) | |
61 | |
62 % convert degree and accidentals to equivalent number of semitones | |
63 [semitone, ok, errors] = degree2semitone(degree,accidentals); | |
64 | |
65 rcclass = mod(semitone,12); | |
66 | |
67 | |
68 success = 1; | |
69 | |
70 else | |
71 | |
72 errormessage = sprintf([errormessage 'Error in interval2rcclass: incorrect interval "' interval '"\n']); | |
73 | |
74 end | |
75 | |
76 if (verbose ==1) && (success ==0) | |
77 fprintf(1,errormessage); | |
78 end | |
79 |