1 """Unit tests for things in jazzparser.formalisms.music_halfspan.semantics
2 that relate specifically to the backoff models.
3
4 """
5 """
6 ============================== License ========================================
7 Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding
8
9 This file is part of The Jazz Parser.
10
11 The Jazz Parser is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
15
16 The Jazz Parser is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with The Jazz Parser. If not, see <http://www.gnu.org/licenses/>.
23
24 ============================ End license ======================================
25
26 """
27 __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>"
28
29 import unittest, os
30 from jazzparser import settings
31
32 from jazzparser.formalisms.music_halfspan.semantics import CoordinateList, \
33 PathCoordinate, EnharmonicCoordinate, Semantics
34 from jazzparser.data import Chord
35
37 """
38 Tests for building LFs from a list of state labels and vice versa.
39
40 """
41 PATHS = [
42 (
43 [(0,0,'T')],
44 ['Im'],
45 [(0,0,'T')],
46 ),
47 (
48 [(0,0,'T'),(1,0,'D'),(0,0,'T')],
49 ['IM7', 'V7', 'I(6)'],
50 [(0,0,'T'),(1,0,'D'),(0,0,'T')],
51 ),
52 (
53 [(0,0,'T'),(3,0,'D'),(2,0,'D'),(3,0,'D'),(2,0,'D'),(1,0,'D'),(0,0,'T')],
54 ['IM7', 'VI7', 'IIm7', 'bIII7', 'IIm7', 'V7', 'IM7'],
55 [(0,0,'T'),(3,0,'D'),(2,0,'D'),(3,0,'D'),(2,0,'D'),(1,0,'D'),(0,0,'T')],
56 ),
57 (
58 [(2,2,'T'),(3,2,'D'),(2,2,'T')],
59 ['bVII', 'IV7', 'bVII'],
60 [(-2,0,'T'),(-1,0,'D'),(-2,0,'T')],
61 ),
62 (
63 [(0,1,'T'),(3,1,'D'),(2,1,'D'),(3,1,'D'),(2,1,'D'),(1,1,'D'),(0,1,'T')],
64 ['IIIM7', 'bII7', 'bV7', 'V7', 'bV7', 'VII7', 'IIIM7'],
65 [(0,1,'T'),(3,1,'D'),(2,1,'D'),(3,1,'D'),(2,1,'D'),(1,1,'D'),(0,1,'T')],
66 )
67 ]
68
70 """
71 Creates a tonal space path, converts it to state labels and converts
72 it back again. This should produce the original path if all goes
73 well.
74
75 Note that the result of the back conversion will always have the
76 path shifted so it starts as close as possible to the origin. This is
77 correct behaviour: the state labels don't encode the enharmonic
78 block that the path starts in and it is merely by convention that we
79 assume the start point.
80
81 Each path-chord sequence pair also gives the expected output, which
82 may differ from the original path only in this respect.
83
84 @todo: update this test
85
86 """
87
88
89 return
90 self.longMessage = True
91
92 for (coords,chords,output) in self.PATHS:
93
94 ens = [EnharmonicCoordinate.from_harmonic_coord((x,y)) for (x,y,fun) in coords]
95 pcs = [PathCoordinate.from_enharmonic_coord(en) for en in ens]
96 time = 0
97 for pc,(__,__,fun) in zip(pcs,coords):
98 pc.function = fun
99 pc.duration = 1
100 pc.time = time
101 time += 1
102 path = Semantics(CoordinateList(items=pcs))
103
104 chords = [Chord.from_name(crd).to_db_mirror() for crd in chords]
105 for chord in chords:
106 chord.duration = 1
107
108 states = lf_chords_to_states(path, chords)
109
110 back = states_chords_to_lf(zip(states,chords))
111
112
113 in_coords = [(x,y) for (x,y,fun) in output]
114 in_funs = [fun for (x,y,fun) in output]
115 out_coords = [point.harmonic_coord for point in back.lf]
116 out_funs = [point.function for point in back.lf]
117
118 self.assertEqual(in_coords, out_coords, msg="coordinates converted to states and back produced something different.\nState labels:\n%s" % (states))
119 self.assertEqual(in_funs, out_funs, msg="coordinates converted to states and back produced different functions.\nState labels:\n%s" % (states))
120