christopherh@1
|
1 %
|
christopherh@1
|
2 % CHECKOMISSIONS
|
christopherh@1
|
3 %
|
christopherh@1
|
4 % [success, errormessage] = checkomissions(shortints, intervals, {verbose})
|
christopherh@1
|
5 %
|
christopherh@1
|
6 % Checks that any omitted intervals are actually present in the interval
|
christopherh@1
|
7 % list that makes up a shorthand definition. For example C:maj(*4) is an
|
christopherh@1
|
8 % incorrect chord because the shorthand does not contain interval 4 so
|
christopherh@1
|
9 % there is no reason to omit it.
|
christopherh@1
|
10 %
|
christopherh@1
|
11 % Arguments 'shortints' and 'intervals' should either be interval lists
|
christopherh@1
|
12 % (characters) or arrays of [degree, modifier, present] triples of the type
|
christopherh@1
|
13 % produced by the function 'parseintervals'.
|
christopherh@1
|
14 %
|
christopherh@1
|
15 % Success = 1 if the interval list does not contain an omitted interval
|
christopherh@1
|
16 % that is not present in the shorthand list.
|
christopherh@1
|
17 %
|
christopherh@1
|
18 % If optional argument 'verbose' is 1, function prints any errormessage to
|
christopherh@1
|
19 % the screen.
|
christopherh@1
|
20 %
|
christopherh@1
|
21 % returns: success (boolean)
|
christopherh@1
|
22 % errormessage (string)
|
christopherh@1
|
23 %
|
christopherh@1
|
24 %
|
christopherh@1
|
25 % Author: Christopher Harte, December 2009
|
christopherh@1
|
26 %
|
christopherh@1
|
27 % Copyright: Centre for Digital Music, Queen Mary University of London 2005
|
christopherh@1
|
28 %
|
christopherh@1
|
29 % This file is part of the C4DM Chord Toolkit V2.0
|
christopherh@1
|
30 %
|
christopherh@1
|
31 % The C4DM Chord Toolkit is free software; you can redistribute it and/or
|
christopherh@1
|
32 % modify it under the terms of the GNU General Public License as published
|
christopherh@1
|
33 % by the Free Software Foundation; either version 2 of the License, or
|
christopherh@1
|
34 % (at your option) any later version.
|
christopherh@1
|
35 %
|
christopherh@1
|
36 % The C4DM Chord Toolkit is distributed in the hope that it will be useful,
|
christopherh@1
|
37 % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
christopherh@1
|
38 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
christopherh@1
|
39 % GNU General Public License for more details.
|
christopherh@1
|
40 %
|
christopherh@1
|
41 % You should have received a copy of the GNU General Public License
|
christopherh@1
|
42 % along with the C4DM Toolkit; if not, write to the Free Software
|
christopherh@1
|
43 % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
christopherh@1
|
44 % USA
|
christopherh@1
|
45
|
christopherh@1
|
46 function [success, errormessage] = checkomissions(shortints,intervals,verbose)
|
christopherh@1
|
47
|
christopherh@1
|
48 if nargin < 3
|
christopherh@1
|
49 verbose = 0;
|
christopherh@1
|
50 end
|
christopherh@1
|
51
|
christopherh@1
|
52 errormessage = '';
|
christopherh@1
|
53
|
christopherh@1
|
54 success = 1;
|
christopherh@1
|
55
|
christopherh@1
|
56 % if 'shortints' is a character string interval list, convert it to
|
christopherh@1
|
57 % [degree,modifier,present] triples
|
christopherh@1
|
58 if ischar(shortints)
|
christopherh@1
|
59 [shortints,success,errormessage] = parseintervals(shortints);
|
christopherh@1
|
60 end
|
christopherh@1
|
61
|
christopherh@1
|
62 % if 'intervals' is a character string interval list, convert it to
|
christopherh@1
|
63 % [degree,modifier,present] triples
|
christopherh@1
|
64 if success && ischar(intervals)
|
christopherh@1
|
65 [intervals, success, errormessage] = parseintervals(intervals);
|
christopherh@1
|
66 end
|
christopherh@1
|
67
|
christopherh@1
|
68 % if everything is ok so far, check any omissions
|
christopherh@1
|
69 if success
|
christopherh@1
|
70
|
christopherh@1
|
71 [sizey,sizex] = size(intervals);
|
christopherh@1
|
72 [sizey2,sizex2] = size(shortints);
|
christopherh@1
|
73
|
christopherh@1
|
74 success = 1;
|
christopherh@1
|
75
|
christopherh@1
|
76 % for each interval in the intervals list
|
christopherh@1
|
77 for indexa = 1:sizey
|
christopherh@1
|
78
|
christopherh@1
|
79 % if it is an omitted interval
|
christopherh@1
|
80 if intervals(indexa,3) == 0
|
christopherh@1
|
81
|
christopherh@1
|
82 % check that the shorthand list contains that interval to omit
|
christopherh@1
|
83 success = 0;
|
christopherh@1
|
84
|
christopherh@1
|
85 for indexb = 1:sizey2
|
christopherh@1
|
86
|
christopherh@1
|
87 if shortints(indexb,1:2) == intervals(indexa,1:2)
|
christopherh@1
|
88 % if the omitted interval is found in the shorthand
|
christopherh@1
|
89 % list then the omission is valid
|
christopherh@1
|
90 success = 1;
|
christopherh@1
|
91 end
|
christopherh@1
|
92 end
|
christopherh@1
|
93 end
|
christopherh@1
|
94 end
|
christopherh@1
|
95 end
|
christopherh@1
|
96
|
christopherh@1
|
97
|
christopherh@1
|
98 % if there was an error, format the error message appropriately:
|
christopherh@1
|
99 if success == 0
|
christopherh@1
|
100 if isempty(errormessage)
|
christopherh@1
|
101 errormessage = sprintf(['Error in checkommisions: ommitted interval not present in shorthand. \n']);
|
christopherh@1
|
102 else
|
christopherh@1
|
103 errormessage = [sprintf(['Error in checkommisions: badly formatted argument \n']) errormessage];
|
christopherh@1
|
104 end
|
christopherh@1
|
105
|
christopherh@1
|
106 if verbose == 1
|
christopherh@1
|
107 fprintf(1,errormessage);
|
christopherh@1
|
108 end
|
christopherh@1
|
109
|
christopherh@1
|
110 end
|