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