music21.noteworthy.translate¶
Module to translate Noteworthy Composer’s NWCTXT format to music21.
NoteworthyTranslator¶
-
class
music21.noteworthy.translate.
NoteworthyTranslator
¶ stores all the data about the current parse context (whether we’re in a slur, tuplet, etc.)
NoteworthyTranslator
methods
-
NoteworthyTranslator.
createBarlines
(attributes)¶ Translates bar lines into music21.
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentPart = stream.Part() >>> nwt.currentMeasure = stream.Measure() >>> nwt.createBarlines({"Style":"MasterRepeatOpen"}) >>> nwt.currentMeasure <music21.stream.Measure 0 offset=0.0> >>> nwt.currentMeasure.leftBarline <music21.bar.Repeat direction=start>
-
NoteworthyTranslator.
createClef
(attributes)¶ Add a new clef to the current measure and return the currentClef.
Clef lines should look like: |Clef|Type:ClefType or |Clef|Type:ClefType|OctaveShift:Octave Down (or Up)
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentMeasure = stream.Measure() >>> nwt.createClef({"Type": "Treble"}) >>> nwt.currentMeasure.show('text') {0.0} <music21.clef.TrebleClef> >>> nwt.currentClef 'TREBLE' >>> nwt.createClef({"Type" : "Bass", "OctaveShift" : "Octave Down"}) >>> nwt.currentMeasure.show('text') {0.0} <music21.clef.TrebleClef> {0.0} <music21.clef.Bass8vbClef>
If no clef can be found then it raises a NoteworthyTranslate exception
>>> nwt.createClef({"Type" : "OBonobo"}) Traceback (most recent call last): NoteworthyTranslateException: Did not find a proper clef in type, OBonobo
-
NoteworthyTranslator.
createDynamicVariance
(attributes)¶ Adding dynamics like “crescendo” to the measure.
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentMeasure = stream.Measure() >>> nwt.createDynamicVariance({"Style" : "Crescendo", "Pos": "-6"}) >>> nwt.currentMeasure.show('text') {0.0} <music21.spanner.Crescendo >
-
NoteworthyTranslator.
createDynamics
(attributes)¶ Adding dynamics like “fff”, “pp”, ... to the measure.
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentMeasure = stream.Measure() >>> nwt.createDynamics({"Style":"fff","Pos":"-8"}) >>> nwt.currentMeasure[0] <music21.dynamics.Dynamic fff >
-
NoteworthyTranslator.
createKey
(attributes)¶ Adds a new key signature to the given measure. Returns the number of sharps (negative for flats)
>>> measureIn = stream.Measure() >>> measureIn.append(note.Rest(quarterLength = 3.0))
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentMeasure = measureIn >>> nwt.createKey({'Signature':'F#,C#,G#,D#'}) >>> nwt.currentKey.sharps 4 >>> measureIn.show('text') {0.0} <music21.note.Rest rest> {3.0} <music21.key.KeySignature of 4 sharps>
-
NoteworthyTranslator.
createLyrics
(attributes)¶ Get a list of lyrics from a Lyric line
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> Lyricslist = nwt.createLyrics({'Text':'"Hello world"'}) >>> Lyricslist[0] 'Hello'
-
NoteworthyTranslator.
createOtherRepetitions
(attributes)¶ Repetitions like “Coda”, “Segno” and some others.
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentMeasure = stream.Measure() >>> nwt.createOtherRepetitions({"Style" : "ToCoda", "Pos": "8", ... "Wide":"Y","Placement":"BestFitForward"}) >>> "Coda" in nwt.currentMeasure[0].classes True
-
NoteworthyTranslator.
createPart
()¶ Add a new part to the score.
-
NoteworthyTranslator.
createTimeSignature
(attributes)¶ Adding a time signature in the score.
>>> measure = stream.Measure() >>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentMeasure = measure >>> nwt.createTimeSignature({"Signature":"4/4"}) >>> measure[0] <music21.meter.TimeSignature 4/4>
-
NoteworthyTranslator.
getMultiplePitchesFromPositionInfo
(posInfo)¶ returns a list of pitch objects given the Pos:... info for a chord.
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentClef = 'BASS' >>> pList = nwt.getMultiplePitchesFromPositionInfo('1,b3,5^') >>> pList [<music21.pitch.Pitch E3>, <music21.pitch.Pitch G-3>, <music21.pitch.Pitch B3>]
-
NoteworthyTranslator.
getOnePitchFromPosition
(pos)¶ get one pitch from a position...
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentClef = 'BASS' >>> p = nwt.getOnePitchFromPosition('b3') >>> p <music21.pitch.Pitch G-3> >>> p.ps 54.0
-
NoteworthyTranslator.
getPitchFromPositionInfo
(posInfo)¶ returns a pitch object given the Pos: info
removes ties and alteration signs. Otherwise is same as getOnePitchFromPosition()
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentClef = 'BASS' >>> p = nwt.getPitchFromPositionInfo('b3^') # removes ties >>> p <music21.pitch.Pitch G-3>
-
NoteworthyTranslator.
getStepAndOctaveFromPosition
(positionNote)¶ Given an int representing the position on the staff for the current clef, returns a string for the step and an int for the octave
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentClef = 'BASS' >>> (step, octave) = nwt.getStepAndOctaveFromPosition(3) >>> (step, octave) ('G', 3)
-
NoteworthyTranslator.
parseFile
(filePath)¶
-
NoteworthyTranslator.
parseList
(dataList)¶ Parses a list where each element is a line from a nwctxt file.
Returns a
Score
object>>> data = [] >>> data.append("!NoteWorthyComposer(2.0)\n") >>> data.append("|AddStaff|\n") >>> data.append("|Clef|Type:Bass\n") >>> data.append("|TimeSig|Signature:4/4\n") >>> data.append("|Note|Dur:Whole|Pos:1\n")
>>> >>> nwt = noteworthy.translate.NoteworthyTranslator() >>> s = nwt.parseList(data) >>> s.show('text') {0.0} <music21.stream.Part ...> {0.0} <music21.stream.Measure 0 offset=0.0> {0.0} <music21.clef.BassClef> {0.0} <music21.meter.TimeSignature 4/4> {0.0} <music21.note.Note E>
-
NoteworthyTranslator.
parseString
(data)¶
-
NoteworthyTranslator.
setDurationForObject
(generalNote, durationInfo)¶ generalNote could be a Note, Chord, or Rest
DurationInfo is a string like:
Whole,Dotted,Slur
-
NoteworthyTranslator.
setTieFromPitchInfo
(noteOrChord, pitchInfo)¶ sets the tie status for a noteOrChord from the pitchInfo
-
NoteworthyTranslator.
translateChord
(attributes)¶ Translation of a music21 chord from a NWC one.
>>> measure = stream.Measure()
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentMeasure = measure >>> nwt.translateChord({'Dur': 'Half', 'Pos': '1,3,#5'}) >>> measure[0] <music21.chord.Chord C5 E5 G#5>
Chords also inherit accidentals: >>> nwt.translateChord({‘Dur’: ‘Half’, ‘Pos’: ‘1,3,5’}) >>> measure[1] <music21.chord.Chord C5 E5 G#5>
-
NoteworthyTranslator.
translateNote
(attributes)¶ Translation of a music21 note from a NWC note.
>>> measure = stream.Measure() >>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentMeasure = measure >>> nwt.translateNote({'Dur': 'Half', 'Pos': '#-3'}) >>> measure[0] <music21.note.Note F#>
Note that the next note in the measure with the same position should inherit the last position’s accidental:
>>> nwt.translateNote({'Dur': 'Half', 'Pos': '-3'}) >>> measure[1] <music21.note.Note F#>
-
NoteworthyTranslator.
translateRest
(attributes)¶ Translation of a music21 rest. Adds the rest to the given measure.
>>> measureIn = stream.Measure() >>> measureIn.append(note.Note("C#4", type='half'))
>>> nwt = noteworthy.translate.NoteworthyTranslator() >>> nwt.currentMeasure = measureIn >>> nwt.translateRest({'Dur': '8th,Dotted'}) >>> nwt.translateRest({'Dur': '4th'}) >>> measureIn.show('text') {0.0} <music21.note.Note C#> {2.0} <music21.note.Rest rest> {2.75} <music21.note.Rest rest>