annotate _chordtools/interval2semitone.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 % INTERVAL2SEMITONE
matthiasm@8 3 %
matthiasm@8 4 % [semitone, success, errormessage] = interval2semitone(interval, accidental, {verbose})
matthiasm@8 5 %
matthiasm@8 6 % Convert an interval and accidentals pair to a semitone value
matthiasm@8 7 %
matthiasm@8 8 % Success = 1 if interval converted correctly, 0 otherwise.
matthiasm@8 9 %
matthiasm@8 10 % If optional argument 'verbose' is 1, function prints any errormessage to
matthiasm@8 11 % the screen.
matthiasm@8 12 %
matthiasm@8 13 % returns: semitone (string)
matthiasm@8 14 % success (boolean)
matthiasm@8 15 % errormessage (string)
matthiasm@8 16 %
matthiasm@8 17 % Author: Christopher Harte, August 2005
matthiasm@8 18 %
matthiasm@8 19 % Copyright: Centre for Digital Music, Queen Mary University of London 2005
matthiasm@8 20 %
matthiasm@8 21 % This file is part of the C4DM Chord Toolkit.
matthiasm@8 22 %
matthiasm@8 23 % The C4DM Chord Toolkit is free software; you can redistribute it and/or
matthiasm@8 24 % modify it under the terms of the GNU General Public License as published
matthiasm@8 25 % by the Free Software Foundation; either version 2 of the License, or
matthiasm@8 26 % (at your option) any later version.
matthiasm@8 27 %
matthiasm@8 28 % The C4DM Chord Toolkit is distributed in the hope that it will be useful,
matthiasm@8 29 % but WITHOUT ANY WARRANTY; without even the implied warranty of
matthiasm@8 30 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
matthiasm@8 31 % GNU General Public License for more details.
matthiasm@8 32 %
matthiasm@8 33 % You should have received a copy of the GNU General Public License
matthiasm@8 34 % along with the C4DM Toolkit; if not, write to the Free Software
matthiasm@8 35 % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
matthiasm@8 36
matthiasm@8 37 %
matthiasm@8 38 function [semitone, success, errormessage] = interval2semitone(interval, accidentals, verbose)
matthiasm@8 39
matthiasm@8 40 if nargin < 3
matthiasm@8 41 % verbose defaults 0
matthiasm@8 42 verbose = 0;
matthiasm@8 43 end
matthiasm@8 44
matthiasm@8 45 errormessage = '';
matthiasm@8 46
matthiasm@8 47 % semitone equivalents for intervals
matthiasm@8 48 % interval 1,2,3,4,5,6,7
matthiasm@8 49 semitonetranslation = [0,2,4,5,7,9,11];
matthiasm@8 50
matthiasm@8 51 semitone = 0;
matthiasm@8 52
matthiasm@8 53 success = 1;
matthiasm@8 54
matthiasm@8 55 if (interval > 0) && (interval < 50)
matthiasm@8 56
matthiasm@8 57 % semitone value is the number of semitones equivalent to the interval
matthiasm@8 58 % added to the number of accidentals (sharps are positive, flats are
matthiasm@8 59 % negative) and the number of octaves above the reference note to
matthiasm@8 60 % account for extensions
matthiasm@8 61
matthiasm@8 62 semitone = semitonetranslation(mod(interval,8) + fix(interval/8)) + accidentals + 12*fix(interval/8);
matthiasm@8 63
matthiasm@8 64 else
matthiasm@8 65 success = 0;
matthiasm@8 66
matthiasm@8 67 errormessage = sprintf('Error in interval2semitone: out of range interval "%d"\n', interval);
matthiasm@8 68
matthiasm@8 69 if verbose == 1
matthiasm@8 70 fprintf(1,errormessage);
matthiasm@8 71 end
matthiasm@8 72 end
matthiasm@8 73