christopherh@1
|
1 %
|
christopherh@1
|
2 %CHORD2NOTES Convert chord symbol to list of constituent notes
|
christopherh@1
|
3 %
|
christopherh@1
|
4 % [chordnotes, bassnote, success, errormessage] = chord2notes(chordsymbol, {verbose})
|
christopherh@1
|
5 %
|
christopherh@1
|
6 % Converts a chord symbol to a cell array of note strings and a bassnote string.
|
christopherh@1
|
7 %
|
christopherh@1
|
8 % In the case of the 'no chord' symbol 'N' function returns an empty array
|
christopherh@1
|
9 %
|
christopherh@1
|
10 % Success = 1 if notes extracted from chordsymbol correctly, 0 otherwise.
|
christopherh@1
|
11 %
|
christopherh@1
|
12 % If optional argument 'verbose' is 1, function prints any errormessage to
|
christopherh@1
|
13 % the screen.
|
christopherh@1
|
14 %
|
christopherh@1
|
15 % calls: getnoteinfo
|
christopherh@1
|
16 % parsenote
|
christopherh@1
|
17 % addshort2list
|
christopherh@1
|
18 % interval2note
|
christopherh@1
|
19 %
|
christopherh@1
|
20 % returns: chordnotes (cell array of note strings)
|
christopherh@1
|
21 % bassnote (string)
|
christopherh@1
|
22 % success (boolean)
|
christopherh@1
|
23 % errormessage (string)
|
christopherh@1
|
24 %
|
christopherh@1
|
25 %
|
christopherh@1
|
26 % Author: Christopher Harte, March 2009
|
christopherh@1
|
27 %
|
christopherh@1
|
28 % Copyright: Centre for Digital Music, Queen Mary University of London 2005
|
christopherh@1
|
29 %
|
christopherh@1
|
30 % This file is part of the C4DM Chord Toolkit V2.0
|
christopherh@1
|
31 %
|
christopherh@1
|
32 % The C4DM Chord Toolkit is free software; you can redistribute it and/or
|
christopherh@1
|
33 % modify it under the terms of the GNU General Public License as published
|
christopherh@1
|
34 % by the Free Software Foundation; either version 2 of the License, or
|
christopherh@1
|
35 % (at your option) any later version.
|
christopherh@1
|
36 %
|
christopherh@1
|
37 % The C4DM Chord Toolkit is distributed in the hope that it will be useful,
|
christopherh@1
|
38 % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
christopherh@1
|
39 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
christopherh@1
|
40 % GNU General Public License for more details.
|
christopherh@1
|
41 %
|
christopherh@1
|
42 % You should have received a copy of the GNU General Public License
|
christopherh@1
|
43 % along with the C4DM Toolkit; if not, write to the Free Software
|
christopherh@1
|
44 % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
christopherh@1
|
45
|
christopherh@1
|
46 %
|
christopherh@1
|
47 function [chordnotes, bassnote, success, errormessage] = chord2notes(chordsymbol, inversion, verbose)
|
christopherh@1
|
48
|
christopherh@1
|
49 %set default inversion to 0
|
christopherh@1
|
50 if nargin < 2
|
christopherh@1
|
51 inversion = 0;
|
christopherh@1
|
52 end
|
christopherh@1
|
53
|
christopherh@1
|
54 % set verbose default to 0
|
christopherh@1
|
55 if nargin < 3
|
christopherh@1
|
56 verbose = 0;
|
christopherh@1
|
57 end
|
christopherh@1
|
58
|
christopherh@1
|
59 errormessage = '';
|
christopherh@1
|
60 mainlist = '';
|
christopherh@1
|
61 success = 1;
|
christopherh@1
|
62 chordnotes = [];
|
christopherh@1
|
63 bassnote = '';
|
christopherh@1
|
64
|
christopherh@1
|
65 % parse the chordsymbol
|
christopherh@1
|
66 [rootnote,shorthand,interval_list,bass, success, errormessage] = getchordinfo(chordsymbol);
|
christopherh@1
|
67
|
christopherh@1
|
68
|
christopherh@1
|
69
|
christopherh@1
|
70
|
christopherh@1
|
71 %if 'no chord' then return N
|
christopherh@1
|
72 if (success == 1)
|
christopherh@1
|
73
|
christopherh@1
|
74
|
christopherh@1
|
75
|
christopherh@1
|
76 if rootnote == 'N'
|
christopherh@1
|
77
|
christopherh@1
|
78 chordnotes = {};
|
christopherh@1
|
79 else
|
christopherh@1
|
80
|
christopherh@1
|
81
|
christopherh@1
|
82 % combine shorthand and interval_list and obtain note names for each
|
christopherh@1
|
83 % interval
|
christopherh@1
|
84 if success
|
christopherh@1
|
85
|
christopherh@1
|
86 [mainlist, success, errormessage] = addshort2list(shorthand, interval_list);
|
christopherh@1
|
87
|
christopherh@1
|
88 if success
|
christopherh@1
|
89
|
christopherh@1
|
90 % convert list of intervals to list of notes
|
christopherh@1
|
91 [chordnotes,success,errormessage] = intervals2notes(mainlist,rootnote);
|
christopherh@1
|
92
|
christopherh@1
|
93 end
|
christopherh@1
|
94
|
christopherh@1
|
95 end
|
christopherh@1
|
96
|
christopherh@1
|
97 % Now find the bass note
|
christopherh@1
|
98
|
christopherh@1
|
99 if success
|
christopherh@1
|
100
|
christopherh@1
|
101 if ~isempty(bass)
|
christopherh@1
|
102
|
christopherh@1
|
103 [bassnote,success,errormessage] = interval2note(bass, rootnote);
|
christopherh@1
|
104
|
christopherh@1
|
105 if inversion
|
christopherh@1
|
106 % if the bass note is a member of the chord
|
christopherh@1
|
107 if length(intersect(bassnote,chordnotes))==1
|
christopherh@1
|
108 %rotate the chord until the bassnote is the first
|
christopherh@1
|
109 %element
|
christopherh@1
|
110 for i=1:length(chordnotes)
|
christopherh@1
|
111 if strcmp(chordnotes{1},bassnote)
|
christopherh@1
|
112 break
|
christopherh@1
|
113 else
|
christopherh@1
|
114 chordnotes = [chordnotes(2:end); chordnotes(1)];
|
christopherh@1
|
115 end
|
christopherh@1
|
116
|
christopherh@1
|
117 end
|
christopherh@1
|
118
|
christopherh@1
|
119 else
|
christopherh@1
|
120 % insert the bassnote at the start of the chord
|
christopherh@1
|
121
|
christopherh@1
|
122 chordnotes = [bassnote; chordnotes];
|
christopherh@1
|
123
|
christopherh@1
|
124
|
christopherh@1
|
125 end
|
christopherh@1
|
126 end
|
christopherh@1
|
127 % if success
|
christopherh@1
|
128 %
|
christopherh@1
|
129 % ilength = length(chordnotes);
|
christopherh@1
|
130 % index = 1;
|
christopherh@1
|
131 %
|
christopherh@1
|
132 % % check if the bass note is included in the other chord notes
|
christopherh@1
|
133 % while index<=ilength
|
christopherh@1
|
134 % if char(bassnote) == char(chordnotes(index))
|
christopherh@1
|
135 % index = ilength +1;
|
christopherh@1
|
136 % contains = 1;
|
christopherh@1
|
137 % else
|
christopherh@1
|
138 % contains = 0;
|
christopherh@1
|
139 % index = index +1;
|
christopherh@1
|
140 % end
|
christopherh@1
|
141 % end
|
christopherh@1
|
142 %
|
christopherh@1
|
143 % if contains == 0
|
christopherh@1
|
144 %
|
christopherh@1
|
145 % % chordnotes = [bassnote; chordnotes];
|
christopherh@1
|
146 % end
|
christopherh@1
|
147 % end
|
christopherh@1
|
148 else
|
christopherh@1
|
149 bassnote = chordnotes(1);
|
christopherh@1
|
150 end
|
christopherh@1
|
151
|
christopherh@1
|
152
|
christopherh@1
|
153 end
|
christopherh@1
|
154 end
|
christopherh@1
|
155 end
|
christopherh@1
|
156
|
christopherh@1
|
157 if success == 0
|
christopherh@1
|
158 errormessage = [errormessage sprintf(['Error in chord2notes: Couldn''t convert chord "' chordsymbol '"\n'])];
|
christopherh@1
|
159 if verbose ==1
|
christopherh@1
|
160 fprintf(1,errormessage);
|
christopherh@1
|
161 end
|
christopherh@1
|
162
|
christopherh@1
|
163
|
christopherh@1
|
164 end
|
christopherh@1
|
165
|
christopherh@1
|
166
|
christopherh@1
|
167 |