Skip to content

Commit

Permalink
search.serial promoted from alpha -- LINT FREE!
Browse files Browse the repository at this point in the history
  • Loading branch information
mscuthbert committed Aug 21, 2016
1 parent 8723e27 commit 8511c03
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 904 deletions.
2 changes: 0 additions & 2 deletions music21/alpha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
__all__ = [ #dirs
'analysis',
'counterpoint',
'search',
'theoryAnalysis',
'trecento',
'webapps',
Expand All @@ -45,7 +44,6 @@

from music21.alpha import analysis
from music21.alpha import counterpoint
from music21.alpha import search
from music21.alpha import theoryAnalysis
from music21.alpha import trecento
from music21.alpha import webapps
Expand Down
137 changes: 70 additions & 67 deletions music21/alpha/medren.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,6 @@ def getStems(self):
return self.stems

def setStem(self, direction):
#NOTE: This method makes it possible to have a semibrevis with a sidestem and a
# downstem. This doesn't mean anything so far as I can tell.
'''
Takes one argument: direction.
Expand Down Expand Up @@ -902,36 +900,40 @@ def setStem(self, direction):
>>> r_3.getStems()
['up']
'''
#NOTE: This method makes it possible to have a semibrevis with a sidestem and a
# downstem. This doesn't mean anything so far as I can tell.

if direction in [None, 'none', 'None']:
if self.mensuralType in ['minima', 'semiminima']:
self.stems = ['up']
else:
self.stems = []
else:
if self.mensuralType in ['brevis','longa', 'maxima']:
raise MedRenException('A note of type %s cannot be equipped with a stem' %
self.mensuralType)
return

if self.mensuralType in ['brevis','longa', 'maxima']:
raise MedRenException('A note of type %s cannot be equipped with a stem' %
self.mensuralType)


if direction in ['down', 'Down']:
direction = 'down'
if len(self.stems) > 1:
raise MedRenException('This note already has the maximum number of stems')
else:
if direction in ['down', 'Down']:
direction = 'down'
if len(self.stems) > 1:
raise MedRenException('This note already has the maximum number of stems')
else:
self.stems.append(direction)

elif direction in ['side', 'Side']:
direction = 'side'
if ((self.mensuralType not in ['semibrevis', 'minima']) or
self.getNumDots() > 0):
raise MedRenException('This note may not have a stem of direction %s' %
direction)
elif len(self.stems) > 1:
raise MedRenException('This note already has the maximum number of stems')
else:
self.stems.append(direction)
else:
raise MedRenException('%s not recognized as a valid stem direction' % direction)
self.stems.append(direction)

elif direction in ['side', 'Side']:
direction = 'side'
if ((self.mensuralType not in ['semibrevis', 'minima']) or
self.getNumDots() > 0):
raise MedRenException('This note may not have a stem of direction %s' %
direction)
elif len(self.stems) > 1:
raise MedRenException('This note already has the maximum number of stems')
else:
self.stems.append(direction)
else:
raise MedRenException('%s not recognized as a valid stem direction' % direction)

def getFlags(self):
'''
Expand Down Expand Up @@ -1510,55 +1512,56 @@ def setStem(self, index, direction, orientation):
direction = None
if orientation == 'None' or direction == 'none':
index = None
if index < self._ligatureLength():
if self.isMaxima(index):
raise MedRenException('cannot place stem at index %d' % index)
if index >= self._ligatureLength():
raise MedRenException('no note exists at index %d' % index)

if self.isMaxima(index):
raise MedRenException('cannot place stem at index %d' % index)

if orientation is None and direction is None:
self.stems[index] = (direction, orientation)
elif orientation in ['left', 'right']:
if index == 0:
prevStem = (None,None)
nextStem = self.getStem(1)
elif index == self._ligatureLength() - 1:
prevStem = self.getStem(self._ligatureLength() - 2)
nextStem = (None,None)
else:
if orientation is None and direction is None:
self.stems[index] = (direction, orientation)
elif orientation in ['left', 'right']:
if index == 0:
prevStem = (None,None)
nextStem = self.getStem(1)
elif index == self._ligatureLength() - 1:
prevStem = self.getStem(self._ligatureLength()-2)
nextStem = (None,None)
prevStem = self.getStem(index - 1)
nextStem = self.getStem(index + 1)

if ((orientation == 'left' and prevStem[1] != 'right')
or (orientation == 'right' and nextStem[1] != 'left')):
if direction == 'down':
if prevStem[0] != 'up':
self.stems[index] = (direction, orientation)
else:
prevStem = self.getStem(index-1)
nextStem = self.getStem(index+1)
if ((orientation == 'left' and prevStem[1] != 'right') or
(orientation == 'right' and nextStem[1] != 'left')):
if direction == 'down':
if prevStem[0] != 'up':
self.stems[index] = (direction, orientation)
else:
raise MedRenException(
'a stem with direction "%s" not permitted at index %d' %
(direction, index))
elif direction == 'up':
if ((index < self._ligatureLength()-1)
and (prevStem[0] != 'up')
and (nextStem[0] is None)
and not self.isMaxima(index+1)):
self.stems[index] = (direction, orientation)
else:
raise MedRenException(
'a stem with direction "%s" not permitted at index %d' %
(direction, index))
else:
raise MedRenException(
'direction "%s" and orientation "%s" not supported for ligatures' %
(direction, orientation))
raise MedRenException(
'a stem with direction "%s" not permitted at index %d' %
(direction, index))
elif direction == 'up':
if ((index < self._ligatureLength() - 1)
and (prevStem[0] != 'up')
and (nextStem[0] is None)
and not self.isMaxima(index + 1)):
self.stems[index] = (direction, orientation)
else:
raise MedRenException(
'a stem with orientation "%s" not permitted at index %d' %
(orientation,index))
'a stem with direction "%s" not permitted at index %d' %
(direction, index))
else:
raise MedRenException(
'direction "%s" and orientation "%s" not supported for ligatures' %
(direction,orientation))
'direction "%s" and orientation "%s" not supported for ligatures' %
(direction, orientation))
else:
raise MedRenException(
'a stem with orientation "%s" not permitted at index %d' %
(orientation,index))
else:
raise MedRenException('no note exists at index %d' % index)
raise MedRenException(
'direction "%s" and orientation "%s" not supported for ligatures' %
(direction,orientation))
self._notes = []

def isReversed(self, index):
Expand Down
5 changes: 0 additions & 5 deletions music21/alpha/search/__init__.py

This file was deleted.

3 changes: 1 addition & 2 deletions music21/alpha/theoryAnalysis/theoryResult.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# License: LGPL or BSD, see license.txt
#-------------------------------------------------------------------------------

import music21
import unittest

class TheoryResult(object):
Expand Down Expand Up @@ -296,7 +295,7 @@ def demo(self):


if __name__ == "__main__":

import music21
music21.mainTest(Test)

#te = TestExternal()
Expand Down
5 changes: 3 additions & 2 deletions music21/alpha/theoryAnalysis/wwnortonMGTA.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

_DOC_IGNORE_MODULE_OR_PACKAGE = True

import copy
import unittest

import music21

from music21 import converter
Expand All @@ -19,8 +22,6 @@
from music21 import note
from music21.alpha.theoryAnalysis import theoryAnalyzer

import unittest
import copy

class wwnortonExercise(object):
'''
Expand Down
3 changes: 1 addition & 2 deletions music21/alpha/trecento/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
__all__ = ['cadencebook', 'capua', 'findTrecentoFragments', 'notation', 'tonality']
__all__ = ['cadencebook', 'findTrecentoFragments', 'notation', 'tonality']

# this is necessary to get these names available with a
# from music21 import * import statement
import sys

from music21.alpha.trecento import cadencebook
from music21.alpha.trecento import capua
from music21.alpha.trecento import findTrecentoFragments
from music21.alpha.trecento import notation
from music21.alpha.trecento import tonality
Expand Down
16 changes: 7 additions & 9 deletions music21/alpha/trecento/cadencebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,15 @@ class TrecentoCadenceWork(object):
beginSnippetPositions = [8]
endSnippetPositions = []

def __init__(self, rowvalues = None, rowDescriptions = None):
if rowvalues == None:
def __init__(self, rowvalues=None, rowDescriptions=None):
if rowvalues is None:
rowvalues = ["", "", "", "", "", "", "", "", "", "", "", "", ""]
if rowDescriptions == None:
if rowDescriptions is None:
rowDescriptions = ["Catalog Number", "Title", "Composer", "EncodedVoices",
"PMFC/CMM Vol.", "PMFC Page Start", "PMFC Page End",
"Time Signature Beginning", "Incipit C", "Incipit T",
"Incipit Ct", "Incipit Type", "Notes"]
self.rowvalues = rowvalues
self.rowvalues = rowvalues
self.rowDescriptions = rowDescriptions
self.fischerNum = rowvalues[0]
self.title = rowvalues[1]
Expand Down Expand Up @@ -373,15 +373,13 @@ def asOpus(self):
'''
returns all snippets as a :class:`~music21.stream.Opus` object
>>> deduto = alpha.trecento.cadencebook.BallataSheet().workByTitle('deduto')
>>> deduto.title
'Deduto sey a quel'
>>> dedutoScore = deduto.asOpus()
>>> dedutoScore
<music21.stream.Opus ...>
>>> #_DOCS_SHOW dedutoScore.show('lily.png')
'''
o = stream.Opus()
md = metadata.Metadata()
Expand All @@ -393,9 +391,9 @@ def asOpus(self):
for thisSnippet in bs:
if thisSnippet is None:
continue
if (thisSnippet.tenor is None and
thisSnippet.cantus is None and
thisSnippet.contratenor is None):
if (thisSnippet.tenor is None
and thisSnippet.cantus is None
and thisSnippet.contratenor is None):
continue
s = stream.Score()
for dummy in range(self.totalVoices):
Expand Down
2 changes: 1 addition & 1 deletion music21/demos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
]

from music21.demos import gatherAccidentals

from music21.demos import trecento

#------------------------------------------------------------------------------
# eof
Expand Down
3 changes: 3 additions & 0 deletions music21/demos/trecento/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# -*- coding: utf-8 -*-
__all__ = ['capua']

from music21.demos.trecento import capua
22 changes: 10 additions & 12 deletions music21/alpha/trecento/capua.py → music21/demos/trecento/capua.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Name: alpha.trecento.capua.py
# Name: demos.trecento.capua.py
# Purpose: The regola of Nicolaus de Capua for Musica Ficta
#
# Authors: Michael Scott Cuthbert
Expand Down Expand Up @@ -63,10 +63,10 @@ def applyCapuaToCadencebookWork(thisWork):
>>> b = alpha.trecento.cadencebook.BallataSheet().makeWork(331) # Francesco, Non Creder Donna
>>> bOrig = copy.deepcopy(b)
>>> alpha.trecento.capua.applyCapuaToCadencebookWork(b)
>>> demos.trecento.capua.applyCapuaToCadencebookWork(b)
>>> bFN = b.asScore().flat.notes
>>> for n in bFN:
... alpha.trecento.capua.capuaFictaToAccidental(n)
... demos.trecento.capua.capuaFictaToAccidental(n)
>>> bOrigFN = bOrig.asScore().flat.notes
>>> for i in range(len(bFN)):
... if bFN[i].pitch != bOrigFN[i].pitch:
Expand Down Expand Up @@ -119,16 +119,14 @@ def capuaRuleOne(srcStream):
n2 = ssn[i+1]
n3 = ssn[i+2]

if n1.isRest or \
n2.isRest or \
n3.isRest:
if (n1.isRest or n2.isRest or n3.isRest):
continue

i1 = interval.notesToInterval(n1,n2)
i2 = interval.notesToInterval(n2,n3)

if n1.pitch.accidental is not None or \
n3.pitch.accidental is not None:
if (n1.pitch.accidental is not None
or n3.pitch.accidental is not None):
continue

### never seems to improve things...
Expand Down Expand Up @@ -570,8 +568,8 @@ def compareThreeFictas(srcStream1, srcStream2):
>>> #_DOCS_SHOW b.show()
>>> b0n = b.parts[0].flat.notesAndRests.stream()
>>> b1n = b.parts[1].flat.notesAndRests.stream()
>>> alpha.trecento.capua.applyCapuaToStream(b0n)
>>> alpha.trecento.capua.compareThreeFictas(b0n, b1n)
>>> demos.trecento.capua.applyCapuaToStream(b0n)
>>> demos.trecento.capua.compareThreeFictas(b0n, b1n)
>>> for n in b0n:
... pass
Expand Down Expand Up @@ -820,7 +818,7 @@ def findCorrections(correctionType="Maj3", startPiece=2, endPiece=459):
# 'pmfcAlt': 4, 'pmfcNotCapua': 1, 'totalNotes': 82}
# >>> foundPieceOpus.show('lily.pdf')
# >>> #_DOCS_SHOW (totalDict, foundPieceOpus) = alpha.trecento.capua.correctedMin6()
# >>> #_DOCS_SHOW (totalDict, foundPieceOpus) = demos.trecento.capua.correctedMin6()
# >>> totalDict = {'potentialChange': 82, 'capuaAlt': 30, 'pmfcAndCapua': 3, #_DOCS_HIDE
# ... 'capuaNotPmfc': 27, 'pmfcAlt': 4, 'pmfcNotCapua': 1, 'totalNotes': 82} #_DOCS_HIDE
# >>> pp(totalDict)
Expand Down Expand Up @@ -933,7 +931,7 @@ def improvedHarmony(startPiece=2, endPiece=459):
Returns a dict showing the results
>>> #_DOCS_SHOW alpha.trecento.capua.improvedHarmony()
>>> #_DOCS_SHOW demos.trecento.capua.improvedHarmony()
>>> print("{'imperfCapua': 22, 'imperfIgnored': 155, " + #_DOCS_HIDE
... "'perfCapua': 194, 'perfIgnored': 4057}") #_DOCS_HIDE
{'imperfCapua': 22, 'imperfIgnored': 155, 'perfCapua': 194, 'perfIgnored': 4057}
Expand Down
4 changes: 2 additions & 2 deletions music21/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,8 +998,8 @@ def tonalCertainty(self,
music21.key.KeySignatureException: cannot process ambiguity without a
list of .alternateInterpretations
>>> k2.alternateInterpretations is None
True
>>> k2.alternateInterpretations
[]
'''
if method == 'correlationCoefficient':
return self._tonalCertainityCorrelationCoefficient(
Expand Down
1 change: 1 addition & 0 deletions music21/lily/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,7 @@ def testStaffLines(self):

#-------------------------------------------------------------------------------
if __name__ == "__main__":
# pylint: disable=ungrouped-imports
import music21
music21.mainTest(Test) #, TestExternal)
#music21.mainTest(TestExternal, 'noDocTest')
Expand Down
Loading

0 comments on commit 8511c03

Please sign in to comment.