def setUp(self): self.commonbar = Bar() self.ebar = Bar('E', (4, 4)) self.fbar = Bar('F', (6, 8)) self.tbar = Bar('C', (4, 4)) self.mbar = Bar('C', (4, 4)) for y in [self.commonbar, self.ebar, self.fbar]: map(lambda x: y + x, ['C', 'E', 'G', 'B']) map(lambda x: self.tbar.place_notes(NoteContainer(x), 6), [ 'C', 'E', 'G', 'B', 'C', 'E', ]) map(lambda x: self.mbar.place_notes(NoteContainer(x), 4), ['C', 'E']) map(lambda x: self.mbar.place_notes(NoteContainer(x), 6), ['G', 'B', 'C' ]) self.track1 = Track() self.track1 + self.commonbar self.track2 = Track() self.track2 + self.commonbar self.track2 + self.ebar self.composition1 = Composition() self.composition1.add_track(self.track1) self.composition2 = Composition() self.composition2.add_track(self.track1) self.composition2.add_track(self.track2)
def place_notes(self, notes, duration): """Place the notes on the current_beat. Notes can be strings, Notes, list of strings, list of Notes or a NoteContainer. Raise a MeterFormatError if the duration is not valid. Return True if succesful, False otherwise (ie. the Bar hasn't got enough room for a note of that duration). """ # note should be able to be one of strings, lists, Notes or # NoteContainers if hasattr(notes, "notes"): pass elif hasattr(notes, "name"): notes = NoteContainer(notes) elif isinstance(notes, six.string_types): notes = NoteContainer(notes) elif isinstance(notes, list): notes = NoteContainer(notes) if self.current_beat + 1.0 / duration <= self.length or self.length == 0.0: self.bar.append([self.current_beat, duration, notes]) self.current_beat += 1.0 / duration return True else: return False
def setUp(self): self.i = Instrument() self.p = Piano() self.g = Guitar() self.notes = NoteContainer(["A", "B", "C", "D", "E"]) self.noteslow = NoteContainer(["C-0", "D-0", "E-0"]) self.noteshigh = NoteContainer( ["A-12", "B-12", "C-12", "D-12", "E-12"])
def get_c_chords(cls): chords = [ NoteContainer(['C-2', 'E-2', 'G-2']), NoteContainer(['F-2', 'A-2', 'C-3']), NoteContainer(['G-2', 'B-2', 'D-3']), NoteContainer(['A-2', 'C-3', 'E-3']), ] return chords
def validate_pb(pb, lsa_ordering, times_dict): for lst in pb: time = lst[0] lsa_code = lst[1] original = list(set(times_dict[time])) decoded = decode_lsas(lsa_code, lsa_ordering) if (not NoteContainer(original) == NoteContainer(decoded)): warnings.warn('incorrect LSA encoding at time = %.3f' % (time))
def setUp(self): self.i = Instrument() self.p = Piano() self.g = Guitar() self.notes = NoteContainer(['A', 'B', 'C', 'D', 'E']) self.noteslow = NoteContainer(['C-0', 'D-0', 'E-0']) self.noteshigh = NoteContainer( ['A-12', 'B-12', 'C-12', 'D-12', 'E-12'])
def test_from_interval_shorthand(self): self.assertEqual( NoteContainer(["C-4", "G-4"]), NoteContainer().from_interval_shorthand("C", "5"), ) self.assertEqual( NoteContainer(["F-3", "C-4"]), NoteContainer().from_interval_shorthand("C", "5", False), )
def test_dotted_notes(self): self.assertEqual( LilyPond.from_NoteContainer(NoteContainer("C"), value.dots(8), standalone=False), "c'8.", ) self.assertEqual( LilyPond.from_NoteContainer(NoteContainer("C"), value.dots(4, 2), standalone=False), "c'4..", )
def setUp(self): self.n1 = NoteContainer() self.n2 = NoteContainer('A') self.n3 = NoteContainer(['A', 'C', 'E']) self.n4 = NoteContainer(['A', 'C', 'E', 'F', 'G']) self.n5 = NoteContainer([ 'A', 'C', 'E', 'F', 'G', 'A', ])
def setUp(self): self.n1 = NoteContainer() self.n2 = NoteContainer("A") self.n3 = NoteContainer(["A", "C", "E"]) self.n4 = NoteContainer(["A", "C", "E", "F", "G"]) self.n5 = NoteContainer([ "A", "C", "E", "F", "G", "A", ])
def test_sort(self): n1 = NoteContainer(['Eb', 'Gb', 'C']) n2 = NoteContainer(['Eb', 'Gb', 'Cb']) n1.sort() n2.sort() self.assertEqual(Note('Eb'), n1[0]) self.assertEqual(Note('Gb'), n2[1])
def test_add_notes(self): self.assertEqual(self.n3, self.n1.add_notes(['A', 'C', 'E'])) self.n1.empty() self.assertEqual(self.n3, self.n1.add_notes([['A', 4], ['C', 5], ['E', 5]])) self.n1.empty() self.assertEqual(self.n2, self.n1.add_notes(Note('A'))) self.n1.empty() self.assertEqual(self.n2, self.n1.add_notes([Note('A')])) self.n1.empty() self.assertEqual(self.n2, self.n1.add_notes('A')) self.n1.empty() self.assertEqual(self.n3, self.n2 + NoteContainer([['C', 5], ['E', 5]])) self.n2 = NoteContainer('A')
def test_sort(self): n1 = NoteContainer(["Eb", "Gb", "C"]) n2 = NoteContainer(["Eb", "Gb", "Cb"]) n1.sort() n2.sort() self.assertEqual(Note("Eb"), n1[0]) self.assertEqual(Note("Gb"), n2[1])
def test_add_notes(self): self.assertEqual(self.n3, self.n1.add_notes(["A", "C", "E"])) self.n1.empty() self.assertEqual(self.n3, self.n1.add_notes([["A", 4], ["C", 5], ["E", 5]])) self.n1.empty() self.assertEqual(self.n2, self.n1.add_notes(Note("A"))) self.n1.empty() self.assertEqual(self.n2, self.n1.add_notes([Note("A")])) self.n1.empty() self.assertEqual(self.n2, self.n1.add_notes("A")) self.n1.empty() self.assertEqual(self.n3, self.n2 + NoteContainer([["C", 5], ["E", 5]])) self.n2 = NoteContainer("A")
def test_is_perfect_consonant(self): self.assert_(NoteContainer(['A', 'E']).is_perfect_consonant()) self.assert_(NoteContainer(['A-4', 'A-6']).is_perfect_consonant()) self.assert_(NoteContainer(['A', 'D']).is_perfect_consonant()) self.assert_(not NoteContainer(['A', 'D']).is_perfect_consonant(False)) self.assert_(not NoteContainer().from_chord('Am' ).is_perfect_consonant()) self.assert_(not NoteContainer().from_chord('C').is_perfect_consonant()) self.assert_(not NoteContainer().from_chord('G').is_perfect_consonant()) self.assert_(not NoteContainer().from_chord('Dm' ).is_perfect_consonant()) self.assert_(not NoteContainer().from_chord('E').is_perfect_consonant())
def test_add_note(self): self.assertEqual(self.n2, self.n2.add_note("A")) self.assertEqual(NoteContainer("A"), self.n1.add_note("A")) self.n1 - "A" self.assertEqual(self.n3 + ["F", "G"], self.n4) self.assertEqual(self.n2 + ["C", "E"], self.n3 - ["F", "G"]) self.n2 - ["C", "E"]
def test_add_note(self): self.assertEqual(self.n2, self.n2.add_note('A')) self.assertEqual(NoteContainer('A'), self.n1.add_note('A')) self.n1 - 'A' self.assertEqual(self.n3 + ['F', 'G'], self.n4) self.assertEqual(self.n2 + ['C', 'E'], self.n3 - ['F', 'G']) self.n2 - ['C', 'E']
def test_is_consonant(self): self.assertTrue(NoteContainer().from_chord("Am").is_consonant()) self.assertTrue(NoteContainer().from_chord("C").is_consonant()) self.assertTrue(NoteContainer().from_chord("G").is_consonant()) self.assertTrue(NoteContainer().from_chord("Dm").is_consonant()) self.assertTrue(NoteContainer().from_chord("E").is_consonant()) self.assertTrue(not NoteContainer().from_chord("E7").is_consonant()) self.assertTrue(not NoteContainer().from_chord("Am7").is_consonant()) self.assertTrue(not NoteContainer().from_chord("Gdim").is_consonant())
def test_is_consonant(self): self.assert_(NoteContainer().from_chord('Am').is_consonant()) self.assert_(NoteContainer().from_chord('C').is_consonant()) self.assert_(NoteContainer().from_chord('G').is_consonant()) self.assert_(NoteContainer().from_chord('Dm').is_consonant()) self.assert_(NoteContainer().from_chord('E').is_consonant()) self.assert_(not NoteContainer().from_chord('E7').is_consonant()) self.assert_(not NoteContainer().from_chord('Am7').is_consonant()) self.assert_(not NoteContainer().from_chord('Gdim').is_consonant())
def test_from_NoteContainer(self): self.assertEqual( LilyPond.from_NoteContainer(NoteContainer("C"), standalone=False), "c'") self.assertEqual( LilyPond.from_NoteContainer(NoteContainer("C"), 4, standalone=False), "c'4") self.assertEqual( LilyPond.from_NoteContainer(NoteContainer(["C", "E"]), standalone=False), "<c' e'>", ) self.assertEqual( LilyPond.from_NoteContainer(NoteContainer(["C", "E"]), 4, standalone=False), "<c' e'>4", ) # issue #37 self.assertEqual( LilyPond.from_NoteContainer(NoteContainer("C"), 16, standalone=False), "c'16", ) self.assertEqual( LilyPond.from_NoteContainer(NoteContainer("C"), 16.0, standalone=False), "c'16", ) self.assertEqual( LilyPond.from_NoteContainer(NoteContainer("C"), value.dots(16), standalone=False), "c'16.", ) self.assertEqual( LilyPond.from_NoteContainer(NoteContainer("C"), 0.25, standalone=False), "c'\\longa", ) self.assertEqual( LilyPond.from_NoteContainer(NoteContainer("C"), 0.5, standalone=False), "c'\\breve", )
def test_to_png(self): self.assert_( LilyPond.to_png( '{ %s }' % LilyPond.from_NoteContainer(NoteContainer('C'), value.dots(8)), 'pn1')) self.assert_(LilyPond.to_png(LilyPond.from_Bar(self.tbar), 'pn2')) self.assert_(LilyPond.to_png(LilyPond.from_Bar(self.mbar), 'pn3'))
def test_set_item(self): b = Bar() b + ['A', 'C', 'E'] c = Bar() c + ['A', 'C', 'E'] self.assertEqual(b, c) c[0] = NoteContainer(['A', 'C', 'E']) self.assertEqual(b, c) c[0] = ['A', 'C', 'E'] self.assertEqual(b, c) c[0] = Note('A') c[0] = c[0][2] + NoteContainer(['C', 'E']) self.assertEqual(b, c) c[0] = Note('A') c[0] = c[0][2] + 'C' c[0] = c[0][2] + 'E' self.assertEqual(b, c)
def test_to_pdf(self): self.assert_( LilyPond.to_pdf( '{ %s }' % LilyPond.from_NoteContainer(NoteContainer('C'), value.dots(8)), 'pdftest first test')) self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.tbar), 'pdftest2')) self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.mbar), 'pdftest3'))
def frets_to_NoteContainer(self, fingering): """Convert a list such as returned by find_fret to a NoteContainer.""" res = [] for (string, fret) in enumerate(fingering): if fret is not None: res.append(self.get_Note(string, fret)) return NoteContainer(res)
def test_set_item(self): b = Bar() b + ["A", "C", "E"] c = Bar() c + ["A", "C", "E"] self.assertEqual(b, c) c[0] = NoteContainer(["A", "C", "E"]) self.assertEqual(b, c) c[0] = ["A", "C", "E"] self.assertEqual(b, c) c[0] = Note("A") c[0] = c[0][2] + NoteContainer(["C", "E"]) self.assertEqual(b, c) c[0] = Note("A") c[0] = c[0][2] + "C" c[0] = c[0][2] + "E" self.assertEqual(b, c)
def __setitem__(self, index, value): """Enable the use of [] = notation on Bars. The value should be a NoteContainer, or a string/list/Note understood by the NoteContainer. """ if hasattr(value, 'notes'): pass elif hasattr(value, 'name'): value = NoteContainer(value) elif type(value) == str: value = NoteContainer(value) elif type(value) == list: res = NoteContainer() for x in value: res + x value = res self.bar[index][2] = value
def test_to_pdf(self): self.assertTrue( LilyPond.to_pdf( "{ %s }" % LilyPond.from_NoteContainer(NoteContainer("C"), value.dots(8)), "pdftest first test", ) ) self.assertTrue(LilyPond.to_pdf(LilyPond.from_Bar(self.tbar), "pdftest2")) self.assertTrue(LilyPond.to_pdf(LilyPond.from_Bar(self.mbar), "pdftest3"))
def test_to_png(self): self.assertTrue( LilyPond.to_png( "{ %s }" % LilyPond.from_NoteContainer(NoteContainer("C"), value.dots(8)), "pn1", )) self.assertTrue(LilyPond.to_png(LilyPond.from_Bar(self.tbar), "pn2")) self.assertTrue(LilyPond.to_png(LilyPond.from_Bar(self.mbar), "pn3"))
def __setitem__(self, index, value): """Enable the use of [] = notation on Bars. The value should be a NoteContainer, or a string/list/Note understood by the NoteContainer. """ if hasattr(value, "notes"): pass elif hasattr(value, "name"): value = NoteContainer(value) elif isinstance(value, six.string_types): value = NoteContainer(value) elif isinstance(value, list): res = NoteContainer() for x in value: res + x value = res self.bar[index][2] = value
def test_is_imperfect_consonant(self): self.assert_(NoteContainer(['A', 'C']).is_imperfect_consonant()) self.assert_(NoteContainer(['A', 'C#']).is_imperfect_consonant()) self.assert_(NoteContainer(['A', 'F']).is_imperfect_consonant()) self.assert_(NoteContainer(['A', 'F#']).is_imperfect_consonant()) self.assert_(not NoteContainer(['A', 'B']).is_imperfect_consonant()) self.assert_(not NoteContainer(['A', 'E']).is_imperfect_consonant()) self.assert_(not NoteContainer(['A-4', 'A-5']).is_imperfect_consonant())
def test_remove_note(self): n = NoteContainer(['C', 'E', 'G']) n.remove_note('C') self.assertEqual(NoteContainer(['E', 'G']), n) n.remove_note('E') self.assertEqual(NoteContainer(['G']), n) n.remove_note('G') self.assertEqual(NoteContainer([]), n)
class test_NoteContainers(unittest.TestCase): def setUp(self): self.n1 = NoteContainer() self.n2 = NoteContainer('A') self.n3 = NoteContainer(['A', 'C', 'E']) self.n4 = NoteContainer(['A', 'C', 'E', 'F', 'G']) self.n5 = NoteContainer([ 'A', 'C', 'E', 'F', 'G', 'A', ]) def test_add_note(self): self.assertEqual(self.n2, self.n2.add_note('A')) self.assertEqual(NoteContainer('A'), self.n1.add_note('A')) self.n1 - 'A' self.assertEqual(self.n3 + ['F', 'G'], self.n4) self.assertEqual(self.n2 + ['C', 'E'], self.n3 - ['F', 'G']) self.n2 - ['C', 'E'] def test_add_notes(self): self.assertEqual(self.n3, self.n1.add_notes(['A', 'C', 'E'])) self.n1.empty() self.assertEqual(self.n3, self.n1.add_notes([['A', 4], ['C', 5], ['E', 5]])) self.n1.empty() self.assertEqual(self.n2, self.n1.add_notes(Note('A'))) self.n1.empty() self.assertEqual(self.n2, self.n1.add_notes([Note('A')])) self.n1.empty() self.assertEqual(self.n2, self.n1.add_notes('A')) self.n1.empty() self.assertEqual(self.n3, self.n2 + NoteContainer([['C', 5], ['E', 5]])) self.n2 = NoteContainer('A') def test_remove_note(self): n = NoteContainer(['C', 'E', 'G']) n.remove_note('C') self.assertEqual(NoteContainer(['E', 'G']), n) n.remove_note('E') self.assertEqual(NoteContainer(['G']), n) n.remove_note('G') self.assertEqual(NoteContainer([]), n) def test_determine(self): n = NoteContainer(['C', 'E', 'G']) self.assertEqual(['C major triad'], n.determine()) n.transpose('3') self.assertEqual(['E major triad'], n.determine()) def test_remove_notes(self): pass def test_sort(self): n1 = NoteContainer(['Eb', 'Gb', 'C']) n2 = NoteContainer(['Eb', 'Gb', 'Cb']) n1.sort() n2.sort() self.assertEqual(Note('Eb'), n1[0]) self.assertEqual(Note('Gb'), n2[1]) def test_getitem(self): self.assertEqual(self.n2[0], Note('A')) self.assertEqual(self.n3[0], Note('A')) self.assertEqual(self.n4[0], Note('A')) self.assertEqual(self.n4[1], Note('C', 5)) self.assertEqual(self.n4[2], Note('E', 5)) def test_transpose(self): n = NoteContainer(['C', 'E', 'G']) self.assertEqual(NoteContainer(['E', 'G#', 'B']), n.transpose('3')) n = NoteContainer(['C-6', 'E-4', 'G-2']) self.assertEqual(NoteContainer(['E-6', 'G#-4', 'B-2']), n.transpose('3' )) def test_get_note_names(self): self.assertEqual(['A', 'C', 'E'], self.n3.get_note_names()) self.assertEqual(['A', 'C', 'E', 'F', 'G'], self.n4.get_note_names()) self.assertEqual(['A', 'C', 'E', 'F', 'G'], self.n5.get_note_names()) def test_from_chord_shorthand(self): self.assertEqual(self.n3, NoteContainer().from_chord_shorthand('Am')) def test_from_progression_shorthand(self): self.assertEqual(self.n3, NoteContainer().from_progression_shorthand('VI')) def test_from_interval_shorthand(self): self.assertEqual(NoteContainer(['C-4', 'G-4']), NoteContainer().from_interval_shorthand('C', '5')) self.assertEqual(NoteContainer(['F-3', 'C-4']), NoteContainer().from_interval_shorthand('C', '5', False)) def test_is_consonant(self): self.assert_(NoteContainer().from_chord('Am').is_consonant()) self.assert_(NoteContainer().from_chord('C').is_consonant()) self.assert_(NoteContainer().from_chord('G').is_consonant()) self.assert_(NoteContainer().from_chord('Dm').is_consonant()) self.assert_(NoteContainer().from_chord('E').is_consonant()) self.assert_(not NoteContainer().from_chord('E7').is_consonant()) self.assert_(not NoteContainer().from_chord('Am7').is_consonant()) self.assert_(not NoteContainer().from_chord('Gdim').is_consonant()) def test_is_perfect_consonant(self): self.assert_(NoteContainer(['A', 'E']).is_perfect_consonant()) self.assert_(NoteContainer(['A-4', 'A-6']).is_perfect_consonant()) self.assert_(NoteContainer(['A', 'D']).is_perfect_consonant()) self.assert_(not NoteContainer(['A', 'D']).is_perfect_consonant(False)) self.assert_(not NoteContainer().from_chord('Am' ).is_perfect_consonant()) self.assert_(not NoteContainer().from_chord('C').is_perfect_consonant()) self.assert_(not NoteContainer().from_chord('G').is_perfect_consonant()) self.assert_(not NoteContainer().from_chord('Dm' ).is_perfect_consonant()) self.assert_(not NoteContainer().from_chord('E').is_perfect_consonant()) def test_is_imperfect_consonant(self): self.assert_(NoteContainer(['A', 'C']).is_imperfect_consonant()) self.assert_(NoteContainer(['A', 'C#']).is_imperfect_consonant()) self.assert_(NoteContainer(['A', 'F']).is_imperfect_consonant()) self.assert_(NoteContainer(['A', 'F#']).is_imperfect_consonant()) self.assert_(not NoteContainer(['A', 'B']).is_imperfect_consonant()) self.assert_(not NoteContainer(['A', 'E']).is_imperfect_consonant()) self.assert_(not NoteContainer(['A-4', 'A-5']).is_imperfect_consonant()) def test_is_dissonant(self): self.assert_(NoteContainer().from_chord('E7').is_dissonant()) self.assert_(NoteContainer().from_chord('Am7').is_dissonant()) self.assert_(NoteContainer().from_chord('Gdim').is_dissonant()) self.assert_(not NoteContainer().from_chord('Am').is_dissonant()) self.assert_(not NoteContainer().from_chord('C').is_dissonant()) self.assert_(not NoteContainer().from_chord('G').is_dissonant()) self.assert_(not NoteContainer().from_chord('Dm').is_dissonant())
def test_determine(self): n = NoteContainer(['C', 'E', 'G']) self.assertEqual(['C major triad'], n.determine()) n.transpose('3') self.assertEqual(['E major triad'], n.determine())
def test_transpose(self): n = NoteContainer(['C', 'E', 'G']) self.assertEqual(NoteContainer(['E', 'G#', 'B']), n.transpose('3')) n = NoteContainer(['C-6', 'E-4', 'G-2']) self.assertEqual(NoteContainer(['E-6', 'G#-4', 'B-2']), n.transpose('3' ))