To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _chordtools / shorthand2degrees.m @ 8:b5b38998ef3b
History | View | Annotate | Download (3.09 KB)
| 1 |
% |
|---|---|
| 2 |
% SHORTHAND2DEGREES |
| 3 |
% |
| 4 |
% [degreelist, success, errormessage] = shorthand2degrees(shorthand, {verbose})
|
| 5 |
% |
| 6 |
% Converts a shorthand string to a degree-list |
| 7 |
% |
| 8 |
% Success = 1 if shorthand is recognised, 0 otherwise. |
| 9 |
% |
| 10 |
% If optional argument 'verbose' is 1, function prints any errormessage to |
| 11 |
% the screen. |
| 12 |
% |
| 13 |
% returns: degreelist (string) |
| 14 |
% success (boolean) |
| 15 |
% errormessage (string) |
| 16 |
% |
| 17 |
% Author: Christopher Harte, August 2005 |
| 18 |
% |
| 19 |
% Copyright: Centre for Digital Music, Queen Mary University of London 2005 |
| 20 |
% |
| 21 |
% This file is part of the C4DM Chord Toolkit. |
| 22 |
% |
| 23 |
% The C4DM Chord Toolkit is free software; you can redistribute it and/or |
| 24 |
% modify it under the terms of the GNU General Public License as published |
| 25 |
% by the Free Software Foundation; either version 2 of the License, or |
| 26 |
% (at your option) any later version. |
| 27 |
% |
| 28 |
% The C4DM Chord Toolkit is distributed in the hope that it will be useful, |
| 29 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 30 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 31 |
% GNU General Public License for more details. |
| 32 |
% |
| 33 |
% You should have received a copy of the GNU General Public License |
| 34 |
% along with the C4DM Toolkit; if not, write to the Free Software |
| 35 |
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 36 |
|
| 37 |
% |
| 38 |
function [degreelist, success, errormessage] = shorthand2degrees(shorthand, verbose) |
| 39 |
|
| 40 |
%set verbose to default to 0;; |
| 41 |
if nargin <2 |
| 42 |
verbose = 0; |
| 43 |
end |
| 44 |
|
| 45 |
degreelist = ''; |
| 46 |
errormessage = ''; |
| 47 |
|
| 48 |
success = 1; |
| 49 |
|
| 50 |
switch(shorthand) |
| 51 |
|
| 52 |
% Empty: |
| 53 |
case '' |
| 54 |
degreelist = ''; %empty degreelist |
| 55 |
|
| 56 |
% Triad chords: |
| 57 |
case 'maj' |
| 58 |
degreelist = '1,3,5'; % major |
| 59 |
case 'min' |
| 60 |
degreelist = '1,b3,5'; % minor |
| 61 |
case 'dim' |
| 62 |
degreelist = '1,b3,b5'; % diminished |
| 63 |
case 'aug' |
| 64 |
degreelist = '1,3,#5'; % augmented |
| 65 |
|
| 66 |
% Seventh chords: |
| 67 |
case 'maj7' |
| 68 |
degreelist = '1,3,5,7'; %major seventh |
| 69 |
case 'min7' |
| 70 |
degreelist = '1,b3,5,b7'; % minor seventh |
| 71 |
case '7' |
| 72 |
degreelist = '1,3,5,b7'; % seventh |
| 73 |
case 'dim7' |
| 74 |
degreelist = '1,b3,b5,bb7'; % diminished seventh |
| 75 |
case 'hdim7' |
| 76 |
degreelist = '1,b3,b5,b7'; % half diminished seventh |
| 77 |
case 'minmaj7' |
| 78 |
degreelist = '1,b3,5,7'; % minor (major seventh) |
| 79 |
|
| 80 |
% Sixth Chords: |
| 81 |
case 'maj6' |
| 82 |
degreelist = '1,3,5,6'; % major sixth |
| 83 |
case 'min6' |
| 84 |
degreelist = '1,b3,5,6'; % minor sixth |
| 85 |
|
| 86 |
% Ninth chords: |
| 87 |
case 'maj9' |
| 88 |
degreelist = '1,3,5,7,9'; % major ninth |
| 89 |
case 'min9' |
| 90 |
degreelist = '1,b3,5,b7,9'; % minor ninth |
| 91 |
case '9' |
| 92 |
degreelist = '1,3,5,b7,9'; % ninth |
| 93 |
|
| 94 |
case 'sus2' |
| 95 |
degreelist = '1,2,5'; % suspended second |
| 96 |
case 'sus4' |
| 97 |
degreelist = '1,4,5'; % suspended fourth |
| 98 |
case 'fullsus' |
| 99 |
degreelist = '1,2,4,5'; % fully suspended chord |
| 100 |
|
| 101 |
|
| 102 |
otherwise |
| 103 |
errormessage = sprintf(['Error in shorthand2degrees: Unrecognised shorthand string "' shorthand '"\n']); |
| 104 |
if verbose == 1 |
| 105 |
fprintf(1,errormessage); |
| 106 |
end |
| 107 |
success = 0; |
| 108 |
|
| 109 |
end |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|