To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / _chordtools / note2fifthinfo.m @ 8:b5b38998ef3b

History | View | Annotate | Download (2.4 KB)

1
%
2
%NOTE2FIFTHINFO find line of fifths natural-position and accidentals
3
% 
4
% [position, accidentals, success,errormessage] = note2fifthinfo(note,{verbose})
5
% 
6
% Converts a note string to a natural position on the line of fifths and its 
7
% corresponding number of sharps or flats. 
8
%
9
% *** NOTE! *** 
10
% Reference for natural positions on line of fifths for this function is F = 0.
11
% 
12
% Success = 1 if note converted correctly, 0 otherwise.
13
% 
14
% If optional argument 'verbose' is 1, function prints any errormessage to 
15
% the screen.
16
% 
17
% calls: parsenote
18
%
19
% returns:  position (integer)
20
%           accidentals (integer)
21
%           success (boolean)
22
%           errormessage (string)
23
% 
24
%
25
% Author: Christopher Harte,  September 2005
26
% 
27
% Copyright: Centre for Digital Music, Queen Mary University of London 2005 
28
%
29
% This file is part of the C4DM Chord Toolkit.  
30
%
31
% The C4DM Chord Toolkit is free software; you can redistribute it and/or 
32
% modify it under the terms of the GNU General Public License as published 
33
% by the Free Software Foundation; either version 2 of the License, or
34
% (at your option) any later version.
35
%
36
% The C4DM Chord Toolkit is distributed in the hope that it will be useful,
37
% but WITHOUT ANY WARRANTY; without even the implied warranty of
38
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
% GNU General Public License for more details.
40
%
41
% You should have received a copy of the GNU General Public License
42
% along with the C4DM Toolkit; if not, write to the Free Software
43
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
44

    
45
%		
46
function [position,accidentals, success, errormessage] = note2fifthinfo(note, verbose)
47

    
48
% set verbose default to 0
49
if nargin < 3
50
   verbose = 0;
51
end
52

    
53
errormessage = '';
54
success = 1;
55
position = '';
56
accidentals = '';
57

    
58

    
59
[natural, accidentals, success, errormessage] = parsenote(note);
60

    
61
if success
62
    switch(natural)
63
        case 'F' 
64
            position = 0;
65

    
66
        case 'C' 
67
            position = 1;
68

    
69
        case 'G' 
70
            position = 2;
71

    
72
        case 'D' 
73
            position = 3;
74

    
75
        case 'A' 
76
            position = 4;
77

    
78
        case 'E' 
79
            position = 5;
80

    
81
        case 'B' 
82
            position = 6;
83

    
84
        otherwise
85
            errormessage = 'Error in note2fifthinfo: unrecognised natural';
86
            success=0;
87
    end
88
end
89
        
90
            
91
if (success == 0) && (verbose == 1)   
92
    fprintf(1,errormessage);
93
end  
94