def __init__(self, *args, **keywords): base.Music21Object.__init__(self) # a list of Contributor objects # there can be more than one composer, or any other combination self.contributors = [] # use addContributor to add. self._date = None # store one or more URLs from which this work came; this could # be local file paths or otherwise self._urls = [] # TODO: need a specific object for copyright and imprint self._imprint = None self.copyright = None # a dictionary of Text elements, where keys are work id strings # all are loaded with None by default self._workIds = OrderedDict() for abbreviation, workId in self.workIdAbbreviationDict.items(): #abbreviation = workIdToAbbreviation(id) if workId in keywords: self._workIds[workId] = Text(keywords[workId]) elif abbreviation in keywords: self._workIds[workId] = Text(keywords[abbreviation]) else: self._workIds[workId] = None # search for any keywords that match attributes # these are for direct Contributor access, must have defined # properties for attr in ['composer', 'date', 'title']: if attr in keywords: setattr(self, attr, keywords[attr])
def setWorkId(self, idStr, value): r''' Directly set a work id, given either as a full string name or as a three character abbreviation. The following work id abbreviations and their full id string are given as follows. In many cases the Metadata object support properties for convenient access to these work ids. Id abbreviations and strings: otl / title, otp / popularTitle, ota / alternativeTitle, opr / parentTitle, oac / actNumber, osc / sceneNumber, omv / movementNumber, omd / movementName, ops / opusNumber, onm / number, ovm / volume, ode / dedication, oco / commission, gtl / groupTitle, gaw / associatedWork, gco / collectionDesignation, txo / textOriginalLanguage, txl / textLanguage, ocy / countryOfComposition, opc / localeOfComposition. >>> md = metadata.Metadata(title='Quartet') >>> md.title 'Quartet' >>> md.setWorkId('otl', 'Trio') >>> md.title 'Trio' >>> md.setWorkId('sdf', None) Traceback (most recent call last): music21.exceptions21.MetadataException: no work id available with id: sdf ''' idStr = idStr.lower() match = False for abbreviation, workId in self.workIdAbbreviationDict.items(): # for id in WORK_IDS: # abbreviation = workIdToAbbreviation(id) if workId.lower() == idStr: self._workIds[workId] = Text(value) match = True break elif abbreviation == idStr: self._workIds[workId] = Text(value) match = True break if not match: raise exceptions21.MetadataException( 'no work id available with id: %s' % idStr)
def opusNumber(self, value): self._workIds['opusNumber'] = Text(value)
def number(self, value): self._workIds['number'] = Text(value)
def movementNumber(self, value): self._workIds['movementNumber'] = Text(value)
def movementName(self, value): self._workIds['movementName'] = Text(value)
def localeOfComposition(self, value): self._workIds['localeOfComposition'] = Text(value)
def alternativeTitle(self, value): self._workIds['alternativeTitle'] = Text(value)
def title(self, value): self._workIds['title'] = Text(value)