To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _chordtools / chord2pitchclasses.m @ 8:b5b38998ef3b
History | View | Annotate | Download (2.47 KB)
| 1 |
% |
|---|---|
| 2 |
%CHORD2PITCHCLASSES Convert chord symbol to array of pitch classes |
| 3 |
% |
| 4 |
% [pitchclasses, bassclass, success, errormessage] = chord2pitchclasses(chordsymbol, {verbose})
|
| 5 |
% |
| 6 |
% Converts a chord symbol to an array of integer pitch class values and a |
| 7 |
% bass pitch class value. Pitch class values are referenced w.r.t. C = 0. |
| 8 |
% |
| 9 |
% In the case of the 'no chord' symbol 'N' function returns an empty array |
| 10 |
% |
| 11 |
% Success = 1 if notes extracted from chordsymbol correctly, 0 otherwise. |
| 12 |
% |
| 13 |
% If optional argument 'verbose' is 1, function prints any errormessage to |
| 14 |
% the screen. |
| 15 |
% |
| 16 |
% calls: chord2notes |
| 17 |
% notes2pitchclasses |
| 18 |
% |
| 19 |
% returns: pitchclasses (array of integers) |
| 20 |
% bassclass (integer) |
| 21 |
% success (boolean) |
| 22 |
% errormessage (string) |
| 23 |
% |
| 24 |
% |
| 25 |
% Author: Christopher Harte, August 2005 |
| 26 |
% |
| 27 |
% Copyright: Centre for Digital Music, Queen Mary University of London 2005 |
| 28 |
% |
| 29 |
% This file is part of the C4DM Chord Toolkit. |
| 30 |
% |
| 31 |
% The C4DM Chord Toolkit is free software; you can redistribute it and/or |
| 32 |
% modify it under the terms of the GNU General Public License as published |
| 33 |
% by the Free Software Foundation; either version 2 of the License, or |
| 34 |
% (at your option) any later version. |
| 35 |
% |
| 36 |
% The C4DM Chord Toolkit is distributed in the hope that it will be useful, |
| 37 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 38 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 39 |
% GNU General Public License for more details. |
| 40 |
% |
| 41 |
% You should have received a copy of the GNU General Public License |
| 42 |
% along with the C4DM Toolkit; if not, write to the Free Software |
| 43 |
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 44 |
|
| 45 |
% |
| 46 |
function [pitchclasses, bassclass, success, errormessage] = chord2pitchclasses(chordsymbol, verbose) |
| 47 |
|
| 48 |
% set verbose default to 0 |
| 49 |
if nargin < 2 |
| 50 |
verbose = 0; |
| 51 |
end |
| 52 |
|
| 53 |
errormessage = ''; |
| 54 |
mainlist = ''; |
| 55 |
success = 1; |
| 56 |
pitchclasses = []; |
| 57 |
bassclass = ''; |
| 58 |
|
| 59 |
% get constituent notes |
| 60 |
[chordnotes, bassnote, success, errormessage] = chord2notes(chordsymbol); |
| 61 |
|
| 62 |
if success && ~isempty(chordnotes) |
| 63 |
% find pitchclasses of notes |
| 64 |
[pitchclasses, success, errormessage] = notes2pitchclasses(chordnotes); |
| 65 |
end |
| 66 |
|
| 67 |
if success && ~isempty(bassnote) |
| 68 |
[bassclass, success, errormessage] = note2pitchclass(char(bassnote)); |
| 69 |
end |
| 70 |
|
| 71 |
if success == 0 |
| 72 |
errormessage = [errormessage sprintf(['Error in chord2pitchclasses: Couldn''t convert chord"' chordsymbol '"\n'])]; |
| 73 |
if verbose ==1 |
| 74 |
fprintf(1,errormessage); |
| 75 |
end |
| 76 |
|
| 77 |
|
| 78 |
end |
| 79 |
|
| 80 |
|
| 81 |
|