Example #1
0
    def test_getBeams_offset(self):
        '''
        Test getting Beams from a Measure that has an anacrusis that makes the
        first note not beamed.
        '''
        m = stream.Measure()
        m.repeatAppend(note.Note(type='eighth'), 5)
        ts = TimeSignature('2/2')

        beams = ts.getBeams(m, measureStartOffset=1.5)
        self.assertIsNone(beams[0])
        for b in beams[1:]:
            self.assertIsNotNone(b)
        match = '''[None,
        <music21.beam.Beams <music21.beam.Beam 1/start>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>>,
        <music21.beam.Beams <music21.beam.Beam 1/stop>>]'''
        self.assertTrue(common.whitespaceEqual(str(beams), match))

        m.append(note.Note(type='eighth'))
        beams = ts.getBeams(m, measureStartOffset=1.0)
        match = '''[<music21.beam.Beams <music21.beam.Beam 1/start>>,
        <music21.beam.Beams <music21.beam.Beam 1/stop>>,
        <music21.beam.Beams <music21.beam.Beam 1/start>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>>,
        <music21.beam.Beams <music21.beam.Beam 1/stop>>]'''
        self.assertTrue(common.whitespaceEqual(str(beams), match), str(beams))

        m = stream.Measure()
        m.repeatAppend(note.Note(type='eighth'), 5)
        ts = TimeSignature('3/2')

        beams = ts.getBeams(m, measureStartOffset=3.5)
        match = '''[None,
        <music21.beam.Beams <music21.beam.Beam 1/start>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>>,
        <music21.beam.Beams <music21.beam.Beam 1/stop>>]'''
        self.assertTrue(common.whitespaceEqual(str(beams), match))

        m = stream.Measure()
        m.repeatAppend(note.Note(type='eighth'), 4)
        ts = TimeSignature('6/8')
        beams = ts.getBeams(m, measureStartOffset=1.0)
        match = '''[None,
        <music21.beam.Beams <music21.beam.Beam 1/start>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>>,
        <music21.beam.Beams <music21.beam.Beam 1/stop>>]'''
        self.assertTrue(common.whitespaceEqual(str(beams), match))

        m.append(note.Note(type='eighth'))
        beams = ts.getBeams(m, measureStartOffset=0.5)
        match = '''[<music21.beam.Beams <music21.beam.Beam 1/start>>,
        <music21.beam.Beams <music21.beam.Beam 1/stop>>,
        <music21.beam.Beams <music21.beam.Beam 1/start>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>>,
        <music21.beam.Beams <music21.beam.Beam 1/stop>>]'''
        self.assertTrue(common.whitespaceEqual(str(beams), match), str(beams))
Example #2
0
    def testScalaScaleA(self):
        # noinspection SpellCheckingInspection
        msg = '''! fj-12tet.scl
!
Franck Jedrzejewski continued fractions approx. of 12-tet
 12
!
89/84
55/49
44/37
63/50
4/3
99/70
442/295
27/17
37/22
98/55
15/8
2/1
'''
        # provide a raw scala string
        sc = scale.ScalaScale('c4', msg)
        self.assertEqual(str(sc),
                         '<music21.scale.ScalaScale C Scala: fj-12tet.scl>')
        # noinspection PyTypeChecker
        pitchesOut = self.pitchOut(sc.getPitches('c2', 'c4'))
        self.assertTrue(
            common.whitespaceEqual(
                pitchesOut, '''
            [C2, C#2(+0c), D2(-0c), E-2(-0c), E2(+0c), F2(-2c), F#2(+0c),
             G2, G#2(+1c), A2(+0c), B-2(+0c), B2(-12c),
             C3, C#3(+0c), D3(-0c), E-3(-0c), E3(+0c), F3(-2c), F#3(+0c),
             G3, G#3(+1c), A3(+0c), B-3(+0c), B3(-12c),
             C4]'''), pitchesOut)
Example #3
0
    def testFromSettings(self):

        unused_env = Environment(forcePlatform="darwin")

        # use a fake ref dict to get settings
        ref = {}
        ref["localCorpusSettings"] = ["x", "y", "z"]
        ref["midiPath"] = "w"
        settings = _environStorage["instance"]._toSettings(ref)

        # this will load values into the env._ref dictionary
        _environStorage["instance"]._fromSettings(settings, _environStorage["instance"]._ref)
        # get xml strings
        match = self.stringFromTree(_environStorage["instance"]._toSettings(_environStorage["instance"]._ref))
        if "encoding" in match:
            enc = "encoding='utf-8'"
        else:
            enc = ""
        canonic = (
            """<?xml version='1.0' """
            + enc
            + """?>
<settings>
  <preference name="autoDownload" value="ask" />
  <preference name="braillePath" />
  <preference name="debug" value="0" />
  <preference name="directoryScratch" />
  <preference name="graphicsPath" value="/Applications/Preview.app" />
  <preference name="ipythonShowFormat" value="ipython.musicxml.png" />
  <preference name="lilypondBackend" value="ps" />
  <preference name="lilypondFormat" value="pdf" />
  <preference name="lilypondPath" 
      value="/Applications/Lilypond.app/Contents/Resources/bin/lilypond" />
  <preference name="lilypondVersion" />
  <localCorporaSettings />
  <localCorpusSettings>
    <localCorpusPath>x</localCorpusPath>
    <localCorpusPath>y</localCorpusPath>
    <localCorpusPath>z</localCorpusPath>
  </localCorpusSettings>
  <preference name="manualCoreCorpusPath" />
  <preference name="midiPath" value="w" />
  <preference name="musescoreDirectPNGPath" 
      value="/Applications/MuseScore 2.app/Contents/MacOS/mscore" />
  <preference name="musicxmlPath" value="/Applications/Finale Notepad 2014.app" />
  <preference name="pdfPath" value="/Applications/Preview.app" />
  <preference name="showFormat" value="musicxml" />
  <preference name="vectorPath" value="/Applications/Preview.app" />
  <preference name="warnings" value="1" />
  <preference name="writeFormat" value="musicxml" />
</settings>
"""
        )
        self.assertTrue(common.whitespaceEqual(canonic, match))
Example #4
0
    def testFromSettings(self):

        unused_env = Environment(forcePlatform='darwin')

        # use a fake ref dict to get settings
        ref = {}
        ref['localCorpusSettings'] = ['x', 'y', 'z']
        ref['midiPath'] = 'w'
        settings = _environStorage['instance']._toSettings(ref)

        # this will load values into the env._ref dictionary
        _environStorage['instance']._fromSettings(
            settings, _environStorage['instance']._ref)
        # get xml strings
        match = self.stringFromTree(_environStorage['instance']._toSettings(
            _environStorage['instance']._ref))
        if 'encoding' in match:
            enc = "encoding='utf-8'"
        else:
            enc = ''
        canonic = """<?xml version='1.0' """ + enc + """?>
<settings>
  <preference name="autoDownload" value="ask" />
  <preference name="braillePath" />
  <preference name="debug" value="0" />
  <preference name="directoryScratch" />
  <preference name="graphicsPath" value="/Applications/Preview.app" />
  <preference name="ipythonShowFormat" value="ipython.musicxml.png" />
  <preference name="lilypondBackend" value="ps" />
  <preference name="lilypondFormat" value="pdf" />
  <preference name="lilypondPath" 
      value="/Applications/Lilypond.app/Contents/Resources/bin/lilypond" />
  <preference name="lilypondVersion" />
  <localCorporaSettings />
  <localCorpusSettings>
    <localCorpusPath>x</localCorpusPath>
    <localCorpusPath>y</localCorpusPath>
    <localCorpusPath>z</localCorpusPath>
  </localCorpusSettings>
  <preference name="manualCoreCorpusPath" />
  <preference name="midiPath" value="w" />
  <preference name="musescoreDirectPNGPath" 
      value="/Applications/MuseScore 2.app/Contents/MacOS/mscore" />
  <preference name="musicxmlPath" value="/Applications/Finale Notepad 2014.app" />
  <preference name="pdfPath" value="/Applications/Preview.app" />
  <preference name="showFormat" value="musicxml" />
  <preference name="vectorPath" value="/Applications/Preview.app" />
  <preference name="warnings" value="1" />
  <preference name="writeFormat" value="musicxml" />
</settings>
"""
        self.assertTrue(common.whitespaceEqual(canonic, match))
Example #5
0
    def testRealizeDescending(self):
        edgeList = ['M2', 'M2', 'm2', 'M2', 'M2', 'M2', 'm2']
        net = IntervalNetwork()
        net.fillBiDirectedEdges(edgeList)

        pitches, nodes = net.realizeDescending('c3', 1, 'c2')
        self.assertEqual(self.pitchOut(pitches),
                         '[C2, D2, E2, F2, G2, A2, B2]')
        self.assertEqual(str(nodes),
                         '[Terminus.LOW, 0, 1, 2, 3, 4, 5]'
                         )

        self.assertEqual(
            self.realizePitchOut(net.realizeDescending('c3', Terminus.HIGH, minPitch='c2')),
            '([C2, D2, E2, F2, G2, A2, B2], [Terminus.LOW, 0, 1, 2, 3, 4, 5])'
        )

        # this only gets one pitch as this is descending and includes reference
        # pitch
        self.assertEqual(str(net.realizeDescending('c3', 1, includeFirst=True)),
                         '([<music21.pitch.Pitch C3>], [Terminus.LOW])')

        self.assertTrue(
            common.whitespaceEqual(
                self.realizePitchOut(net.realizeDescending('g3', 1, 'g0', includeFirst=True)),
                '''([G0, A0, B0, C1, D1, E1, F#1,
                     G1, A1, B1, C2, D2, E2, F#2,
                     G2, A2, B2, C3, D3, E3, F#3, G3],
                    [Terminus.LOW, 0, 1, 2, 3, 4, 5,
                     Terminus.LOW, 0, 1, 2, 3, 4, 5,
                     Terminus.LOW, 0, 1, 2, 3, 4, 5,
                     Terminus.LOW])'''
            )
        )

        self.assertEqual(self.realizePitchOut(
            net.realizeDescending('d6', 5, 'd4', includeFirst=True)),
            '([D4, E4, F#4, G4, A4, B4, C5, D5, E5, F#5, G5, A5, B5, C6, D6], '
            + '[3, 4, 5, Terminus.LOW, 0, 1, 2, 3, 4, 5, Terminus.LOW, 0, 1, 2, 3])'
        )

        self.assertEqual(self.realizePitchOut(net.realizeAscending('c3', 1)),
                         '([C3, D3, E3, F3, G3, A3, B3, C4], '
                         + '[Terminus.LOW, 0, 1, 2, 3, 4, 5, Terminus.HIGH])')

        self.assertEqual(self.realizePitchOut(net.realizeAscending('g#2', 3)),
                         '([G#2, A2, B2, C#3, D#3, E3], [1, 2, 3, 4, 5, Terminus.HIGH])')

        self.assertEqual(self.realizePitchOut(net.realizeAscending('g#2', 3, maxPitch='e4')),
                         '([G#2, A2, B2, C#3, D#3, E3, F#3, G#3, A3, B3, C#4, D#4, E4], '
                         + '[1, 2, 3, 4, 5, Terminus.HIGH, 0, 1, 2, 3, 4, 5, Terminus.HIGH])')
Example #6
0
    def testGetBeams(self):
        ts = TimeSignature('6/8')
        durList = [16, 16, 16, 16, 8, 16, 16, 16, 16, 8]

        notesList = [note.Note(quarterLength=4 / d) for d in durList]
        beams = ts.getBeams(notesList)
        match = '''[<music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/continue>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/continue>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/stop>>,
        <music21.beam.Beams <music21.beam.Beam 1/stop>>,
        <music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/continue>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/continue>>,
        <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/stop>>,
        <music21.beam.Beams <music21.beam.Beam 1/stop>>]'''

        self.assertTrue(common.whitespaceEqual(str(beams), match))
Example #7
0
 def testMicrotoneD(self):
     # the microtonal scale used by padberg
     f = [
         440, 458 + 1 / 3, 476 + 2 / 3, 495, 513 + 1 / 3, 531 + 2 / 3, 550,
         568 + 1 / 3, 586 + 2 / 3, 605, 623 + 1 / 3, 641 + 2 / 3, 660,
         678 + 1 / 3, 696 + 2 / 3, 715, 733 + 1 / 3, 751 + 2 / 3, 770,
         788 + 1 / 3, 806 + 2 / 3, 825, 843 + 1 / 3, 861 + 2 / 3
     ]
     self.assertEqual(len(f), 24)
     pList = []
     for fq in f:
         p = pitch.Pitch()
         p.frequency = fq
         pList.append(str(p))
     self.assertTrue(
         common.whitespaceEqual(
             str(pList),
             '''
             ['A4', 'A~4(+21c)', 'B`4(-11c)', 'B4(+4c)', 'B~4(+17c)', 'C~5(-22c)',
              'C#5(-14c)', 'C#~5(-7c)', 'D5(-2c)', 'D~5(+1c)', 'E-5(+3c)', 'E`5(+3c)',
              'E5(+2c)', 'E~5(-1c)', 'F5(-4c)', 'F~5(-9c)', 'F#5(-16c)', 'F#~5(-23c)',
              'F#~5(+19c)', 'G5(+10c)', 'G~5(-1c)', 'G#5(-12c)', 'G#~5(-24c)', 'G#~5(+14c)']''',
         ), str(pList))
Example #8
0
    def testScaleArbitrary(self):
        sc1 = scale.MajorScale('g')
        self.assertEqual(sorted([str(x) for x in sc1.abstract._net.nodes.keys()]),
                         ['0', '1', '2', '3', '4', '5', 'Terminus.HIGH', 'Terminus.LOW'])
        self.assertEqual(sorted(sc1.abstract._net.edges.keys()),
                         [0, 1, 2, 3, 4, 5, 6])

        nodes = ({'id': Terminus.LOW, 'degree': 1},
                 {'id': 0, 'degree': 2},
                 {'id': Terminus.HIGH, 'degree': 3},
                 )

        edges = ({'interval': 'm2',
                  'connections': (
                      [Terminus.LOW, 0, Direction.BI],
                  )},
                 {'interval': 'M3',
                  'connections': (
                      [0, Terminus.HIGH, Direction.BI],
                  )},
                 )

        net = IntervalNetwork()
        net.fillArbitrary(nodes, edges)
        self.assertTrue(common.whitespaceEqual(str(net.edges),
                                               '''
            OrderedDict([(0, <music21.scale.intervalNetwork.Edge Direction.BI m2
                                [(Terminus.LOW, 0), (0, Terminus.LOW)]>),
                         (1, <music21.scale.intervalNetwork.Edge Direction.BI M3
                                [(0, Terminus.HIGH), (Terminus.HIGH, 0)]>)])'''
                                               ),
                        str(net.edges))

        self.assertEqual(net.degreeMax, 3)
        self.assertEqual(net.degreeMaxUnique, 2)

        self.assertEqual(self.pitchOut(net.realizePitch('c4', 1)), '[C4, D-4, F4]')
Example #9
0
    def testToSettings(self):
        env = Environment(forcePlatform='darwin')
        settingsTree = _environStorage['instance']._toSettings(
            _environStorage['instance']._ref)
        match = self.stringFromTree(settingsTree)
        self.maxDiff = None
        if 'encoding' in match:
            enc = "encoding='utf-8'"
        else:
            enc = ''
        canonic = """<?xml version='1.0' """ + enc + """?>
<settings>
  <preference name="autoDownload" value="ask" />
  <preference name="braillePath" />
  <preference name="debug" value="0" />
  <preference name="directoryScratch" />
  <preference name="graphicsPath" value="/Applications/Preview.app" />
  <preference name="ipythonShowFormat" value="ipython.musicxml.png" />
  <preference name="lilypondBackend" value="ps" />
  <preference name="lilypondFormat" value="pdf" />
  <preference name="lilypondPath" 
      value="/Applications/Lilypond.app/Contents/Resources/bin/lilypond" />
  <preference name="lilypondVersion" />
  <localCorporaSettings />
  <localCorpusSettings />
  <preference name="manualCoreCorpusPath" />
  <preference name="midiPath" value="/Applications/QuickTime Player.app" />
  <preference name="musescoreDirectPNGPath" 
      value="/Applications/MuseScore 2.app/Contents/MacOS/mscore" />
  <preference name="musicxmlPath" value="/Applications/Finale Notepad 2014.app" />
  <preference name="pdfPath" value="/Applications/Preview.app" />
  <preference name="showFormat" value="musicxml" />
  <preference name="vectorPath" value="/Applications/Preview.app" />
  <preference name="warnings" value="1" />
  <preference name="writeFormat" value="musicxml" />
</settings>
"""
        self.assertTrue(common.whitespaceEqual(canonic, match))

        # try adding some local corpus settings
        env['localCorpusSettings'] = ['a', 'b', 'c']
        env['localCorporaSettings']['foo'] = ['bar', 'baz', 'quux']
        settingsTree = _environStorage['instance']._toSettings(
            _environStorage['instance']._ref)
        match = self.stringFromTree(settingsTree)
        if 'encoding' in match:
            enc = "encoding='utf-8'"
        else:
            enc = ''
        canonic = """<?xml version='1.0' """ + enc + """?>
<settings>
  <preference name="autoDownload" value="ask" />
  <preference name="braillePath" />
  <preference name="debug" value="0" />
  <preference name="directoryScratch" />
  <preference name="graphicsPath" value="/Applications/Preview.app" />
  <preference name="ipythonShowFormat" value="ipython.musicxml.png" />
  <preference name="lilypondBackend" value="ps" />
  <preference name="lilypondFormat" value="pdf" />
  <preference name="lilypondPath" 
      value="/Applications/Lilypond.app/Contents/Resources/bin/lilypond" />
  <preference name="lilypondVersion" />
  <localCorporaSettings>
    <localCorpusSettings name="foo">
      <localCorpusPath>bar</localCorpusPath>
      <localCorpusPath>baz</localCorpusPath>
      <localCorpusPath>quux</localCorpusPath>
    </localCorpusSettings>
  </localCorporaSettings>
  <localCorpusSettings>
    <localCorpusPath>a</localCorpusPath>
    <localCorpusPath>b</localCorpusPath>
    <localCorpusPath>c</localCorpusPath>
  </localCorpusSettings>
  <preference name="manualCoreCorpusPath" />
  <preference name="midiPath" value="/Applications/QuickTime Player.app" />
  <preference name="musescoreDirectPNGPath" 
      value="/Applications/MuseScore 2.app/Contents/MacOS/mscore" />
  <preference name="musicxmlPath" value="/Applications/Finale Notepad 2014.app" />
  <preference name="pdfPath" value="/Applications/Preview.app" />
  <preference name="showFormat" value="musicxml" />
  <preference name="vectorPath" value="/Applications/Preview.app" />
  <preference name="warnings" value="1" />
  <preference name="writeFormat" value="musicxml" />
</settings>
"""
        self.assertTrue(common.whitespaceEqual(canonic, match))
Example #10
0
    def testToSettings(self):
        env = Environment(forcePlatform='darwin')
        settingsTree = _environStorage['instance']._toSettings(
            _environStorage['instance']._ref)
        match = self.stringFromTree(settingsTree)
        self.maxDiff = None
        if 'encoding' in match:
            enc = "encoding='utf-8'"
        else:
            enc = ''
        canonic = """<?xml version='1.0' """ + enc + """?>
<settings>
  <preference name="autoDownload" value="ask" />
  <preference name="braillePath" />
  <preference name="debug" value="0" />
  <preference name="directoryScratch" />
  <preference name="graphicsPath" value="/Applications/Preview.app" />
  <preference name="ipythonShowFormat" value="ipython.musicxml.png" />
  <preference name="lilypondBackend" value="ps" />
  <preference name="lilypondFormat" value="pdf" />
  <preference name="lilypondPath" 
      value="/Applications/Lilypond.app/Contents/Resources/bin/lilypond" />
  <preference name="lilypondVersion" />
  <localCorporaSettings />
  <localCorpusSettings />
  <preference name="manualCoreCorpusPath" />
  <preference name="midiPath" value="/Applications/QuickTime Player.app" />
  <preference name="musescoreDirectPNGPath" 
      value="/Applications/MuseScore 2.app/Contents/MacOS/mscore" />
  <preference name="musicxmlPath" value="/Applications/Finale Notepad 2014.app" />
  <preference name="pdfPath" value="/Applications/Preview.app" />
  <preference name="showFormat" value="musicxml" />
  <preference name="vectorPath" value="/Applications/Preview.app" />
  <preference name="warnings" value="1" />
  <preference name="writeFormat" value="musicxml" />
</settings>
"""
        self.assertTrue(common.whitespaceEqual(canonic, match))

        # try adding some local corpus settings
        env['localCorpusSettings'] = ['a', 'b', 'c']
        env['localCorporaSettings']['foo'] = ['bar', 'baz', 'quux']
        settingsTree = _environStorage['instance']._toSettings(
            _environStorage['instance']._ref)
        match = self.stringFromTree(settingsTree)
        if 'encoding' in match:
            enc = "encoding='utf-8'"
        else:
            enc = ''
        canonic = """<?xml version='1.0' """ + enc + """?>
<settings>
  <preference name="autoDownload" value="ask" />
  <preference name="braillePath" />
  <preference name="debug" value="0" />
  <preference name="directoryScratch" />
  <preference name="graphicsPath" value="/Applications/Preview.app" />
  <preference name="ipythonShowFormat" value="ipython.musicxml.png" />
  <preference name="lilypondBackend" value="ps" />
  <preference name="lilypondFormat" value="pdf" />
  <preference name="lilypondPath" 
      value="/Applications/Lilypond.app/Contents/Resources/bin/lilypond" />
  <preference name="lilypondVersion" />
  <localCorporaSettings>
    <localCorpusSettings name="foo">
      <localCorpusPath>bar</localCorpusPath>
      <localCorpusPath>baz</localCorpusPath>
      <localCorpusPath>quux</localCorpusPath>
    </localCorpusSettings>
  </localCorporaSettings>
  <localCorpusSettings>
    <localCorpusPath>a</localCorpusPath>
    <localCorpusPath>b</localCorpusPath>
    <localCorpusPath>c</localCorpusPath>
  </localCorpusSettings>
  <preference name="manualCoreCorpusPath" />
  <preference name="midiPath" value="/Applications/QuickTime Player.app" />
  <preference name="musescoreDirectPNGPath" 
      value="/Applications/MuseScore 2.app/Contents/MacOS/mscore" />
  <preference name="musicxmlPath" value="/Applications/Finale Notepad 2014.app" />
  <preference name="pdfPath" value="/Applications/Preview.app" />
  <preference name="showFormat" value="musicxml" />
  <preference name="vectorPath" value="/Applications/Preview.app" />
  <preference name="warnings" value="1" />
  <preference name="writeFormat" value="musicxml" />
</settings>
"""
        self.assertTrue(common.whitespaceEqual(canonic, match))