def generate_csound_intonation(): # We don't specify a lessonfile manager since we don't need # any of the methods that depend on it. page = fp.Page(u"Experimental CSound exercises", fp.Column()) fileheader = fp.FileHeader(1, page) section = fp.LinkList(u"Melodic intervals") page[-1].append(section) for idx, cname in enumerate(interval_names): subpage = fp.Page(Interval(cname).get_cname().title(), fp.Column()) section.append(subpage) sect = fp.LinkList(Interval(cname).get_cname().title()) subpage[-1].append(sect) for cent in cents: csound_intonation2(False, cname, cent) sect.append("solfege:lesson-files/csound-intonation-%s-%icent" % (iname_to_fn(cname), cent)) section = fp.LinkList(u"Harmonic intervals") col = fp.Column() page.append(col) page[-1].append(section) for idx, cname in enumerate(interval_names): subpage = fp.Page(Interval(cname).get_cname().title(), fp.Column()) section.append(subpage) sect = fp.LinkList(Interval(cname).get_cname().title()) subpage[-1].append(sect) for cent in cents: csound_intonation2(True, cname, cent) sect.append( "solfege:lesson-files/csound-intonation-harmonic-%s-%icent" % (iname_to_fn(cname), cent)) f = codecs.open("exercises/standard/csound-tree.txt", "w", "utf-8") fileheader.dump(f) f.close()
def test_add_d5(self): a = MusicalPitch.new_from_notename("b") b = Interval("-d5") self.assertEquals((a + b).get_octave_notename(), "eis") a = MusicalPitch.new_from_notename("bis") b = Interval("-d5") self.assertEquals((a + b).get_octave_notename(), "eisis") a = MusicalPitch.new_from_notename("bisis") b = Interval("-d5") self.assertEquals((a + b).get_octave_notename(), "fisis")
def test_constructor(self): for s, a, b, c, i, steps in ( ('p1', 0, 0, 0, 0, 1), ('d1', 0, 0, -1, -1, 1), ('a1', 0, 0, 1, 1, 1), ('p4', 3, 0, 0, 5, 4), ('p5', 4, 0, 0, 7, 5), ('p8', 0, 1, 0, 12, 8), ('d8', 0, 1, -1, 11, 8), ('a8', 0, 1, 1, 13, 8), ('p11', 3, 1, 0, 17, 11), # octave + fourth ('p12', 4, 1, 0, 19, 12), # octave + fifth ('p15', 0, 2, 0, 24, 15), # 2*octave ('d15', 0, 2, -1, 23, 15), # 2*octave ('a15', 0, 2, 1, 25, 15), # 2*octave ('m2', 1, 0, -1, 1, 2), ('M2', 1, 0, 0, 2, 2), ('M3', 2, 0, 0, 4, 3), ('M6', 5, 0, 0, 9, 6), ('M9', 1, 1, 0, 14, 9), ('m10', 2, 1, -1, 15, 10), # tenth ('M13', 5, 1, 0, 21, 13), # octave + sixth ('m14', 6, 1, -1, 22, 14), # octave + seventh ('M16', 1, 2, 0, 26, 16), # 2*octave + second ): n = Interval(s) self.assertEquals((n.m_interval, n.m_octave, n.m_mod), (a, b, c)) self.assertEquals(repr(n), s) self.assertEquals(i, n.get_intvalue()) self.assertEquals(steps, n.steps())
def csound_intonation2(harmonic, interval_name, cent): i = Interval(interval_name) if harmonic: hs = "harmonic-" else: hs = "" filename = os.path.join( "exercises", "standard", "lesson-files", "csound-intonation-%s%s-%icent" % (hs, iname_to_fn(interval_name), cent)) f = codecs.open(filename, 'w', 'utf-8') print >> f, "# Solfege - free ear training software" print >> f, "# Copyright (C) 2004, 2005, 2011 Tom Cato Amundsen" print >> f, "# License is GPL, see file COPYING" print >> f print >> f, "header {" print >> f, ' lesson_id = "csound-intonation-%s%s-%icent"' % ( hs, iname_to_fn(interval_name), cent) print >> f, ' module = idbyname' print >> f, ' help = "idbyname-intonation"' print >> f, ' title = _("Is the interval flat, in tune or sharp? %%s cent wrong") %% %i' % cent print >> f, ' lesson_heading = _("Just interval: %%s") %% _("%s") + " (%s)"' % ( i.get_cname(), ratio_dict[i.get_cname_short()][1]) print >> f, ' filldir = vertic' print >> f, '}' for c in range(12): hz = 220 * 2**(c / 12) hz2 = hz * ratio_dict[i.get_cname_short()][0] for label, mult in (("intonation|flat", -cent), ("intonation|in tune", 0), ("intonation|sharp", cent)): print >> f print >> f, 'question {' print >> f, ' name = _i("%s")' % label print >> f, ' set=%i' % c print >> f, ' csound(load("share/sinus.orc"), """' print >> f, ' f1 0 4096 10 1 1.25 0.95 0.8 0.6 0.4 0.2 ' if harmonic: print >> f, ' i1 0 1 %f' % hz print >> f, ' i1 0 1 %f' % (hz2 * 2**(mult / 1200)) else: print >> f, ' i1 0 1 %f' % hz print >> f, ' i1 + 1 %f' % (hz2 * 2**(mult / 1200)) print >> f, ' """)' print >> f, "}" f.close()
def csound_intonation2(harmonic, interval_name, cent): i = Interval(interval_name) if harmonic: hs = "harmonic-" else: hs = "" filename = saveto / ("csound-intonation-%s%s-%icent" % (hs, iname_to_fn(interval_name), cent)) f = filename.open("w") f.write("""# Solfege - free ear training software # Copyright (C) 2004, 2005, 2011, 2016 Tom Cato Amundsen # License is GPL, see file COPYING header {{ lesson_id = "csound-intonation-{0}{1}-{2}cent" module = idbyname help = "idbyname-intonation" title = _("Is the interval flat, in tune or sharp? %s cent wrong") % {3} lesson_heading = _("Just interval: %s") % _("{4}") + " ({5})" filldir = vertic }} """.format(hs, iname_to_fn(interval_name), cent, cent, # 0-3 i.get_cname(), ratio_dict[i.get_cname_short()][1])) # 4-5 for c in range(12): hz = 220 * 2 ** (c / 12) hz2 = hz * ratio_dict[i.get_cname_short()][0] for label, mult in (("intonation|flat", -cent), ("intonation|in tune", 0), ("intonation|sharp", cent)): f.write(""" question {{ name = _i("{0}") set={1} csound(load("share/sinus.orc"), \"\"\" f1 0 4096 10 1 1.25 0.95 0.8 0.6 0.4 0.2 """.format(label, c)) if harmonic: f.write(' i1 0 1 %f\n' % hz) f.write(' i1 0 1 %f\n' % (hz2 * 2**(mult / 1200))) else: f.write(' i1 0 1 %f\n' % hz) f.write(' i1 + 1 %f\n' % (hz2 * 2**(mult / 1200))) f.write(' """)\n') f.write("}\n") f.close()
def test_addition(self): a = MusicalPitch.new_from_notename("c'") b = Interval("m2") self.assertEquals((a + b).get_octave_notename(), "des'")
'M3': (5 / 4, "5:4"), 'p4': (4 / 3, "4:3"), 'p5': (3 / 2, "3:2"), 'm6': (8 / 5, "8:5"), 'M6': (5 / 3, "5:3"), 'm7': (16 / 9, "16:9"), 'M7': (15 / 8, "15:8"), 'p8': (2, "2:1"), 'm9': (1 + 16 / 15, "1+16:15"), 'M9': (1 + 9 / 8, "1+9:8"), 'm10': (1 + 6 / 5, "1+6:5"), 'M10': (1 + 5 / 4, "1+5:4"), } interval_names = list(ratio_dict.keys()) interval_names.sort(key=lambda i: Interval(i).get_intvalue()) # different number of cents the intonation questions should be wrong. cents = (40, 30, 20, 15, 10, 8, 6, 5) def write_file_copyright(f): f.write("# Solfege - free ear training software\n") f.write("# Copyright (C) 2007, 2008, 2011, 2016 Tom Cato Amundsen\n") f.write("# License is GPL, see file COPYING\n") f.write("# Generated by tools/generate_lessonfiles.py\n") def question(f, b, c): low = 60 tone_a = MusicalPitch.new_from_int(low)
def test_add_interval_fail(self): n = MusicalPitch.new_from_int(120) i = Interval("M10") self.assertRaises(ValueError, lambda: n + i)