MCPcopy Create free account
hub / github.com/bspaans/python-mingus / from_NoteContainer

Function from_NoteContainer

mingus/extra/lilypond.py:76–120  ·  view source on GitHub ↗

Get a NoteContainer object and return the LilyPond equivalent in a string. The second argument determining the duration of the NoteContainer is optional. When the standalone argument is True the result of this function can be used directly by functions like to_png. It is mostly

(nc, duration=None, standalone=True)

Source from the content-addressed store, hash-verified

74
75
76def from_NoteContainer(nc, duration=None, standalone=True):
77 """Get a NoteContainer object and return the LilyPond equivalent in a
78 string.
79
80 The second argument determining the duration of the NoteContainer is
81 optional. When the standalone argument is True the result of this
82 function can be used directly by functions like to_png. It is mostly
83 here to be used by from_Bar.
84 """
85 # Throw exception
86 if nc is not None and not hasattr(nc, "notes"):
87 return False
88
89 # Return rests for None or empty lists
90 if nc is None or len(nc.notes) == 0:
91 result = "r"
92 elif len(nc.notes) == 1:
93
94 # Return a single note if the list contains only one note
95 result = from_Note(nc.notes[0], standalone=False)
96 else:
97 # Return the notes grouped in '<' and '>'
98 result = "<"
99 for notes in nc.notes:
100 result += from_Note(notes, standalone=False) + " "
101 result = result[:-1] + ">"
102
103 # Add the duration
104 if duration != None:
105 parsed_value = value.determine(duration)
106
107 # Special case: check for longa and breve in the duration (issue #37)
108 dur = parsed_value[0]
109 if dur == value.longa:
110 result += "\\longa"
111 elif dur == value.breve:
112 result += "\\breve"
113 else:
114 result += str(int(parsed_value[0]))
115 for i in range(parsed_value[1]):
116 result += "."
117 if not standalone:
118 return result
119 else:
120 return "{ %s }" % result
121
122
123def from_Bar(bar, showkey=True, showtime=True):

Callers 1

from_BarFunction · 0.70

Calls 2

determineMethod · 0.80
from_NoteFunction · 0.70

Tested by

no test coverage detected