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

Source Code for Module jazzparser.misc.chordlabel.data

 1  """Data structures for chord labeler. 
 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  from jazzparser.utils.chords import int_to_note_name 
29   
30 -class ChordLabel(object):
31 """ 32 Representation of a chord label. Simple wrapper around what could really 33 just be represented as a small tuple. Using this class allows us to make 34 it clearer what the fields represent and provide easy access to conversions 35 (e.g. string representation). 36 37 C{key} may be None if you wish to store a chord label without a key value. 38 39 """
40 - def __init__(self, root, label, key, model_label=None):
41 self.root = root % 12 42 self.label = label 43 self.key = key 44 self.model_label = model_label 45 46 if self.key is not None: 47 self.key = self.key % 12
48
49 - def __eq__(self, other):
50 return type(self) == type(other) and \ 51 self.root == other.root and \ 52 self.label == other.label and \ 53 self.key == other.key
54
55 - def __str__(self):
56 if self.key is not None: 57 return "%s%s/%s" % (int_to_note_name[self.root], \ 58 self.label, 59 int_to_note_name[self.key]) 60 else: 61 return "%s%s" % (int_to_note_name[self.root], self.label)
62
63 - def __repr__(self):
64 return str(self)
65