annotate _chordtools/chord2notes.m @ 9:4ea6619cb3f5 tip

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