Mercurial > hg > c4dm-chord-transcriptions
comparison chordtools/short2quality.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 %SHORT2QUALITY return the quality of a given shorthand string | |
3 % | |
4 % [quality,success, errormessage] = short2quality(shorthand, {verbose}) | |
5 % | |
6 % Returns the quality of a given shorthand string. Quality values are from | |
7 % the enumeration: | |
8 % | |
9 % 0 Major | |
10 % 1 Minor | |
11 % 2 Diminished | |
12 % 3 Augmented | |
13 % 4 Suspended | |
14 % | |
15 % | |
16 % Success = 1 if symbols parsed correctly, 0 otherwise. | |
17 % | |
18 % If optional argument 'verbose' is 1, function prints any errormessage to | |
19 % the screen. | |
20 % | |
21 % calls: | |
22 % | |
23 % returns: quality (integer) | |
24 % success (boolean) | |
25 % errormessage (string) | |
26 % | |
27 % | |
28 % Author: Christopher Harte, March 2009 | |
29 % | |
30 % Copyright: Centre for Digital Music, Queen Mary University of London 2005 | |
31 % | |
32 % This file is part of the C4DM Chord Toolkit V2.0 | |
33 % | |
34 % The C4DM Chord Toolkit is free software; you can redistribute it and/or | |
35 % modify it under the terms of the GNU General Public License as published | |
36 % by the Free Software Foundation; either version 2 of the License, or | |
37 % (at your option) any later version. | |
38 % | |
39 % The C4DM Chord Toolkit is distributed in the hope that it will be useful, | |
40 % but WITHOUT ANY WARRANTY; without even the implied warranty of | |
41 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
42 % GNU General Public License for more details. | |
43 % | |
44 % You should have received a copy of the GNU General Public License | |
45 % along with the C4DM Toolkit; if not, write to the Free Software | |
46 % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
47 | |
48 % | |
49 function [quality,success,errormessage] = short2quality(shorthand,verbose) | |
50 | |
51 if nargin < 2 | |
52 verbose = 0; | |
53 end | |
54 | |
55 success = 1; | |
56 errormessage = ''; | |
57 quality = ''; | |
58 | |
59 switch shorthand | |
60 | |
61 | |
62 % triads | |
63 case 'maj' | |
64 quality = 0; | |
65 case 'min' | |
66 quality = 1; | |
67 case 'dim' | |
68 quality = 2; | |
69 case 'aug' | |
70 quality = 3; | |
71 | |
72 % sevenths | |
73 case 'maj7' | |
74 quality = 0; | |
75 case 'min7' | |
76 quality = 1; | |
77 case '7' | |
78 quality = 0; | |
79 case 'minmaj7' | |
80 quality = 1; | |
81 case 'dim7' | |
82 quality = 2; | |
83 case 'hdim7' | |
84 quality = 2; | |
85 | |
86 % sixths | |
87 case 'maj6' | |
88 quality = 0; | |
89 case 'min6' | |
90 quality = 1; | |
91 | |
92 % ninths | |
93 | |
94 case '9' | |
95 quality = 0; | |
96 case 'maj9' | |
97 quality = 0; | |
98 case 'min9' | |
99 quality = 1; | |
100 | |
101 % suspended | |
102 case 'sus4' | |
103 quality = 4; | |
104 case 'sus2' | |
105 quality = 4; | |
106 | |
107 otherwise | |
108 success = 0; | |
109 errormessage = ['Error in short2quality: unrecognised shorthand: ' shorthand]; | |
110 end | |
111 | |
112 | |
113 if (success ==0) && (verbose == 1) | |
114 fprintf(1,errormessage); | |
115 end |