Mercurial > hg > c4dm-chord-transcriptions
comparison chordtools/intervals2semitones.m @ 1:8973548174c1 tip
adding tools to repo
author | christopherh |
---|---|
date | Mon, 06 May 2013 14:43:47 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:0a4ad3e72e75 | 1:8973548174c1 |
---|---|
1 % | |
2 %INTERVALS2SEMITONES convert an interval list to an array of semitone values | |
3 % | |
4 % [semitones, success, errormessage] = intervals2semitones(interval_list, {verbose}) | |
5 % | |
6 % Converts a list of intervals to corresponding semitone degrees | |
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 interval2semitone | |
14 % | |
15 % returns: semitones (array of integers) | |
16 % success (boolean) | |
17 % errormessage (string) | |
18 % | |
19 % | |
20 % Author: Christopher Harte, March 2009 | |
21 % | |
22 % Copyright: Centre for Digital Music, Queen Mary University of London 2005 | |
23 % | |
24 % This file is part of the C4DM Chord Toolkit V2.0 | |
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] = intervals2semitones(interval_list, verbose) | |
42 | |
43 % set verbose default to 0 | |
44 if nargin < 2 | |
45 verbose = 0; | |
46 end | |
47 | |
48 errormessage = ''; | |
49 | |
50 ilength = length(interval_list); | |
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 (interval_list(index) ~= ',') | |
69 | |
70 tempstring(tempindex) = interval_list(index); | |
71 tempindex = tempindex +1; | |
72 index = index + 1; | |
73 | |
74 if(index > ilength) | |
75 break; | |
76 end | |
77 | |
78 if (interval_list(index) == ',') && (index == ilength) | |
79 success = 0; | |
80 errormessage = sprintf(['Error in intervals2semitones: interval list finishes with a comma "' interval_list '"\n']); | |
81 end | |
82 | |
83 | |
84 end | |
85 | |
86 [semitones(parindex),ok, error] = interval2semitone(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 intervals2semitones: incorrect interval in list "' interval_list '"\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 |