Package jazzparser :: Package misc :: Package chordlabel :: Module chord_vocabs
[hide private]
[frames] | no frames]

Source Code for Module jazzparser.misc.chordlabel.chord_vocabs

  1  """Predefined chord vocabs for the chord labeling model. 
  2   
  3  """ 
  4  """ 
  5  ============================== License ======================================== 
  6   Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding 
  7    
  8   This file is part of The Jazz Parser. 
  9    
 10   The Jazz Parser is free software: you can redistribute it and/or modify 
 11   it under the terms of the GNU General Public License as published by 
 12   the Free Software Foundation, either version 3 of the License, or 
 13   (at your option) any later version. 
 14    
 15   The Jazz Parser is distributed in the hope that it will be useful, 
 16   but WITHOUT ANY WARRANTY; without even the implied warranty of 
 17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 18   GNU General Public License for more details. 
 19    
 20   You should have received a copy of the GNU General Public License 
 21   along with The Jazz Parser.  If not, see <http://www.gnu.org/licenses/>. 
 22   
 23  ============================ End license ====================================== 
 24   
 25  """ 
 26  __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>"  
 27   
 28  """ 
 29  Chord vocabularies defined for MIREX 2011 tasks. 
 30   
 31  See http://www.music-ir.org/mirex/wiki/2010:Audio_Chord_Estimation. 
 32   
 33  """ 
 34   
 35  MIREX_DYAD = { 
 36      'maj' : [0, 4, 7], 
 37      'min' : [0, 3, 7] 
 38  } 
 39   
 40  MIREX_TRIAD = { 
 41      'maj' : [0, 4, 7], 
 42      'min' : [0, 3, 7], 
 43      'aug' : [0, 4, 8], 
 44      'dim' : [0, 3, 6], 
 45      'sus2' : [0, 2, 7], 
 46      'sus4' : [0, 5, 7] 
 47  } 
 48   
 49  MIREX_TETRAD = { 
 50      'maj'      : [0, 4, 7], 
 51      'min'      : [0, 3, 7], 
 52      'aug'      : [0, 4, 8], 
 53      'dim'      : [0, 3, 6], 
 54      'sus2'     : [0, 2, 7], 
 55      'sus4'     : [0, 5, 7], 
 56          'maj7'     : [0, 4, 7, 11], 
 57          '7'        : [0, 4, 7, 10], 
 58          'maj(9)'   : [0, 4, 7, 2], 
 59          'aug(7)'   : [0, 4, 8, 11], 
 60          'min(7)'   : [0, 3, 7, 11], 
 61          'min7'     : [0, 3, 7, 10], 
 62          'min(9)'   : [0, 3, 7, 2], 
 63          'dim(7)'   : [0, 3, 6, 11], 
 64          'hdim7'    : [0, 3, 6, 10], 
 65          'sus4(7)'  : [0, 5, 7, 11], 
 66          'sus4(b7)' : [0, 5, 7, 10], 
 67          'dim7'     : [0, 3, 6, 9] 
 68  } 
 69   
 70  TRIAD = { 
 71      'maj' : [0, 4, 7], 
 72      'min' : [0, 3, 7], 
 73      'aug' : [0, 4, 8], 
 74      'dim' : [0, 3, 6], 
 75      'sus4' : [0, 5, 7] 
 76  } 
 77   
 78  TETRAD = { 
 79      'maj'      : [0, 4, 7], 
 80      'min'      : [0, 3, 7], 
 81      'aug'      : [0, 4, 8], 
 82      'dim'      : [0, 3, 6], 
 83      'sus4'     : [0, 5, 7], 
 84          'maj7'     : [0, 4, 7, 11], 
 85          '7'        : [0, 4, 7, 10], 
 86          'min7'     : [0, 3, 7, 10], 
 87          'hdim7'    : [0, 3, 6, 10], 
 88          'dim7'     : [0, 3, 6, 9] 
 89  } 
 90   
 91   
 92  """ 
 93  Mappings from the chord labels in the chord corpus to each of the above  
 94  chord vocabularies. 
 95   
 96  """ 
 97   
 98  MIREX_DYAD_CORPUS_MAPPING = [ 
 99      # (corpus, here) 
100      ("", "maj"), 
101      ("m", "min"), 
102      ("M7", "maj"), 
103      ("o7", "min"), 
104      ("%7", "min"), 
105      ("aug", "maj"), 
106      ("m,b5", "min"), 
107      ("b5", "maj"), 
108      ("m,M7", "min"), 
109      ("7", "maj"), 
110      ("m7", "min"), 
111      ("aug7", "maj"), 
112      ("b5,7", "maj"), 
113      ("sus4", "maj"), 
114      ("sus4,7", "maj"), 
115      ("aug,M7", "maj"), 
116      ("b5,M7", "maj"), 
117      ("#5,m7", "maj") 
118  ] 
119   
120  MIREX_TRIAD_CORPUS_MAPPING = [ 
121      ("", "maj"), 
122      ("m", "min"), 
123      ("M7", "maj"), 
124      ("o7", "dim"), 
125      ("%7", "dim"), 
126      ("aug", "aug"), 
127      ("m,b5", "dim"), 
128      ("b5", "maj"), 
129      ("m,M7", "min"), 
130      ("7", "maj"), 
131      ("m7", "min"), 
132      ("aug7", "aug"), 
133      ("b5,7", "maj"), 
134      ("sus4", "sus4"), 
135      ("sus4,7", "sus4"), 
136      ("aug,M7", "aug"), 
137      ("b5,M7", "maj"), 
138      ("#5,m7", "aug"), 
139      # We need something to map to sus2 
140      ("", "sus2"), 
141  ] 
142   
143  MIREX_TETRAD_CORPUS_MAPPING = [ 
144      ("", "maj"), 
145      ("m", "min"), 
146      ("M7", "maj7"), 
147      ("o7", "dim7"), 
148      ("%7", "hdim7"), 
149      ("aug", "aug"), 
150      ("m,b5", "dim"), 
151      ("b5", "maj"), 
152      ("m,M7", "min(7)"), 
153      ("7", "7"), 
154      ("m7", "min7"), 
155      ("aug7", "aug"), 
156      ("b5,7", "7"), 
157      ("sus4", "sus4"), 
158      ("sus4,7", "sus4(b7)"), 
159      ("aug,M7", "aug"), 
160      ("b5,M7", "dim(7)"), 
161      ("#5,m7", "aug(7)"), 
162      # We also need something to map to the remaining MIREX chords 
163      ("", "sus2"), 
164      ("M7", "maj(9)"), 
165      ("m7", "min(9)"), 
166      ("sus4", "sus4(7)") 
167  ] 
168   
169  TRIAD_CORPUS_MAPPING = [ 
170      ("", "maj"), 
171      ("m", "min"), 
172      ("M7", "maj"), 
173      ("o7", "dim"), 
174      ("%7", "dim"), 
175      ("aug", "aug"), 
176      ("m,b5", "dim"), 
177      ("b5", "maj"), 
178      ("m,M7", "min"), 
179      ("7", "maj"), 
180      ("m7", "min"), 
181      ("aug7", "aug"), 
182      ("b5,7", "maj"), 
183      ("sus4", "sus4"), 
184      ("sus4,7", "sus4"), 
185      ("aug,M7", "aug"), 
186      ("b5,M7", "maj"), 
187      ("#5,m7", "aug"), 
188  ] 
189   
190  TETRAD_CORPUS_MAPPING = [ 
191      ("", "maj"), 
192      ("m", "min"), 
193      ("M7", "maj7"), 
194      ("o7", "dim7"), 
195      ("%7", "hdim7"), 
196      ("aug", "aug"), 
197      ("m,b5", "dim"), 
198      ("b5", "maj"), 
199      ("m,M7", "min"), 
200      ("7", "7"), 
201      ("m7", "min7"), 
202      ("aug7", "aug"), 
203      ("b5,7", "7"), 
204      ("sus4", "sus4"), 
205      ("sus4,7", "sus4"), 
206      ("aug,M7", "aug"), 
207      ("b5,M7", "dim"), 
208      ("#5,m7", "aug"), 
209  ] 
210   
211   
212  ######################## Utilities and index ############################# 
213   
214 -def get_mapping(mapping, reverse=False):
215 """ 216 Gets a dict of the given list mapping, optionally reversing it. Where a 217 mapping is not unique, the first instance is used. 218 219 """ 220 if reverse: 221 mapping = [(y,x) for (x,y) in mapping] 222 223 dic = {} 224 for (source,target) in mapping: 225 if source not in dic: 226 dic[source] = target 227 228 return dic
229 230 CHORD_VOCABS = { 231 'mirex-dyad' : (MIREX_DYAD, MIREX_DYAD_CORPUS_MAPPING), 232 'mirex-triad' : (MIREX_TRIAD, MIREX_TRIAD_CORPUS_MAPPING), 233 'mirex-tetrad' : (MIREX_TETRAD, MIREX_TETRAD_CORPUS_MAPPING), 234 'triad' : (TRIAD, TRIAD_CORPUS_MAPPING), 235 'tetrad' : (TETRAD, TETRAD_CORPUS_MAPPING), 236 } 237