To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _chordtools / degrees2semitones.m
History | View | Annotate | Download (2.83 KB)
| 1 |
% |
|---|---|
| 2 |
%DEGREES2SEMITONES convert a degree list to an array of semitone values |
| 3 |
% |
| 4 |
% [semitones, success, errormessage] = degrees2semitones(degreelist, {verbose})
|
| 5 |
% |
| 6 |
% Converts a list of degrees to corresponding semitone intervals |
| 7 |
% |
| 8 |
% Success = 1 if symbols parsed correctly, 0 otherwise. |
| 9 |
% |
| 10 |
% If optional argument 'verbose' is 1, function prints any errormessage to |
| 11 |
% the screen. |
| 12 |
% |
| 13 |
% calls degree2semitone |
| 14 |
% |
| 15 |
% returns: semitones (array of integers) |
| 16 |
% success (boolean) |
| 17 |
% errormessage (string) |
| 18 |
% |
| 19 |
% |
| 20 |
% Author: Christopher Harte, August 2005 |
| 21 |
% |
| 22 |
% Copyright: Centre for Digital Music, Queen Mary University of London 2005 |
| 23 |
% |
| 24 |
% This file is part of the C4DM Chord Toolkit. |
| 25 |
% |
| 26 |
% The C4DM Chord Toolkit is free software; you can redistribute it and/or |
| 27 |
% modify it under the terms of the GNU General Public License as published |
| 28 |
% by the Free Software Foundation; either version 2 of the License, or |
| 29 |
% (at your option) any later version. |
| 30 |
% |
| 31 |
% The C4DM Chord Toolkit is distributed in the hope that it will be useful, |
| 32 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 33 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 34 |
% GNU General Public License for more details. |
| 35 |
% |
| 36 |
% You should have received a copy of the GNU General Public License |
| 37 |
% along with the C4DM Toolkit; if not, write to the Free Software |
| 38 |
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 39 |
% |
| 40 |
|
| 41 |
function [semitones, success, errormessage] = degrees2semitones(degreelist, verbose) |
| 42 |
|
| 43 |
% set verbose default to 0 |
| 44 |
if nargin < 2 |
| 45 |
verbose = 0; |
| 46 |
end |
| 47 |
|
| 48 |
errormessage = ''; |
| 49 |
|
| 50 |
ilength = length(degreelist); |
| 51 |
|
| 52 |
index = 1; |
| 53 |
|
| 54 |
tempindex = 1; |
| 55 |
|
| 56 |
tempstring = ''; |
| 57 |
|
| 58 |
success = 1; |
| 59 |
|
| 60 |
parindex = 1; |
| 61 |
|
| 62 |
semitones = []; |
| 63 |
|
| 64 |
|
| 65 |
while index <= ilength |
| 66 |
|
| 67 |
|
| 68 |
while (degreelist(index) ~= ',') |
| 69 |
|
| 70 |
tempstring(tempindex) = degreelist(index); |
| 71 |
tempindex = tempindex +1; |
| 72 |
index = index + 1; |
| 73 |
|
| 74 |
if(index > ilength) |
| 75 |
break; |
| 76 |
end |
| 77 |
|
| 78 |
if (degreelist(index) == ',') && (index == ilength) |
| 79 |
success = 0; |
| 80 |
errormessage = sprintf(['Error in degrees2semitones: degree list finishes with a comma "' degreelist '"\n']); |
| 81 |
end |
| 82 |
|
| 83 |
|
| 84 |
end |
| 85 |
|
| 86 |
[semitones(parindex),ok, error] = degree2semitone(tempstring); |
| 87 |
% concatenate error messages if there are any... |
| 88 |
errormessage = [errormessage error]; |
| 89 |
|
| 90 |
if(ok == 1) |
| 91 |
tempstring = ''; |
| 92 |
tempindex = 1; |
| 93 |
parindex = parindex + 1; |
| 94 |
index = index + 1; |
| 95 |
else |
| 96 |
|
| 97 |
errormessage = [errormessage sprintf(['Error in degrees2semitones: incorrect degree in list "' degreelist '"\n'])]; |
| 98 |
success = 0; |
| 99 |
index = ilength +1; |
| 100 |
end |
| 101 |
|
| 102 |
|
| 103 |
end |
| 104 |
|
| 105 |
if (success == 0) && (verbose == 1) |
| 106 |
|
| 107 |
fprintf(1,errormessage) |
| 108 |
|
| 109 |
end |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|